David B.
David B.

Reputation: 838

ArgumentError when trying to pass nested parameters in rspec

When I'm trying to execute the following line

post :create, user: Fabricate.attributes_for(:user)

I get this error message ArgumentError: unknown keyword: user.
Here's the code I was originally trying to run:

describe 'POST create' do
   context 'with valid input' do
     it 'creates the user' do
       post :create, user: Fabricate.attributes_for(:user)
       expect(User.count).to eq(1)
     end
   end
end

Upvotes: 0

Views: 215

Answers (1)

max
max

Reputation: 102250

One of the changes in Rails 5 is that the testing request methods accept only keyword arguments instead of passing any arbitrary hash option as a param which was the behavior in Rails 4.

post :create, params: { user: Fabricate.attributes_for(:user) }

Upvotes: 3

Related Questions