尝试在rspec中传递嵌套参数时出现ArgumentError

时间:2017-04-30 15:06:42

标签: ruby-on-rails ruby testing rspec rspec-rails

当我试图执行以下行

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

我收到此错误消息ArgumentError: unknown keyword: user 这是我最初尝试运行的代码:

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

1 个答案:

答案 0 :(得分:3)

changes in Rails 5之一是测试请求方法只接受关键字参数,而不是将任意哈希选项作为参数传递给Rails 4中的行为。

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