0

这是规范的基本思想:

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"

我正在展示<%= "#{time_ago_in_words(m.created_at)} ago" %>我希望完全不同的 24 小时。我错过了什么?

4

1 回答 1

0

问题是误解了旅行方法与冻结方法的目的。

冻结在选定的时刻停止时间,旅行将时间设置到选定的时刻,但它从那里自由移动。

我通过在示例中将 Travel 替换为 Freeze 解决了这个问题。

于 2012-07-05T18:05:49.253 回答