Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make sure the helpers and models reload in RSpec when I'm using Spork?

It seems like my helpers (and sometimes my models) aren't being reloaded on each run with Spork. What should I be putting into my "Spork.each_run" block?

like image 775
kfitzpatrick Avatar asked Nov 28 '11 22:11

kfitzpatrick


2 Answers

I had the same issue, so I set 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 this in your config/environments/test.rb:

config.cache_classes = !(ENV['DRB'] == 'true')
like image 194
Ben Taitelbaum Avatar answered Nov 13 '22 02:11

Ben Taitelbaum


It may be because you load them in the prefork block. If you load the stuff there, your test run faster, but sometimes you need to reload. You could load on the "each_run" block, but test would be slower. If you prefer speed, you can restart the Spork server when you see that you need the reload. This way, the prefork block will run again and your models and helpers will be reloaded.

like image 41
mornaner Avatar answered Nov 13 '22 01:11

mornaner