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?
How do I make sure the helpers and models reload in RSpec when I'm using Spork?
Asked Answered
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')
Yes same for me @JoshuaMuheim, did you fix? –
Linehan
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.
OK, if I wanted to reload a particular set, would I just require it normally? –
Arbitrate
I think so, just put it in the each_run block. –
Fetish
I never had these problems, and maybe it's because I'm also using the Guard gem like described in Ryan Bates' RailsCast?
© 2022 - 2024 — McMap. All rights reserved.
Failure/Error: ActiveRecord::StatementInvalid: ArgumentError: prepare called on a closed database: rollback transaction # /Users/josh/.rvm/gems/ruby-1.9.3-p0@iq/gems/sqlite3-1.3.6/lib/sqlite3/database.rb:91:in
initialize'` – Carryingon