[rspec-users] controller spec not loading controller classes

David Chelimsky dchelimsky at gmail.com
Wed Mar 14 20:37:44 UTC 2012


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


More information about the rspec-users mailing list