Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spork Capybara, config.cache_classes conflict

I'm trying to setup Spork and Capybara with TestUnit, and am running into a test.rb config problem.

The issue is that Spork requires that config.cache_classes be set to false, so that changes in the model can be reflected when running tests without having to reset Spork all the time.

Capybara, on the other hand, seems to require that config.cache_classes be set to true, otherwise the integration tests just don't seem to work.

I'm just looking for any possible solution / explanation for this. Is this something that only exists within TestUnit, or is this perhaps a bug and I should report it as such? Any help would be greatly appreciated!

like image 915
joeellis Avatar asked Oct 10 '22 19:10

joeellis


2 Answers

I would recommend taking an approach similar to this one. The main thing you'll want to do is set your config.cache_classes to true, but force Spork to reload your models and dependencies on each run:

Spork.each_run do
  ActiveSupport::Dependencies.clear
  ActiveRecord::Base.instantiate_observers
end if Spork.using_spork?

Hopefully this will allow the cache_classes to be true for Capybara, but it will also allow your models and observers to be reloaded between test runs.

like image 180
Pan Thomakos Avatar answered Oct 14 '22 05:10

Pan Thomakos


I ran into a similar issue with spork and cucumber. The solution I found was :

config.cache_classes = (ENV['DRB'] == 'true' ? false : true)

spork sets the DRB environment. I dont think this is the most elegant way to solve this, but if capybara sets some env variable, you could use that ?

like image 41
Amit Avatar answered Oct 14 '22 05:10

Amit