let(:valid_attributes) {
{
"first_name" => "MyString",
"last_name" => "LastName",
"email" => "[email protected]",
"password" => "password12345",
"password_confirmation" => "password12345"
}
}
it "sets session when" do
post :create, {:user => valid_attributes}, valid_session
expect(session[:user_id]).to eq(valid_attributes.id)
end
當我上述試驗運行,它失敗 故障/錯誤:預期(會話[:USER_ID])。爲eq(valid_attributes [ 「ID」])Rspec的滑軌誤差
預期:無
得到:1
但是,當我改變它下面的代碼,它通過測試。但是這兩者之間有什麼區別。爲什麼第一個失敗。
it "sets session when" do
post :create, {:user => valid_attributes}, valid_session
expect(session[:user_id]).to eq(User.find_by(email: valid_attributes["email"]).id)
end