I am writing a controller spec (RSpec with Devise), and I know that the response returns the parameter I passed in to it (correctly so), because I see it in the output as this:
...@params={"email" => "[email protected]", ...
This is my controller spec:
describe 'POST #create' do
context 'when invited user IS an existing user' do
before :each do
@users = [
attributes_for(:user),
attributes_for(:user),
attributes_for(:user)
]
end
it 'correctly finds User record of invited user' do
login_user
post :create, { email: @users.first[:email] }
expect(response.params[:email]).to include(@users.first[:email])
end
end
end
When I run the test above, I get this error:
1) Users::InvitationsController POST #create when invited user IS an existing user correctly finds User record of invited user
Failure/Error: expect(response.params[:email]).to include(@users.first[:email])
NoMethodError:
undefined method `params' for #<ActionController::TestResponse:0x007fa50d1ee6a0>
This is what the entire output of the response looks like:
https://gist.github.com/marcamillion/c2e3f4d0bdae05c2be1f
I tried to paste it here, but SO screamed at me for exceeding the 30,000 character limit. I would have truncated it, but didn't want to remove any info that may be necessary.
What I am trying to do is basically verify that the email in params[:email]
contained in the response
is the same email I passed to it. I know it is intuitively but I would like to do it programmatically.
undefined method `params' for ActionController::TestResponse:0x007fa50d1ee6a0
You should use controller.params[:email]
instead of response.params[:email]
params
are bound to the controller
not response
.