human_reporter 0.0.1
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/lib/human_reporter.rb +182 -0
- metadata +85 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 464612f36e579a4a1c9b5092773416386362ea714af1dffba933c016e3eea190
|
|
4
|
+
data.tar.gz: bcb06392eeb9b3495bafc50eafe642264edcf7d70b1b53e9b43e63e4089271f7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '069cea29c639bf6aa12c397f2d57ed5adc65d3361927ff7cf79afc7d17e07e86d5f9e4cfb391159f7530fadc39e95c936579966c133005296ea4c4a2ac4430cc'
|
|
7
|
+
data.tar.gz: f9806577e12be84491a64d803b3901bc1621d45a6847c112a6dc286995fe6ea5dd3855c077802f8ae67cb627646ad5230deb5d15ca4e47984aea9032ae6692dc
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
require 'minitest'
|
|
2
|
+
# require 'minitest/human_reporter_plugin'
|
|
3
|
+
|
|
4
|
+
class Minitest::Test
|
|
5
|
+
def assert_equal expected, actual, msg = nil
|
|
6
|
+
return true if expected == actual
|
|
7
|
+
|
|
8
|
+
handler = handler(expected, actual)
|
|
9
|
+
|
|
10
|
+
return super(expected, actual, msg) if expected.nil? || actual.nil? || handler.nil?
|
|
11
|
+
|
|
12
|
+
raise Minitest::Assertion, handler.message()
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def handler(expected, actual)
|
|
16
|
+
case expected
|
|
17
|
+
when Array
|
|
18
|
+
ArrayHandler.new(expected, actual)
|
|
19
|
+
when Hash
|
|
20
|
+
HashHandler.new(expected, actual)
|
|
21
|
+
when String
|
|
22
|
+
StringHandler.new(expected, actual)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Handler
|
|
28
|
+
RED = 31
|
|
29
|
+
GREEN = 32
|
|
30
|
+
|
|
31
|
+
attr_reader :expected, :actual
|
|
32
|
+
|
|
33
|
+
def initialize(expected, actual)
|
|
34
|
+
@expected = expected
|
|
35
|
+
@actual = actual
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def message
|
|
39
|
+
raise "plz implement me"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def intersection
|
|
43
|
+
raise "plz implement me"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def missing
|
|
47
|
+
raise "plz implement me"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def remaining
|
|
51
|
+
raise "plz implement me"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class ArrayHandler < Handler
|
|
56
|
+
def intersection
|
|
57
|
+
@intersection ||= expected & actual
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def missing
|
|
61
|
+
@missing ||= expected - intersection
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def remaining
|
|
65
|
+
@remaining ||= actual - intersection
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def message
|
|
69
|
+
result = ""
|
|
70
|
+
print_with_colour(RED, result, expected, "Expected", intersection)
|
|
71
|
+
print_with_colour(GREEN, result, actual, " Actual", intersection)
|
|
72
|
+
|
|
73
|
+
if missing.any? || remaining.any?
|
|
74
|
+
result << "\n"
|
|
75
|
+
|
|
76
|
+
result << " Missing: #{missing.inspect}\n" unless missing.empty?
|
|
77
|
+
result << " Remaining: #{remaining.inspect}\n" unless remaining.empty?
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
if expected.to_set == actual.to_set
|
|
81
|
+
result << "\n Both arrays have the same elements, but order matters in array comparisons."
|
|
82
|
+
result << " If element order does not matter, you can call '.to_set' on both before asserting.\n"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
result
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def print_with_colour(colour, message, enumerable, title, intersection)
|
|
91
|
+
message << " #{title}: ["
|
|
92
|
+
|
|
93
|
+
first = true
|
|
94
|
+
enumerable.each do |e|
|
|
95
|
+
message << ", " unless first
|
|
96
|
+
first = false
|
|
97
|
+
|
|
98
|
+
if !intersection.include?(e)
|
|
99
|
+
message << "\e[#{colour}m#{e.inspect}\e[0m"
|
|
100
|
+
else
|
|
101
|
+
message << e.inspect
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
message << "]\n"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
class HashHandler < Handler
|
|
110
|
+
def intersection
|
|
111
|
+
@intersection ||= expected.select do |key, value|
|
|
112
|
+
actual.key?(key) && actual[key] == value
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def missing
|
|
117
|
+
@missing ||= expected.reject do |key, value|
|
|
118
|
+
intersection.key?(key) && intersection[key] == value
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def remaining
|
|
123
|
+
@remaining ||= actual.reject do |key, value|
|
|
124
|
+
intersection.key?(key) && intersection[key] == value
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def message
|
|
129
|
+
result = ""
|
|
130
|
+
print_with_colour(RED, result, expected, "Expected", intersection)
|
|
131
|
+
print_with_colour(GREEN, result, actual, " Actual", intersection)
|
|
132
|
+
|
|
133
|
+
if missing.any? || remaining.any?
|
|
134
|
+
result << "\n"
|
|
135
|
+
|
|
136
|
+
result << " Missing: #{missing.inspect}\n" unless missing.empty?
|
|
137
|
+
result << " Remaining: #{remaining.inspect}\n" unless remaining.empty?
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
result
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
private
|
|
144
|
+
|
|
145
|
+
def print_with_colour(colour, message, enumerable, title, intersection)
|
|
146
|
+
message << " #{title}: {"
|
|
147
|
+
|
|
148
|
+
first = true
|
|
149
|
+
enumerable.each do |k, v|
|
|
150
|
+
message << ", " unless first
|
|
151
|
+
first = false
|
|
152
|
+
|
|
153
|
+
item_message = "#{k.inspect}=>#{v.inspect}"
|
|
154
|
+
if intersection.key?(k) && intersection[k] == v
|
|
155
|
+
message << item_message
|
|
156
|
+
else
|
|
157
|
+
message << "\e[#{colour}m#{item_message}\e[0m"
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
message << "}\n"
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
class StringHandler < Handler
|
|
166
|
+
def message
|
|
167
|
+
result = ""
|
|
168
|
+
|
|
169
|
+
if actual.start_with?(expected)
|
|
170
|
+
result << " Expected: #{expected.inspect}\n"
|
|
171
|
+
result << " Actual: \"#{expected}\e[#{GREEN}m#{actual[expected.size..-1]}\e[0m\"\n"
|
|
172
|
+
elsif expected.start_with?(actual)
|
|
173
|
+
result << " Expected: \"#{actual}\e[#{RED}m#{expected[actual.size..-1]}\e[0m\"\n"
|
|
174
|
+
result << " Actual: #{actual.inspect}\n"
|
|
175
|
+
else
|
|
176
|
+
result << " Expected: \"\e[#{RED}m#{expected}\e[0m\"\n"
|
|
177
|
+
result << " Actual: \"\e[#{GREEN}m#{actual}\e[0m\"\n"
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
result
|
|
181
|
+
end
|
|
182
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: human_reporter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Lucas Uyezu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-02-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: byebug
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '10.0'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 10.0.0
|
|
23
|
+
type: :development
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '10.0'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 10.0.0
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: minitest
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '5.11'
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 5.11.3
|
|
43
|
+
type: :development
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - "~>"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '5.11'
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 5.11.3
|
|
53
|
+
description: A MiniTest report designed for human beings, with detailed information
|
|
54
|
+
on where the differences are
|
|
55
|
+
email: lucas@uyezu.com
|
|
56
|
+
executables: []
|
|
57
|
+
extensions: []
|
|
58
|
+
extra_rdoc_files: []
|
|
59
|
+
files:
|
|
60
|
+
- lib/human_reporter.rb
|
|
61
|
+
homepage: https://github.com/lucasuyezu/human_reporter
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata: {}
|
|
65
|
+
post_install_message:
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 2.7.6
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 4
|
|
84
|
+
summary: A MiniTest report designed for human beings
|
|
85
|
+
test_files: []
|