Spork Capybara, conflict config.cache_classes

I am trying to configure Spork and Capybara using TestUnit and I am running into the test.rb configuration problem.

The problem is that Spork requires config.cache_classes to be set to false, so changes to 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 work.

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

+5
source share
2 answers

I would recommend applying an approach similar to this one. The main thing you need to do is set config.cache_classes to true, but make Spork reload your models and dependencies for each run:

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

Hopefully this allows cache caches to be true for Capybara, but it also allows you to reload your models and observers between test runs.

+3
source

I ran into a similar problem with pork cucumber. The solution I found was:

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

spork sets up a DRB environment. I don't think this is the most elegant way to solve this problem, but if capybara sets some env variable, can you use it?

+1
source

All Articles