GithubHelp home page GithubHelp logo

Comments (20)

timcharper avatar timcharper commented on June 23, 2024

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.

from spork.

knoopx avatar knoopx commented on June 23, 2024

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?

from spork.

timcharper avatar timcharper commented on June 23, 2024

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?

from spork.

rainux avatar rainux commented on June 23, 2024

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!

from spork.

knoopx avatar knoopx commented on June 23, 2024

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.

from spork.

rainux avatar rainux commented on June 23, 2024

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

from spork.

bbhoss avatar bbhoss commented on June 23, 2024

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!

from spork.

timcharper avatar timcharper commented on June 23, 2024

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.

from spork.

bbhoss avatar bbhoss commented on June 23, 2024

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

from spork.

timcharper avatar timcharper commented on June 23, 2024

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

from spork.

bbhoss avatar bbhoss commented on June 23, 2024

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.

from spork.

thheller avatar thheller commented on June 23, 2024

@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

from spork.

bbhoss avatar bbhoss commented on June 23, 2024

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

from spork.

petRUShka avatar petRUShka commented on June 23, 2024

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

from spork.

astyagun avatar astyagun commented on June 23, 2024

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.

from spork.

timcharper avatar timcharper commented on June 23, 2024

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

from spork.

astyagun avatar astyagun commented on June 23, 2024

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.

from spork.

timcharper avatar timcharper commented on June 23, 2024

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...

from spork.

timcharper avatar timcharper commented on June 23, 2024

(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.)

from spork.

astyagun avatar astyagun commented on June 23, 2024

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 :)

from spork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.