Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix excon adapter so that it records a response even when excon raise…

…s an error due to an unexpected response.

Closes #77.
  • Loading branch information...
commit ca1e54a6a29ae684ee6510e0b4f02236b2134eb4 1 parent 00f50c2
@myronmarston authored
View
2  CHANGELOG.md
@@ -6,6 +6,8 @@
* Fix excon adapter to properly handle queries specified as a hash.
* Fix excon adapter to stub a response with a hash as excon expects
[Wesley Beary](https://github.com/geemus).
+* Fix excon adapter so that it records a response even when excon raises
+ an error due to an unexpected response.
## 1.10.0 (May 18, 2011)
View
18 lib/vcr/http_stubbing_adapters/excon.rb
@@ -134,9 +134,25 @@ def http_connections_allowed?
VCR::HttpStubbingAdapters::Excon.http_connections_allowed?
end
+ def response_from_excon_error(error)
+ if error.respond_to?(:response)
+ error.response
+ elsif error.respond_to?(:socket_error)
+ response_from_excon_error(error.socket_error)
+ else
+ warn "WARNING: VCR could not extract a response from Excon error (#{error.inspect})"
+ end
+ end
+
def perform_real_request
connection = ::Excon.new(uri)
- response = connection.request(params.merge(:mock => false))
+
+ response = begin
+ connection.request(params.merge(:mock => false))
+ rescue ::Excon::Errors::Error => e
+ yield response_from_excon_error(e) if block_given?
+ raise e
+ end
yield response if block_given?
View
14 spec/vcr/http_stubbing_adapters/excon_spec.rb
@@ -55,5 +55,19 @@
recorded.should == "FOO!"
end
end
+
+ context 'when Excon raises an error due to an unexpected response status' do
+ it 'still records properly' do
+ described_class.http_connections_allowed = true
+
+ VCR.should_receive(:record_http_interaction) do |interaction|
+ interaction.response.status.code.should == 404
+ end
+
+ expect {
+ Excon.get("http://localhost:#{VCR::SinatraApp.port}/not_found", :expects => 200)
+ }.to raise_error(Excon::Errors::Error)
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.