Browse files

Add `parsed_uri` convenience method to request

  • Loading branch information...
1 parent 7baf5f0 commit 0aba90db2454641f8a016e72766af11c21d19b99 @rhburrows rhburrows committed with Sep 25, 2012
View
2 lib/vcr/request_ignorer.rb
@@ -13,7 +13,7 @@ class RequestIgnorer
def initialize
ignore_request do |request|
- host = VCR.configuration.uri_parser.parse(request.uri).host
+ host = request.parsed_uri.host
ignored_hosts.include?(host)
end
end
View
10 lib/vcr/request_matcher_registry.rb
@@ -18,7 +18,7 @@ def matches?(request_1, request_2)
# @private
class URIWithoutParamsMatcher < Struct.new(:params_to_ignore)
def partial_uri_from(request)
- VCR.configuration.uri_parser.parse(request.uri).tap do |uri|
+ request.parsed_uri.tap do |uri|
return request.uri unless uri.query # ignore uris without params, e.g. "http://example.com/"
uri.query = uri.query.split('&').tap { |params|
@@ -113,16 +113,12 @@ def register_built_ins
register(:headers) { |r1, r2| r1.headers == r2.headers }
register(:host) do |r1, r2|
- uri_parser.parse(r1.uri).host == uri_parser.parse(r2.uri).host
+ r1.parsed_uri.host == r2.parsed_uri.host
end
register(:path) do |r1, r2|
- uri_parser.parse(r1.uri).path == uri_parser.parse(r2.uri).path
+ r1.parsed_uri.path == r2.parsed_uri.path
end
end
-
- def uri_parser
- VCR.configuration.uri_parser
- end
end
end
View
6 lib/vcr/structs.rb
@@ -231,6 +231,10 @@ def self.from_hash(hash)
:skip_port_stripping
end
+ def parsed_uri
+ VCR.configuration.uri_parser.parse(uri)
+ end
+
@@object_method = Object.instance_method(:method)
def method(*args)
return super if args.empty?
@@ -321,7 +325,7 @@ def to_proc
def without_standard_port(uri)
return uri if uri.nil?
- u = VCR.configuration.uri_parser.parse(uri)
+ u = parsed_uri
return uri unless [['http', 80], ['https', 443]].include?([u.scheme, u.port])
u.port = nil
u.to_s
View
4 spec/vcr/configuration_spec.rb
@@ -102,10 +102,12 @@
end
describe '#ignore_request' do
+ let(:uri){ URI('http://foo.com') }
+
it 'registers the given block with the request ignorer' do
block_called = false
subject.ignore_request { |r| block_called = true }
- VCR.request_ignorer.ignore?(stub(:uri => 'http://foo.com/'))
+ VCR.request_ignorer.ignore?(stub(:parsed_uri => uri))
block_called.should be_true
end
end
View
19 spec/vcr/structs_spec.rb
@@ -290,6 +290,25 @@ def assert_yielded_keys(hash, *keys)
assert_yielded_keys hash['response']['status'], 'code', 'message'
end
end
+
+ describe "#parsed_uri" do
+ before :each do
+ uri_parser.stub(:parse).and_return(uri)
+ VCR.stub_chain(:configuration, :uri_parser).and_return(uri_parser)
+ end
+
+ let(:uri_parser){ mock('parser') }
+ let(:uri){ mock('uri').as_null_object }
+
+ it "parses the uri using the current uri_parser" do
+ uri_parser.should_receive(:parse).with(request.uri)
+ request.parsed_uri
+ end
+
+ it "returns the parsed uri" do
+ request.parsed_uri.should == uri
+ end
+ end
end
describe HTTPInteraction::HookAware do

0 comments on commit 0aba90d

Please sign in to comment.