这是规范的基本思想:
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 小时。我错过了什么?