minitest-holdify 1.3.0 → 1.3.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 +4 -4
- data/lib/holdify/feedback.rb +18 -8
- data/lib/holdify/hold.rb +0 -4
- data/lib/holdify/store.rb +6 -7
- data/lib/holdify.rb +1 -1
- data/lib/minitest/holdify_plugin.rb +6 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aff615590c52a4b538a92ae7e90dd24a6d4f5461e70b3cc240f5a30a819a8855
|
|
4
|
+
data.tar.gz: 6a0977317a054b2e6c89c403715c2815cd3d24d479161f83c622acb55ded2aeb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f0553c5e76cced33e96d49adf7b89929d2d119d3f375ac36ea1aa3fac2a5786cfc65000aaefae5bf5066f94921840549927761a36b2f9832f6ea770a8a71702
|
|
7
|
+
data.tar.gz: 73ff0933e454a35def50e40b2cf46b82a45a4fa801c6dbb2dcb9a36d4ef11ddd91ee51649260f60e544ef581e7768942076aa1a4120aae4aeabf5a4d4a65cb79
|
data/lib/holdify/feedback.rb
CHANGED
|
@@ -68,8 +68,8 @@ module Holdify
|
|
|
68
68
|
def git_command = "git diff --no-index --no-color --unified=1000 #{@exp_path} #{@act_path}"
|
|
69
69
|
|
|
70
70
|
def diff
|
|
71
|
-
@exp_path = create_tempfile(@expected).path
|
|
72
|
-
@act_path = create_tempfile(@actual).path
|
|
71
|
+
@exp_path = create_tempfile(@expected, 'expected').path
|
|
72
|
+
@act_path = create_tempfile(@actual, 'actual').path
|
|
73
73
|
|
|
74
74
|
stdout, = Open3.capture3(git_command)
|
|
75
75
|
regex = /\A[^@]*\r?\n/m # cleanup git headers
|
|
@@ -83,9 +83,9 @@ module Holdify
|
|
|
83
83
|
# :nocov:
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
def create_tempfile(obj)
|
|
86
|
+
def create_tempfile(obj, type)
|
|
87
87
|
Tempfile.create.tap do |file|
|
|
88
|
-
file.write(
|
|
88
|
+
file.write(Store.hold_dump(obj).sub(/(?=\n)/, type))
|
|
89
89
|
file.close
|
|
90
90
|
end
|
|
91
91
|
end
|
|
@@ -94,17 +94,27 @@ module Holdify
|
|
|
94
94
|
width = 0
|
|
95
95
|
lineno = [@yaml_lno - 1]
|
|
96
96
|
lines.map.with_index do |line, i|
|
|
97
|
-
if i.zero?
|
|
98
|
-
|
|
99
|
-
width = (@yaml_lno + w).to_s.length
|
|
97
|
+
if i.zero? # @@ ... @@
|
|
98
|
+
width, line = render_hunk(line)
|
|
100
99
|
next line
|
|
101
100
|
end
|
|
102
|
-
next if i == 1
|
|
101
|
+
next if i == 1 || (i == 2 && !Holdify.color) # ---
|
|
103
102
|
|
|
104
103
|
render_line(line, lineno, width)
|
|
105
104
|
end.compact
|
|
106
105
|
end
|
|
107
106
|
|
|
107
|
+
def render_hunk(line)
|
|
108
|
+
width = 0
|
|
109
|
+
hunk = line.gsub(/([-+]\d+),(\d+)\s+([-+]\d+),(\d+)/) do
|
|
110
|
+
v1, = $2.to_i - 1 # rubocop:disable Style/PerlBackrefs
|
|
111
|
+
v2 = $4.to_i - 1 # rubocop:disable Style/PerlBackrefs
|
|
112
|
+
width = (@yaml_lno + [v1, v2].max).to_s.length
|
|
113
|
+
"#{$1},#{v1} #{$3},#{v2}" # rubocop:disable Style/PerlBackrefs
|
|
114
|
+
end
|
|
115
|
+
[width, hunk]
|
|
116
|
+
end
|
|
117
|
+
|
|
108
118
|
def render_line(line, lineno, width)
|
|
109
119
|
type = line[0]
|
|
110
120
|
line = line[1..]
|
data/lib/holdify/hold.rb
CHANGED
|
@@ -51,10 +51,6 @@ module Holdify
|
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
def warn_for(actual)
|
|
55
|
-
warn("[holdify] The value from #{Holdify.relative(@test_loc.path)}:#{@test_loc.lineno} is:\n[holdify] => #{actual.inspect}")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
54
|
def feedback(*) = Feedback.new(self, *).message
|
|
59
55
|
end
|
|
60
56
|
end
|
data/lib/holdify/store.rb
CHANGED
|
@@ -11,6 +11,11 @@ module Holdify
|
|
|
11
11
|
def register(target, obj); end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
def self.hold_dump(obj)
|
|
15
|
+
visitor = NoAliasVisitor.create
|
|
16
|
+
visitor << obj
|
|
17
|
+
visitor.tree.to_yaml
|
|
18
|
+
end
|
|
14
19
|
extend Forwardable
|
|
15
20
|
|
|
16
21
|
def_delegator :@source, :xxh
|
|
@@ -38,17 +43,11 @@ module Holdify
|
|
|
38
43
|
output["L#{lineno} #{xxh}"] = @data[lineno]
|
|
39
44
|
end
|
|
40
45
|
|
|
41
|
-
File.write(@path, hold_dump(output))
|
|
46
|
+
File.write(@path, self.class.hold_dump(output))
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
private
|
|
45
50
|
|
|
46
|
-
def hold_dump(obj)
|
|
47
|
-
visitor = NoAliasVisitor.create
|
|
48
|
-
visitor << obj
|
|
49
|
-
visitor.tree.to_yaml
|
|
50
|
-
end
|
|
51
|
-
|
|
52
51
|
def load_and_align
|
|
53
52
|
{}.tap do |aligned|
|
|
54
53
|
data = YAML.unsafe_load_file(@path) || {}
|
data/lib/holdify.rb
CHANGED
|
@@ -68,17 +68,19 @@ module Minitest
|
|
|
68
68
|
expected = @hold.(actual, **)
|
|
69
69
|
|
|
70
70
|
begin
|
|
71
|
-
if
|
|
71
|
+
if inspect
|
|
72
|
+
message = ['INSPECT[?]', message].compact.join(' ')
|
|
73
|
+
flunk(message)
|
|
74
|
+
elsif actual.nil?
|
|
72
75
|
assert_nil expected, message
|
|
73
76
|
else
|
|
74
77
|
send(assertion || :assert_equal, expected, actual, message)
|
|
75
78
|
end
|
|
76
79
|
rescue Minitest::Assertion => e
|
|
77
|
-
|
|
80
|
+
feedback = @hold.feedback(e.location, expected, actual, message)
|
|
81
|
+
raise(Minitest::Assertion, feedback)
|
|
78
82
|
end
|
|
79
83
|
|
|
80
|
-
@hold.warn_for(actual) if inspect
|
|
81
|
-
|
|
82
84
|
expected
|
|
83
85
|
end
|
|
84
86
|
|