tl;dr: unable to rspec-test the devise controllers, help.
I am using Devise and have the following routes (default devise_for
routes):
GET /users/cancel(.:format) devise/registrations#cancel
POST /users(.:format) devise/registrations#create
GET /users/sign_up(.:format) devise/registrations#new
GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
I would like to test, using Rspec, that my controller method is spitting out the right output from a given set of parameters.
My spec file looks like this:
describe Users::RegistrationsController, type: 'controller' do
it 'creates a user with given parameters' do
post 'create', username: 'jonsnow', password: '012345678912345', authenticity_token: '12345'
expect(response.status).to eq(200)
end
end
The error I get is:
Failure/Error: post 'create', username: 'jonsnow', password: '012345678912345', authenticity_token: '12345'
ActionController::UrlGenerationError:
No route matches {:action=>"create", :controller=>"users/registrations"}
It makes sense since I am using devise_for
default routes and as you can see from the rake routes
results, the correct route is devise/registrations#create
, but I can't seem to find a way to specify the controller name to devise/registrations
. I think it's 'inflected' from the controller class name or something to users/registrations
. And I would preferably like to avoid messing with my routes in order to make my test successful. How can I accomplish that? (Please explain) Thanks in advance.
My gem versions:
rspec '3.2.1'
ruby '2.1.5'
rails '4.2.0'
Users::RegistrationsController
is correct? maybeDevise
? – hlcfan