Displaying 1 result from an estimated 1 matches for "original_today".
2008 Nov 19
3
Mock today
...c date for the purpose of testing. In other words, I want
to do something like this:
mock_today(Date.new(2008, 2, 1)) do
... test code...
end
My implementation for mock_today is:
def mock_today(date)
$_mock_test_date = date
Date.class_eval do
class <<self
alias original_today today
end
def self.today
$_mock_test_date
end
end
yield
Date.class_eval do
class <<self
alias today original_today
end
end
end
So my questions are:
1) Is it a good idea to mock Date.today?
2) Can my implementation of mock...