Open jakeonrails opened 12 years ago
+1 Any workarounds or other info? I'm seeing the same behavior, where models directly in app/models/.rb are being reloaded correctly, but models in app/models/subdir/.rb are not.
Is this a confirmed defect?
@jakeonrails The research I've done on this indicated that you need to put ActiveSupport::Dependencies.clear
in your each_run section like so:
Spork.each_run do
ActiveSupport::Dependencies.clear
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
end
I noticed in your issue report you have that in the prefork section.
Im having the same issue, were you able to fix this?
The fix @kevinzen posted worked for me.
@kevinzen's fix worked for me. Thanks!
Adding ActiveSupport::Dependencies.clear
broke all of my tests, with "uninitialized constant" errors.
A better solution was to add gem 'spork-rails'
to my Gemfile
. It takes care of this reloading stuff for you.
Hi everyone, I've created a gist with my code that has worked for me: https://gist.github.com/acnalssoe/5202221 I think it's better than workarounds, such as requiring the files in the spec_helper, that could lead to a Constant already defined.
@acnalesso The posted gist is no longer available. Can you post your workaround here?
Thanks,
I just added watch(%r{^lib/.+\.rb$})
to my guardfile. But that was just a workaround. Ultimately I found that the real problem was this:
"Another thing to watch out for with Factory Girl is when specifying a class for a factory, using a class constant will cause the model to be preloaded in prefork preventing reloading, whereas using a string will not."
From: https://github.com/sporkrb/spork/wiki/Spork.trap_method-Jujitsu
Thanks @sslotnick! This is just what was causing an issue for me. Don't have to restart guard each time I change my models.
I'm using Spork with Rspec.
I have a class called Project inside a module MyApplication.
When I change the code (even deleting everything in the project.rb file) project_spec gives the exact same output before the change.
When I remove the class from the module and put it in the global namespace, changes in project.rb are reflected on each run of project_spec.
Am I overlooking a configuration or something?
test.rb:
spec_helper.rb:
Gemfile