2017-04-27 109 views
-1

我混淆了使用红宝石散列码格式和letRspec让散列键意外=>,期待'}'

这在正常情况下工作。

{ 
      "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, 
         ^
+1

我认为,问题是,你需要将你的哈希移到在'..“之后加一个'{}'并移除'''easy'},' –

+0

你的问题是什么? – sawa

+0

顺便说一下,在代码中甚至没有''id“=> 3'。 – sawa

回答

2
  1. 如果您的区段跨越超过一行使用do/end
  2. 当上述操作后,您会看到你错过了两个开{}哈希:

    let(:wrong_question1) do 
        { 
          "id" => 1, 
        "description" => "test 3", 
        "difficulty" => { "id" => 1, "description" => "easy" } 
        } 
    end