class VCR::RequestMatcherRegistry
Keeps track of the different request matchers.
Constants
- DEFAULT_MATCHERS
The default request matchers used for any cassette that does not specify request matchers.
Public Class Methods
new()
click to toggle source
@private
# File lib/vcr/request_matcher_registry.rb, line 47 def initialize @registry = {} register_built_ins end
Public Instance Methods
[](matcher)
click to toggle source
@private
# File lib/vcr/request_matcher_registry.rb, line 62 def [](matcher) @registry.fetch(matcher) do matcher.respond_to?(:call) ? Matcher.new(matcher) : raise_unregistered_matcher_error(matcher) end end
register(name, &block)
click to toggle source
@private
# File lib/vcr/request_matcher_registry.rb, line 53 def register(name, &block) if @registry.has_key?(name) warn "WARNING: There is already a VCR request matcher registered for #{name.inspect}. Overriding it." end @registry[name] = Matcher.new(block) end
uri_without_params(*ignores)
click to toggle source
Builds a dynamic request matcher that matches on a URI while ignoring the named query parameters. This is useful for dealing with non-deterministic URIs (i.e. that have a timestamp or request signature parameter).
@example
without_timestamp = VCR.request_matchers.uri_without_param(:timestamp) # use it directly... VCR.use_cassette('example', :match_requests_on => [:method, without_timestamp]) { } # ...or register it as a named matcher VCR.configure do |c| c.register_request_matcher(:uri_without_timestamp, &without_timestamp) end VCR.use_cassette('example', :match_requests_on => [:method, :uri_without_timestamp]) { }
@param ignores [Array<#to_s>] The names of the query parameters to ignore @return [#call] the request matcher
# File lib/vcr/request_matcher_registry.rb, line 89 def uri_without_params(*ignores) uri_without_param_matchers[ignores] end
Also aliased as: uri_without_param
Private Instance Methods
raise_unregistered_matcher_error(name)
click to toggle source
# File lib/vcr/request_matcher_registry.rb, line 103 def raise_unregistered_matcher_error(name) raise Errors::UnregisteredMatcherError.new "There is no matcher registered for #{name.inspect}. " + "Did you mean one of #{@registry.keys.map(&:inspect).join(', ')}?" end
register_built_ins()
click to toggle source
# File lib/vcr/request_matcher_registry.rb, line 109 def register_built_ins register(:method) { |r1, r2| r1.method == r2.method } register(:uri) { |r1, r2| r1.uri == r2.uri } register(:body) { |r1, r2| r1.body == r2.body } register(:headers) { |r1, r2| r1.headers == r2.headers } register(:host) do |r1, r2| r1.parsed_uri.host == r2.parsed_uri.host end register(:path) do |r1, r2| r1.parsed_uri.path == r2.parsed_uri.path end end
uri_without_param_matchers()
click to toggle source
# File lib/vcr/request_matcher_registry.rb, line 96 def uri_without_param_matchers @uri_without_param_matchers ||= Hash.new do |hash, params| params = params.map(&:to_s) hash[params] = URIWithoutParamsMatcher.new(params) end end