How can I make sure that helpers and models reload in RSpec when I use Spork?

It seems that my helpers (and sometimes my models) do not restart every time I start Spork. What should I put in my Spork.each_run block?

+8
ruby-on-rails rspec rspec-rails helpers spork
source share
3 answers

I had the same problem, so I installed this in my each_run block:

Spork.each_run do # This code will be run each time you run your specs. ActiveSupport::Dependencies.clear ActiveRecord::Base.instantiate_observers FactoryGirl.reload Dir[File.join(File.dirname(__FILE__), '..', 'app', 'helpers', '*.rb')].each do |file| require file end end 

Also, don't forget about this in your config / environment / test.rb:

 config.cache_classes = !(ENV['DRB'] == 'true') 
+8
source share

Perhaps this is due to the fact that you are loading them into the preview block. If you download material, your test runs faster, but sometimes you need to reload. You can load the "each_run" block, but the test will be slower. If you prefer speed, you can restart the Spork server when you see that you need a reboot. Thus, the pre-production block will start again, and your models and helpers will be rebooted.

+1
source share

I have never had these problems, and perhaps because I also use the Guard Guard as described in the Rails Bast RatesCast?

http://railscasts.com/episodes/285-spork

-3
source share

All Articles