rspec-resembles_json_matchers 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +96 -0
- data/.travis.yml +3 -5
- data/Changelog.md +4 -0
- data/Guardfile +1 -1
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_42.gemfile +1 -1
- data/gemfiles/rails_42.gemfile.lock +1 -1
- data/gemfiles/rails_5.gemfile +1 -1
- data/gemfiles/rails_5.gemfile.lock +1 -1
- data/lib/rspec/resembles_json_matchers.rb +12 -12
- data/lib/rspec/resembles_json_matchers/attribute_differ.rb +29 -22
- data/lib/rspec/resembles_json_matchers/attribute_matcher.rb +39 -16
- data/lib/rspec/resembles_json_matchers/json_matcher.rb +14 -26
- data/lib/rspec/resembles_json_matchers/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c9a61de4b2be0f18eada606356321688910baf9dc9a8c662648bea89e068422
|
4
|
+
data.tar.gz: '068d9310ca39fb2bdf735b3bdf0bf1ce94b64c649f43ab19f86361b1ec3213d2'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 100c49f936bc8177ee0ab361d920cf2ade74b4c5cf07d17adbff6372aabe9b6ba7cee3f8c6120233bfb276913fac56c9901cc700762bfac356273d63d47d0c4f
|
7
|
+
data.tar.gz: 844f1bf3f602a8a33f0fde5154c99cfa2f8ad92704070356ab5d56fb59eb9563a4d79fc3f633a96e3ee3950d577179ffbddd1568e0b310fe283f2ade5b4bb666
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
Rails:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
DisplayCopNames: true
|
6
|
+
DisplayStyleGuide: true
|
7
|
+
TargetRailsVersion: 5.1
|
8
|
+
TargetRubyVersion: 2.5
|
9
|
+
|
10
|
+
Include:
|
11
|
+
- "**/Rakefile"
|
12
|
+
- "**/config.ru"
|
13
|
+
Exclude:
|
14
|
+
- "vendor/**/*"
|
15
|
+
- "spec/fixtures/**/*"
|
16
|
+
- "bin/**/*"
|
17
|
+
- "script/**/*"
|
18
|
+
- "node_modules/**/*"
|
19
|
+
|
20
|
+
inherit_from:
|
21
|
+
- http://relaxed.ruby.style/rubocop.yml
|
22
|
+
# Rules subject to debate
|
23
|
+
Metrics/LineLength:
|
24
|
+
Max: 120
|
25
|
+
|
26
|
+
Metrics/BlockLength:
|
27
|
+
ExcludedMethods:
|
28
|
+
- describe
|
29
|
+
- context
|
30
|
+
- it
|
31
|
+
- specify
|
32
|
+
Exclude:
|
33
|
+
- "lib/tasks/**/*"
|
34
|
+
- "config/routes.rb"
|
35
|
+
Rails/Date:
|
36
|
+
Enabled: false
|
37
|
+
Rails/TimeZone:
|
38
|
+
Enabled: false
|
39
|
+
Rails/RelativeDateConstant:
|
40
|
+
Enabled: false
|
41
|
+
Style/AndOr:
|
42
|
+
EnforcedStyle: conditionals
|
43
|
+
Layout/CaseIndentation:
|
44
|
+
IndentOneStep: true
|
45
|
+
Style/Documentation:
|
46
|
+
Enabled: false
|
47
|
+
Style/EachWithObject:
|
48
|
+
Enabled: false
|
49
|
+
Layout/ExtraSpacing:
|
50
|
+
Exclude:
|
51
|
+
- "config/routes.rb"
|
52
|
+
Style/FrozenStringLiteralComment:
|
53
|
+
Enabled: true
|
54
|
+
Style/HashSyntax:
|
55
|
+
Exclude:
|
56
|
+
- "lib/tasks/**/*"
|
57
|
+
Layout/MultilineOperationIndentation:
|
58
|
+
EnforcedStyle: indented
|
59
|
+
Style/NumericLiterals:
|
60
|
+
Enabled: true
|
61
|
+
Exclude:
|
62
|
+
- "spec/**/*"
|
63
|
+
Layout/EmptyLinesAroundClassBody:
|
64
|
+
EnforcedStyle: empty_lines_special
|
65
|
+
Layout/EmptyLinesAroundModuleBody:
|
66
|
+
EnforcedStyle: empty_lines_special
|
67
|
+
Style/SingleLineBlockParams:
|
68
|
+
Enabled: false
|
69
|
+
Style/StringLiterals:
|
70
|
+
EnforcedStyle: double_quotes
|
71
|
+
Style/StringLiteralsInInterpolation:
|
72
|
+
EnforcedStyle: double_quotes
|
73
|
+
Layout/MultilineMethodCallIndentation:
|
74
|
+
Exclude:
|
75
|
+
- "spec/**/*.rb"
|
76
|
+
Style/FormatString:
|
77
|
+
Enabled: false
|
78
|
+
Style/FormatStringToken:
|
79
|
+
Enabled: false
|
80
|
+
Style/SymbolArray:
|
81
|
+
MinSize: 4
|
82
|
+
Style/WordArray:
|
83
|
+
MinSize: 4
|
84
|
+
Lint/UnusedBlockArgument:
|
85
|
+
Enabled: false
|
86
|
+
Lint/UnusedMethodArgument:
|
87
|
+
Enabled: false
|
88
|
+
Performance/Casecmp:
|
89
|
+
Enabled: false
|
90
|
+
Performance/RedundantMerge:
|
91
|
+
MaxKeyValuePairs: 1
|
92
|
+
Style/ClassCheck:
|
93
|
+
Enabled: false
|
94
|
+
Style/SignalException:
|
95
|
+
Enabled: false
|
96
|
+
|
data/.travis.yml
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.4
|
4
|
-
- 2.5
|
5
|
-
before_install: gem install bundler
|
3
|
+
- "2.4"
|
4
|
+
- "2.5"
|
5
|
+
before_install: gem update --system && gem install bundler
|
6
6
|
gemfile:
|
7
|
-
- gemfiles/rails_32.gemfile
|
8
7
|
- gemfiles/rails_42.gemfile
|
9
|
-
- gemfiles/rails_42_rspec_33.gemfile
|
10
8
|
- gemfiles/rails_5.gemfile
|
11
9
|
matrix:
|
12
10
|
fast_finish: true
|
data/Changelog.md
CHANGED
data/Guardfile
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
guard :rspec,
|
28
28
|
# cmd: "bin/rspec --no-profile --fail-fast",
|
29
29
|
cmd: "bin/rspec --no-profile",
|
30
|
-
failed_mode: :
|
30
|
+
failed_mode: :focus,
|
31
31
|
run_all: { cmd: "bin/rspec --no-profile --tag ~type:feature" }, # skip feature specs on "all"
|
32
32
|
notification: true,
|
33
33
|
all_on_start: false,
|
data/gemfiles/rails_42.gemfile
CHANGED
data/gemfiles/rails_5.gemfile
CHANGED
@@ -3,18 +3,18 @@ require "rspec/resembles_json_matchers/string_indent"
|
|
3
3
|
|
4
4
|
module RSpec
|
5
5
|
module ResemblesJsonMatchers
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
require "rspec/resembles_json_matchers/helpers"
|
7
|
+
require "rspec/resembles_json_matchers/attribute_matcher"
|
8
|
+
require "rspec/resembles_json_matchers/json_matcher"
|
9
|
+
|
10
|
+
require "rspec/resembles_json_matchers/resembles_any_of_matcher"
|
11
|
+
require "rspec/resembles_json_matchers/resembles_route_matcher"
|
12
|
+
require "rspec/resembles_json_matchers/resembles_date_matcher"
|
13
|
+
require "rspec/resembles_json_matchers/resembles_numeric_matcher"
|
14
|
+
require "rspec/resembles_json_matchers/resembles_string_matcher"
|
15
|
+
require "rspec/resembles_json_matchers/resembles_boolean_matcher"
|
16
|
+
require "rspec/resembles_json_matchers/resembles_nil_matcher"
|
17
|
+
require "rspec/resembles_json_matchers/resembles_class_matcher"
|
18
18
|
|
19
19
|
def iso8601_timestamp
|
20
20
|
match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/)
|
@@ -51,20 +51,11 @@ module RSpec::ResemblesJsonMatchers
|
|
51
51
|
@buffer.puts
|
52
52
|
else
|
53
53
|
if nested_matcher?(matcher.value_matcher)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
@buffer.print(",") unless last
|
60
|
-
@buffer.puts
|
61
|
-
else
|
62
|
-
@buffer.print NORMAL_COLOR
|
63
|
-
@buffer.print prefix + " " + "#{matcher.attribute_name.to_json}: "
|
64
|
-
render(matcher.value_matcher, prefix: prefix + " ")
|
65
|
-
@buffer.print(",") unless last
|
66
|
-
@buffer.puts
|
67
|
-
end
|
54
|
+
@buffer.print NORMAL_COLOR
|
55
|
+
@buffer.print prefix + " " + "#{matcher.attribute_name.to_json}: "
|
56
|
+
render(matcher.value_matcher, prefix: prefix + " ")
|
57
|
+
@buffer.print(",") unless last
|
58
|
+
@buffer.puts
|
68
59
|
else
|
69
60
|
@buffer.print REMOVED_COLOR
|
70
61
|
@buffer.print prefix
|
@@ -78,18 +69,34 @@ module RSpec::ResemblesJsonMatchers
|
|
78
69
|
@buffer.print NORMAL_COLOR
|
79
70
|
@buffer.print(",") unless last
|
80
71
|
@buffer.puts
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
@buffer.puts
|
88
|
-
end
|
72
|
+
@buffer.print ADDED_COLOR
|
73
|
+
@buffer.print prefix + "+ #{matcher.attribute_name.to_json}: "
|
74
|
+
render(matcher.actual_value, prefix: prefix + " ")
|
75
|
+
@buffer.print NORMAL_COLOR
|
76
|
+
@buffer.print(",") unless last
|
77
|
+
@buffer.puts
|
89
78
|
end
|
90
79
|
end
|
91
80
|
end
|
92
81
|
|
82
|
+
def render_MissingAttributeMatcher(matcher, prefix: "", last: false)
|
83
|
+
prefix = prefix + (prefix.include?("-") ? " " : "- ")
|
84
|
+
@buffer.print REMOVED_COLOR
|
85
|
+
@buffer.print prefix + "#{matcher.attribute_name.to_json}: "
|
86
|
+
render(matcher.value_matcher, prefix: prefix)
|
87
|
+
@buffer.print(",") unless last
|
88
|
+
@buffer.puts
|
89
|
+
end
|
90
|
+
|
91
|
+
def render_ExtraAttributeMatcher(matcher, prefix: "", last: false)
|
92
|
+
prefix = prefix + "+ "
|
93
|
+
@buffer.print ADDED_COLOR
|
94
|
+
@buffer.print prefix + matcher.attribute_name.to_json + ": "
|
95
|
+
render(matcher.actual_value, prefix: prefix)
|
96
|
+
@buffer.print "," unless last
|
97
|
+
@buffer.puts
|
98
|
+
end
|
99
|
+
|
93
100
|
def render_ResemblesAnyOfMatcher(matcher, prefix: "", **opts)
|
94
101
|
@buffer.puts "["
|
95
102
|
if matcher.actual.nil? || matcher.actual.empty?
|
@@ -1,13 +1,15 @@
|
|
1
1
|
require "active_support/core_ext/hash/indifferent_access"
|
2
|
+
require "active_support/core_ext/object/try"
|
2
3
|
|
3
4
|
module RSpec::ResemblesJsonMatchers
|
4
5
|
|
5
6
|
class AttributeMatcher
|
6
7
|
include RSpec::ResemblesJsonMatchers::Helpers
|
8
|
+
Undefined = Object.new # TODO use Dry::Core::Constants::Undefined
|
7
9
|
|
8
10
|
attr_reader :attribute_name, :expected, :document
|
9
11
|
|
10
|
-
def initialize(attribute_name, expected = NullMatcher)
|
12
|
+
def initialize(attribute_name, expected = NullMatcher.new)
|
11
13
|
@attribute_name, @expected = attribute_name, expected
|
12
14
|
end
|
13
15
|
|
@@ -18,15 +20,11 @@ module RSpec::ResemblesJsonMatchers
|
|
18
20
|
def matches?(document)
|
19
21
|
@document = document.try(:with_indifferent_access)
|
20
22
|
|
21
|
-
@matched =
|
23
|
+
@matched = document.key?(attribute_name) && expected.matches?(actual_value)
|
22
24
|
end
|
23
25
|
|
24
26
|
def failure_message
|
25
|
-
|
26
|
-
%{Expected document to have attribute #{attribute_name.inspect}}
|
27
|
-
else
|
28
|
-
%{Expected attribute #{attribute_name.inspect} to #{value_matcher.description}, but it was #{actual_value.inspect}}
|
29
|
-
end
|
27
|
+
%{Expected attribute #{attribute_name.inspect} to #{value_matcher.description}, but it was #{actual_value.inspect}}
|
30
28
|
end
|
31
29
|
|
32
30
|
def matched?
|
@@ -45,14 +43,6 @@ module RSpec::ResemblesJsonMatchers
|
|
45
43
|
document.fetch(attribute_name, nil)
|
46
44
|
end
|
47
45
|
|
48
|
-
def missing_attribute?
|
49
|
-
!has_attribute?
|
50
|
-
end
|
51
|
-
|
52
|
-
def has_attribute?
|
53
|
-
document && document.key?(attribute_name)
|
54
|
-
end
|
55
|
-
|
56
46
|
NullMatcher = Class.new do
|
57
47
|
def matches?(*_args)
|
58
48
|
true
|
@@ -70,7 +60,40 @@ module RSpec::ResemblesJsonMatchers
|
|
70
60
|
def ===(_other)
|
71
61
|
true
|
72
62
|
end
|
73
|
-
end
|
63
|
+
end
|
74
64
|
|
75
65
|
end
|
66
|
+
|
67
|
+
class MissingAttributeMatcher < AttributeMatcher
|
68
|
+
def matches?(document)
|
69
|
+
@document = document.try(:with_indifferent_access)
|
70
|
+
false
|
71
|
+
end
|
72
|
+
|
73
|
+
def failure_message
|
74
|
+
"Document had is missing attribute #{attribute_name.inspect}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def description
|
78
|
+
"be present"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class ExtraAttributeMatcher < AttributeMatcher
|
83
|
+
|
84
|
+
def matches?(document)
|
85
|
+
@document = document.try(:with_indifferent_access)
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
89
|
+
def failure_message
|
90
|
+
"Document had unexpected attribute #{attribute_name.inspect}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def description
|
94
|
+
"not be present"
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
76
99
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "active_support/core_ext/hash/keys" # stringify_keys
|
2
2
|
require "json"
|
3
3
|
|
4
|
+
require "rspec/matchers"
|
4
5
|
require "rspec/resembles_json_matchers/attribute_differ"
|
5
6
|
|
6
7
|
module RSpec::ResemblesJsonMatchers
|
@@ -20,9 +21,10 @@ module RSpec::ResemblesJsonMatchers
|
|
20
21
|
|
21
22
|
def matches?(actual_json)
|
22
23
|
@actual = actual_json.try(:deep_stringify_keys)
|
24
|
+
# Can't use #all? because it stops on the first false
|
23
25
|
all_passed = true
|
24
|
-
expected_matchers.each do |key,
|
25
|
-
result =
|
26
|
+
expected_matchers.each do |key, matcher|
|
27
|
+
result = matcher.matches?(actual)
|
26
28
|
all_passed &&= result
|
27
29
|
end
|
28
30
|
all_passed
|
@@ -43,8 +45,14 @@ module RSpec::ResemblesJsonMatchers
|
|
43
45
|
|
44
46
|
def expected_matchers
|
45
47
|
@expected_matchers ||= {}.tap do |hsh|
|
46
|
-
expected.each do |
|
47
|
-
|
48
|
+
(expected.keys + actual.keys).uniq.each do |key|
|
49
|
+
expected_value = matcherize(expected[key])
|
50
|
+
hsh[key.to_s] =
|
51
|
+
if !expected.key?(key) then ExtraAttributeMatcher.new(key, expected_value)
|
52
|
+
elsif !actual.key?(key) then MissingAttributeMatcher.new(key, expected_value)
|
53
|
+
else
|
54
|
+
AttributeMatcher.new(key, expected_value)
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
@@ -57,29 +65,9 @@ module RSpec::ResemblesJsonMatchers
|
|
57
65
|
out << "\n}"
|
58
66
|
end
|
59
67
|
|
60
|
-
def
|
61
|
-
|
62
|
-
case line.chr[0]
|
63
|
-
when "-" then red line
|
64
|
-
when "+" then green line
|
65
|
-
end
|
66
|
-
end.compact
|
67
|
-
end
|
68
|
-
|
69
|
-
def color(text, color_code)
|
70
|
-
"\e[#{color_code}m#{text}\e[0m"
|
71
|
-
end
|
72
|
-
|
73
|
-
def red(text)
|
74
|
-
color(text, 31)
|
75
|
-
end
|
76
|
-
|
77
|
-
def green(text)
|
78
|
-
color(text, 32)
|
68
|
+
def actual
|
69
|
+
@actual ||= {}
|
79
70
|
end
|
80
71
|
|
81
|
-
def normal(text)
|
82
|
-
color(text, 0)
|
83
|
-
end
|
84
72
|
end
|
85
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-resembles_json_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Sadauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -219,6 +219,7 @@ extra_rdoc_files: []
|
|
219
219
|
files:
|
220
220
|
- ".gitignore"
|
221
221
|
- ".rspec"
|
222
|
+
- ".rubocop.yml"
|
222
223
|
- ".travis.yml"
|
223
224
|
- Appraisals
|
224
225
|
- Changelog.md
|
@@ -228,6 +229,7 @@ files:
|
|
228
229
|
- Rakefile
|
229
230
|
- bin/rspec
|
230
231
|
- examples/example_spec.rb
|
232
|
+
- gemfiles/.bundle/config
|
231
233
|
- gemfiles/rails_42.gemfile
|
232
234
|
- gemfiles/rails_42.gemfile.lock
|
233
235
|
- gemfiles/rails_5.gemfile
|
@@ -271,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
273
|
version: '0'
|
272
274
|
requirements: []
|
273
275
|
rubyforge_project:
|
274
|
-
rubygems_version: 2.7.
|
276
|
+
rubygems_version: 2.7.6
|
275
277
|
signing_key:
|
276
278
|
specification_version: 4
|
277
279
|
summary: Helpful matchers for comparing JSON documents.
|