Reputation: 189
I want to test my method Account.find whether it returns me the right result or not. I get the below error.
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: undefined local variable or method response.
How can i check for the right response
and response code
.
Upvotes: 0
Views: 43
Reputation: 4643
This won't work as what you want to actually test is the request answer. Try:
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
Upvotes: 1