Run an HTTP request to return an HTTPartyResponse using Net :: HTTPResponse

I am trying to write the rspec specification to verify that my logic can handle a specific Net :: HTTPResponse that has a 401 status code. Since I use HTTParty, .get will return me HTTPartyResponse, ll get Net :: HTTPResponse with 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) 
+6
source share
2 answers

I realized that this is the right way

 it 'will test this' do stub_request(:any, /hello.com/).to_return(:status => [401, "Forbidden"]) ... end 

HTTParty should parse the HTTP push response and return an HTTPartyResponse to me.

+4
source

You can use Webmock , which supports mocking HTTParty requests.

+4
source

Source: https://habr.com/ru/post/918889/


All Articles