[rspec-users] getting ActionController::RoutingError when I test namespaced controllers

Lille lille.penguini at gmail.com
Thu Feb 2 19:06:15 EST 2012


When I use these commands from the application root

rspec spec
rspec spec/controllers

I get errors (an example will be shown below) for every controller
test in my subdirectory spec/controllers/api/beta, where the
controller namespacing is carried over in any test as follows

describe Api::Beta1::ThingController ...

Somehow, I do NOT get any errors for the tests in the subdirectory
when I run this command from the application root

rspec spec/controllers/api/beta

Here is an example of the error I get, with backtrace:

  23) Api::Beta1::ThingController#loan server-side failure should have
status code 500 and expected message body
     Failure/Error: response = post(action, params)
     ActionController::RoutingError:
       No route matches {:controller=>"api/beta1/
thing", :action=>"loan"}
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:464:in
`raise_routing_error'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:460:in
`rescue in generate'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:452:in
`generate'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:493:in
`generate'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:489:in
`generate_extras'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:485:in
`extra_keys'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_controller/test_case.rb:145:in
`assign_parameters'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_controller/test_case.rb:438:in `process'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_controller/test_case.rb:49:in `process'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/
actionpack-3.1.0/lib/action_controller/test_case.rb:370:in `post'
     # ./spec/controllers/api/beta1/thing_controller_spec.rb:72:in
`raw_post'
     # ./spec/controllers/api/beta1/thing_controller_spec.rb:57:in
`block (3 levels) in <top (required)>'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/hooks.rb:35:in `instance_eval'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/hooks.rb:35:in `run_in'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/hooks.rb:70:in `block in run_all'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/hooks.rb:70:in `each'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/hooks.rb:70:in `run_all'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/hooks.rb:116:in `run_hook'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:221:in `block in
eval_before_eachs'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:221:in `each'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:221:in `eval_before_eachs'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example.rb:145:in `run_before_each'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example.rb:47:in `block in run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example.rb:107:in `with_around_hooks'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example.rb:45:in `run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:294:in `block in
run_examples'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:290:in `map'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:290:in `run_examples'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:262:in `run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:263:in `block in run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:263:in `map'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/example_group.rb:263:in `run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/command_line.rb:24:in `block (2 levels) in
run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/command_line.rb:24:in `map'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/command_line.rb:24:in `block in run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/reporter.rb:12:in `report'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/command_line.rb:21:in `run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/runner.rb:69:in `run'
     # /Users/lille/.rvm/gems/ruby-1.9.2-p290 at rails310/gems/rspec-
core-2.6.4/lib/rspec/core/runner.rb:11:in `block in autorun'

I missed this issue when developing my tests, because I was running
them using the command that succeeds. Now, I'm in trouble because I
want to step back and test everything with a simple command from the
app root:

rpsec spec

(Sorry to any bothered readers for any undue brevity in the previous
post-response cycle, but I've assumed that the type of error
(RoutingError) in combination with the way rspec works and fails for
my functional tests was adequate to suggest a fix.)

Thanks,

Lille


More information about the rspec-users mailing list