我寫了一個測驗,它看起來很接近但不太正確。
it "adds the correct permissions" do
subject
expect(policy.permissions).to have_key("users")
expect(policy.permissions["users"]).to eq({ "all_users" => {
can_view: false,
can_manage: false,
} })
end
輸出:
expected: {"all_users"=>{:can_manage=>false, :can_view=>false}}
got: {"all_users"=>{"can_manage"=>false, "can_view"=>false}}
顯然我很接近,但我不確定在:符號與"got"測驗本身的輸出方面的交易是什么。我怎樣才能讓它通過?
uj5u.com熱心網友回復:
字串鍵不等于 Hash 類中的符號鍵。下面是示例代碼:
hash = {}
hash[:a] = 1
hash['b'] = 2
hash[:a] # returns 1
hash['a'] # returns nil
hash[:b] # returns nil
hash['b'] #returns 2
所以你應該期待這樣的結果:
expect(policy.permissions["users"]).to eq({ 'all_users' => { 'can_view' => false, 'can_manage' => false, } })
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/498036.html
