-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spork + rspec-2 + rails-3 doesn't reload models by default #37
Comments
Great news. Yes, I'm betting models are getting preloaded. It's a nasty duck punch to make spork do it's magic with Rails, unfortunately. I'm hoping the Rails 3 cleans up it's architecture. I'm dreading figuring out how to get the tests running with Bundler... there's so much uncertainty around it still. |
Are you at RC this week? |
No, at home. |
What should I do to avoid this issue? If I set config.cache_classes to false I have very many test fails of my apps. |
I pushed spork 0.8.4 out, it includes a patch contributed by Elliot Winkler that fixes the bundler/spork conflict with the diagnoser mode. Can you run Tim |
My system: $ spork -d > out.txt https://gist.github.com/bfb318c6375c444ed395 And my spec_helper: https://gist.github.com/1d92348b08b71a5fc798
|
same problem that petRUShka with Ruby 1.8.7 & Rails 3.0.0.beta4 (config.cache_classes to false => many test fails) and model modification not reloaded. my spork -d: http://gist.github.com/435745 |
I can confirm this issue with the latest version of REE (2010.02) - model modifications are not reloaded |
I have a similar issue, however only some models are reloading. My User model does not reload, but my Order model does... |
Any news about the resolution of this problem? |
No, but I did just get the spork cucumber testsuite to work with bundler (as in, it can test with a rails project generated using a bundler gemfile)! This is, in my opinion, a HUGE step forward and has been a primary hold-back rails 3.0 support. |
Great to hear that, thk for the update! |
OK... so spork totally isn't compatible with rails 3.0 right now. It's been using the Unknown framework, which basically leaves you on your own to make stuff you want loaded each time is done in an each_run block.... |
It'll be easy to fix? |
For me this solution does reload models: http://github.com/rspec/rspec-core/issues/issue/62/#issue/62/comment/305544 |
Same here, the solution on the rspec-core issues works for me too. |
All interested parties: try out 0.9.0 RC2. At least the integration tests show that model reloading is occurring. I've still got some doubts about observers triggering pre-loading of models, and have noticed that mongoid seems to want to eagerload the model universe as well. Tim |
So, do we have to remove the fix from http://github.com/rspec/rspec-core/issues/issue/62/#issue/62/comment/305544 after we've upgraded to 0.9.0 RC2 ? or else ? |
Hmm, I don't know. Try it and see? (it shouldn't be preloading application files.. although some things may still trigger it). It seems like it's best to avoid preloading any application files (app// and lib/), but I can see the merit in that being an easy, reliable solution (although it feels a little messy). ... so... you tell me? |
Ok, so, I upgraded to 0.9.0.rc2, removed the fix from the rspec-core issue 62's comment, and I ran the tests once, changed a model so that some tests should fail, and with spork, the model was not reloaded, it was still giving me a all's ok result, restarting spork gives me the errors I was expecting, correcting the model back still gives me the errors. |
OK :) there's likely something else triggering the models to load during boot. Do you have observers loaded? Can you post the interesting pieces from the result of `spork -d' |
No observers. Here's the
|
huh, I'll be. It doesn't show that you're models are being preloaded (scratches head until bald spot occurs) I'm seriously stumped here. |
I'm also using rspec 2 / Rails 3.0.0 / Spork '0.9.0.rc2' and it is not reloading models either. I can't use the hack above because I'm also using database_cleaner with my Capybara/Selenium Webdriver tests - gives me a wierd TypeMismatch error - somehow the classes are defined twice. I resorted to doing the following: Spork.each_run do This code will be run each time you run your specs.Force-load all the app files.Ugly spork hack because it doesn't work with Rails 3 - remove as soon as spork is fixedsilence_warnings do |
spork -d didn't reveal anything but I think I've found out where the models are being preloaded - via factory_girl I did this by placing the following lines on top of one of my models (person.rb), and then tail'ed the test.log: begin http://pastie.org/private/vheva2yln2qtfywhwrtqw I wonder if it's possible to trap the method like you do for other things... Steve |
So weird that it is preloaded but not showing up in your `spork -d'. I'll have to try and play around with a test project and see if I can reproduce here. Trapping the method seems like the best approach. The find_definitions method looks like the best bet. Try this:
Put it so it gets called before the environment is loaded, and after factory_girl is loaded (you may need to manually require...) |
OK I've figured it out. It was factory_girl_rails that was causing the preload (which wasn't picked up by spork -d) but it is required as a gem so I moved the gem to its own 'development' only group so it isn't loaded by spork prefork: group :development do When it comes to spec_helper I manually require it myself (I put all my factories in spec/factories) - you might change that: Spork.each_run do The models seem to reload properly now. |
One problem I had once i finally got spork to reload my models properly was that I could not run a db:reset. I got errors complaining about factory girl not being able to find my database tables, which makes sense since the reset just dropped them! With the changes in the comment above I no longer needed to load FG within any of the Gemfile groups so i made a separate group that still gets loaded by bundler, but doesn't load FG in any of my environments, leaving spork to load it manually.
I'm still not exactly sure what caused db:reset to flip out, but this little hack fixed it. |
I'm having this same problem with factory girl. I can't require factory_girl in each_run because I get an error
Very frustrating. Any suggestions? |
https://github.com/Cluster444/zmchapters/blob/74df4d6bb85d3cf25afae028302a6b23d5d07700/Gemfile That's how i've setup factory girl and it seems to work ok. I've only ever run into a problem with my User model not reloading, the rest of them reload fine. |
Hi there, this is the code I settled on with a co-worker today and it seems to do the trick. Put it in application.rb :
|
This is my Spork.prefork block |
I've written a wiki entry on this: https://github.com/timcharper/spork/wiki/Troubleshooting |
I can verify that the suggestion in the wiki does not solve the problem with FactoryGirl 2.1.0 & Rails 3.1. I found it necessary to reload all the models, otherwise changes would not be picked up. Spork.each_run do
require 'factory_girl_rails'
# reload all the models
Dir["#{Rails.root}/app/models/**/*.rb"].each do |model|
load model
end
end I'll update the wiki article now. |
This solution works but I'm getting a lot of warnings on every test run because i have constants defined in my models /home/morr/develop/site/app/models/group_join_policy.rb:2: warning: already initialized constant Free |
The problem is the models are getting preloaded. Spork states that any code that is preloaded will be cached from run to run. Use |
I just : Spork.each_run do
require 'factory_girl_rails'
end And in my Gemfile : gem 'factory_girl_rails', :require => false |
+1 on @jc00ke 's last comment. I tried everything else in this thread to no avail on Rails 3.1.1 with FactoryGirl. I have to explicitly reload all the models. When I run Finally, once I add foreman or guard into the mix, event @jc00ke 's advice doesn't fix the issue :-( |
I also rely on a workaround like wakiki and jc00ke's to make models reload with spork:
Edit: got silence_warnings to work |
Is this issue solved?, I'm using 1.0.0rc and get the same behavior. |
Ok, I switched to fork-rails and it works now. |
I just got rspec-2 working with spork and rails-3. I haven't had a chance to investigate why yet, but with this configuration we need to set config.cache_classes = false to get models to reload. This suggests that rails is eager loading models during the prefork (which in my case is not asking to load anything under app). Something we can manage from spork?
The text was updated successfully, but these errors were encountered: