Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara::FrozenInTime error in integration specs using Rspec + Timecop + Capybara + Capybara Webkit

I'm seeing an error in some integration specs, using rspec, capybara, capybara-webkit and timecop.

Capybara::FrozenInTime:
   time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead

The only gem that I know that freezes time is Timecop, but I'm not using it in the test case that fails.

Since the error occurs only sometimes I can't even know if its gone or not after changing something.

like image 815
hsgubert Avatar asked Aug 21 '12 19:08

hsgubert


2 Answers

The end of the error message holds the solution:

consider using time travelling instead

Just change Timecop.freeze to Timecop.travel. Timecop.freeze breaks Capybara's auto-wait feature.

In addition, I would call Timecop.return in an after block, as it will be associated with the most recent travel block:

after :each do
  Timecop.return
end
like image 149
Matt Dressel Avatar answered Oct 16 '22 20:10

Matt Dressel


The solution I found was to add

before :each do
  Timecop.return
end

in spec_helper.rb.

This way we garantee that the time is not frozen before each test, although the only ones that have this problem are the ones executed in a webdriver different from rack-test. In my case capybara-webkit.

like image 21
hsgubert Avatar answered Oct 16 '22 20:10

hsgubert