2012-06-24 15 views
6

Sto provando a scrivere una specifica rspec per verificare che la mia logica sia in grado di gestire un particolare Net :: HTTPResponse che ha il codice di stato 401. Come io ' m usando HTTParty, .get mi restituirà un HTTPartyResponse e recupererò Net :: HTTPResponse con httparty_repsonse_object.response.Stub una richiesta http per restituire una HTTPartyResponse con una Net :: HTTPResponse

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) 

risposta

4

ho capito questo è il modo corretto

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

HTTParty è supposto per analizzare la risposta http schernito e mi ha restituito un HTTPartyResponse.

4

È possibile utilizzare Webmock, che supporta le richieste HTTParty fittizie.

Problemi correlati