Thursday 15 March 2012

ruby on rails - How to examine the response of an API post in an RSpec? -



ruby on rails - How to examine the response of an API post in an RSpec? -

below rspec. notice 3 lines commented out. rspec passes.

describe "/my_api_endpoint" 'blah blah blah' post "/my_api_endpoint", @params # expect(response).to be_success # json = json.parse(response.body) # puts "json = #{json}" last_response.should be_ok end end

however, not need know post returned success, need examine json returns. somehow cannot this. when comment 3 lines in, next error

nameerror: undefined local variable or method `response' <rspec::core::examplegroup::nested_1::nested_9:0x007f84c58c31f0>`

how examine results of post?

my work colleague provided me answer:

for sinatra apps response in last_response not in response.

ruby-on-rails rspec

No comments:

Post a Comment