title: Rspec expect receive(...).with(time_range)
body: <p>According to the <a href="https://relishapp.com/rspec/rspec-mocks/v/3-5/docs/setting-constraints/matching-arguments" rel="nofollow noreferrer">rspec expect message docs</a>, when we use code like:</p>
  
  <pre><code>expect(double).to receive(:message).with(argument)
  </code></pre>
  
  <p>and <code>argument</code> responds to <code>#===</code>, Rspec will call <code>argument.===</code> on whatever is actually passed in.  But what should I do if I want to check that a range of times is actually passed in?  </p>
  
  <p>For example, I wanted to test that this method sends the right message with the correct arguments (it's simplified):  </p>
  
  <pre><code>def in_date_range(range)
    activities.by_created_at(range)
  end
  </code></pre>
  
  <p>And a test like: </p>
  
  <pre><code>it 'passes correct arguments' do
    range = Time.new(0)..(Time.new(0) + 1.hour)
  
    expect(activities).to receive(:by_created_at).with(range)
  
    in_date_range(range)
  end
  </code></pre>
  
  <p>This fails with <code>TypeError: can't iterate from Time</code></p>
  
  <p>I am suspecting it's because which rspec tries to call <code>#===</code> on my time range and runs into trouble.  </p>
  
  <p>Is there a way to check that my range of times is actually the range I pass in? </p>
  
  <p>I'm not actually looking for the times to overlap, but rather that the ranges are the same: That have the same start and end points.  </p>
  
  <p>I suppose one way we can do this is to write a custom matcher, but it seems an unusual route. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Another possible solution is to split the method into two pieces:</p>
  
  <pre><code>def compute_range(time_in)
    (computations)
    time1..time2
  end
  
  def in_date_range(time_in)
    range = compute_range(time_in)
    activities.by_created_at(range)
  end
  </code></pre>
  
  <p>Then I can test compute method that it returns the proper range, and the for the larger method I can test that passes in the correct input, and takes the output of the smaller method  it takes the result from the first and passes into the other method, sidestepping the confusion of checking ranges in message.</p>
  
  <p>This doesn't fully answer the question - how do you check 'receive a specific range' with the rspec receive(:message), but is enough for me right now.  </p>