I had problems for ages in RSpec with my models not being reloaded between Spork runs.
I eventually fixed this by changing the following line in config/environments/test.rb
:
config.cache_classes = true
became
config.cache_classes = false
HOWEVER... while this solved the issues for RSpec, Cucumber requires that cache_classes is set to true. https://rspec.lighthouseapp.com/projects/16211/tickets/165
Is there a canonical solution to this that works for both RSpec and Cucumber and which reloads RSpec models successfully?
Footnote
* Other changes that I implemented to make RSpec reload models included adding the following lines to spec_helper.rb
:
ActiveSupport::Dependencies.clear
FactoryGirl.reload
None of these lines solved the problem without also setting cache_classes=true
line.
I had this problem, and for me it was due to Rails' threadsafe mode. Ensuring config.threadsafe! is not called in my test environment fixed it for me. This is because threadsafe mode prevents code from reloading on each request and disables automatic dependency loading, which I guess spork was relying on in each_run.
I was calling config.threadsafe! in application.rb, so I removed that call from there, and put it in development.rb and production.rb instead. Now I can leave config.cache_classes set to true, and rspec and cucumber work happily under spork. Note that I was using Mongoid in my persistence layer and Machinist instead of FactoryGirl so YMMV.