webmock 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +8 -0
- data/README.md +3 -0
- data/lib/webmock/api.rb +2 -0
- data/lib/webmock/request_pattern.rb +68 -66
- data/lib/webmock/version.rb +1 -1
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.8.2
|
4
|
+
|
5
|
+
* Prevent Webmock `hash_including` from overriding RSpec version 1 `hash_including` method.
|
6
|
+
|
7
|
+
Thanks to [Joe Karayusuf](https://github.com/karayusuf)
|
8
|
+
|
9
|
+
* Ensured WebMock handles RSpec 1 `hash_including` matcher for matching query params and body.
|
10
|
+
|
3
11
|
## 1.8.1
|
4
12
|
|
5
13
|
* Ensured WebMock doesn't interfere with `em-synchrony`, when `em-synchrony/em-http` is not included.
|
data/README.md
CHANGED
@@ -697,6 +697,9 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
697
697
|
* Dimitrij Denissenko
|
698
698
|
* Marnen Laibow-Koser
|
699
699
|
* Evgeniy Dolzhenko
|
700
|
+
* Nick Recobra
|
701
|
+
* Jordan Elver
|
702
|
+
* Joe Karayusuf
|
700
703
|
|
701
704
|
For a full list of contributors you can visit the
|
702
705
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
data/lib/webmock/api.rb
CHANGED
@@ -35,6 +35,8 @@ module WebMock
|
|
35
35
|
def hash_including(expected)
|
36
36
|
if defined?(::RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)
|
37
37
|
RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new(expected)
|
38
|
+
elsif defined?(::Spec::Mocks::ArgumentMatchers::HashIncludingMatcher)
|
39
|
+
Spec::Mocks::ArgumentMatchers::HashIncludingMatcher.new(expected)
|
38
40
|
else
|
39
41
|
WebMock::Matchers::HashIncludingMatcher.new(expected)
|
40
42
|
end
|
@@ -40,19 +40,19 @@ module WebMock
|
|
40
40
|
private
|
41
41
|
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
def assign_options(options)
|
44
|
+
@body_pattern = BodyPattern.new(options[:body]) if options.has_key?(:body)
|
45
|
+
@headers_pattern = HeadersPattern.new(options[:headers]) if options.has_key?(:headers)
|
46
|
+
@uri_pattern.add_query_params(options[:query]) if options.has_key?(:query)
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
49
|
+
def create_uri_pattern(uri)
|
50
|
+
if uri.is_a?(Regexp)
|
51
|
+
URIRegexpPattern.new(uri)
|
52
|
+
else
|
53
|
+
URIStringPattern.new(uri)
|
55
54
|
end
|
55
|
+
end
|
56
56
|
|
57
57
|
end
|
58
58
|
|
@@ -82,7 +82,8 @@ module WebMock
|
|
82
82
|
query_params
|
83
83
|
elsif query_params.is_a?(WebMock::Matchers::HashIncludingMatcher)
|
84
84
|
query_params
|
85
|
-
elsif defined?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher) && query_params.is_a?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)
|
85
|
+
elsif (defined?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher) && query_params.is_a?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)) ||
|
86
|
+
(defined?(Spec::Mocks::ArgumentMatchers::HashIncludingMatcher) && query_params.is_a?(Spec::Mocks::ArgumentMatchers::HashIncludingMatcher))
|
86
87
|
WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(query_params)
|
87
88
|
else
|
88
89
|
Addressable::URI.parse('?' + query_params).query_values
|
@@ -161,7 +162,8 @@ module WebMock
|
|
161
162
|
def initialize(pattern)
|
162
163
|
@pattern = if pattern.is_a?(Hash)
|
163
164
|
normalize_hash(pattern)
|
164
|
-
elsif defined?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher) && pattern.is_a?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)
|
165
|
+
elsif (defined?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher) && pattern.is_a?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)) ||
|
166
|
+
(defined?(Spec::Mocks::ArgumentMatchers::HashIncludingMatcher) && pattern.is_a?(Spec::Mocks::ArgumentMatchers::HashIncludingMatcher))
|
165
167
|
WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(pattern)
|
166
168
|
else
|
167
169
|
pattern
|
@@ -186,62 +188,62 @@ module WebMock
|
|
186
188
|
end
|
187
189
|
|
188
190
|
private
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
end
|
191
|
+
def body_as_hash(body, content_type)
|
192
|
+
case BODY_FORMATS[content_type]
|
193
|
+
when :json then
|
194
|
+
WebMock::Util::JSON.parse(body)
|
195
|
+
when :xml then
|
196
|
+
Crack::XML.parse(body)
|
197
|
+
else
|
198
|
+
Addressable::URI.parse('?' + body).query_values
|
198
199
|
end
|
200
|
+
end
|
199
201
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
end
|
202
|
+
# Compare two hashes for equality
|
203
|
+
#
|
204
|
+
# For two hashes to match they must have the same length and all
|
205
|
+
# values must match when compared using `#===`.
|
206
|
+
#
|
207
|
+
# The following hashes are examples of matches:
|
208
|
+
#
|
209
|
+
# {a: /\d+/} and {a: '123'}
|
210
|
+
#
|
211
|
+
# {a: '123'} and {a: '123'}
|
212
|
+
#
|
213
|
+
# {a: {b: /\d+/}} and {a: {b: '123'}}
|
214
|
+
#
|
215
|
+
# {a: {b: 'wow'}} and {a: {b: 'wow'}}
|
216
|
+
#
|
217
|
+
# @param [Hash] query_parameters typically the result of parsing
|
218
|
+
# JSON, XML or URL encoded parameters.
|
219
|
+
#
|
220
|
+
# @param [Hash] pattern which contains keys with a string, hash or
|
221
|
+
# regular expression value to use for comparison.
|
222
|
+
#
|
223
|
+
# @return [Boolean] true if the paramaters match the comparison
|
224
|
+
# hash, false if not.
|
225
|
+
def matching_hashes?(query_parameters, pattern)
|
226
|
+
return false unless query_parameters.is_a?(Hash)
|
227
|
+
return false unless query_parameters.keys.sort == pattern.keys.sort
|
228
|
+
query_parameters.each do |key, actual|
|
229
|
+
expected = pattern[key]
|
230
|
+
|
231
|
+
if actual.is_a?(Hash) && expected.is_a?(Hash)
|
232
|
+
return false unless matching_hashes?(actual, expected)
|
233
|
+
else
|
234
|
+
return false unless expected === actual
|
234
235
|
end
|
235
|
-
true
|
236
236
|
end
|
237
|
+
true
|
238
|
+
end
|
237
239
|
|
238
|
-
|
239
|
-
|
240
|
-
|
240
|
+
def empty_string?(string)
|
241
|
+
string.nil? || string == ""
|
242
|
+
end
|
241
243
|
|
242
|
-
|
243
|
-
|
244
|
-
|
244
|
+
def normalize_hash(hash)
|
245
|
+
Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(hash).sort]
|
246
|
+
end
|
245
247
|
|
246
248
|
end
|
247
249
|
|
@@ -268,9 +270,9 @@ module WebMock
|
|
268
270
|
|
269
271
|
private
|
270
272
|
|
271
|
-
|
272
|
-
|
273
|
-
|
273
|
+
def empty_headers?(headers)
|
274
|
+
headers.nil? || headers == {}
|
275
|
+
end
|
274
276
|
end
|
275
277
|
|
276
278
|
end
|
data/lib/webmock/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 1.8.
|
9
|
+
- 2
|
10
|
+
version: 1.8.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bartosz Blimke
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03-
|
18
|
+
date: 2012-03-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: addressable
|