我想测试我的方法Account.find是否返回正确的结果。我得到以下错误。
it "can find an account " do
Account.find(id: @acc.id, authorization: @token);
expect(response.status).to have_http_status(200);
body = JSON.parse(response.body)
expect(body["name"]).to eq "Test"
end
NameError:未定义的局部变量或方法响应。
如何检查右response
和response code
。
答案 0 :(得分:1)
这不起作用,因为你想要实际测试的是请求答案。尝试:
it "can find an account that this user belongs to" do
get "/accounts/#{@acc.id}/", headers # like the token or whatever your api needs
expect(response).to be_success
# now you have the response.body available to do:
body = JSON.parse(response.body)
expect(body["name"]).to eq "Test"
end