接收错误的RSpec的PUT,但不是POST [英] Receiving error in RSpec for PUT, but not POST
问题描述
在我的规格,当我运行下面的POST请求,一切工作正常。
In my specs, when I run the POST request below, everything works fine.
before do
request_payload = {
player: {
first_name: "Joe",
last_name: "Carradine",
team_id: "1"
}
}
post :create, request_payload
end
但是当我运行一个规格为PUT:
But when I run a spec for PUT:
before do
request_payload = {
player: {
first_name: "Buck",
last_name: "Carradine",
team_id: "1"
}
}
put :update, id: 3, request_payload
end
我得到这样一个错误:
I get an error like this:
[filename]_spec.rb:139: syntax error, unexpected '\n', expecting tASSOC (SyntaxError)
[filename]_spec.rb:198: syntax error, unexpected $end, expecting keyword_end
任何想法?是否有把不同的语法,我不知道的?
Any ideas? Is there a different syntax for PUT I'm not aware of?
推荐答案
要解决语法错误,使用放:更新{ID:3},request_payload
不是, 放:更新,ID:3,request_payload
。红宝石只支持裸(如卷曲braceless)哈希值作为最后一个参数的方法,所以 ID:3
而不被包裹不能出现在参数列表的中间大括号内。
To fix the syntax error, use put :update, { id: 3 }, request_payload
, not put :update, id: 3, request_payload
. Ruby only supports "bare" (e.g. curly-braceless) hashes as the last argument to the method, so id: 3
cannot appear in the middle of an argument list without being wrapped in curly braces.
这篇关于接收错误的RSpec的PUT,但不是POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!