以下是该规范的基本思想:
before :each do
Timecop.freeze(Time.local(2012, 07, 01, 12, 0, 0)) #frozen at July 1st, 2012 at noon
#create record code
end
it 'shows how long ago the message was recieved' do
Timecop.travel(Time.local(2012, 07, 02, 12, 0, 0)) #move to July 2nd
page.should have_content "1 day ago"
end
after :each do
Timecop.return #release freeze
end它会出现以下错误:
expected there to be content "1 day ago" in "less than a minute ago"我展示的是24小时完全不同的<%= "#{time_ago_in_words(m.created_at)} ago" %>。我遗漏了什么?
发布于 2012-07-06 02:05:49
问题是误解了旅行方法与冻结方法的目的。
冻结在选定的时刻停止时间,旅行将时间设置为选定的时刻,但它从那里自由移动。
我在示例中用Freeze替换了Travel,从而解决了这个问题。
https://stackoverflow.com/questions/11252448
复制相似问题