Skip to content
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

App reloading rails-3.0.0/ruby1.9.2-p0/spork-0.9.0.rc2 #52

Closed
knoopx opened this issue Sep 29, 2010 · 20 comments
Closed

App reloading rails-3.0.0/ruby1.9.2-p0/spork-0.9.0.rc2 #52

knoopx opened this issue Sep 29, 2010 · 20 comments

Comments

@knoopx
Copy link

knoopx commented Sep 29, 2010

Hello, I'm trying out spork (0.9.0.rc2) with a brand new rails (3.0.0) app. I'm unable to make spork to reload files/classes. Once spork is launched, controllers, models, routes or specs are no longer reloaded. I've read all related issues here and tried all possible workarounds but nothing seems to work. Can you please provide up to date information about the status of reloading?

@timcharper
Copy link
Contributor

Can you provide a demo application for me to look at where it's not working?

The cucumber integration features are all passing, and are specifically testing to make sure that models, controllers, routes, etc. are reloaded with rails. I have no idea why your specs would not be reloaded :)

Basically, if your application loads it during boot, then it is not reloaded during the life of spork. So you must organization your application accordingly. Unfortunately, some gems insist on being magical and reaching into your application for you (curses!). In these cases, you must fight black magic with black magic, and use Spork.trap_method and Spork.trap_class_method.

@knoopx
Copy link
Author

knoopx commented Sep 29, 2010

Well, I'm running sport in a large app. I will try to create a blank rails app and try it again. Btw spork -d outputs this:

Using RSpec
Preloading Rails environment
Loading Spork.prefork block...

  • Spork Diagnosis -
    -- Summary --
    config/application.rb
    config/boot.rb
    config/initializers/app.rb
    config/initializers/backtrace_silencers.rb
    config/initializers/compass.rb
    config/initializers/devise.rb
    config/initializers/formtastic.rb
    config/initializers/inflections.rb
    config/initializers/mime_types.rb
    config/initializers/secret_token.rb
    config/initializers/session_store.rb
    config/routes.rb
    spec/spec_helper.rb

by what I understood, everything else not shown here should be auto-reloaded, right?

@timcharper
Copy link
Contributor

Well I doubt you'll run into it with a blank app, because that's exactly what the integration tests do and it works :)

See if you can verify when your models are being loaded. At the top of one of your model files, put a `puts caller' statement. Then, send me that stack trace when running spork / specs. Do you see the stacktrace each time you run specs, the first time you run specs, or when starting up the server?

@rainux
Copy link

rainux commented Sep 30, 2010

I have the same issue for a real app running with rails-3.0.0 ree-1.8.7 spork-0.9.0.rc2, here is the stack trace via puts caller:

rainux@mutalisk ~/devel/my_app
% spork
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:454:in `load'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:454:in `load_file'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:453:in `load_file'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:340:in `require_or_load'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:300:in `depend_on'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:216:in `require_dependency'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/mongoid-2.0.0.beta.18/lib/rails/mongoid.rb:12:in `load_models'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/mongoid-2.0.0.beta.18/lib/rails/mongoid.rb:11:in `each'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/mongoid-2.0.0.beta.18/lib/rails/mongoid.rb:11:in `load_models'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/paths.rb:102:in `each'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/paths.rb:102:in `each'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/mongoid-2.0.0.beta.18/lib/rails/mongoid.rb:10:in `load_models'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/mongoid-2.0.0.beta.18/lib/mongoid/railtie.rb:81:in `_callback_before_7'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/callbacks.rb:424:in `_run_prepare_callbacks'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.0/lib/action_dispatch/middleware/callbacks.rb:40:in `initialize'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.0/lib/action_dispatch/middleware/stack.rb:33:in `new'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.0/lib/action_dispatch/middleware/stack.rb:33:in `build'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.0/lib/action_dispatch/middleware/stack.rb:79:in `build'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/application.rb:208:in `inject'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.0/lib/action_dispatch/middleware/stack.rb:79:in `each'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.0/lib/action_dispatch/middleware/stack.rb:79:in `inject'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.0/lib/action_dispatch/middleware/stack.rb:79:in `build'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/application.rb:162:in `build_middleware_stack'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/application/finisher.rb:35
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `instance_exec'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `run'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/initializable.rb:50:in `run_initializers'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/initializable.rb:49:in `each'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/initializable.rb:49:in `run_initializers'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/application.rb:134:in `initialize!'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/application.rb:77:in `send'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0/lib/rails/application.rb:77:in `method_missing'
/home/rainux/devel/my_app/config/environment.rb:5
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
/home/rainux/devel/my_app/spec/spec_helper.rb:10
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/bin/../lib/spork.rb:23:in `prefork'
/home/rainux/devel/my_app/spec/spec_helper.rb:4
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/lib/spork/test_framework.rb:138:in `preload'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/lib/spork/app_framework/rails.rb:8:in `preload'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/lib/spork/test_framework.rb:134:in `preload'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/bin/../lib/spork.rb:61:in `exec_prefork'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/lib/spork/test_framework.rb:120:in `preload'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/lib/spork/run_strategy/forking.rb:25:in `preload'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/bin/../lib/spork/runner.rb:74:in `run'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/bin/../lib/spork/runner.rb:10:in `run'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/gems/spork-0.9.0.rc2/bin/spork:10
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/bin/spork:19:in `load'
/home/rainux/.rvm/gems/ree-1.8.7-2010.02/bin/spork:19
Spork is ready and listening on 8989!

@knoopx
Copy link
Author

knoopx commented Sep 30, 2010

Ok, realized that bundler was loading spork-0.8.4. After explicitly specifying spork version on Gemfile, reloading of controllers/models/specs seems to work fine. Integration tests work only if cache_classes = true. Routes do not reload.

@rainux
Copy link

rainux commented Sep 30, 2010

I've already specified spork version via '>= 0.9.0.rc2'.

@bbhoss
Copy link

bbhoss commented Oct 17, 2010

Still having this issue with Rails 3 and Ruby 1.9.2. I'm trying to use steak with spork. It works well, except it doesn't reload my models, and possibly other things I haven't realized. It seems to reload the views fine. Please fix this or give me a hint on where to start! Having to wait 10 seconds for rails 3 to start is really slowing me down!

Thanks!

@timcharper
Copy link
Contributor

Want to help? Produce a small rails app (as small as possible) to reproduce this issue. If you look at the cucumber features, spork does work with reloading models, routes, controllers, etc. It has something to do with one of plugins you are using. And I can't reproduce it because I don't know what it is.

@bbhoss
Copy link

bbhoss commented Oct 17, 2010

Thanks, I will try to get this for you. Where in Spork is the reload stuff called?

@timcharper
Copy link
Contributor

It isn't called :) The first idea is to prevent it from being loaded it at all.

@bbhoss
Copy link

bbhoss commented Oct 17, 2010

Ok, I have a reproducible app. It LOOKS like it has to do with Mongoid. The app is here: http://github.com/bbhoss/spork_bug_example
Basically, bundle install, then comment out the "charp" method inside of the bug model. Then start spork with bundle exec spork. Once spork is up and ready, I run
rspec -X --drb-port 8989 spec/models/bug_spec.rb
The test should fail, as charp doesn't exist. Without doing anything else, uncomment the method charp in the bug model, and run the exact same rspec command above. The test should still fail, with the same nomethoderror. If you run rspec spec/models/bug_spec.rb (which doesn't use spork), the test should pass.

Hope this helps! Let me know if you need anything else.

@thheller
Copy link

@bbhoss: mongoid loads every model on init. It is required to trap this method so it get executed AFTER the fork. AFAICT everything works as expected after doing this.

Create a config/initializers/spork_traps.rb

if defined?(Spork)
  Spork.trap_class_method(Rails::Mongoid, :load_models)
end

@bbhoss
Copy link

bbhoss commented Dec 7, 2010

Sorry for the long wait, this didn't fix it for me. Looks promising though.

@petRUShka
Copy link

Same issue with routes.rb. Spork cuc dosnt' reload routes.rb

@astyagun
Copy link

astyagun commented Feb 6, 2011

I've encountered a model reloading problem as well. In my case it has something to do with Machinist. Here is a simple app that demonstrates the problem https://github.com/iast/spork-model-reload-problem-demo .
Commenting/uncommenting line 3 in test_model.rb should change the result of test. Which doesn't happen when RSpec is run in DRb mode with Spork.

@timcharper
Copy link
Contributor

Spork can't prevent every unwanted preload, so some work will need to be done by the developer to prevent such occurrences.

Some examples on how to solve some common problems are and will be collected here:

http://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu

@astyagun
Copy link

astyagun commented Feb 8, 2011

Thanks for the tip. Unfortunately I wasn't able to find which method should be trapped. But thankfully there's other solution that worked for me:

https://github.com/iast/spork-model-reload-problem-demo/commit/a2178bce4ca0d6c6d0ba73e30f7428f6a13bc0fc#diff-1

I simply prevented Machinist's blueprints.rb file from being loaded in prefork block and am manually loading it in each_run block.

@timcharper
Copy link
Contributor

Hah, ok, yes, that would definitely cause it :) (loading machinist blueprints.rb in the prefork block).

I would recommend loading all spec support files in each_run, since its likely you'll want to modify them while you're working on your specs...

@timcharper
Copy link
Contributor

(I'm sorry I didn't see that in your demo app earlier... sigh, I kind of failed you on support there. It has been a crazy time in my life and its taken me 6 mos to get back into the swing of open source again, it seems.)

@astyagun
Copy link

astyagun commented Feb 8, 2011

I didn't realize that putting blueprints.rb into prefork block can cause such a problem :\
And also there is a concern about performance of each spec run, which caused me to move as much code as possible into prefork block, obviously :)

Well, the problem is solved and I can continue enjoying using Spork with my tests and that's what matters :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants