What is the best way to write unit test for code which gets current time? For example some object might be created only at business days, other objects take into account current time when checking permissions to execute some actions, etc.
I guess that I should mock up the Date.today and and Time.now. Is this right approach?
Update: Both solutions (a) Time.is and (b) Time.stubs(:now).returns(t) work. (a) is very nice approach but (b) solution will be more consistent with other test code.
At this question an author asks for a general solution. For Ruby, in my option two above solutions are simpler and therefore better than extracting code which gets current date / time.
BTW I recommend to use Chronic to get required time, e.g.
require 'Chronic'
mon = Chronic.parse("next week monday")
Time.stubs(:now).returns(mon)