Use expect_json helper method for determining JSON response status

This commit is contained in:
Scott Schneider 2015-07-28 14:14:34 -07:00
parent add88c7bba
commit 2d514f53bf
3 changed files with 61 additions and 132 deletions

14
spec/helpers.rb Normal file
View file

@ -0,0 +1,14 @@
def expect_json(
ok = true,
http = 200
)
expect(last_response.header['Content-Type']).to eq('application/json')
if (ok == true) then
expect(JSON.parse(last_response.body)['ok']).to eq(true)
else
expect(JSON.parse(last_response.body)['ok']).to eq(false)
end
expect(last_response.status).to eq(http)
end