rspec-json_matchers 0.1.0.alpha.3 → 0.1.0.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +16 -0
  3. data/.rubocop.yml +477 -22
  4. data/.travis.yml +12 -3
  5. data/Appraisals +24 -4
  6. data/Gemfile +1 -0
  7. data/README.md +37 -20
  8. data/Rakefile +1 -0
  9. data/gemfiles/rspec_3_0.gemfile +2 -1
  10. data/gemfiles/rspec_3_1.gemfile +2 -1
  11. data/gemfiles/rspec_3_2.gemfile +2 -1
  12. data/gemfiles/rspec_3_3.gemfile +2 -1
  13. data/gemfiles/rspec_3_4.gemfile +7 -0
  14. data/gemfiles/rspec_3_5.gemfile +7 -0
  15. data/gemfiles/rspec_3_6.gemfile +7 -0
  16. data/lib/rspec/json_matchers/expectation.rb +6 -2
  17. data/lib/rspec/json_matchers/expectations/mixins/built_in.rb +84 -5
  18. data/lib/rspec/json_matchers/expectations/private.rb +4 -2
  19. data/lib/rspec/json_matchers/matchers.rb +0 -1
  20. data/lib/rspec/json_matchers/matchers/be_json_matcher.rb +0 -14
  21. data/lib/rspec/json_matchers/matchers/be_json_with_content_matcher.rb +144 -5
  22. data/lib/rspec/json_matchers/utils/key_path/extraction.rb +8 -8
  23. data/lib/rspec/json_matchers/utils/key_path/path.rb +1 -1
  24. data/lib/rspec/json_matchers/version.rb +1 -1
  25. data/rspec-json_matchers.gemspec +3 -2
  26. metadata +16 -13
  27. data/lib/rspec/json_matchers/comparers.rb +0 -13
  28. data/lib/rspec/json_matchers/comparers/abstract_comparer.rb +0 -323
  29. data/lib/rspec/json_matchers/comparers/comparison_result.rb +0 -22
  30. data/lib/rspec/json_matchers/comparers/exact_keys_comparer.rb +0 -27
  31. data/lib/rspec/json_matchers/comparers/include_keys_comparer.rb +0 -26
  32. data/lib/rspec/json_matchers/matchers/be_json_with_sizes_matcher.rb +0 -24
  33. data/lib/rspec/json_matchers/matchers/be_json_with_something_matcher.rb +0 -188
@@ -45,13 +45,13 @@ module RSpec
45
45
 
46
46
  private
47
47
 
48
- attr_accessor(*[
48
+ attr_accessor(
49
49
  :object,
50
- ])
51
- attr_reader(*[
50
+ )
51
+ attr_reader(
52
52
  :path,
53
53
  :failed,
54
- ])
54
+ )
55
55
  alias_method :failed?, :failed
56
56
 
57
57
  # @param path_part [String]
@@ -119,12 +119,12 @@ module RSpec
119
119
  Result.new(object.slice(index), true)
120
120
  end
121
121
 
122
- attr_accessor(*[
122
+ attr_accessor(
123
123
  :object,
124
- ])
125
- attr_reader(*[
124
+ )
125
+ attr_reader(
126
126
  :path_part,
127
- ])
127
+ )
128
128
  end
129
129
 
130
130
  # @api private
@@ -25,7 +25,7 @@ module RSpec
25
25
  |
26
26
  #{Regexp.escape(PATH_PART_SPLITTER)}$
27
27
  )
28
- /x.freeze
28
+ /x
29
29
 
30
30
  # Creates a {Path}
31
31
  # with a {String} (mainly from external)
@@ -5,6 +5,6 @@ module RSpec
5
5
  # The version of the gem
6
6
  # Used for generating the value in gemspec file
7
7
  # Also can be referenced by code for debugging or other purposes
8
- VERSION = "0.1.0.alpha.3"
8
+ VERSION = "0.1.0.alpha.4".freeze
9
9
  end
10
10
  end
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # rubocop:disable Style/MethodCallWithArgsParentheses
2
3
  lib = File.expand_path("../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require "rspec/json_matchers/version"
@@ -30,7 +31,7 @@ Gem::Specification.new do |spec|
30
31
  spec.add_dependency "abstract_class", "~> 1.0", ">= 1.0.1"
31
32
 
32
33
  spec.add_development_dependency "bundler", "~> 1.5"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rake", ">= 10.0", "<= 13.0"
34
35
 
35
36
  spec.add_development_dependency "appraisal", "~> 2.0"
36
37
 
@@ -43,7 +44,7 @@ Gem::Specification.new do |spec|
43
44
  spec.add_development_dependency "rubocop", "~> 0.32"
44
45
  spec.add_development_dependency "inch", "~> 0.6"
45
46
 
46
- spec.required_ruby_version = ">= 2.0.0"
47
+ spec.required_ruby_version = ">= 2.1.0"
47
48
 
48
49
  spec.required_rubygems_version = ">= 1.4.0"
49
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-json_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha.3
4
+ version: 0.1.0.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - PikachuEXE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -76,16 +76,22 @@ dependencies:
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '10.0'
82
+ - - "<="
83
+ - !ruby/object:Gem::Version
84
+ version: '13.0'
82
85
  type: :development
83
86
  prerelease: false
84
87
  version_requirements: !ruby/object:Gem::Requirement
85
88
  requirements:
86
- - - "~>"
89
+ - - ">="
87
90
  - !ruby/object:Gem::Version
88
91
  version: '10.0'
92
+ - - "<="
93
+ - !ruby/object:Gem::Version
94
+ version: '13.0'
89
95
  - !ruby/object:Gem::Dependency
90
96
  name: appraisal
91
97
  requirement: !ruby/object:Gem::Requirement
@@ -181,6 +187,7 @@ executables: []
181
187
  extensions: []
182
188
  extra_rdoc_files: []
183
189
  files:
190
+ - ".codeclimate.yml"
184
191
  - ".gitignore"
185
192
  - ".rubocop.yml"
186
193
  - ".travis.yml"
@@ -195,13 +202,11 @@ files:
195
202
  - gemfiles/rspec_3_1.gemfile
196
203
  - gemfiles/rspec_3_2.gemfile
197
204
  - gemfiles/rspec_3_3.gemfile
205
+ - gemfiles/rspec_3_4.gemfile
206
+ - gemfiles/rspec_3_5.gemfile
207
+ - gemfiles/rspec_3_6.gemfile
198
208
  - lib/rspec-json_matchers.rb
199
209
  - lib/rspec/json_matchers.rb
200
- - lib/rspec/json_matchers/comparers.rb
201
- - lib/rspec/json_matchers/comparers/abstract_comparer.rb
202
- - lib/rspec/json_matchers/comparers/comparison_result.rb
203
- - lib/rspec/json_matchers/comparers/exact_keys_comparer.rb
204
- - lib/rspec/json_matchers/comparers/include_keys_comparer.rb
205
210
  - lib/rspec/json_matchers/expectation.rb
206
211
  - lib/rspec/json_matchers/expectations.rb
207
212
  - lib/rspec/json_matchers/expectations/abstract.rb
@@ -211,8 +216,6 @@ files:
211
216
  - lib/rspec/json_matchers/matchers.rb
212
217
  - lib/rspec/json_matchers/matchers/be_json_matcher.rb
213
218
  - lib/rspec/json_matchers/matchers/be_json_with_content_matcher.rb
214
- - lib/rspec/json_matchers/matchers/be_json_with_sizes_matcher.rb
215
- - lib/rspec/json_matchers/matchers/be_json_with_something_matcher.rb
216
219
  - lib/rspec/json_matchers/utils.rb
217
220
  - lib/rspec/json_matchers/utils/collection_keys_extractor.rb
218
221
  - lib/rspec/json_matchers/utils/key_path/extraction.rb
@@ -231,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
234
  requirements:
232
235
  - - ">="
233
236
  - !ruby/object:Gem::Version
234
- version: 2.0.0
237
+ version: 2.1.0
235
238
  required_rubygems_version: !ruby/object:Gem::Requirement
236
239
  requirements:
237
240
  - - ">="
@@ -239,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
242
  version: 1.4.0
240
243
  requirements: []
241
244
  rubyforge_project:
242
- rubygems_version: 2.4.6
245
+ rubygems_version: 2.6.8
243
246
  signing_key:
244
247
  specification_version: 4
245
248
  summary: A collection of RSpec matchers for testing JSON data.
@@ -1,13 +0,0 @@
1
- require_relative "comparers/exact_keys_comparer"
2
- require_relative "comparers/include_keys_comparer"
3
-
4
- module RSpec
5
- module JsonMatchers
6
- # @api private
7
- #
8
- # All classes & modules here (including itself) are for internal use only
9
- # They could be renamed or re-structured anytime
10
- module Comparers
11
- end
12
- end
13
- end
@@ -1,323 +0,0 @@
1
- require "abstract_class"
2
- require "forwardable"
3
- require "set"
4
- require_relative "../expectation"
5
- require_relative "comparison_result"
6
-
7
- module RSpec
8
- module JsonMatchers
9
- module Comparers
10
- # @api private
11
- # @abstract
12
- #
13
- # The parent of all comparer classes
14
- # It holds most of the responsibility
15
- # The subclasses only need to implement the behaviour of matching keys
16
- # when both expected & actual are same type of collection
17
- class AbstractComparer
18
- attr_reader(*[
19
- :actual,
20
- :expected,
21
- :reasons,
22
- :value_matching_proc,
23
- ])
24
-
25
- # Creates a comparer that actually use the {value_matching_proc}
26
- # for matching {#actual} and {#expected}
27
- # This class is respossible to aggregating
28
- # the matching result for each element of {#expected},
29
- # and compare the keys/indices as well
30
- #
31
- # @param actual [Object]
32
- # the actual "thing", should be an {Enumerable}
33
- # @param expected [Object]
34
- # the expected "thing", should be an {Enumerable}
35
- # @param reasons [Array<String>]
36
- # failure reasons, mostly the path parts
37
- # @param value_matching_proc [Proc]
38
- # the proc that actually compares
39
- # the expected & actual and returns a boolean
40
- def initialize(actual, expected, reasons, value_matching_proc)
41
- @actual = actual
42
- @expected = expected
43
- @reasons = reasons
44
-
45
- @value_matching_proc = value_matching_proc
46
- end
47
-
48
- # @return [Boolean]
49
- # `true` if #actual & #expected are the same
50
- def compare
51
- return ComparisonResult.new(true, reasons) if has_matched_value?
52
-
53
- has_matched_collection?
54
- end
55
-
56
- private
57
-
58
- def has_matched_value?
59
- value_matching_proc.call(expected, actual)
60
- end
61
-
62
- def has_matched_collection?
63
- return ComparisonResult.new(false, reasons) unless is_collection?
64
- return ComparisonResult.new(false, reasons) unless has_matched_class?
65
- return ComparisonResult.new(false, reasons) unless has_matched_keys?
66
-
67
- ComparisonResult.new(has_matched_values?, reasons)
68
- end
69
-
70
- def is_collection?
71
- actual.is_a?(Array) || actual.is_a?(Hash)
72
- end
73
-
74
- def has_matched_class?
75
- actual.class == expected.class
76
- end
77
-
78
- # @note with side effect on `#reasons`
79
- def has_matched_keys?
80
- fail NotImplementedError
81
- end
82
-
83
- # @note with side effect on `#reasons`
84
- def has_matched_values?
85
- comparison_result = EXPECTED_VALUE_CLASS_TO_EXPECTATION_MAPPING.
86
- fetch(expected.class).
87
- new(self).
88
- comparison_result
89
-
90
- comparison_result.matched?.tap do |matched|
91
- @reasons = comparison_result.reasons unless matched
92
- end
93
- end
94
-
95
- def actual_keys
96
- @actual_keys ||= Utils::CollectionKeysExtractor.extract(actual)
97
- end
98
-
99
- def expected_keys
100
- @expected_keys ||= Utils::CollectionKeysExtractor.extract(expected)
101
- end
102
-
103
- # Represents an "expectation" for matching all elements
104
- # in {#actual} & {#expected}
105
- class HasMatchedValues
106
- extend AbstractClass
107
- extend Forwardable
108
-
109
- public
110
-
111
- # Create a "matching" operation object
112
- # that can return a {Comparers::ComparisonResult}
113
- #
114
- # @param comparer [AbstractComparer]
115
- # the comparer that creates this object, for fetching values
116
- def initialize(comparer)
117
- @comparer = comparer
118
- end
119
-
120
- def comparison_result
121
- each_element_enumerator.each do |element|
122
- result = comparison_result_for_element(element)
123
-
124
- return result unless result.matched?
125
- end
126
-
127
- Comparers::ComparisonResult.new(true, reasons)
128
- end
129
-
130
- def each_element_enumerator
131
- fail NotImplementedError
132
- end
133
-
134
- def has_matched_value_class
135
- fail NotImplementedError
136
- end
137
-
138
- private
139
-
140
- def_delegators(*[
141
- :comparer,
142
- :expected,
143
- :reasons,
144
- ])
145
-
146
- attr_reader(*[
147
- :comparer,
148
- ])
149
-
150
- def comparer_class
151
- comparer.class
152
- end
153
-
154
- def comparison_result_for_element(element)
155
- has_matched_value_class.
156
- new(
157
- element,
158
- comparer,
159
- ).comparison_result
160
- end
161
-
162
- # Represents an "expectation" for matching one element
163
- # in {#actual} & {#expected}
164
- class HasMatchedValue
165
- extend AbstractClass
166
- extend Forwardable
167
-
168
- public
169
-
170
- # Create a "matching" operation object
171
- # that can return a {Comparers::ComparisonResult}
172
- # Unlike {HasMatchedValues}, this is for an element of `expected`
173
- #
174
- # @param element [Integer, String, Symbol]
175
- # a index/key from expected (not value)
176
- # @param (see HasMatchedValues#initialize)
177
- def initialize(element, comparer)
178
- @element = element
179
- @comparer = comparer
180
- end
181
-
182
- def comparison_result
183
- return false unless actual_contain_element?
184
-
185
- result.tap do |result|
186
- next if result.matched?
187
- result.reasons.push(reason)
188
- end
189
- end
190
-
191
- private
192
-
193
- attr_reader(*[
194
- :element,
195
- :comparer,
196
- ])
197
-
198
- def_delegators(*[
199
- :comparer,
200
- :expected,
201
- :actual,
202
- :reasons,
203
- :value_matching_proc,
204
- ])
205
-
206
- def comparer_class
207
- comparer.class
208
- end
209
-
210
- def result
211
- @result ||= comparer_class.
212
- new(
213
- actual_for_element,
214
- expected_for_element,
215
- reasons,
216
- value_matching_proc,
217
- ).
218
- compare
219
- end
220
-
221
- def actual_contain_element?
222
- fail NotImplementedError
223
- end
224
-
225
- def actual_for_element
226
- fail NotImplementedError
227
- end
228
-
229
- def expected_for_element
230
- fail NotImplementedError
231
- end
232
-
233
- def reason
234
- fail NotImplementedError
235
- end
236
- end
237
- end
238
-
239
- # (see HasMatchedValues)
240
- # {#expected} should be {Array}
241
- class HasMatchedArrayValues < HasMatchedValues
242
- def each_element_enumerator
243
- expected.each_index
244
- end
245
-
246
- def has_matched_value_class
247
- HasMatchedArrayValue
248
- end
249
-
250
- # (see HasMatchedValues::HasMatchedValue)
251
- # {#expected} should be {Array}
252
- class HasMatchedArrayValue < HasMatchedValues::HasMatchedValue
253
- private
254
-
255
- alias_method :index, :element
256
-
257
- public
258
-
259
- def actual_contain_element?
260
- index < actual.size
261
- end
262
-
263
- def actual_for_element
264
- actual[index]
265
- end
266
-
267
- def expected_for_element
268
- expected[index]
269
- end
270
-
271
- def reason
272
- "[#{index}]"
273
- end
274
- end
275
- end
276
-
277
- # (see HasMatchedValues)
278
- # {#expected} should be {Hash}
279
- class HasMatchedHashValues < HasMatchedValues
280
- def each_element_enumerator
281
- expected.each_key
282
- end
283
-
284
- def has_matched_value_class
285
- HasMatchedHashValue
286
- end
287
-
288
- # (see HasMatchedValues::HasMatchedValue)
289
- # {#expected} should be {Array}
290
- class HasMatchedHashValue < HasMatchedValues::HasMatchedValue
291
- private
292
-
293
- alias_method :key, :element
294
-
295
- public
296
-
297
- def actual_contain_element?
298
- actual.key?(key.to_s)
299
- end
300
-
301
- def actual_for_element
302
- actual[key.to_s]
303
- end
304
-
305
- def expected_for_element
306
- expected[key]
307
- end
308
-
309
- def reason
310
- key
311
- end
312
- end
313
- end
314
-
315
- EXPECTED_VALUE_CLASS_TO_EXPECTATION_MAPPING = {
316
- Array => HasMatchedArrayValues,
317
- Hash => HasMatchedHashValues,
318
- }.freeze
319
- private_constant :EXPECTED_VALUE_CLASS_TO_EXPECTATION_MAPPING
320
- end
321
- end
322
- end
323
- end