I know that I can stub out a method on
allow(Date).to receive(:today).and_return Date.new(2015,11,10)
So now if within my spec the code calls
I can be assured that it will return a Date object with the value of 11/10/2015.
I have a scope that utilizes
. The user specifies the number
of years ago for the scope: Ex:
I am trying to test this scope. In order to do so I need to control the
is referencing. For instance, I would always want the Date to be 1/1/2010. This way I will know that
will return 1/1/2005, and 2.years.ago would return 1/1/2008.
The issue is that I do not know what to stub out. I do not know how to keep the Date consistent which
Hopefully this makes sense. I just need to control the Date that
uses. How can I stub that out?
I looked a bit at ActiveSupport::Duration
, but I'm not sure if that is the right place to look.