Navigation Menu

Skip to content

Commit

Permalink
Ensure #request_stubbed? works, regardless of if the uri is a string …
Browse files Browse the repository at this point in the history
…or URI.
  • Loading branch information
myronmarston committed Jun 15, 2010
1 parent 1bb664d commit c6d4a06
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/vcr/http_stubbing_adapters/webmock.rb
Expand Up @@ -44,7 +44,7 @@ def restore_stubs_checkpoint(checkpoint_name)
end

def request_stubbed?(method, uri)
!!::WebMock.registered_request?(::WebMock::RequestSignature.new(method, uri))
!!::WebMock.registered_request?(::WebMock::RequestSignature.new(method, uri.to_s))
end

def request_uri(net_http, request)
Expand Down
19 changes: 12 additions & 7 deletions spec/support/http_stubbing_adapter.rb
Expand Up @@ -74,6 +74,11 @@ def self.test_real_http_request(http_allowed)
end
end

def test_request_stubbed(method, url, expected)
subject.request_stubbed?(method, url).should == expected
subject.request_stubbed?(method, URI.parse(url)).should == expected
end

[true, false].each do |http_allowed|
context "when #http_connections_allowed is set to #{http_allowed}" do
before(:each) { subject.http_connections_allowed = http_allowed }
Expand Down Expand Up @@ -112,13 +117,13 @@ def self.test_real_http_request(http_allowed)
end

it 'returns true from #request_stubbed? for the requests that are stubbed' do
subject.request_stubbed?(:post, 'http://example.com').should be_true
subject.request_stubbed?(:get, 'http://example.com/foo').should be_true
test_request_stubbed(:post, 'http://example.com', true)
test_request_stubbed(:get, 'http://example.com/foo', true)
end

it 'returns false from #request_stubbed? for requests that are not stubbed' do
subject.request_stubbed?(:post, 'http://example.com/foo').should be_false
subject.request_stubbed?(:get, 'http://google.com').should be_false
test_request_stubbed(:post, 'http://example.com/foo', false)
test_request_stubbed(:get, 'http://google.com', false)
end

it 'gets the stubbed responses when multiple post requests are made to http://example.com' do
Expand All @@ -136,9 +141,9 @@ def self.test_real_http_request(http_allowed)
test_real_http_request(http_allowed)

it 'returns false from #request_stubbed?' do
subject.request_stubbed?(:get, 'http://example.com/foo').should be_false
subject.request_stubbed?(:post, 'http://example.com').should be_false
subject.request_stubbed?(:get, 'http://google.com').should be_false
test_request_stubbed(:get, 'http://example.com/foo', false)
test_request_stubbed(:post, 'http://example.com', false)
test_request_stubbed(:get, 'http://google.com', false)
end
end
end
Expand Down

0 comments on commit c6d4a06

Please sign in to comment.