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

#rSpecHashIncludingMatcher?

Constructor Details

This class inherits a constructor from WebMock::URIPattern

Instance Method Details

#add_query_params(query_params) ⇒ Object



185
186
187
188
189
190
191
192
# File 'lib/webmock/request_pattern.rb', line 185

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)


172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/webmock/request_pattern.rb', line 172

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



194
195
196
197
198
# File 'lib/webmock/request_pattern.rb', line 194

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