match_json 0.0.5 → 0.0.6
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 +1 -0
- data/.travis.yml +6 -0
- data/README.md +92 -55
- data/Rakefile +9 -0
- data/assets/match.png +0 -0
- data/lib/match_json.rb +0 -1
- data/lib/match_json/matchers.rb +12 -2
- data/lib/match_json/matchers/include_json.rb +5 -5
- data/lib/match_json/version.rb +1 -1
- data/match_json.gemspec +4 -1
- data/spec/match_json/{matchers_spec.rb → include_json_spec.rb} +16 -13
- data/spec/match_json/match_json_spec.rb +7 -0
- data/test/match_json/include_json_test.rb +115 -0
- data/test/match_json/match_json_test.rb +7 -0
- data/test/test_helper.rb +5 -0
- metadata +58 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3c7c510c21202dd35ddd777bb65d506e7ac9b0d9
|
|
4
|
+
data.tar.gz: f0636b35b386bb55f6e9633483bdb8fc49f19ba2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f4cb5db29a34ba6498967e6d2a623ebe35f9f31f407d75a3a0d9288034a170ae0a5ad4f9aca54f98b10c1991ac192680412dd6b7d1ed6c4e177048807bb94d5
|
|
7
|
+
data.tar.gz: 33cd7763ee83844e16ccd025c3f6ef18e14a9a183373e37a738c9a1799bccc9fe9eb99d0e8ce73354b60b312dbea7883b4327ec4f2c8e40ebd4b119b16a8a3ce
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
|
@@ -1,97 +1,134 @@
|
|
|
1
|
-
#
|
|
2
|
-
[](https://codeclimate.com/github/WhitePayments/match_json)
|
|
1
|
+
# MatchJSON [](https://codeclimate.com/github/WhitePayments/match_json)
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+

|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
recommend to use [json-schema](https://github.com/ruby-json-schema/json-schema)
|
|
8
|
-
as a perfect companion to MatchJson.
|
|
5
|
+
Test your JSON in RSpec and Cucumber, like a boss.
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
> The **only** matcher I let my kids play with
|
|
8
|
+
> -- Mom
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
## Getting Started
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
Ever since the dawn of mankind, humans everywhere have been searching for a tool to test their JSON.
|
|
15
13
|
|
|
14
|
+
Then computers were invented.
|
|
15
|
+
|
|
16
|
+
Then matchJSON came about.
|
|
17
|
+
|
|
18
|
+
Then everyone lived happily ever after.
|
|
19
|
+
|
|
20
|
+
*Stop warping your brain with hard-to-read regex and weird-looking tests.*
|
|
21
|
+
|
|
22
|
+
**The old, yucky way:**
|
|
23
|
+
```ruby
|
|
24
|
+
it "returns the current pony" do
|
|
25
|
+
get "/ponies/#{pony.id}"
|
|
26
|
+
|
|
27
|
+
current_pony = JSON.parse(response.body)["pony"]
|
|
28
|
+
expect(current_pony["cuteness"]).to eq 90
|
|
29
|
+
expect(current_pony["fluffiness"]).to eq "extra-fluffy"
|
|
30
|
+
expect(current_pony["name"]).to eq "McPony"
|
|
31
|
+
end
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**The new, cool way:**
|
|
16
35
|
```ruby
|
|
17
|
-
it
|
|
18
|
-
get
|
|
36
|
+
it "returns the current pony" do
|
|
37
|
+
get "/ponies/#{pony.id}"
|
|
19
38
|
|
|
20
|
-
expect(response).to
|
|
39
|
+
expect(response).to match_json(<<-JSON)
|
|
21
40
|
{
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"created_at": "{date_time_iso8601}"
|
|
41
|
+
"cuteness": 90,
|
|
42
|
+
"fluffiness": "extra-fluffy",
|
|
43
|
+
"name": "McPony",
|
|
26
44
|
}
|
|
27
45
|
JSON
|
|
28
46
|
end
|
|
47
|
+
```
|
|
29
48
|
|
|
30
|
-
|
|
31
|
-
get '/charges'
|
|
49
|
+
Wait, you already use **[JSON-Schema](https://github.com/ruby-json-schema/json-schema)**? We're BFFs :heart:
|
|
32
50
|
|
|
33
|
-
|
|
51
|
+
```ruby
|
|
52
|
+
it "returns the current pony" do
|
|
53
|
+
get "/ponies/#{pony.id}"
|
|
54
|
+
|
|
55
|
+
# JSON-Schema to check the schema
|
|
56
|
+
expect(response).to match_response_schema(:pony)
|
|
57
|
+
|
|
58
|
+
# MatchJSON to test the values (gotta love explicit tests)
|
|
59
|
+
expect(response).to match_json(<<-JSON)
|
|
34
60
|
{
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"amount": 100,
|
|
39
|
-
"currency": "USD",
|
|
40
|
-
"created_at": "{date_time_iso8601}"
|
|
41
|
-
}
|
|
42
|
-
]
|
|
61
|
+
"cuteness": 90,
|
|
62
|
+
"fluffiness": "extra-fluffy",
|
|
63
|
+
"name": "McPony",
|
|
43
64
|
}
|
|
44
65
|
JSON
|
|
45
66
|
end
|
|
46
67
|
```
|
|
47
68
|
|
|
48
|
-
|
|
49
|
-
```id``` or ```created_at``` or even ```email``` you can use 'pattern' instead.
|
|
50
|
-
|
|
51
|
-
You can use the following predefined patterns:
|
|
52
|
-
|
|
53
|
-
* date_time_iso8601
|
|
54
|
-
* date
|
|
55
|
-
* uuid
|
|
56
|
-
* email
|
|
57
|
-
* string
|
|
69
|
+
## Installation
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
new patterns:
|
|
71
|
+
- Drop this baby into your Gemfile like so:
|
|
61
72
|
|
|
62
73
|
```ruby
|
|
63
|
-
|
|
74
|
+
gem 'match_json'
|
|
64
75
|
```
|
|
65
76
|
|
|
66
|
-
|
|
77
|
+
- Run `bundle`
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## Advanced usage
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Patterns
|
|
84
|
+
|
|
85
|
+
Add some patterns in the mix to make things interesting:
|
|
67
86
|
|
|
68
87
|
```ruby
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
# RSpec
|
|
89
|
+
it 'returns ponies' do
|
|
90
|
+
get '/ponies/#{pony.id}'
|
|
91
|
+
|
|
92
|
+
expect(response).to match_json(<<-JSON)
|
|
93
|
+
{
|
|
94
|
+
"id": "{uuid}", # UUID Pattern
|
|
95
|
+
"cuteness": 90,
|
|
96
|
+
"fluffiness": "extra-fluffy",
|
|
97
|
+
"name": "McPony",
|
|
98
|
+
"created_at": "{date_time_iso8601}" # DateTime pattern (well, duh)
|
|
99
|
+
}
|
|
100
|
+
JSON
|
|
73
101
|
end
|
|
74
102
|
```
|
|
75
103
|
|
|
76
|
-
|
|
104
|
+
Here's a list of the built-in patterns we provide:
|
|
105
|
+
* `date_time_iso8601`
|
|
106
|
+
* `date`
|
|
107
|
+
* `uuid`
|
|
108
|
+
* `email`
|
|
109
|
+
* `string`
|
|
77
110
|
|
|
78
|
-
|
|
111
|
+
### Define your own patterns
|
|
112
|
+
|
|
113
|
+
Just add them to `spec/support/match_json.rb`:
|
|
79
114
|
|
|
80
115
|
```ruby
|
|
81
|
-
|
|
116
|
+
MatchJson::Matchers::IncludeJson::PATTERNS['id'] = /\A\d{6}\z/
|
|
82
117
|
```
|
|
83
118
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
$ bundle
|
|
87
|
-
|
|
88
|
-
Or install it yourself as:
|
|
119
|
+
and then use it in your spec like so:
|
|
89
120
|
|
|
90
|
-
|
|
121
|
+
```ruby
|
|
122
|
+
it 'uses patten to check value' do
|
|
123
|
+
expect(%Q({"one": "123456"})).to match_json(%Q({"one": "{id}"}))
|
|
124
|
+
# .. you can even do this:
|
|
125
|
+
expect(%Q({"one": 123456})).to match_json(%Q({"one": {id}}))
|
|
126
|
+
end
|
|
127
|
+
```
|
|
91
128
|
|
|
92
129
|
## Contributing
|
|
93
130
|
|
|
94
|
-
1. Fork it ( https://github.com/[
|
|
131
|
+
1. Fork it ( https://github.com/[your-github-username]/match_json/fork )
|
|
95
132
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
96
133
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
97
134
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/assets/match.png
ADDED
|
Binary file
|
data/lib/match_json.rb
CHANGED
data/lib/match_json/matchers.rb
CHANGED
|
@@ -8,6 +8,16 @@ module MatchJson
|
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
RSpec
|
|
12
|
-
|
|
11
|
+
if defined?(RSpec)
|
|
12
|
+
RSpec.configure do |config|
|
|
13
|
+
config.include MatchJson::Matchers
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
RSpec::Matchers.alias_matcher :match_json, :include_json
|
|
17
|
+
elsif defined?(Minitest)
|
|
18
|
+
class Minitest::Test
|
|
19
|
+
include MatchJson::Matchers
|
|
20
|
+
|
|
21
|
+
alias_method :match_json, :include_json
|
|
22
|
+
end
|
|
13
23
|
end
|
|
@@ -36,13 +36,13 @@ module MatchJson
|
|
|
36
36
|
|
|
37
37
|
def hash_included?(actual, expected, nested, raise_error)
|
|
38
38
|
if compared_different_types?(actual, expected)
|
|
39
|
-
@failure_message = %Q(Different types of compared elements:\n #{actual.class} for #{actual}\nand #{expected.class} for #{expected})
|
|
39
|
+
@failure_message = %Q(Different types of compared elements:\n #{actual.class} for #{actual.to_json}\nand #{expected.class} for #{expected.to_json})
|
|
40
40
|
throw(:match, false)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
expected.each do |key, value|
|
|
44
44
|
if (!equal_value?(actual[key], value, "#{nested} > #{key}", raise_error))
|
|
45
|
-
@failure_message = %Q("#{key}"
|
|
45
|
+
@failure_message = %Q("#{key}":#{value.to_json} was not found in\n #{actual.to_json})
|
|
46
46
|
|
|
47
47
|
if raise_error
|
|
48
48
|
throw(:match, false)
|
|
@@ -56,9 +56,9 @@ module MatchJson
|
|
|
56
56
|
def array_included?(actual, expected, nested, raise_error)
|
|
57
57
|
expected.each do |value|
|
|
58
58
|
if actual.nil? || (!actual.any? { |actual_value| equal_value?(actual_value, value, nested, false) })
|
|
59
|
-
@failure_message = %Q("#{value}" was not found in\n )
|
|
60
|
-
@failure_message << %Q("#{nested}"
|
|
61
|
-
@failure_message << "#{actual.
|
|
59
|
+
@failure_message = %Q("#{value.to_json}" was not found in\n )
|
|
60
|
+
@failure_message << %Q("#{nested}":) if !nested.empty?
|
|
61
|
+
@failure_message << "#{actual.to_json}"
|
|
62
62
|
|
|
63
63
|
if raise_error
|
|
64
64
|
throw(:match, false)
|
data/lib/match_json/version.rb
CHANGED
data/match_json.gemspec
CHANGED
|
@@ -18,7 +18,10 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
spec.
|
|
21
|
+
spec.add_development_dependency "rspec", ">= 3.0", "< 4.0"
|
|
22
|
+
spec.add_development_dependency "minitest", "~> 5.8"
|
|
23
|
+
spec.add_development_dependency "minitest-matchers", "~> 1.4"
|
|
24
|
+
spec.add_development_dependency "minitest-byebug"
|
|
22
25
|
spec.add_development_dependency "bundler", "~> 1.7"
|
|
23
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
27
|
end
|
|
@@ -8,35 +8,35 @@ describe "include_json" do
|
|
|
8
8
|
it "fails when expected object is not included" do
|
|
9
9
|
expect {
|
|
10
10
|
expect(%Q({ "one": 1 })).to include_json(%Q({ "one": 2 }))
|
|
11
|
-
}.to fail_with(%Q("one"
|
|
11
|
+
}.to fail_with(%Q("one":2 was not found in\n {"one":1}))
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it 'passes when array is partially included' do
|
|
15
|
-
expect(%Q([1,
|
|
16
|
-
expect(%Q([1,
|
|
15
|
+
expect(%Q([1,2,3])).to include_json(%Q([3,2]))
|
|
16
|
+
expect(%Q([1,2,3])).to include_json(%Q([1,2,3]))
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it 'fails when there is no such array' do
|
|
20
20
|
expect {
|
|
21
|
-
expect(%Q([1,
|
|
22
|
-
}.to fail_with(%Q("5" was not found in\n [1,
|
|
21
|
+
expect(%Q([1,2,3])).to include_json(%Q([3,5]))
|
|
22
|
+
}.to fail_with(%Q("5" was not found in\n [1,2,3]))
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
context 'when object contains array' do
|
|
26
26
|
it 'passes when array included' do
|
|
27
|
-
expect(%Q({ "array" : [1,
|
|
27
|
+
expect(%Q({ "array" : [1,2,3] })).to include_json(%Q({ "array" : [3,2,1] }))
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it 'fails with there is no such array' do
|
|
31
31
|
expect {
|
|
32
|
-
expect(%Q({ "array" : [1,
|
|
33
|
-
}.to fail_with(%Q("5" was not found in\n " > array"
|
|
32
|
+
expect(%Q({ "array" : [1,2,3] })).to include_json(%Q({ "array" : [5,1] }))
|
|
33
|
+
}.to fail_with(%Q("5" was not found in\n " > array":[1,2,3]))
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it 'fails with there is null instead of array' do
|
|
37
37
|
expect {
|
|
38
38
|
expect(%Q({ "array" : null })).to include_json(%Q({ "array" : [5] }))
|
|
39
|
-
}.to fail_with(%Q("5" was not found in\n " > array"
|
|
39
|
+
}.to fail_with(%Q("5" was not found in\n " > array":null))
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -48,7 +48,7 @@ describe "include_json" do
|
|
|
48
48
|
it 'fails when there is no such object in array' do
|
|
49
49
|
expect {
|
|
50
50
|
expect(%Q([ { "one": 1 }, { "two": 2 }])).to include_json(%Q([ { "one": 2 }]))
|
|
51
|
-
}.to fail_with(%Q(\"{"one"
|
|
51
|
+
}.to fail_with(%Q(\"{"one":2}\" was not found in\n [{"one":1},{"two":2}]))
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -56,7 +56,7 @@ describe "include_json" do
|
|
|
56
56
|
it 'fails if object was not found' do
|
|
57
57
|
expect {
|
|
58
58
|
expect(%Q([ { "one": { "array": [1,2,3] } } ])).to include_json(%Q([ { "one": { "array": [1,2,3,4] } } ]))
|
|
59
|
-
}.to fail_with(%Q("{"one"
|
|
59
|
+
}.to fail_with(%Q("{"one":{"array":[1,2,3,4]}}" was not found in\n [{"one":{"array":[1,2,3]}}]))
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ describe "include_json" do
|
|
|
64
64
|
it 'fails with clean message' do
|
|
65
65
|
expect {
|
|
66
66
|
expect(%Q([ { "one": 1 } ])).to include_json(%Q({ "one": 1 }))
|
|
67
|
-
}.to fail_with(%Q(Different types of compared elements:\n Array for [{"one"
|
|
67
|
+
}.to fail_with(%Q(Different types of compared elements:\n Array for [{"one":1}]\nand Hash for {"one":1}))
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
@@ -91,7 +91,10 @@ describe "include_json" do
|
|
|
91
91
|
|
|
92
92
|
expect {
|
|
93
93
|
expect(%Q({"one": "abcdef"})).to include_json(%Q({"one": "{id}"}))
|
|
94
|
-
}.to fail_with(%Q("one"
|
|
94
|
+
}.to fail_with(%Q("one":"{id}" was not found in\n {"one":"abcdef"}))
|
|
95
|
+
expect {
|
|
96
|
+
expect(%Q({"one": true})).to include_json(%Q({"one": {id}}))
|
|
97
|
+
}.to fail_with(%Q("one":"{id}:non-string" was not found in\n {"one":true}))
|
|
95
98
|
end
|
|
96
99
|
end
|
|
97
100
|
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe "include_json" do
|
|
4
|
+
it 'passes when object is partially included' do
|
|
5
|
+
expect(%Q({ "one": 1, "two": 2 })).must include_json(%Q({ "one": 1 }))
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "fails when expected object is not included" do
|
|
9
|
+
err = expect {
|
|
10
|
+
expect(%Q({ "one": 1 })).must include_json(%Q({ "one": 2 }))
|
|
11
|
+
}.must_raise(Exception)
|
|
12
|
+
err.message.must_equal(%Q("one":2 was not found in\n {"one":1}.))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'passes when array is partially included' do
|
|
16
|
+
expect(%Q([1,2,3])).must include_json(%Q([3,2]))
|
|
17
|
+
expect(%Q([1,2,3])).must include_json(%Q([1,2,3]))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'fails when there is no such array' do
|
|
21
|
+
err = expect {
|
|
22
|
+
expect(%Q([1,2,3])).must include_json(%Q([3,5]))
|
|
23
|
+
}.must_raise(Exception)
|
|
24
|
+
err.message.must_equal(%Q("5" was not found in\n [1,2,3].))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe 'when object contains array' do
|
|
28
|
+
it 'passes when array included' do
|
|
29
|
+
expect(%Q({ "array" : [1,2,3] })).must include_json(%Q({ "array" : [3,2,1] }))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'fails with there is no such array' do
|
|
33
|
+
err = expect {
|
|
34
|
+
expect(%Q({ "array" : [1,2,3] })).must include_json(%Q({ "array" : [5,1] }))
|
|
35
|
+
}.must_raise(Exception)
|
|
36
|
+
err.message.must_equal(%Q("5" was not found in\n " > array":[1,2,3].))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'fails with there is null instead of array' do
|
|
40
|
+
err = expect {
|
|
41
|
+
expect(%Q({ "array" : null })).must include_json(%Q({ "array" : [5] }))
|
|
42
|
+
}.must_raise(Exception)
|
|
43
|
+
err.message.must_equal(%Q("5" was not found in\n " > array":null.))
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe 'when array contains object' do
|
|
48
|
+
it 'passes when object included in array' do
|
|
49
|
+
expect(%Q([ { "one": 1 }, { "two": 2 }])).must include_json(%Q([ { "one": 1 }]))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'fails when there is no such object in array' do
|
|
53
|
+
err1 = expect {
|
|
54
|
+
expect(%Q([ { "one": 1 }, { "two": 2 }])).must include_json(%Q([ { "one": 2 }]))
|
|
55
|
+
}.must_raise(Exception)
|
|
56
|
+
err1.message.must_equal(%Q(\"{"one":2}\" was not found in\n [{"one":1},{"two":2}].))
|
|
57
|
+
|
|
58
|
+
err2 = expect {
|
|
59
|
+
expect(%Q({ "array" : null })).must include_json(%Q({ "array" : [5] }))
|
|
60
|
+
}.must_raise(Exception)
|
|
61
|
+
err2.message.must_equal(%Q("5" was not found in\n " > array":null.))
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe 'in multilevel structure' do
|
|
66
|
+
it 'fails if object was not found' do
|
|
67
|
+
err = expect {
|
|
68
|
+
expect(%Q([ { "one": { "array": [1,2,3] } } ])).must include_json(%Q([ { "one": { "array": [1,2,3,4] } } ]))
|
|
69
|
+
}.must_raise(Exception)
|
|
70
|
+
err.message.must_equal(%Q("{"one":{"array":[1,2,3,4]}}" was not found in\n [{"one":{"array":[1,2,3]}}].))
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe 'when ckeck for inclusion of different types' do
|
|
75
|
+
it 'fails with clean message' do
|
|
76
|
+
err = expect {
|
|
77
|
+
expect(%Q([ { "one": 1 } ])).must include_json(%Q({ "one": 1 }))
|
|
78
|
+
}.must_raise(Exception)
|
|
79
|
+
err.message.must_equal(%Q(Different types of compared elements:\n Array for [{"one":1}]\nand Hash for {"one":1}.))
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe 'with pattern' do
|
|
84
|
+
it 'passes when value matches pattern' do
|
|
85
|
+
expect(%Q({"one": "test@exmaple.com"})).must include_json(%Q({"one": "{email}"}))
|
|
86
|
+
expect(%Q({"one": "2020-12-22"})).must include_json(%Q({"one": "{date}"}))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe 'with custom pattern' do
|
|
91
|
+
before do
|
|
92
|
+
MatchJson::Matchers::IncludeJson::PATTERNS['id'] = /\A\d{6}\z/
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
after do
|
|
96
|
+
MatchJson::Matchers::IncludeJson::PATTERNS.delete('id')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'uses patten to check value' do
|
|
100
|
+
expect(%Q({"one": "123456"})).must include_json(%Q({"one": "{id}"}))
|
|
101
|
+
expect(%Q({"one": 123456})).must include_json(%Q({"one": {id}}))
|
|
102
|
+
expect(%Q({"one": "123456"})).wont include_json(%Q({"one": {id}}))
|
|
103
|
+
|
|
104
|
+
err1 = expect {
|
|
105
|
+
expect(%Q({"one": "abcdef"})).must include_json(%Q({"one": "{id}"}))
|
|
106
|
+
}.must_raise(Exception)
|
|
107
|
+
err1.message.must_equal(%Q("one":"{id}" was not found in\n {"one":"abcdef"}.))
|
|
108
|
+
|
|
109
|
+
err2 = expect {
|
|
110
|
+
expect(%Q({"one": true})).must include_json(%Q({"one": {id}}))
|
|
111
|
+
}.must_raise(Exception)
|
|
112
|
+
err2.message.must_equal(%Q("one":"{id}:non-string" was not found in\n {"one":true}.))
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
data/test/test_helper.rb
ADDED
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.6
|
|
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:
|
|
12
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
@@ -21,7 +21,7 @@ dependencies:
|
|
|
21
21
|
- - "<"
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
23
|
version: '4.0'
|
|
24
|
-
type: :
|
|
24
|
+
type: :development
|
|
25
25
|
prerelease: false
|
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
|
27
27
|
requirements:
|
|
@@ -31,6 +31,48 @@ dependencies:
|
|
|
31
31
|
- - "<"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '4.0'
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: minitest
|
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '5.8'
|
|
41
|
+
type: :development
|
|
42
|
+
prerelease: false
|
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.8'
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: minitest-matchers
|
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.4'
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.4'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: minitest-byebug
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
type: :development
|
|
70
|
+
prerelease: false
|
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
34
76
|
- !ruby/object:Gem::Dependency
|
|
35
77
|
name: bundler
|
|
36
78
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -67,19 +109,25 @@ extensions: []
|
|
|
67
109
|
extra_rdoc_files: []
|
|
68
110
|
files:
|
|
69
111
|
- ".gitignore"
|
|
112
|
+
- ".travis.yml"
|
|
70
113
|
- CHANGELOG.md
|
|
71
114
|
- Gemfile
|
|
72
115
|
- LICENSE.txt
|
|
73
116
|
- README.md
|
|
74
117
|
- Rakefile
|
|
118
|
+
- assets/match.png
|
|
75
119
|
- lib/match_json.rb
|
|
76
120
|
- lib/match_json/matchers.rb
|
|
77
121
|
- lib/match_json/matchers/include_json.rb
|
|
78
122
|
- lib/match_json/version.rb
|
|
79
123
|
- match_json.gemspec
|
|
80
|
-
- spec/match_json/
|
|
124
|
+
- spec/match_json/include_json_spec.rb
|
|
125
|
+
- spec/match_json/match_json_spec.rb
|
|
81
126
|
- spec/spec_helper.rb
|
|
82
127
|
- spec/support/fail_matchers.rb
|
|
128
|
+
- test/match_json/include_json_test.rb
|
|
129
|
+
- test/match_json/match_json_test.rb
|
|
130
|
+
- test/test_helper.rb
|
|
83
131
|
homepage: https://github.com/WhitePayments/match_json
|
|
84
132
|
licenses:
|
|
85
133
|
- MIT
|
|
@@ -100,11 +148,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
100
148
|
version: '0'
|
|
101
149
|
requirements: []
|
|
102
150
|
rubyforge_project:
|
|
103
|
-
rubygems_version: 2.
|
|
151
|
+
rubygems_version: 2.5.1
|
|
104
152
|
signing_key:
|
|
105
153
|
specification_version: 4
|
|
106
154
|
summary: RSpec matcher for JSON documents
|
|
107
155
|
test_files:
|
|
108
|
-
- spec/match_json/
|
|
156
|
+
- spec/match_json/include_json_spec.rb
|
|
157
|
+
- spec/match_json/match_json_spec.rb
|
|
109
158
|
- spec/spec_helper.rb
|
|
110
159
|
- spec/support/fail_matchers.rb
|
|
160
|
+
- test/match_json/include_json_test.rb
|
|
161
|
+
- test/match_json/match_json_test.rb
|
|
162
|
+
- test/test_helper.rb
|