minitest-extended_assertions 1.0.0
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 +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +26 -0
- data/lib/minitest/extended_assertions/deep_comparator.rb +72 -0
- data/lib/minitest/extended_assertions/version.rb +5 -0
- data/lib/minitest/extended_assertions.rb +30 -0
- data/lib/minitest-extended_assertions.rb +1 -0
- data/minitest-extended_assertions.gemspec +29 -0
- data/spec/assertions_spec.rb +35 -0
- data/spec/coverage_helper.rb +5 -0
- data/spec/deep_comparator_spec.rb +215 -0
- data/spec/equal_array_examples.rb +23 -0
- data/spec/equal_hash_examples.rb +23 -0
- data/spec/equal_json_examples.rb +23 -0
- data/spec/expectations_spec.rb +35 -0
- data/spec/minitest_helper.rb +29 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6933733fceba655d3faf0f17c953eedb60935c3e0c0a4ecd95f48b9cc1bd63db
|
4
|
+
data.tar.gz: f07810fa561e61bf1a0e8126f6896cfea35f5a5192dbefff5714e0486a33f312
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c79457cbc5fb21792dd5dca2b6602979e4934c63b0dc603428c58e9acdef542cf8be3ccb958b57555e8ca8b6e988a1160ba8dfe8b6aa76b76e6eba08f9da34ac
|
7
|
+
data.tar.gz: 47994b846cbe1541387e8726e6eb00a978d48a6510aedaba111f1f1b11c683eae3ffd217c069ab37ed772fa774523484bebf34f66f26676aaa190399d7836c48
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
minitest-extended_assertions
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.7.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Gabriel Naiman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Minitest::ExtendedAssertions
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/minitest-extended_assertions)
|
4
|
+
[](https://travis-ci.com/gabynaiman/minitest-extended_assertions)
|
5
|
+
[](https://coveralls.io/github/gabynaiman/minitest-extended_assertions?branch=master)
|
6
|
+
[](https://codeclimate.com/github/gabynaiman/minitest-extended_assertions)
|
7
|
+
|
8
|
+
Extended assertions for Minitest
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'minitest-extended_assertions'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install minitest-extended_assertions
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Hash
|
29
|
+
```ruby
|
30
|
+
expected = {a: 1, b: 2}
|
31
|
+
actual = {a: 2, b: 1}
|
32
|
+
|
33
|
+
assert_equal_hash expected, actual
|
34
|
+
actual.must_equal_hash expected
|
35
|
+
|
36
|
+
# [:a]
|
37
|
+
# Expected: 1
|
38
|
+
# Actual: 2
|
39
|
+
|
40
|
+
# [:b]
|
41
|
+
# Expected: 2
|
42
|
+
# Actual: 1
|
43
|
+
```
|
44
|
+
|
45
|
+
### Array
|
46
|
+
```ruby
|
47
|
+
expected = [1, 2, 3, 4]
|
48
|
+
actual = [1, 20, 3, 40]
|
49
|
+
|
50
|
+
assert_equal_array expected, actual
|
51
|
+
actual.must_equal_array expected
|
52
|
+
|
53
|
+
# [1]
|
54
|
+
# Expected: 2
|
55
|
+
# Actual: 20
|
56
|
+
|
57
|
+
# [3]
|
58
|
+
# Expected: 4
|
59
|
+
# Actual: 40
|
60
|
+
```
|
61
|
+
|
62
|
+
### JSON
|
63
|
+
```ruby
|
64
|
+
expected = '{"a": 1, "b": 2}'
|
65
|
+
actual = '{"a": 2, "b": 1}'
|
66
|
+
|
67
|
+
assert_equal_json expected, actual
|
68
|
+
actual.must_equal_json expected
|
69
|
+
|
70
|
+
# ["a"]
|
71
|
+
# Expected: 1
|
72
|
+
# Actual: 2
|
73
|
+
|
74
|
+
# ["b"]
|
75
|
+
# Expected: 2
|
76
|
+
# Actual: 1
|
77
|
+
```
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/minitest-extended_assertions.
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:spec) do |t|
|
5
|
+
t.libs << 'spec'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.pattern = ENV['DIR'] ? File.join(ENV['DIR'], '**', '*_spec.rb') : 'spec/**/*_spec.rb'
|
8
|
+
t.verbose = false
|
9
|
+
t.warning = false
|
10
|
+
t.loader = nil if ENV['TEST']
|
11
|
+
ENV['TEST'], ENV['LINE'] = ENV['TEST'].split(':') if ENV['TEST'] && !ENV['LINE']
|
12
|
+
t.options = ''
|
13
|
+
t.options << "--name=/#{ENV['NAME']}/ " if ENV['NAME']
|
14
|
+
t.options << "-l #{ENV['LINE']} " if ENV['LINE'] && ENV['TEST']
|
15
|
+
t.ruby_opts << '-W0'
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: :spec
|
19
|
+
|
20
|
+
desc 'Pry console'
|
21
|
+
task :console do
|
22
|
+
require 'minitest-extended_assertions'
|
23
|
+
require 'pry'
|
24
|
+
ARGV.clear
|
25
|
+
Pry.start
|
26
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Minitest
|
2
|
+
module ExtendedAssertions
|
3
|
+
class DeepComparator
|
4
|
+
|
5
|
+
class Difference
|
6
|
+
|
7
|
+
attr_reader :path, :expected, :actual
|
8
|
+
|
9
|
+
def initialize(path, expected, actual)
|
10
|
+
@path = path
|
11
|
+
@expected = expected
|
12
|
+
@actual = actual
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
{
|
17
|
+
path: path,
|
18
|
+
expected: expected,
|
19
|
+
actual: actual
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
[path, "Expected: #{expected.inspect}", " Actual: #{actual.inspect}"].compact.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
|
31
|
+
def compare(expected, actual, path=nil)
|
32
|
+
if expected.class != actual.class
|
33
|
+
[Difference.new(path, expected, actual)]
|
34
|
+
else
|
35
|
+
if expected.is_a? Hash
|
36
|
+
compare_hash expected, actual, path
|
37
|
+
elsif expected.is_a? Array
|
38
|
+
compare_array expected, actual, path
|
39
|
+
elsif expected != actual
|
40
|
+
[Difference.new(path, expected, actual)]
|
41
|
+
else
|
42
|
+
[]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def compare_hash(expected, actual, path)
|
50
|
+
if expected.keys.sort != actual.keys.sort
|
51
|
+
[Difference.new("#{path}.keys", expected.keys.sort, actual.keys.sort)]
|
52
|
+
else
|
53
|
+
expected.flat_map do |k, v|
|
54
|
+
compare v, actual[k], "#{path}[#{k.inspect}]"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def compare_array(expected, actual, path)
|
60
|
+
if expected.count != actual.count
|
61
|
+
[Difference.new("#{path}.count", expected.count, actual.count)]
|
62
|
+
else
|
63
|
+
expected.flat_map.with_index do |v, i|
|
64
|
+
compare v, actual[i], "#{path}[#{i}]"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require_relative 'extended_assertions/version'
|
4
|
+
require_relative 'extended_assertions/deep_comparator'
|
5
|
+
|
6
|
+
module Minitest
|
7
|
+
module Assertions
|
8
|
+
|
9
|
+
def assert_equal_hash(expected, actual)
|
10
|
+
differences = ExtendedAssertions::DeepComparator.compare expected, actual
|
11
|
+
assert differences.empty?, differences.map(&:to_s).join("\n\n")
|
12
|
+
end
|
13
|
+
alias_method :assert_equal_array, :assert_equal_hash
|
14
|
+
|
15
|
+
def assert_equal_json(expected, actual)
|
16
|
+
assert_equal_hash JSON.parse(expected), JSON.parse(actual)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
module Expectations
|
22
|
+
|
23
|
+
infect_an_assertion :assert_equal_hash, :must_equal_hash
|
24
|
+
|
25
|
+
infect_an_assertion :assert_equal_array, :must_equal_array
|
26
|
+
|
27
|
+
infect_an_assertion :assert_equal_json, :must_equal_json
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'minitest/extended_assertions'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require_relative 'lib/minitest/extended_assertions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'minitest-extended_assertions'
|
8
|
+
spec.version = Minitest::ExtendedAssertions::VERSION
|
9
|
+
spec.authors = ['Gabriel Naiman']
|
10
|
+
spec.email = ['gabynaiman@gmail.com']
|
11
|
+
spec.summary = 'Extended assertions for Minitest'
|
12
|
+
spec.description = 'Extended assertions for Minitest'
|
13
|
+
spec.homepage = 'https://github.com/gabynaiman/minitest-extended_assertions'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'minitest', '~> 5.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
24
|
+
spec.add_development_dependency 'minitest-colorin', '~> 0.1'
|
25
|
+
spec.add_development_dependency 'minitest-line', '~> 0.6'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.12'
|
27
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
28
|
+
spec.add_development_dependency 'pry-nav', '~> 1.0'
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Minitest::Assertions do
|
4
|
+
|
5
|
+
describe 'assert_equal_hash' do
|
6
|
+
|
7
|
+
include EqualHashExamples
|
8
|
+
|
9
|
+
def run_assertion(expected, actual)
|
10
|
+
assert_equal_hash expected, actual
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'assert_equal_array' do
|
16
|
+
|
17
|
+
include EqualArrayExamples
|
18
|
+
|
19
|
+
def run_assertion(expected, actual)
|
20
|
+
assert_equal_array expected, actual
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'assert_equal_json' do
|
26
|
+
|
27
|
+
include EqualJsonExamples
|
28
|
+
|
29
|
+
def run_assertion(expected, actual)
|
30
|
+
assert_equal_json expected, actual
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Minitest::ExtendedAssertions::DeepComparator do
|
4
|
+
|
5
|
+
def assert_differences(expected, actual, expected_diffs)
|
6
|
+
actual_diffs = Minitest::ExtendedAssertions::DeepComparator.compare expected, actual
|
7
|
+
|
8
|
+
assert_equal expected_diffs, actual_diffs.map { |d| d.to_h.reject { |k,v| v.nil? } }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Primitives' do
|
12
|
+
|
13
|
+
it 'Equal' do
|
14
|
+
assert_differences 1, 1, []
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'Different values' do
|
18
|
+
assert_differences 1, 2, [expected: 1, actual: 2]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'Different types' do
|
22
|
+
assert_differences 1, 'text', [expected: 1, actual: 'text']
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'Hashes' do
|
28
|
+
|
29
|
+
it 'Equal' do
|
30
|
+
expected = {a: 1, b: 2}
|
31
|
+
actual = {b: 2, a: 1}
|
32
|
+
|
33
|
+
assert_differences expected, actual, []
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'Different keys' do
|
37
|
+
expected = {a: 1, b: 2}
|
38
|
+
actual = {c: 3}
|
39
|
+
|
40
|
+
assert_differences expected, actual, [path: '.keys', expected: [:a, :b], actual: [:c]]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'Different values' do
|
44
|
+
expected = {a: 1, b: 2}
|
45
|
+
actual = {b: 3, a: 4}
|
46
|
+
|
47
|
+
assert_differences expected, actual, [
|
48
|
+
{path: '[:a]', expected: 1, actual: 4},
|
49
|
+
{path: '[:b]', expected: 2, actual: 3}
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'Arrays' do
|
56
|
+
|
57
|
+
it 'Equal' do
|
58
|
+
expected = [1, 2]
|
59
|
+
actual = [1, 2]
|
60
|
+
|
61
|
+
assert_differences expected, actual, []
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'Different size' do
|
65
|
+
expected = [1, 2, 3]
|
66
|
+
actual = [1, 2]
|
67
|
+
|
68
|
+
assert_differences expected, actual, [path: '.count', expected: 3, actual: 2]
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'Different values' do
|
72
|
+
expected = [1, 3, 4]
|
73
|
+
actual = [1, 2, 5]
|
74
|
+
|
75
|
+
assert_differences expected, actual, [
|
76
|
+
{path: '[1]', expected: 3, actual: 2},
|
77
|
+
{path: '[2]', expected: 4, actual: 5}
|
78
|
+
]
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'Nested' do
|
84
|
+
|
85
|
+
describe 'Hash -> Hash -> Hash' do
|
86
|
+
|
87
|
+
let :expected do
|
88
|
+
{
|
89
|
+
key_1: 1,
|
90
|
+
key_2: {
|
91
|
+
key_2_1: 2,
|
92
|
+
key_2_2: {
|
93
|
+
key_2_2_1: 3
|
94
|
+
}
|
95
|
+
},
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'Equal' do
|
100
|
+
actual = deep_clone expected
|
101
|
+
|
102
|
+
assert_differences expected, actual, []
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'Different' do
|
106
|
+
actual = deep_clone expected
|
107
|
+
actual[:key_1] = 10
|
108
|
+
actual[:key_2][:key_2_1] = 20
|
109
|
+
actual[:key_2][:key_2_2][:key_2_2_1] = 30
|
110
|
+
|
111
|
+
assert_differences expected, actual, [
|
112
|
+
{path: '[:key_1]', expected: 1, actual: 10},
|
113
|
+
{path: '[:key_2][:key_2_1]', expected: 2, actual: 20},
|
114
|
+
{path: '[:key_2][:key_2_2][:key_2_2_1]', expected: 3, actual: 30}
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'Array -> Array -> Arrary' do
|
121
|
+
|
122
|
+
let :expected do
|
123
|
+
[1, [2, [3, 4]]]
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'Equal' do
|
127
|
+
actual = deep_clone expected
|
128
|
+
|
129
|
+
assert_differences expected, actual, []
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'Different' do
|
133
|
+
actual = deep_clone expected
|
134
|
+
actual[0] = 10
|
135
|
+
actual[1][0] = 20
|
136
|
+
actual[1][1][0] = 30
|
137
|
+
|
138
|
+
assert_differences expected, actual, [
|
139
|
+
{path: '[0]', expected: 1, actual: 10},
|
140
|
+
{path: '[1][0]', expected: 2, actual: 20},
|
141
|
+
{path: '[1][1][0]', expected: 3, actual: 30}
|
142
|
+
]
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
describe 'Hash -> Array -> Hash -> Array' do
|
148
|
+
|
149
|
+
let :expected do
|
150
|
+
{
|
151
|
+
key_1: 1,
|
152
|
+
key_2: [
|
153
|
+
2,
|
154
|
+
{
|
155
|
+
key_2_1: 3,
|
156
|
+
key_2_2: [4, 5]
|
157
|
+
}
|
158
|
+
]
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'Equal' do
|
163
|
+
actual = deep_clone expected
|
164
|
+
|
165
|
+
assert_differences expected, actual, []
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'Different' do
|
169
|
+
actual = deep_clone expected
|
170
|
+
actual[:key_1] = 10
|
171
|
+
actual[:key_2][0] = 20
|
172
|
+
actual[:key_2][1][:key_2_1] = 30
|
173
|
+
actual[:key_2][1][:key_2_2][0] = 40
|
174
|
+
|
175
|
+
assert_differences expected, actual, [
|
176
|
+
{path: '[:key_1]', expected: 1, actual: 10},
|
177
|
+
{path: '[:key_2][0]', expected: 2, actual: 20},
|
178
|
+
{path: '[:key_2][1][:key_2_1]', expected: 3, actual: 30},
|
179
|
+
{path: '[:key_2][1][:key_2_2][0]', expected: 4, actual: 40}
|
180
|
+
]
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
describe 'Difference' do
|
188
|
+
|
189
|
+
let (:difference) { Minitest::ExtendedAssertions::DeepComparator::Difference.new '[:key]', 1, 2 }
|
190
|
+
|
191
|
+
let (:difference_without_path) { Minitest::ExtendedAssertions::DeepComparator::Difference.new nil, 1, 2 }
|
192
|
+
|
193
|
+
it 'to_h' do
|
194
|
+
expected = {path: '[:key]', expected: 1, actual: 2}
|
195
|
+
assert_equal expected, difference.to_h
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'to_h (without path)' do
|
199
|
+
expected = {path: nil, expected: 1, actual: 2}
|
200
|
+
assert_equal expected, difference_without_path.to_h
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'to_s' do
|
204
|
+
expected = "[:key]\nExpected: 1\n Actual: 2"
|
205
|
+
assert_equal expected, difference.to_s
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'to_s (without path)' do
|
209
|
+
expected = "Expected: 1\n Actual: 2"
|
210
|
+
assert_equal expected, difference_without_path.to_s
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module EqualArrayExamples
|
2
|
+
|
3
|
+
extend Minitest::Spec::DSL
|
4
|
+
|
5
|
+
it 'Success' do
|
6
|
+
expected = [1, 2, 3]
|
7
|
+
actual = [1, 2, 3]
|
8
|
+
|
9
|
+
run_assertion expected, actual
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'Fail' do
|
13
|
+
expected = [1, 2, 3, 4]
|
14
|
+
actual = [1, 20, 3, 40]
|
15
|
+
|
16
|
+
expected_error = "[1]\nExpected: 2\n Actual: 20\n\n[3]\nExpected: 4\n Actual: 40"
|
17
|
+
|
18
|
+
assert_fail_with_error(expected_error) do
|
19
|
+
run_assertion expected, actual
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module EqualHashExamples
|
2
|
+
|
3
|
+
extend Minitest::Spec::DSL
|
4
|
+
|
5
|
+
it 'Success' do
|
6
|
+
expected = {a: 1, b: 2}
|
7
|
+
actual = {a: 1, b: 2}
|
8
|
+
|
9
|
+
run_assertion expected, actual
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'Fail' do
|
13
|
+
expected = {a: "1", b: 2}
|
14
|
+
actual = {a: 2, b: true}
|
15
|
+
|
16
|
+
expected_error = "[:a]\nExpected: \"1\"\n Actual: 2\n\n[:b]\nExpected: 2\n Actual: true"
|
17
|
+
|
18
|
+
assert_fail_with_error(expected_error) do
|
19
|
+
run_assertion expected, actual
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module EqualJsonExamples
|
2
|
+
|
3
|
+
extend Minitest::Spec::DSL
|
4
|
+
|
5
|
+
it 'Success' do
|
6
|
+
expected = '{"a": 1, "b": 2}'
|
7
|
+
actual = '{"a": 1, "b": 2}'
|
8
|
+
|
9
|
+
run_assertion expected, actual
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'Fail' do
|
13
|
+
expected = '{"a": "1", "b": 2}'
|
14
|
+
actual = '{"a": 2, "b": true}'
|
15
|
+
|
16
|
+
expected_error = "[\"a\"]\nExpected: \"1\"\n Actual: 2\n\n[\"b\"]\nExpected: 2\n Actual: true"
|
17
|
+
|
18
|
+
assert_fail_with_error(expected_error) do
|
19
|
+
run_assertion expected, actual
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe Minitest::Expectations do
|
4
|
+
|
5
|
+
describe 'must_equal_hash' do
|
6
|
+
|
7
|
+
include EqualHashExamples
|
8
|
+
|
9
|
+
def run_assertion(expected, actual)
|
10
|
+
actual.must_equal_hash expected
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'must_equal_array' do
|
16
|
+
|
17
|
+
include EqualArrayExamples
|
18
|
+
|
19
|
+
def run_assertion(expected, actual)
|
20
|
+
actual.must_equal_array expected
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'must_equal_json' do
|
26
|
+
|
27
|
+
include EqualJsonExamples
|
28
|
+
|
29
|
+
def run_assertion(expected, actual)
|
30
|
+
actual.must_equal_json expected
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'coverage_helper'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/colorin'
|
4
|
+
require 'pry-nav'
|
5
|
+
|
6
|
+
require 'minitest/extended_assertions'
|
7
|
+
require_relative 'equal_hash_examples'
|
8
|
+
require_relative 'equal_array_examples'
|
9
|
+
require_relative 'equal_json_examples'
|
10
|
+
|
11
|
+
class Minitest::Test
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def assert_fail_with_error(expected_error)
|
16
|
+
begin
|
17
|
+
yield
|
18
|
+
fail "Expected assertion fail with message:\n#{expected_error}"
|
19
|
+
|
20
|
+
rescue Minitest::Assertion => error
|
21
|
+
assert_equal expected_error, error.message
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def deep_clone(object)
|
26
|
+
Marshal.load(Marshal.dump(object))
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-extended_assertions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel Naiman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-colorin
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-line
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.12'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-nav
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
description: Extended assertions for Minitest
|
112
|
+
email:
|
113
|
+
- gabynaiman@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".coveralls.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".ruby-gemset"
|
121
|
+
- ".ruby-version"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- lib/minitest-extended_assertions.rb
|
128
|
+
- lib/minitest/extended_assertions.rb
|
129
|
+
- lib/minitest/extended_assertions/deep_comparator.rb
|
130
|
+
- lib/minitest/extended_assertions/version.rb
|
131
|
+
- minitest-extended_assertions.gemspec
|
132
|
+
- spec/assertions_spec.rb
|
133
|
+
- spec/coverage_helper.rb
|
134
|
+
- spec/deep_comparator_spec.rb
|
135
|
+
- spec/equal_array_examples.rb
|
136
|
+
- spec/equal_hash_examples.rb
|
137
|
+
- spec/equal_json_examples.rb
|
138
|
+
- spec/expectations_spec.rb
|
139
|
+
- spec/minitest_helper.rb
|
140
|
+
homepage: https://github.com/gabynaiman/minitest-extended_assertions
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubygems_version: 3.1.2
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Extended assertions for Minitest
|
163
|
+
test_files:
|
164
|
+
- spec/assertions_spec.rb
|
165
|
+
- spec/coverage_helper.rb
|
166
|
+
- spec/deep_comparator_spec.rb
|
167
|
+
- spec/equal_array_examples.rb
|
168
|
+
- spec/equal_hash_examples.rb
|
169
|
+
- spec/equal_json_examples.rb
|
170
|
+
- spec/expectations_spec.rb
|
171
|
+
- spec/minitest_helper.rb
|