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!
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.
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 ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With