Class: WebMock::URIStringPattern

Inherits:
URIPattern show all
Defined in:
lib/webmock/request_pattern.rb

Instance Method Summary collapse

Methods inherited from URIPattern

#initialize

Methods included from RSpecMatcherDetector

#rSpecHashExcludingMatcher?, #rSpecHashIncludingMatcher?

Constructor Details

This class inherits a constructor from WebMock::URIPattern

Instance Method Details

#add_query_params(query_params) ⇒ Object



204
205
206
207
208
209
210
211
# File 'lib/webmock/request_pattern.rb', line 204

def add_query_params(query_params)
  super
  if @query_params.is_a?(Hash) || @query_params.is_a?(String)
    query_hash = (WebMock::Util::QueryMapper.query_to_values(@pattern.query, notation: Config.instance.query_values_notation) || {}).merge(@query_params)
    @pattern.query = WebMock::Util::QueryMapper.values_to_query(query_hash, notation: WebMock::Config.instance.query_values_notation)
    @query_params = nil
  end
end

#matches?(uri) ⇒ Boolean

Returns:

  • (Boolean)


191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/webmock/request_pattern.rb', line 191

def matches?(uri)
  if @pattern.is_a?(Addressable::URI)
    if @query_params
      uri.omit(:query) === @pattern &&
      (@query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation))
    else
      uri === @pattern
    end
  else
    false
  end
end

#to_sObject



213
214
215
216
217
# File 'lib/webmock/request_pattern.rb', line 213

def to_s
  str = WebMock::Util::URI.strip_default_port_from_uri_string(@pattern.to_s)
  str += " with query params #{@query_params.inspect}" if @query_params
  str
end