我开始一个新项目,我的第一个Rails 5.1.0。我有我的第一个请求规范的pb。Rspec请求规格和Rails 5
describe 'Users', type: :request do
it 'are created from external data' do
json_string = File.read('path/to/test_data/user_data.json')
params = { user: JSON.parse(json_string) }
headers = { "CONTENT_TYPE" => "application/json" }
expect do
post '/api/v1/users', params.to_s, headers
end.to change {
User.count
}.by(1)
expect(response.status).to eq 200
end
end
此规格返回错误ArgumentError: wrong number of arguments (given 3, expected 1)
。 official documentation不多说。
如果我拿出.to_s,并发送哈希值,像这样:
post '/api/v1/users', params, headers
我得到另一个错误:
ArgumentError: unknown keyword: user
任何想法?
你说得对:)我猜他们的文档已经过时了......你能复制粘贴你答案的答案字段,所以我可以接受它吗? – Ruff9