rspec-rails: ActionController::RoutingError: No route matches [...]
I’m writting an API for a pet project of mine and was running rails 3.2.9 I decided to update rails in order to avoid security problems but I suddenly ran into some problems.
I’ve been able to resolve most of them but I keep getting this and don’t know what to do with it.
I am using RSPEC to test a json API and until this upgrade everything was going just fine and all routes were working perfectly.
I’m not sure wether it’s a bug or a bad usage from me, so I’m sorry if it’s the former. Here is my code :
Routes :
Fake::Application.routes.draw do
namespace :api do
namespace :v1 do
scope '/user' do
match "signup" => "registrations#create", :via => :post
match "delete" => "registrations#destroy", :via => :delete
match "login" => "sessions#create", :via => :post
match "logout" => "sessions#destroy", :via => :delete
end
end
end
end
Spec :
require 'spec_helper'
describe Api::V1::SessionsController do
before do
@user = {
:email => Faker::Internet::email,
:pseudo => Faker::Internet::user_name,
:password => Faker::Lorem::words(2).join
}
user = User.create @user
end
context 'should login in' do
it 'should be ok ' do
post '/api/v1/user/login', :user => @user
JSON.parse(response.body)["success"].should == true
end
it 'should fail without credentials' do
post '/api/v1/user/login', {}
JSON.parse(response.body)["success"].should == false
end
end
end
And the result :
± rspec spec/controllers/sessions_controller_spec.rb 5:21:10 PM
Rack::File headers parameter replaces cache_control after Rack 1.5.
FF
Failures:
1) Api::V1::SessionsController should login in should be ok with auth_token
Failure/Error: post '/api/v1/user/login', :user => @user
ActionController::RoutingError:
No route matches {:user=>{:email=>"meghan.breitenberg@bodehansen.org", :pseudo=>"linwood_gislason", :password=>"repellendusaliquid"}, :controller=>"api/v1/sessions", :action=>"/api/v1/user/login"}
# ./spec/controllers/sessions_controller_spec.rb:17:in `block (3 levels) in <top (required)>'
2) Api::V1::SessionsController should login in should fail without credentials
Failure/Error: post '/api/v1/user/login', {}
ActionController::RoutingError:
No route matches {:controller=>"api/v1/sessions", :action=>"/api/v1/user/login"}
# ./spec/controllers/sessions_controller_spec.rb:22:in `block (3 levels) in <top (required)>'
Finished in 0.50905 seconds
2 examples, 2 failures
Failed examples:
rspec ./spec/controllers/sessions_controller_spec.rb:15 # Api::V1::SessionsController should login in should be ok with auth_token
rspec ./spec/controllers/sessions_controller_spec.rb:21 # Api::V1::SessionsController should login in should fail without credentials
Edit :
Rails version : 3.2.11 Rspec version : 2.12.2 Ruby version : ruby 1.9.3p0
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 36 (10 by maintainers)
That is quite intentional. We don’t want to have to release the whole suite to do patch releases on each gem, so the rspec gem depends on “rspec-xxx”, “~> 2.12.0” where xxx is replaced by each of “core”, “expectations”, and “mocks”: https://github.com/rspec/rspec/blob/master/rspec.gemspec#L31
In this case, 2.12.1 is the latest 2.12 release of rspec-core and rspec-mocks, whereas 2.12.2 is the latest release of rspec-expectations. Make sense?
Ok thanks, it’s working as expected.
I don’t understand it though, why is it working under this repertory and not under the classic “controllers” (as it was before the rails update that broke everything) ? Can’t find any ressource on that.
I’ll go with this for now, but this is weird 😕
Thanks