最好的设置方法是什么Time.now
为了在单元测试中测试时间敏感的方法?
我真的很喜欢Timecop https://github.com/travisjeffery/timecop图书馆。您可以以块形式进行时间扭曲(就像时间扭曲一样):
Timecop.travel(6.days.ago) do
@model = TimeSensitiveMode.new
end
assert @model.times_up!
(是的,你可以嵌套块形式的时间旅行。)
您还可以进行声明式时间旅行:
class MyTest < Test::Unit::TestCase
def setup
Timecop.travel(...)
end
def teardown
Timecop.return
end
end
我有一些cucumber http://wiki.github.com/aslakhellesoy/cucumber时间警察的帮手here http://gist.github.com/154616。他们让你做这样的事情:
Given it is currently January 24, 2008
And I go to the new post page
And I fill in "title" with "An old post"
And I fill in "body" with "..."
And I press "Submit"
And we jump in our Delorean and return to the present
When I go to the home page
I should not see "An old post"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)