Class: WebMock::URIPattern
Instance Method Summary
collapse
#rSpecHashExcludingMatcher?, #rSpecHashIncludingMatcher?
Constructor Details
#initialize(pattern) ⇒ URIPattern
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/webmock/request_pattern.rb', line 111
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
|
Instance Method Details
#add_query_params(query_params) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/webmock/request_pattern.rb', line 123
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) ⇒ Boolean
138
139
140
|
# File 'lib/webmock/request_pattern.rb', line 138
def matches?(uri)
pattern_matches?(uri) && query_params_matches?(uri)
end
|
#to_s ⇒ Object
142
143
144
145
146
|
# File 'lib/webmock/request_pattern.rb', line 142
def to_s
str = pattern_inspect
str += " with query params #{@query_params.inspect}" if @query_params
str
end
|