title: How to stub out Date that is implicitly referenced by years.ago in RSpec?
body: <p>I know that I can stub out a method on <code>Date</code> like so:</p>
  
  <pre><code>allow(Date).to receive(:today).and_return Date.new(2015,11,10)
  </code></pre>
  
  <p>So now if within my spec the code calls <code>Date.today</code> I can be assured that it will return a Date object with the value of 11/10/2015.</p>
  
  <p>I have a scope that utilizes <code>years.ago.to_date</code>.  The user specifies the <em>number</em> of years ago for the scope:  Ex: <code>5.years.ago</code>, <code>2.years.ago</code>.  </p>
  
  <p>I am trying to test this scope.  In order to do so I need to control the <code>Date</code> that <code>years.ago</code> is referencing.  For instance, I would always want the Date to be 1/1/2010.  This way I will know that <code>5.years.ago</code> will return 1/1/2005, and 2.years.ago would return 1/1/2008.</p>
  
  <p>The issue is that I do not know what to stub out.  I do not know how to keep the Date consistent which <code>years.ago</code> uses.  </p>
  
  <p>Hopefully this makes sense.  I just need to control the Date that <code>years.ago</code> uses.  How can I stub that out?</p>
  
  <p>I looked a bit at <a href="http://api.rubyonrails.org/classes/ActiveSupport/Duration.html#method-i-ago" rel="nofollow">ActiveSupport::Duration</a>, but I'm not sure if that is the right place to look. </p>