I'm trying to write a rspec spec to test that my logic is able to handle a particular Net::HTTPResponse that has status code 401. As I'm using HTTParty, .get will return me a HTTPartyResponse and I'll retrieve the Net::HTTPResponse with the httparty_repsonse_object.response.
net_response_object = Net::HTTPResponse.new(1.1, 401, 'Forbidden')
#not sure what to do here? write a test double to return a net_response_object?
stub_request(:any, /hello.com/).to_return(a_http_party_response_object)
I figured out this is the correct way
it 'will test this' do
stub_request(:any, /hello.com/).to_return(:status => [401, "Forbidden"])
...
end
HTTParty is supposed to parse the mocked http response and return me a HTTPartyResponse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With