class WebMock::URIPattern

Public Class Methods

new(pattern) click to toggle source
# File lib/webmock/request_pattern.rb, line 113
def initialize(pattern)
  @pattern = if pattern.is_a?(Addressable::URI) \
                || pattern.is_a?(Addressable::Template)
    pattern
  elsif pattern.respond_to?(:call)
    pattern
  else
    WebMock::Util::URI.normalize_uri(pattern)
  end
  @query_params = nil
end

Public Instance Methods

add_query_params(query_params) click to toggle source
# File lib/webmock/request_pattern.rb, line 125
def add_query_params(query_params)
  @query_params = if query_params.is_a?(Hash)
    query_params
  elsif query_params.is_a?(WebMock::Matchers::HashIncludingMatcher) \
          || query_params.is_a?(WebMock::Matchers::HashExcludingMatcher)
    query_params
  elsif rSpecHashIncludingMatcher?(query_params)
    WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(query_params)
  elsif rSpecHashExcludingMatcher?(query_params)
    WebMock::Matchers::HashExcludingMatcher.from_rspec_matcher(query_params)
  else
    WebMock::Util::QueryMapper.query_to_values(query_params, notation: Config.instance.query_values_notation)
  end
end
matches?(uri) click to toggle source
# File lib/webmock/request_pattern.rb, line 140
def matches?(uri)
  pattern_matches?(uri) && query_params_matches?(uri)
end
to_s() click to toggle source
# File lib/webmock/request_pattern.rb, line 144
def to_s
  str = pattern_inspect
  str += " with query params #{@query_params.inspect}" if @query_params
  str
end

Private Instance Methods

pattern_inspect() click to toggle source
# File lib/webmock/request_pattern.rb, line 152
def pattern_inspect
  @pattern.inspect
end
query_params_matches?(uri) click to toggle source
# File lib/webmock/request_pattern.rb, line 156
def query_params_matches?(uri)
  @query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation)
end