Created
April 26, 2014 15:16
-
-
Save leemour/11322648 to your computer and use it in GitHub Desktop.
RSpec time stubbing without Timecop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Timecop is fun, but you don't need a whole gem for that. Just use | |
#Time.stub(:now), e.g. | |
describe "time" do | |
before do | |
@fake_time = Time.now | |
Time.stub(:now) { @fake_time } | |
end | |
it "is equal" do | |
Time.now.should == Time.now # now it passes | |
end | |
it "is close" do | |
Time.now.should be_within(0.1).of(Time.now) | |
end | |
end | |
#It's easy to move @fake_time around in the middle of a spec, too, to | |
#simulate time passing or to zap over to e.g. the moment when daylight | |
#savings happens. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment