Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for :expects option in Excon adapter

  • Loading branch information...
commit 77d9c11f64f761c2ee05200a913d35311a0d327d 1 parent 2c596fa
Evgeniy Dolzhenko authored
View
9 lib/webmock/http_lib_adapters/excon_adapter.rb
@@ -87,7 +87,14 @@ def request_kernel(params, &block)
if mock_response = WebMock::StubRegistry.instance.response_for_request(mock_request)
ExconAdapter.perform_callbacks(mock_request, mock_response, :real_request => false)
- ExconAdapter.real_response(mock_response)
+ response = ExconAdapter.real_response(mock_response)
+
+ if params.has_key?(:expects) && ![*params[:expects]].include?(response.status)
+ raise(Excon::Errors.status_error(params, response))
+ else
+ response
+ end
+
elsif WebMock.net_connect_allowed?(mock_request.uri)
real_response = super
ExconAdapter.perform_callbacks(mock_request, ExconAdapter.mock_response(real_response), :real_request => true)
View
6 spec/acceptance/excon/excon_spec.rb
@@ -11,6 +11,11 @@
Excon.get('http://example.com', :path => "resource/", :query => {:a => 1, :b => 2}).body.should == "abc"
end
+ it 'should support Excon :expects options' do
+ stub_request(:get, "http://example.com/").to_return(:body => 'a')
+ lambda { Excon.get('http://example.com', :expects => 204) }.should raise_error(Excon::Errors::OK)
+ end
+
let(:file) { File.new(__FILE__) }
let(:file_contents) { File.new(__FILE__).read }
@@ -27,4 +32,3 @@
yielded_request_body.should eq(file_contents)
end
end
-
Please sign in to comment.
Something went wrong with that request. Please try again.