当我试图执行以下行
时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
答案 0 :(得分:3)
changes in Rails 5之一是测试请求方法只接受关键字参数,而不是将任意哈希选项作为参数传递给Rails 4中的行为。
post :create, params: { user: Fabricate.attributes_for(:user) }