2012-06-24 11 views
6

私のロジックがステータスコード401を持つ特定のNet :: HTTPResponseを処理できることをテストするためにrspec仕様を書こうとしています。 HTTPartyを使用して、.getは私にHTTPartyResponseを返し、私はhttperty_repsonse_object.responseでNet :: HTTPResponseを取得します。Net :: HTTPResponseを使用してHTTPartyResponseを返すHTTPリクエストをスタブします

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) 

答えて

4

私はこれが正しい方法

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

HTTPartyです考え出しは嘲笑HTTPレスポンスを解析してくれHTTPartyResponseを返すことになっています。

4

あなたはHTTParty要求をあざけるサポートする、Webmockを使用することができます。

関連する問題