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

all_on_start: false option causes rails environment not to load #26

Open
nilbus opened this issue Apr 24, 2013 · 4 comments
Open

all_on_start: false option causes rails environment not to load #26

nilbus opened this issue Apr 24, 2013 · 4 comments

Comments

@nilbus
Copy link
Collaborator

nilbus commented Apr 24, 2013

My tests run fine when using the standard options, but setting all_on_start to false causes the Rails environment not to load.

guard 'jruby-rspec', :all_after_pass => false, :all_on_start => true do

When I run guard and edit a file (in this case an ActiveRecord model), it tells me ActiveRecord is an uninitialized constant:

22:32:59 - ERROR - Guard::JRubyRSpec failed to achieve its <run_on_changes>, exception was:
> [#] NameError: uninitialized constant ActiveRecord
> [#] org/jruby/RubyModule.java:2642:in `const_missing'
> [#] ./app/models/address.rb:1:in `(root)'
> [#] org/jruby/RubyKernel.java:1058:in `load'
> [#] ./app/models/address.rb:88:in `reload_paths'
> [#] org/jruby/RubyArray.java:1615:in `each'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-jruby-rspec-0.1.7/lib/guard/jruby-rspec.rb:73:in `reload_paths'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-jruby-rspec-0.1.7/lib/guard/jruby-rspec.rb:54:in `run_on_changes'
> [#] org/jruby/RubyKernel.java:2080:in `send'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:99:in `run_supervised_task'
> [#] org/jruby/RubyKernel.java:1183:in `catch'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:97:in `run_supervised_task'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:144:in `run_first_task_found'
> [#] org/jruby/RubyArray.java:1615:in `each'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:142:in `run_first_task_found'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:79:in `run_on_changes'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:175:in `scoped_guards'
> [#] org/jruby/RubyArray.java:1615:in `each'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:173:in `scoped_guards'
> [#] org/jruby/RubyKernel.java:1183:in `catch'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:172:in `scoped_guards'
> [#] org/jruby/RubyArray.java:1615:in `each'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:170:in `scoped_guards'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard/runner.rb:72:in `run_on_changes'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard.rb:105:in `setup_listener'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard.rb:368:in `within_preserved_state'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard.rb:365:in `within_preserved_state'
> [#] /home/vagrant/ws/rental_express/ROOT/rails/vendor/gems/guard-1.8.0/lib/guard.rb:104:in `setup_listener'
@nilbus
Copy link
Collaborator Author

nilbus commented Apr 25, 2013

This is happening whenever a project file gets modified before any spec is loaded, since spec_helper is what loads the environment.

I worked around this by adding require 'spec/spec_helper to my Guardfile, but I think guard-jruby-rspec should be loading the spec_helper. Do you agree?

@jkutner
Copy link
Owner

jkutner commented Apr 25, 2013

Because not every project will necessarily have a spec_helper file, we can't load it by default. guard-rspec works the same way, and you can see in the examples they've put spec_helper in the Guardfile. https://github.com/guard/guard-rspec/blob/master/README.md

Sorry, but i think your solution is the best it's going to get.

@jkutner jkutner closed this as completed Apr 25, 2013
@nilbus
Copy link
Collaborator Author

nilbus commented Apr 25, 2013

Thanks for looking into it. Their examples watch for changes in spec_helper but don't load it with require. I'm still not quite sure what guard-rspec does that makes the difference.

@jkutner
Copy link
Owner

jkutner commented Apr 25, 2013

Hmm, sorry - i didn't catch that difference. I'll take a closer look when i get a chance.

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

2 participants