webmock 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.
@@ -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
- 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
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
- def create_uri_pattern(uri)
50
- if uri.is_a?(Regexp)
51
- URIRegexpPattern.new(uri)
52
- else
53
- URIStringPattern.new(uri)
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
- def body_as_hash(body, content_type)
190
- case BODY_FORMATS[content_type]
191
- when :json then
192
- WebMock::Util::JSON.parse(body)
193
- when :xml then
194
- Crack::XML.parse(body)
195
- else
196
- Addressable::URI.parse('?' + body).query_values
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
- # Compare two hashes for equality
201
- #
202
- # For two hashes to match they must have the same length and all
203
- # values must match when compared using `#===`.
204
- #
205
- # The following hashes are examples of matches:
206
- #
207
- # {a: /\d+/} and {a: '123'}
208
- #
209
- # {a: '123'} and {a: '123'}
210
- #
211
- # {a: {b: /\d+/}} and {a: {b: '123'}}
212
- #
213
- # {a: {b: 'wow'}} and {a: {b: 'wow'}}
214
- #
215
- # @param [Hash] query_parameters typically the result of parsing
216
- # JSON, XML or URL encoded parameters.
217
- #
218
- # @param [Hash] pattern which contains keys with a string, hash or
219
- # regular expression value to use for comparison.
220
- #
221
- # @return [Boolean] true if the paramaters match the comparison
222
- # hash, false if not.
223
- def matching_hashes?(query_parameters, pattern)
224
- return false unless query_parameters.is_a?(Hash)
225
- return false unless query_parameters.keys.sort == pattern.keys.sort
226
- query_parameters.each do |key, actual|
227
- expected = pattern[key]
228
-
229
- if actual.is_a?(Hash) && expected.is_a?(Hash)
230
- return false unless matching_hashes?(actual, expected)
231
- else
232
- return false unless expected === actual
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
- def empty_string?(string)
239
- string.nil? || string == ""
240
- end
240
+ def empty_string?(string)
241
+ string.nil? || string == ""
242
+ end
241
243
 
242
- def normalize_hash(hash)
243
- Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(hash).sort]
244
- end
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
- def empty_headers?(headers)
272
- headers.nil? || headers == {}
273
- end
273
+ def empty_headers?(headers)
274
+ headers.nil? || headers == {}
275
+ end
274
276
  end
275
277
 
276
278
  end
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '1.8.1' unless defined?(::WebMock::VERSION)
2
+ VERSION = '1.8.2' unless defined?(::WebMock::VERSION)
3
3
  end
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: 53
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 8
9
- - 1
10
- version: 1.8.1
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-05 00:00:00 Z
18
+ date: 2012-03-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: addressable