On my rspec I call the rails helper method freeze_time
before do
freeze_time
end
Do I need to run something to unfreeze Time after the specs
after do
#unfreeze time
end
On my rspec I call the rails helper method freeze_time
before do
freeze_time
end
Do I need to run something to unfreeze Time after the specs
after do
#unfreeze time
end
yes, you have to. Normally I use this with a block so that I don't impact other test example in case i forgot the unfreeze. This is quite common when the spec file is kinda big.
it 'testing freeze time' do
freeze_time do
# do some stuff
end
# time is no longer freeze from now on
end
You need to use travel_back to go back to original time like this.
after do
travel_back
end
Here is the documentation of travel_back.
Actually @lacostenycoder freeze_time calls travel_to, with Time.now, so that's not quite right.
If you don't want to deal with travelling back, you can use freeze_time or travel_to with a block though like:
freeze_time do
example.run
end