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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c4027d485fb16d15e957b930a8da529ab72cbe1
4
- data.tar.gz: 23bbd0c28f7c4ca0428f880641b51fb3c34d8abc
3
+ metadata.gz: 27009176eb3e76417efbe93b3347432a98ef73f5
4
+ data.tar.gz: fdd7af554496ea29734494456fce808273054c39
5
5
  SHA512:
6
- metadata.gz: b353ade92cb392f4f73611b6220b461c1ead810545a55ca44eef92b532d5fbd56f13709b41f0f7fb8c7ef694f30ce05226447d184b028b81727f84f7406a237b
7
- data.tar.gz: 129aa8951a8953e668ef81c2d9943aa7fc9043d46bebd4ed8f1cb25c7c04dd676be336c2a02a49b2becd9e8b6806f564035ee7114cd9ecea01c1761c76da0cf4
6
+ metadata.gz: 7e0896d6f40a3790297fe882591c1696dcf505b508c8b5be2a477aed36a6700588f5920c477186b30d63b663f2e7b6569d7dd0eecc8e13a72af7329475dff5a8
7
+ data.tar.gz: 7d92f63a92b995f4c91d5b21f6cd233a0e5da9e603d3fea71b6d013d3819f1c94220054ab4a2fbdd6f33643ee978766c72766b98f157426f671ea2c014bce3d1
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in minitest-match_json.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'codeclimate-test-reporter', require: nil
8
+ end
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Minitest::MatchJson
2
2
 
3
- Compare two JSON objects. If a String is passed in, it is expected to be valid JSON, any other type will be converted to json if possible.
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 compared the two JSON objects. Options to control the output format and number of context lines to be displayed can be passed through to Diffy.
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.verbose = false
13
+ t.libs.push 'test'
8
14
  end
9
-
15
+ task test: 'coverage:clean'
10
16
  task default: :test
@@ -9,27 +9,27 @@ module Minitest
9
9
  module MatchJson
10
10
  class << self
11
11
  attr_writer :configuration
12
- end
13
12
 
14
- def self.configuration
15
- @configuration ||= Configuration.new
16
- end
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
17
16
 
18
- def self.configure
19
- yield configuration
20
- end
17
+ def configure
18
+ yield configuration
19
+ end
21
20
 
22
- def self.compare_json(actual_json, expected_json)
23
- Diffy::Diff.new(
24
- expected_json,
25
- actual_json,
26
- context: configuration.context
27
- ).to_s(configuration.format)
28
- end
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
- def self.pretty_json(param)
31
- json = (param.is_a?(String)) ? param : param.to_json
32
- JSON.pretty_generate(JSON.parse(json))
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
@@ -1,6 +1,6 @@
1
1
  module Minitest
2
2
  # JSON matchers
3
3
  module MatchJson
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
@@ -25,5 +25,4 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.7'
27
27
  spec.add_development_dependency 'rake', '~> 10.0'
28
- spec.add_development_dependency 'simplecov'
29
28
  end
@@ -1,9 +1,4 @@
1
- require 'simplecov'
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
- pass
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\": 4
55
- + \"b\": 5
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\": 4,
83
- + \"b\": 5,
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\": 4\e[0m
109
- \e[32m+ \"b\": 5\e[0m
131
+ \e[31m- \"b\": 5\e[0m
132
+ \e[32m+ \"b\": 4\e[0m
110
133
  }
111
134
  \
112
135
 
@@ -0,0 +1,10 @@
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.configuration.git_dir = '.'
3
+ CodeClimate::TestReporter.start
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+
8
+ gem 'minitest'
9
+ require 'minitest/autorun'
10
+ require 'minitest/match_json'
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.1.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-19 00:00:00.000000000 Z
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