Chris Ochs
2012-Mar-14 19:32 UTC
[rspec-users] controller spec not loading controller classes
This is jruby 1.6.7, rspec 2, rails 3.0.9. I have a simple controller spec as follows: describe MoneyController, :type => :controller do describe "GET payout" do it "Pays out currency to user" do money = double("Cloud::Money") get :payout end end end Running rake spec results in the following. MoneyController is in app/controllers, but rspec isn''t loading any of my controllers. NameError: uninitialized constant MoneyController const_missing at org/jruby/RubyModule.java:2642 const_missing at /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/backward_compatibility.rb:24 (root) at /home/marvel/server/rails/spec/controllers/money_controller_spec.rb:1 load at org/jruby/RubyKernel.java:1058 load_spec_files at /home/marvel/server/rails/spec/controllers/money_controller_spec.rb:698 collect at org/jruby/RubyArray.java:2331 load_spec_files at /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698 run at /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22 run_in_process at /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80 run at /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69 autorun at /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10 Digging deeper, I see that rake spec loads up rails, then quits and then just runs rspec manually? It does this for all types of rspec tests. Wth? Immediately before the above backtrace, this is what I see: /home/marvel/.rvm/rubies/jruby-1.6.7/bin/jruby -S rspec ./spec/test_spec.rb ./spec/controllers/money_controller_spec.rb ./spec/models/dataset_spec.rb Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120314/c88b6ae2/attachment-0001.html>
David Chelimsky
2012-Mar-14 20:37 UTC
[rspec-users] controller spec not loading controller classes
On Wed, Mar 14, 2012 at 2:32 PM, Chris Ochs <chris at ochsnet.com> wrote:> This is jruby 1.6.7, rspec 2, rails 3.0.9. > > I have a simple controller spec as follows:Does this file require "spec_helper"? If not, that''s probably the problem.> describe MoneyController, :type => :controller do > ? describe "GET payout" do > ??? it "Pays out currency to user" do > ????? money = double("Cloud::Money") > ????? get :payout > ??? end > ? end > end > > Running rake spec results in the following.?? MoneyController is in > app/controllers, but rspec isn''t loading any of my controllers. > > NameError: uninitialized constant MoneyController > ??? const_missing at org/jruby/RubyModule.java:2642 > ??? const_missing at > /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/backward_compatibility.rb:24 > ?????????? (root) at > /home/marvel/server/rails/spec/controllers/money_controller_spec.rb:1 > ???????????? load at org/jruby/RubyKernel.java:1058 > ? load_spec_files at > /home/marvel/server/rails/spec/controllers/money_controller_spec.rb:698 > ????????? collect at org/jruby/RubyArray.java:2331 > ? load_spec_files at > /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698 > ????????????? run at > /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22 > ?? run_in_process at > /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80 > ????????????? run at > /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69 > ????????? autorun at > /home/marvel/.rvm/gems/jruby-1.6.7/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10 > > > Digging deeper, I see? that rake spec loads up rails, then quits and then > just runs rspec manually? It does this for all types of rspec tests.? Wth?When you run "rake anything" in Rails, you start off in the development environment, so rspec''s rake task (and rails'' test task) shells out to a new process, allowing spec/spec_helper.rb (or test/test_helper.rb) to set the environment to ''test'' (or anything you replace that with). Unfortunately, the end result is you load the rails env twice. You can bypass this by just typing rspec directly.> Immediately before the above backtrace, this is what I see: > > /home/marvel/.rvm/rubies/jruby-1.6.7/bin/jruby -S rspec ./spec/test_spec.rb > ./spec/controllers/money_controller_spec.rb ./spec/models/dataset_spec.rb > > Chris > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Chris Ochs
2012-Mar-14 20:46 UTC
[rspec-users] controller spec not loading controller classes
On Wednesday, March 14, 2012 1:37:44 PM UTC-7, dchel... at gmail.com wrote:> > On Wed, Mar 14, 2012 at 2:32 PM, Chris Ochs <chris at ochsnet.com> wrote: > > This is jruby 1.6.7, rspec 2, rails 3.0.9. > > > > I have a simple controller spec as follows: > > Does this file require "spec_helper"? If not, that''s probably the problem. >Ok I feel dumb now. I was thinking there had to be something really simple and stupid I was missing, and that''s it:) Thanks! Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120314/434654f0/attachment-0001.html>
David Chelimsky
2012-Mar-14 20:57 UTC
[rspec-users] controller spec not loading controller classes
On Wed, Mar 14, 2012 at 3:46 PM, Chris Ochs <chris at ochsnet.com> wrote:> > > On Wednesday, March 14, 2012 1:37:44 PM UTC-7, dchel... at gmail.com wrote: >> >> On Wed, Mar 14, 2012 at 2:32 PM, Chris Ochs <chris at ochsnet.com> wrote: >> > This is jruby 1.6.7, rspec 2, rails 3.0.9. >> > >> > I have a simple controller spec as follows: >> >> Does this file require "spec_helper"? If not, that''s probably the problem. > > > Ok I feel dumb now.? I was thinking there had to be something really simple > and stupid I was missing, and that''s it:)Happy to help. Cheers, David