minitest-match_json 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/README.md +4 -2
- data/Rakefile +9 -3
- data/lib/minitest/match_json.rb +18 -18
- data/lib/minitest/match_json/version.rb +1 -1
- data/minitest-match_json.gemspec +0 -1
- data/test/minitest/match_json_test.rb +38 -15
- data/test/test_helper.rb +10 -0
- metadata +4 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27009176eb3e76417efbe93b3347432a98ef73f5
|
4
|
+
data.tar.gz: fdd7af554496ea29734494456fce808273054c39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e0896d6f40a3790297fe882591c1696dcf505b508c8b5be2a477aed36a6700588f5920c477186b30d63b663f2e7b6569d7dd0eecc8e13a72af7329475dff5a8
|
7
|
+
data.tar.gz: 7d92f63a92b995f4c91d5b21f6cd233a0e5da9e603d3fea71b6d013d3819f1c94220054ab4a2fbdd6f33643ee978766c72766b98f157426f671ea2c014bce3d1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Minitest::MatchJson
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/ggordon/minitest-match_json.svg?branch=master)](https://travis-ci.org/ggordon/minitest-match_json) [![Gem Version](https://badge.fury.io/rb/minitest-match_json.svg)](http://badge.fury.io/rb/minitest-match_json) [![Code Climate](https://codeclimate.com/github/ggordon/minitest-match_json/badges/gpa.svg)](https://codeclimate.com/github/ggordon/minitest-match_json) [![Test Coverage](https://codeclimate.com/github/ggordon/minitest-match_json/badges/coverage.svg)](https://codeclimate.com/github/ggordon/minitest-match_json)
|
4
|
+
|
5
|
+
Compare a JSON string to another JSON object. If a String is passed in, it is expected to be valid JSON, any other type will be converted to json if possible.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -24,7 +26,7 @@ Or install it yourself as:
|
|
24
26
|
require 'minitest-match_json'
|
25
27
|
```
|
26
28
|
|
27
|
-
[Diffy](https://github.com/samg/diffy) is used to
|
29
|
+
[Diffy](https://github.com/samg/diffy) is used to compare the two JSON objects. Options to control the output format and number of context lines to be displayed can be passed through to Diffy.
|
28
30
|
|
29
31
|
```ruby
|
30
32
|
Minitest::MatchJson.configure do |config|
|
data/Rakefile
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
3
|
|
4
|
+
namespace :coverage do
|
5
|
+
desc 'Delete previous coverage results'
|
6
|
+
task :clean do
|
7
|
+
rm_rf 'coverage'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
4
11
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs << 'lib'
|
6
12
|
t.pattern = 'test/**/*_test.rb'
|
7
|
-
t.
|
13
|
+
t.libs.push 'test'
|
8
14
|
end
|
9
|
-
|
15
|
+
task test: 'coverage:clean'
|
10
16
|
task default: :test
|
data/lib/minitest/match_json.rb
CHANGED
@@ -9,27 +9,27 @@ module Minitest
|
|
9
9
|
module MatchJson
|
10
10
|
class << self
|
11
11
|
attr_writer :configuration
|
12
|
-
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def configure
|
18
|
+
yield configuration
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
def compare_json(actual_json, expected_json)
|
22
|
+
Diffy::Diff.new(
|
23
|
+
expected_json,
|
24
|
+
actual_json,
|
25
|
+
context: configuration.context
|
26
|
+
).to_s(configuration.format)
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def pretty_json(param)
|
30
|
+
json = (param.is_a?(String)) ? param : param.to_json
|
31
|
+
JSON.pretty_generate(JSON.parse(json))
|
32
|
+
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -73,6 +73,6 @@ module Minitest
|
|
73
73
|
#
|
74
74
|
# Fails unless the subject and parameter are equivalent JSON
|
75
75
|
#
|
76
|
-
infect_an_assertion :assert_match_json, :must_match_json
|
76
|
+
String.infect_an_assertion :assert_match_json, :must_match_json, true
|
77
77
|
end
|
78
78
|
end
|
data/minitest-match_json.gemspec
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
SimpleCov.start
|
3
|
-
|
4
|
-
gem 'minitest'
|
5
|
-
require 'minitest/autorun'
|
6
|
-
require 'minitest/match_json'
|
1
|
+
require 'test_helper'
|
7
2
|
|
8
3
|
describe Minitest do
|
9
4
|
describe 'Configuration' do
|
@@ -28,12 +23,40 @@ describe Minitest do
|
|
28
23
|
json = '{"a": 2, "b": 4}'
|
29
24
|
begin
|
30
25
|
json.must_match_json 2
|
31
|
-
rescue MiniTest::Assertion
|
32
|
-
|
26
|
+
rescue MiniTest::Assertion => expected_failure
|
27
|
+
expected_failure.message.must_match /Parameter cannot be converted to JSON/
|
33
28
|
end
|
34
29
|
end
|
35
30
|
|
36
|
-
it 'returns a default result when failing' do
|
31
|
+
it 'returns a default result when failing with assert' do
|
32
|
+
Minitest::MatchJson.configure do |config|
|
33
|
+
config.format = :text
|
34
|
+
end
|
35
|
+
|
36
|
+
json = '{"b": 5}'
|
37
|
+
hash = { b: 4 }
|
38
|
+
|
39
|
+
out, _ = capture_io do
|
40
|
+
begin
|
41
|
+
assert_match_json json, hash
|
42
|
+
rescue MiniTest::Assertion
|
43
|
+
pass
|
44
|
+
end
|
45
|
+
end
|
46
|
+
out.must_equal(<<STR
|
47
|
+
|
48
|
+
{
|
49
|
+
- \"b\": 5
|
50
|
+
+ \"b\": 4
|
51
|
+
}
|
52
|
+
\
|
53
|
+
|
54
|
+
STR
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
it 'returns a default result when failing with spec' do
|
37
60
|
Minitest::MatchJson.configure do |config|
|
38
61
|
config.format = :text
|
39
62
|
end
|
@@ -51,8 +74,8 @@ describe Minitest do
|
|
51
74
|
out.must_equal(<<STR
|
52
75
|
|
53
76
|
{
|
54
|
-
- \"b\":
|
55
|
-
+ \"b\":
|
77
|
+
- \"b\": 5
|
78
|
+
+ \"b\": 4
|
56
79
|
}
|
57
80
|
\
|
58
81
|
|
@@ -79,8 +102,8 @@ STR
|
|
79
102
|
out.must_equal(<<STR
|
80
103
|
|
81
104
|
\"a\": 3,
|
82
|
-
- \"b\":
|
83
|
-
+ \"b\":
|
105
|
+
- \"b\": 5,
|
106
|
+
+ \"b\": 4,
|
84
107
|
\"c\": 5
|
85
108
|
|
86
109
|
STR
|
@@ -105,8 +128,8 @@ STR
|
|
105
128
|
out.must_equal(<<STR
|
106
129
|
|
107
130
|
{
|
108
|
-
\e[31m- \"b\":
|
109
|
-
\e[32m+ \"b\":
|
131
|
+
\e[31m- \"b\": 5\e[0m
|
132
|
+
\e[32m+ \"b\": 4\e[0m
|
110
133
|
}
|
111
134
|
\
|
112
135
|
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-match_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '10.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: simplecov
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
description: Compare two JSON objects with pretty diffs
|
98
84
|
email:
|
99
85
|
- gfgordon@gmail.com
|
@@ -113,6 +99,7 @@ files:
|
|
113
99
|
- lib/minitest/match_json/version.rb
|
114
100
|
- minitest-match_json.gemspec
|
115
101
|
- test/minitest/match_json_test.rb
|
102
|
+
- test/test_helper.rb
|
116
103
|
homepage: http://ggordon.github.io/minitest-match_json
|
117
104
|
licenses:
|
118
105
|
- MIT
|
@@ -139,3 +126,4 @@ specification_version: 4
|
|
139
126
|
summary: Compare two JSON objects
|
140
127
|
test_files:
|
141
128
|
- test/minitest/match_json_test.rb
|
129
|
+
- test/test_helper.rb
|