Hi,
I am attempting to stub a get request with HTTParty, but it's not working as I would expect.
citydeal_response = HTTParty.get "/citydeal/#{citydeal_id}" #full url provided with base_uri
Later on I'm calling this response as follows:
citydeal_response.first["merchantId"]
This works when testing against live data, but in my spec tests, it fails, likely because I can only pass a string in the body of the stub_request return:
Live inspect:
#<HTTParty::Response:0x7f8ed149a450 parsed_response=[{\"merchantId\"=>119074}] ...
Live parsed response:
[{"dealId"=>119074}]
Test inspect:
#<HTTParty::Response:0x7fbd39ddbca8 parsed_response="[{\"merchantId\":856742}]" ...
Test parsed response:
[{"merchantId":856742}]
Current stub_request (not stubbing a return for the entire body because it's huge and I'm only working with this one part):
stub_request(:get, @get_citydeal_url).to_return(:status => 200, :body => [{"merchantId"=>856742}].to_json, :headers => {})
If I use to_json or wrap the body in '', I get IndexError: string not matched - which makes sense, as .first for this string is "[". If I don't include these, and pass an array, the error is NoMethodError: undefined method `strip' for [{"merchantId"=>856742}]:Array
What am I doing wrong here? Hopefully it's simple, because I'm stumped. Also, let me know if I can provide any additional detail. Thanks.