match_json 0.0.4 → 0.0.5
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/CHANGELOG.md +2 -0
- data/README.md +2 -0
- data/lib/match_json/matchers/include_json.rb +11 -5
- data/lib/match_json/version.rb +1 -1
- data/spec/match_json/matchers_spec.rb +8 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85aee492f202a8aa740ce50b390990f23c896950
|
4
|
+
data.tar.gz: 2d60002f2d1993bbbb51aa85e2b62d1d73aa149d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e4c6e88d0c4a29f1dc0c19e5b121999a2bdf4538f70abe2ba43b0edfca6f69a45c1454501cfbd0ad5202269e9c5d519125b61d4310004c581130e355b3abb37
|
7
|
+
data.tar.gz: 7b4ba9b8fa5ea69078cecf230264f10faa463c52bf348ac15c1d3a16065e22f2e65eab96bb23ace6ad7429ce7ad248bb7dc1f98581fa80e9d3488060e088f8ab
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -11,13 +11,13 @@ module MatchJson
|
|
11
11
|
}
|
12
12
|
|
13
13
|
def initialize(expected_json)
|
14
|
-
@expected_json = JSON.parse(expected_json)
|
14
|
+
@expected_json = JSON.parse(expected_json.gsub(/(?<!")(\{\w+\})(?!")/, '"\1:non-string"'))
|
15
15
|
end
|
16
16
|
|
17
17
|
def matches?(actual_json)
|
18
18
|
@actual_json = actual_json.respond_to?(:body) ? JSON.parse(actual_json.body) : JSON.parse(actual_json)
|
19
19
|
|
20
|
-
|
20
|
+
catch(:match) { json_included?(@actual_json, @expected_json) }
|
21
21
|
end
|
22
22
|
|
23
23
|
def failure_message
|
@@ -55,10 +55,10 @@ module MatchJson
|
|
55
55
|
|
56
56
|
def array_included?(actual, expected, nested, raise_error)
|
57
57
|
expected.each do |value|
|
58
|
-
if (!actual.any? { |actual_value| equal_value?(actual_value, value, nested, false) })
|
58
|
+
if actual.nil? || (!actual.any? { |actual_value| equal_value?(actual_value, value, nested, false) })
|
59
59
|
@failure_message = %Q("#{value}" was not found in\n )
|
60
60
|
@failure_message << %Q("#{nested}"=>) if !nested.empty?
|
61
|
-
@failure_message << "#{actual}"
|
61
|
+
@failure_message << "#{actual.nil? ? "nil" : actual}"
|
62
62
|
|
63
63
|
if raise_error
|
64
64
|
throw(:match, false)
|
@@ -85,7 +85,9 @@ module MatchJson
|
|
85
85
|
reg_exp = value.match(/{re:(.*)}/)[1]
|
86
86
|
actual =~ Regexp.new(reg_exp)
|
87
87
|
when pattern?(value)
|
88
|
-
actual =~ PATTERNS["#{value.
|
88
|
+
actual =~ PATTERNS["#{value.tr('{}', '')}"]
|
89
|
+
when non_string_pattern?(value) && !actual.is_a?(String)
|
90
|
+
actual.to_s =~ PATTERNS["#{value.tr('{}', '').sub(':non-string', '')}"]
|
89
91
|
else
|
90
92
|
value == actual
|
91
93
|
end
|
@@ -95,6 +97,10 @@ module MatchJson
|
|
95
97
|
!!(str =~ /\A\{\w+\}\z/)
|
96
98
|
end
|
97
99
|
|
100
|
+
def non_string_pattern?(str)
|
101
|
+
!!(str =~ /\A\{\w+\}:non-string\z/)
|
102
|
+
end
|
103
|
+
|
98
104
|
def regexp?(str)
|
99
105
|
!!(str =~ /\A\{re:.+\}\z/)
|
100
106
|
end
|
data/lib/match_json/version.rb
CHANGED
@@ -32,6 +32,12 @@ describe "include_json" do
|
|
32
32
|
expect(%Q({ "array" : [1, 2, 3] })).to include_json(%Q({ "array" : [5, 1] }))
|
33
33
|
}.to fail_with(%Q("5" was not found in\n " > array"=>[1, 2, 3]))
|
34
34
|
end
|
35
|
+
|
36
|
+
it 'fails with there is null instead of array' do
|
37
|
+
expect {
|
38
|
+
expect(%Q({ "array" : null })).to include_json(%Q({ "array" : [5] }))
|
39
|
+
}.to fail_with(%Q("5" was not found in\n " > array"=>nil))
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
context 'when array contains object' do
|
@@ -80,6 +86,8 @@ describe "include_json" do
|
|
80
86
|
|
81
87
|
it 'uses patten to check value' do
|
82
88
|
expect(%Q({"one": "123456"})).to include_json(%Q({"one": "{id}"}))
|
89
|
+
expect(%Q({"one": 123456})).to include_json(%Q({"one": {id}}))
|
90
|
+
expect(%Q({"one": "123456"})).not_to include_json(%Q({"one": {id}}))
|
83
91
|
|
84
92
|
expect {
|
85
93
|
expect(%Q({"one": "abcdef"})).to include_json(%Q({"one": "{id}"}))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: match_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Gabriel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-03-
|
12
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -67,6 +67,7 @@ extensions: []
|
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
69
|
- ".gitignore"
|
70
|
+
- CHANGELOG.md
|
70
71
|
- Gemfile
|
71
72
|
- LICENSE.txt
|
72
73
|
- README.md
|
@@ -99,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
100
|
version: '0'
|
100
101
|
requirements: []
|
101
102
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.4.
|
103
|
+
rubygems_version: 2.4.6
|
103
104
|
signing_key:
|
104
105
|
specification_version: 4
|
105
106
|
summary: RSpec matcher for JSON documents
|