rspec-json_matchers 0.1.0.alpha.1 → 0.1.0.alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.rubocop.yml +31 -0
- data/Gemfile +1 -1
- data/README.md +36 -0
- data/Rakefile +1 -1
- data/doc/Story.md +129 -0
- data/lib/rspec-json_matchers.rb +1 -1
- data/lib/rspec/json_matchers/comparers/abstract_comparer.rb +111 -77
- data/lib/rspec/json_matchers/comparers/comparison_result.rb +1 -1
- data/lib/rspec/json_matchers/comparers/exact_keys_comparer.rb +6 -6
- data/lib/rspec/json_matchers/comparers/include_keys_comparer.rb +5 -6
- data/lib/rspec/json_matchers/expectation.rb +81 -31
- data/lib/rspec/json_matchers/expectations/abstract.rb +4 -3
- data/lib/rspec/json_matchers/expectations/core.rb +12 -8
- data/lib/rspec/json_matchers/expectations/mixins/built_in.rb +25 -13
- data/lib/rspec/json_matchers/expectations/private.rb +40 -33
- data/lib/rspec/json_matchers/matchers.rb +3 -3
- data/lib/rspec/json_matchers/matchers/be_json_matcher.rb +16 -6
- data/lib/rspec/json_matchers/matchers/be_json_with_sizes_matcher.rb +4 -1
- data/lib/rspec/json_matchers/matchers/be_json_with_something_matcher.rb +51 -37
- data/lib/rspec/json_matchers/utils/collection_keys_extractor.rb +4 -3
- data/lib/rspec/json_matchers/utils/key_path/extraction.rb +149 -0
- data/lib/rspec/json_matchers/utils/key_path/path.rb +18 -12
- data/lib/rspec/json_matchers/version.rb +3 -1
- data/rspec-json_matchers.gemspec +7 -5
- metadata +7 -5
- data/lib/rspec/json_matchers/utils/key_path/extraction_result.rb +0 -22
- data/lib/rspec/json_matchers/utils/key_path/extractor.rb +0 -70
@@ -1,8 +1,10 @@
|
|
1
1
|
module RSpec
|
2
|
+
# The actual namespace for this gem
|
3
|
+
# All other classes/modules are defined within this module
|
2
4
|
module JsonMatchers
|
3
5
|
# The version of the gem
|
4
6
|
# Used for generating the value in gemspec file
|
5
7
|
# Also can be referenced by code for debugging or other purposes
|
6
|
-
VERSION = "0.1.0.alpha.
|
8
|
+
VERSION = "0.1.0.alpha.2"
|
7
9
|
end
|
8
10
|
end
|
data/rspec-json_matchers.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "rspec/json_matchers/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "rspec-json_matchers"
|
@@ -9,16 +9,18 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["PikachuEXE"]
|
10
10
|
spec.email = ["pikachuexe@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary =
|
12
|
+
spec.summary = "A collection of RSpec matchers for testing JSON data."
|
13
13
|
spec.description = <<-DESC
|
14
14
|
This gem provides a collection of RSpec matchers for testing JSON data.
|
15
|
-
It aims to make JSON testing flexible & easier,
|
15
|
+
It aims to make JSON testing flexible & easier,
|
16
|
+
especially for testing multiple properties.
|
16
17
|
It does not and will not have anything related to JSON Schema.
|
17
18
|
DESC
|
18
19
|
spec.homepage = "https://github.com/PikachuEXE/rspec-json_matchers"
|
19
20
|
spec.license = "MIT"
|
20
21
|
|
21
|
-
spec.files = `git ls-files -z`.split("\x0").
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").
|
23
|
+
reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
24
|
spec.bindir = "exe"
|
23
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
26
|
spec.require_paths = ["lib"]
|
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.
|
4
|
+
version: 0.1.0.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PikachuEXE
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -172,7 +172,8 @@ dependencies:
|
|
172
172
|
version: '0.6'
|
173
173
|
description: |2
|
174
174
|
This gem provides a collection of RSpec matchers for testing JSON data.
|
175
|
-
It aims to make JSON testing flexible & easier,
|
175
|
+
It aims to make JSON testing flexible & easier,
|
176
|
+
especially for testing multiple properties.
|
176
177
|
It does not and will not have anything related to JSON Schema.
|
177
178
|
email:
|
178
179
|
- pikachuexe@gmail.com
|
@@ -181,6 +182,7 @@ extensions: []
|
|
181
182
|
extra_rdoc_files: []
|
182
183
|
files:
|
183
184
|
- ".gitignore"
|
185
|
+
- ".rubocop.yml"
|
184
186
|
- ".travis.yml"
|
185
187
|
- Appraisals
|
186
188
|
- CHANGELOG.md
|
@@ -188,6 +190,7 @@ files:
|
|
188
190
|
- LICENSE.txt
|
189
191
|
- README.md
|
190
192
|
- Rakefile
|
193
|
+
- doc/Story.md
|
191
194
|
- gemfiles/rspec_3_0.gemfile
|
192
195
|
- gemfiles/rspec_3_1.gemfile
|
193
196
|
- gemfiles/rspec_3_2.gemfile
|
@@ -212,8 +215,7 @@ files:
|
|
212
215
|
- lib/rspec/json_matchers/matchers/be_json_with_something_matcher.rb
|
213
216
|
- lib/rspec/json_matchers/utils.rb
|
214
217
|
- lib/rspec/json_matchers/utils/collection_keys_extractor.rb
|
215
|
-
- lib/rspec/json_matchers/utils/key_path/
|
216
|
-
- lib/rspec/json_matchers/utils/key_path/extractor.rb
|
218
|
+
- lib/rspec/json_matchers/utils/key_path/extraction.rb
|
217
219
|
- lib/rspec/json_matchers/utils/key_path/path.rb
|
218
220
|
- lib/rspec/json_matchers/version.rb
|
219
221
|
- rspec-json_matchers.gemspec
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module RSpec
|
2
|
-
module JsonMatchers
|
3
|
-
module Utils
|
4
|
-
# @api private
|
5
|
-
module KeyPath
|
6
|
-
# Only as a value object
|
7
|
-
class ExtractionResult
|
8
|
-
attr_reader :object, :successful
|
9
|
-
|
10
|
-
def initialize(object, successful)
|
11
|
-
@object = object
|
12
|
-
@successful = successful
|
13
|
-
end
|
14
|
-
|
15
|
-
def failed?
|
16
|
-
!successful
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require_relative "path"
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module JsonMatchers
|
5
|
-
module Utils
|
6
|
-
# @api private
|
7
|
-
module KeyPath
|
8
|
-
class Extractor
|
9
|
-
|
10
|
-
private
|
11
|
-
attr_accessor *[
|
12
|
-
:object,
|
13
|
-
]
|
14
|
-
attr_reader *[
|
15
|
-
:path,
|
16
|
-
]
|
17
|
-
public
|
18
|
-
|
19
|
-
# Create a new extractor with the "source object"
|
20
|
-
# and the path to be used for extracting our target object
|
21
|
-
#
|
22
|
-
# @param object [Object]
|
23
|
-
# The source object to extract our target object from
|
24
|
-
# @param path [String, Path]
|
25
|
-
# the path of target object
|
26
|
-
# Will convert into {Path}
|
27
|
-
#
|
28
|
-
# @see JsonMatchers::Matchers::BeJsonWithSomethingMatcher#at_path
|
29
|
-
def initialize(object, path)
|
30
|
-
@object = object
|
31
|
-
@path = KeyPath::Path.new(path)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Actually perform the extraction and return the result
|
35
|
-
# Since the object could be falsy,
|
36
|
-
# an object of custom class is returned instead of the object only
|
37
|
-
#
|
38
|
-
# Assume the path to be valid
|
39
|
-
#
|
40
|
-
# @return (see Path#extract)
|
41
|
-
def extract
|
42
|
-
path.each_path_part do |path_part|
|
43
|
-
self.object = case object
|
44
|
-
when Hash
|
45
|
-
# Allow nil as object, but disallow key to be absent
|
46
|
-
unless object.key?(path_part)
|
47
|
-
return ExtractionResult.new(object, false)
|
48
|
-
end
|
49
|
-
object.fetch(path_part)
|
50
|
-
when Array
|
51
|
-
index = path_part.to_i
|
52
|
-
# Disallow index to be out of range
|
53
|
-
# Disallow negative number as index
|
54
|
-
unless (path_part =~ /\A\d+\z/) && index < object.size
|
55
|
-
return ExtractionResult.new(object, false)
|
56
|
-
end
|
57
|
-
object.slice(index)
|
58
|
-
else
|
59
|
-
# Disallow non JSON collection type
|
60
|
-
return ExtractionResult.new(object, false)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
ExtractionResult.new(object, true)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|