Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # delorean.rb
- require File.dirname(__FILE__) + '/../spec_helper'
- require RAILS_ROOT + "/lib/current_time"
- describe CurrentTime do
- describe "with_current_time" do
- it "should travel through time" do
- two_weeks_ago = 2.weeks.ago
- with_current_time(two_weeks_ago) do
- Time.now.should be_close(two_weeks_ago, 1.second)
- Date.today.should == two_weeks_ago.to_date
- end
- end
- it "should return to the future" do
- today = Date.today
- with_current_time(2.weeks.ago) {}
- Date.today.should == today
- end
- it "should travel through time several times" do
- expected = (1.year - 2.weeks).ago.to_date
- with_current_time(1.year.ago) do
- with_current_time(2.weeks.from_now) do
- Date.today.should == expected
- end
- end
- end
- it "should still return to the future" do
- today = Date.today
- with_current_time(2.weeks.ago) do
- with_current_time(1.year.from_now) {}
- end
- Date.today.should == today
- end
- end
- end
Add Comment
Please, Sign In to add comment