我在使用ruby哈希密钥格式和let
时感到困惑。
这适用于正常情况。
{
"id" => 1,
"description" => "test 3",
"difficulty" => { "id" => 1, "description" => "easy" },
}
但在let
阻止
以下是代码:
describe 'incorrect_question' do
let(:wrong_question1) {
"id" => 1,
"description" => "test 3",
"difficulty" => { "id" => 1, "description" => "easy" },
}
it 'does something' do
# ...
end
end
导致以下异常:
syntax error, unexpected =>, expecting '}' (SyntaxError)
"id" => 1,
^
答案 0 :(得分:2)
do
/ end
。完成上述操作后,您会发现您错过了哈希的开头{
和结束}
:
let(:wrong_question1) do
{
"id" => 1,
"description" => "test 3",
"difficulty" => { "id" => 1, "description" => "easy" }
}
end