probatio 1.2.1 → 1.4.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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +74 -1
- data/exe/proba +1 -1
- data/lib/probatio/assertions.rb +7 -6
- data/lib/probatio/errors.rb +279 -0
- data/lib/probatio/examples/a_test.rb +53 -0
- data/lib/probatio/helpers.rb +16 -0
- data/lib/probatio.rb +4 -157
- data/probatio.gemspec +2 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5935c5e5ed80703f327b9080a0853dec130b1e5b595f29a5ee914a493865368b
|
4
|
+
data.tar.gz: 37167cd9088927754eddc83b2f75a765be851c6e6c2b602e1f77d6c1c60b681e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3ac2a8013890f1b9d05bf2b836e2360081082a99135173976685c6cd7d4bac74534771c2d4e7d4e358577632b97377a8998e2c4715386b6e9b0da20f743c10b
|
7
|
+
data.tar.gz: e0e7595dd5163fa4c43f574dea4af27eb03ea684ed10ed54c6f50ceaecd2db81dc6c328b409ff80374419f94cf5b3d6fd308caf1928c2ab5eadd982e25f65ece
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
# CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## probatio 1.4.0 released 2025-10-13
|
6
|
+
|
7
|
+
* Work on StringDiff, HashDiff, and ArrayDiff
|
8
|
+
* Use diff-lcs for StringDiff
|
9
|
+
|
10
|
+
|
11
|
+
## probatio 1.3.0 released 2025-08-08
|
12
|
+
|
13
|
+
* Add windows? and jruby? to Probatio::Group
|
14
|
+
* Alias `assert_nothing_raised` to `assert_no_error`
|
15
|
+
|
16
|
+
|
5
17
|
## probatio 1.2.1 released 2025-05-20
|
6
18
|
|
7
19
|
* Tighten Probatio.beep and friends
|
data/README.md
CHANGED
@@ -39,6 +39,7 @@ Usage: bundle exec proba [OPTIONS] [DIRS] [FILES] [OTHERS] [ENVS]
|
|
39
39
|
-d, --debug smr 's' for start opts, 'm' for messages, 'r' for $DEBUG
|
40
40
|
-x, --example Outputs an example test file
|
41
41
|
-X, --plugin-example Outputs an example plugin file
|
42
|
+
-b, --beep[s] {n || 1} Beeps n time before exit
|
42
43
|
--mangle Turns the given _spec.rb files into proba _test.rb
|
43
44
|
|
44
45
|
Dirs:
|
@@ -174,6 +175,8 @@ group 'core' do
|
|
174
175
|
assert_no_error lambda { do_this_or_that() }
|
175
176
|
assert_not_error { do_this_or_that() }
|
176
177
|
assert_not_error lambda { do_this_or_that() }
|
178
|
+
assert_nothing_raised { do_this_or_that() }
|
179
|
+
assert_nothing_raised lambda { do_this_or_that() }
|
177
180
|
# checks that the block or Proc does not raise an error
|
178
181
|
|
179
182
|
assert_hashy(
|
@@ -230,6 +233,51 @@ group 'core < sub-core < sub-sub-core' do
|
|
230
233
|
test 'that' do
|
231
234
|
end
|
232
235
|
end
|
236
|
+
|
237
|
+
|
238
|
+
group 'notcore' do
|
239
|
+
|
240
|
+
# A section allows for some kind of "inheritance" between groups...
|
241
|
+
#
|
242
|
+
section 'with db' do
|
243
|
+
|
244
|
+
setup do
|
245
|
+
|
246
|
+
prepare_db
|
247
|
+
end
|
248
|
+
|
249
|
+
before do
|
250
|
+
|
251
|
+
reset_and_load_fixtures
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
group 'alpha' do
|
256
|
+
|
257
|
+
group 'without db' do
|
258
|
+
|
259
|
+
# ...
|
260
|
+
end
|
261
|
+
|
262
|
+
group 'with db' do
|
263
|
+
|
264
|
+
# gets the setup and before from the "with db" section
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
group 'bravo' do
|
269
|
+
|
270
|
+
group 'without db' do
|
271
|
+
|
272
|
+
# ...
|
273
|
+
end
|
274
|
+
|
275
|
+
group 'with db' do
|
276
|
+
|
277
|
+
# gets the setup and before from the "with db" section
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
233
281
|
```
|
234
282
|
|
235
283
|
|
@@ -276,10 +324,13 @@ some_env:
|
|
276
324
|
{
|
277
325
|
USER: "jmettraux",
|
278
326
|
HOME: "/home/jmettraux",
|
279
|
-
PATH: "/home/jmettraux/.gem/ruby/3.3/bin:/home/jmettraux/.pkg_rubies/ruby33:/usr/local/jdk-21/bin:/home/jmettraux/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin",
|
280
327
|
SHELL: "/usr/local/bin/fish",
|
281
328
|
GEM_HOME: "/home/jmettraux/.gem/ruby/3.3",
|
282
329
|
PWD: "/home/jmettraux/w/probatio/test",
|
330
|
+
PATH:
|
331
|
+
"/home/jmettraux/.gem/ruby/3.3/bin:/home/jmettraux/.pkg_rubies/ruby33:" +
|
332
|
+
"/usr/local/jdk-21/bin:/home/jmettraux/bin:/bin:/usr/bin:/sbin:" +
|
333
|
+
"/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin",
|
283
334
|
},
|
284
335
|
}
|
285
336
|
```
|
@@ -289,6 +340,28 @@ Probatio uses it when servicing `bundle exec proba 0` or `bundle exe proba -1`.
|
|
289
340
|
It can also be useful to other tools around probatio.
|
290
341
|
|
291
342
|
|
343
|
+
## Helpers
|
344
|
+
|
345
|
+
Built-in helpers:
|
346
|
+
```ruby
|
347
|
+
jruby? # => returns true when running on JRuby
|
348
|
+
windows? # => returns true when running on Windows
|
349
|
+
```
|
350
|
+
|
351
|
+
_Waiter_ helpers:
|
352
|
+
```ruby
|
353
|
+
wait_for {
|
354
|
+
some_condition == true
|
355
|
+
}
|
356
|
+
wait_for(timeout: 60, frequency: 1) { # wait for 60 seconds, check every sec
|
357
|
+
some_condition == true
|
358
|
+
}
|
359
|
+
wait_until { # wait_until is an alias to wait_for
|
360
|
+
some_condition == true
|
361
|
+
}
|
362
|
+
```
|
363
|
+
|
364
|
+
|
292
365
|
## Warnings
|
293
366
|
|
294
367
|
```
|
data/exe/proba
CHANGED
@@ -100,7 +100,7 @@ if switches['-h'] || switches['--help']
|
|
100
100
|
-d, --debug smr 's' for start opts, 'm' for messages, 'r' for $DEBUG
|
101
101
|
-x, --example Outputs an example test file
|
102
102
|
-X, --plugin-example Outputs an example plugin file
|
103
|
-
-b, --
|
103
|
+
-b, --beep[s] {n || 1} Beeps n time before exit
|
104
104
|
--mangle Turns the given _spec.rb files into proba _test.rb
|
105
105
|
|
106
106
|
Dirs:
|
data/lib/probatio/assertions.rb
CHANGED
@@ -176,6 +176,7 @@ class Probatio::Context
|
|
176
176
|
err && "no error expected but returned #{err.class} #{err.name}" }
|
177
177
|
end
|
178
178
|
alias assert_no_error assert_not_error
|
179
|
+
alias assert_nothing_raised assert_not_error
|
179
180
|
|
180
181
|
# Checks whether its "_assert_something", if that's the case,
|
181
182
|
# just flags the assertion as :pending an moves on
|
@@ -298,13 +299,13 @@ class Probatio::Context
|
|
298
299
|
|
299
300
|
def extract_file_and_line(backtrace)
|
300
301
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
302
|
+
l =
|
303
|
+
backtrace.find { |l| l.index('_test.rb') } ||
|
304
|
+
backtrace.find { |l| ! l.index('/lib/probatio/') }
|
305
|
+
m =
|
306
|
+
l && l.match(/([^:]+):(\d+)/)
|
305
307
|
|
306
|
-
m
|
307
|
-
m && [ m[1], m[2].to_i ]
|
308
|
+
m ? [ m[1], m[2].to_i ] : [ nil, -1 ]
|
308
309
|
end
|
309
310
|
|
310
311
|
def extract_assert_method(backtrace)
|
@@ -0,0 +1,279 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# probatio/errors.rb
|
4
|
+
|
5
|
+
module Probatio
|
6
|
+
|
7
|
+
class AssertionError < StandardError
|
8
|
+
|
9
|
+
attr_reader :assertion, :arguments, :test, :file, :line
|
10
|
+
attr_accessor :nested_error
|
11
|
+
|
12
|
+
alias path file
|
13
|
+
|
14
|
+
def initialize(assertion, arguments, error_or_message, test, file, line)
|
15
|
+
|
16
|
+
@assertion = assertion
|
17
|
+
@arguments = arguments
|
18
|
+
|
19
|
+
@test = test
|
20
|
+
|
21
|
+
@file = file
|
22
|
+
@line = line
|
23
|
+
|
24
|
+
if error_or_message.is_a?(String)
|
25
|
+
@msg = error_or_message
|
26
|
+
else
|
27
|
+
@msg = "error while asserting: " + error_or_message.message
|
28
|
+
@nested_error = error_or_message
|
29
|
+
end
|
30
|
+
|
31
|
+
super(@msg)
|
32
|
+
end
|
33
|
+
|
34
|
+
def location
|
35
|
+
|
36
|
+
[ @file, @line ]
|
37
|
+
end
|
38
|
+
|
39
|
+
def loc
|
40
|
+
|
41
|
+
location.map(&:to_s).join(':')
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
|
46
|
+
"#{self.class.name}: #{@msg}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def trail
|
50
|
+
|
51
|
+
@test.trail + "\n" +
|
52
|
+
Probatio.c.red("#{' ' * (test.depth + 1)}#{loc} --> #{@msg}")
|
53
|
+
end
|
54
|
+
|
55
|
+
def source_line
|
56
|
+
|
57
|
+
@source_line ||=
|
58
|
+
File.readlines(@file)[@line - 1]
|
59
|
+
end
|
60
|
+
|
61
|
+
def source_lines
|
62
|
+
|
63
|
+
@source_lines ||=
|
64
|
+
Probatio::AssertionError.select_source_lines(@file, @line)
|
65
|
+
end
|
66
|
+
|
67
|
+
def summary(indent='')
|
68
|
+
|
69
|
+
nl = "\n" + indent
|
70
|
+
|
71
|
+
tw = Probatio.term_width - 4 - indent.length
|
72
|
+
|
73
|
+
as =
|
74
|
+
@arguments.find { |a| a.inspect.length > tw } ?
|
75
|
+
@arguments.collect { |a|
|
76
|
+
if (s0 = a.inspect).length < tw
|
77
|
+
nl + ' ' + s0 + "\n"
|
78
|
+
else
|
79
|
+
s1 = StringIO.new; PP.pp(a, s1, tw)
|
80
|
+
qualify_argument(a) + "\n" +
|
81
|
+
indent + s1.string.gsub(/^(.*)$/) { " #{$1}" }
|
82
|
+
end } :
|
83
|
+
@arguments.collect(&:inspect)
|
84
|
+
|
85
|
+
s = StringIO.new
|
86
|
+
s << indent << @assertion << ':'
|
87
|
+
|
88
|
+
case @arguments.collect(&:class)
|
89
|
+
when [ Hash, Hash ]
|
90
|
+
as.each_with_index { |a, i| s << nl << ' %d: %s' % [ i, a ] }
|
91
|
+
output_hash_diff(indent, s)
|
92
|
+
when [ Array, Array ]
|
93
|
+
output_array_diff(indent, s)
|
94
|
+
when [ String, String ]
|
95
|
+
output_string_diff(indent, s)
|
96
|
+
else
|
97
|
+
as.each_with_index { |a, i| s << nl << ' %d: %s' % [ i, a ] }
|
98
|
+
end
|
99
|
+
|
100
|
+
s.string
|
101
|
+
end
|
102
|
+
|
103
|
+
class << self
|
104
|
+
|
105
|
+
def select_source_lines(path, line)
|
106
|
+
|
107
|
+
return [] unless path
|
108
|
+
|
109
|
+
File.readlines(path).each_with_index.to_a[line - 1..-1]
|
110
|
+
.map { |l, i| [ i + 1, l.rstrip ] }
|
111
|
+
.take_while { |_, l|
|
112
|
+
l = l.strip
|
113
|
+
l.length > 0 && l != 'end' && l != '}' }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
protected
|
118
|
+
|
119
|
+
def output_hash_diff(indent, s)
|
120
|
+
|
121
|
+
nl = "\n" + indent
|
122
|
+
|
123
|
+
c = Probatio.c
|
124
|
+
|
125
|
+
d0 = @arguments[0].to_a - @arguments[1].to_a
|
126
|
+
d1 = @arguments[1].to_a - @arguments[0].to_a
|
127
|
+
|
128
|
+
dh = {}
|
129
|
+
d0.each { |k, v| dh[k] = [ v, nil ] }
|
130
|
+
d1.each { |k, v| dv = (dh[k] ||= [ nil, nil ]); dv[1] = v }
|
131
|
+
|
132
|
+
s << nl << ' Hash diff:'
|
133
|
+
dh.each do |k, (v0, v1)|
|
134
|
+
s << nl << ' ' << c.yellow(k.inspect) << c.dg << ' =>'
|
135
|
+
s << nl << ' ' << c.white(0) << c.dg << ': ' << v0.inspect
|
136
|
+
s << " -- has_key? #{@arguments[0].has_key?(k)}" if v0 == nil
|
137
|
+
s << nl << ' ' << c.white(1) << c.dg << ': ' << v1.inspect
|
138
|
+
s << " -- has_key? #{@arguments[1].has_key?(k)}" if v1 == nil
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def output_string_diff(indent, s)
|
143
|
+
|
144
|
+
a0, a1 = @arguments
|
145
|
+
a0l, a1l = a0.length, a1.length
|
146
|
+
a0c, a1c = a0.lines.count, a1.lines.count
|
147
|
+
|
148
|
+
sep = "\n" + ('-' * 49)
|
149
|
+
c = Probatio.c
|
150
|
+
|
151
|
+
s <<
|
152
|
+
sep << " length: #{a0l} / lines: #{a0c}\n" <<
|
153
|
+
c.yellow << a0 << c.dark_grey <<
|
154
|
+
sep << " length: #{a1l} / lines: #{a1c}\n" <<
|
155
|
+
c.yellow << a1 << c.dark_grey <<
|
156
|
+
sep
|
157
|
+
|
158
|
+
ls0 = @arguments[0].lines.map(&:chomp)
|
159
|
+
ls1 = @arguments[1].lines.map(&:chomp)
|
160
|
+
|
161
|
+
return if ls0.length < 2 && ls1.length < 2
|
162
|
+
|
163
|
+
output_sdiff(ls0, ls1, s)
|
164
|
+
end
|
165
|
+
|
166
|
+
def output_array_diff(indent, s)
|
167
|
+
|
168
|
+
a0, a1 = @arguments
|
169
|
+
a0c, a1c = a0.count, a1.count
|
170
|
+
|
171
|
+
sep = "\n" + ('-' * 49)
|
172
|
+
c = Probatio.c
|
173
|
+
|
174
|
+
s << c.dg << sep << "length: #{a0c}\n" << c.white << a0.inspect
|
175
|
+
s << c.dg << sep << "length: #{a1c}\n" << c.white << a1.inspect
|
176
|
+
s << c.dg << sep
|
177
|
+
|
178
|
+
s0 = a0.collect { |e| e.is_a?(String) ? e : e.inspect }
|
179
|
+
s1 = a1.collect { |e| e.is_a?(String) ? e : e.inspect }
|
180
|
+
|
181
|
+
output_sdiff(s0, s1, s)
|
182
|
+
end
|
183
|
+
|
184
|
+
def output_sdiff(a0, a1, s)
|
185
|
+
|
186
|
+
c = Probatio.c
|
187
|
+
nl = "\n"
|
188
|
+
sep = "\n" + ('-' * 49)
|
189
|
+
|
190
|
+
diff = Diff::LCS.sdiff(a0, a1).collect(&:to_a)
|
191
|
+
|
192
|
+
maxl = diff
|
193
|
+
.inject([]) { |a, d| a << d[1][0]; a << d[2][0]; a }
|
194
|
+
.max.to_s.length
|
195
|
+
forl = "%0#{maxl}d"
|
196
|
+
|
197
|
+
#ov = c.rev(' ')
|
198
|
+
ov = c.dg + c.rev('<')
|
199
|
+
fence = lambda { |s| s + (s.match?(/\s$/) ? ov : '') }
|
200
|
+
|
201
|
+
s << nl << c.dg << sep
|
202
|
+
diff.each do |d|
|
203
|
+
if d[0] == '='
|
204
|
+
s << nl << c.dg << '= ' << (forl % d[1][0]) << ' ' << d[1][1]
|
205
|
+
elsif d[0] == '+'
|
206
|
+
#s << nl << d.inspect
|
207
|
+
s << nl << c.gn << '+ ' << (forl % d[2][0]) << ' ' << fence[d[2][1]]
|
208
|
+
elsif d[0] == '-'
|
209
|
+
#s << nl << d.inspect
|
210
|
+
s << nl << c.rd << '- ' << (forl % d[1][0]) << ' ' << fence[d[1][1]]
|
211
|
+
else # '!'
|
212
|
+
a, b = d[1], d[2]
|
213
|
+
s << nl << c.y << '! ' << (forl % a[0]) << ' ' << fence[a[1]]
|
214
|
+
s << nl << c.y << ' ' << (forl % b[0]) << ' ' << fence[b[1]]
|
215
|
+
end
|
216
|
+
end
|
217
|
+
s << c.dg << sep << c.reset
|
218
|
+
end
|
219
|
+
|
220
|
+
def qualify_argument(a)
|
221
|
+
|
222
|
+
'<' +
|
223
|
+
a.class.to_s +
|
224
|
+
(a.respond_to?(:size) ? " size:#{a.size}" : '') +
|
225
|
+
'>'
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
module ExtraErrorMethods
|
230
|
+
|
231
|
+
attr_accessor :test
|
232
|
+
|
233
|
+
def path; test.path; end
|
234
|
+
def location; [ path, line ]; end
|
235
|
+
def loc; location.map(&:to_s).join(':'); end
|
236
|
+
|
237
|
+
def trail
|
238
|
+
|
239
|
+
msg = "#{self.class}: #{self.message.inspect}"
|
240
|
+
|
241
|
+
@test.trail + "\n" +
|
242
|
+
Probatio.c.red("#{' ' * (test.depth + 1)}#{loc} --> #{msg}")
|
243
|
+
end
|
244
|
+
|
245
|
+
def source_lines
|
246
|
+
|
247
|
+
@source_lines ||=
|
248
|
+
Probatio::AssertionError.select_source_lines(test.path, line)
|
249
|
+
end
|
250
|
+
|
251
|
+
def summary(indent='')
|
252
|
+
|
253
|
+
o = StringIO.new
|
254
|
+
|
255
|
+
o << self.class.name << ': ' << self.message.inspect << "\n"
|
256
|
+
|
257
|
+
i = backtrace.index { |l| l.match?(/\/lib\/probatio\.rb:/) } || -1
|
258
|
+
|
259
|
+
backtrace[0..i]
|
260
|
+
.inject(o) { |o, l| o << indent << l << "\n" }
|
261
|
+
|
262
|
+
o.string
|
263
|
+
end
|
264
|
+
|
265
|
+
def line
|
266
|
+
|
267
|
+
backtrace.each do |l|
|
268
|
+
|
269
|
+
ss = l.split(':')
|
270
|
+
|
271
|
+
next unless ss.find { |e| e == test.path }
|
272
|
+
return ss.find { |e| e.match?(/^\d+$/) }.to_i
|
273
|
+
end
|
274
|
+
|
275
|
+
-1
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
@@ -69,6 +69,14 @@ group 'core' do
|
|
69
69
|
# checks that the given Proc raises an ArgumentError and
|
70
70
|
# the error message == "bad"
|
71
71
|
|
72
|
+
assert_no_error { do_this_or_that() }
|
73
|
+
assert_no_error lambda { do_this_or_that() }
|
74
|
+
assert_not_error { do_this_or_that() }
|
75
|
+
assert_not_error lambda { do_this_or_that() }
|
76
|
+
assert_nothing_raised { do_this_or_that() }
|
77
|
+
assert_nothing_raised lambda { do_this_or_that() }
|
78
|
+
# checks that the block or Proc does not raise an error
|
79
|
+
|
72
80
|
assert_hashy(
|
73
81
|
this_thing => 1,
|
74
82
|
that_thing => 'two')
|
@@ -124,3 +132,48 @@ group 'core < sub-core < sub-sub-core' do
|
|
124
132
|
end
|
125
133
|
end
|
126
134
|
|
135
|
+
|
136
|
+
group 'notcore' do
|
137
|
+
|
138
|
+
# A section allows for some kind of "inheritance" between groups...
|
139
|
+
#
|
140
|
+
section 'with db' do
|
141
|
+
|
142
|
+
setup do
|
143
|
+
|
144
|
+
prepare_db
|
145
|
+
end
|
146
|
+
|
147
|
+
before do
|
148
|
+
|
149
|
+
reset_and_load_fixtures
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
group 'alpha' do
|
154
|
+
|
155
|
+
group 'without db' do
|
156
|
+
|
157
|
+
# ...
|
158
|
+
end
|
159
|
+
|
160
|
+
group 'with db' do
|
161
|
+
|
162
|
+
# gets the setup and before from the "with db" section
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
group 'bravo' do
|
167
|
+
|
168
|
+
group 'without db' do
|
169
|
+
|
170
|
+
# ...
|
171
|
+
end
|
172
|
+
|
173
|
+
group 'with db' do
|
174
|
+
|
175
|
+
# gets the setup and before from the "with db" section
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
data/lib/probatio/helpers.rb
CHANGED
@@ -8,6 +8,22 @@ module Probatio::Helpers
|
|
8
8
|
|
9
9
|
Probatio.beep(count || 0)
|
10
10
|
end
|
11
|
+
|
12
|
+
def jruby?
|
13
|
+
|
14
|
+
!! RUBY_PLATFORM.match?(/java/)
|
15
|
+
end
|
16
|
+
|
17
|
+
def windows?
|
18
|
+
|
19
|
+
Gem.win_platform?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
class Probatio::Group
|
25
|
+
|
26
|
+
include Probatio::Helpers
|
11
27
|
end
|
12
28
|
|
13
29
|
class Probatio::Section
|
data/lib/probatio.rb
CHANGED
@@ -7,15 +7,18 @@ require 'set'
|
|
7
7
|
require 'stringio'
|
8
8
|
require 'io/console'
|
9
9
|
|
10
|
+
require 'diff-lcs'
|
11
|
+
|
10
12
|
require 'colorato'
|
11
13
|
|
12
14
|
require 'probatio/debug'
|
15
|
+
require 'probatio/errors'
|
13
16
|
require 'probatio/more'
|
14
17
|
|
15
18
|
|
16
19
|
module Probatio
|
17
20
|
|
18
|
-
VERSION = '1.
|
21
|
+
VERSION = '1.4.0'
|
19
22
|
|
20
23
|
class << self
|
21
24
|
|
@@ -758,162 +761,6 @@ module Probatio
|
|
758
761
|
# where beep and friends are defined...
|
759
762
|
end
|
760
763
|
|
761
|
-
class AssertionError < StandardError
|
762
|
-
|
763
|
-
attr_reader :assertion, :arguments, :test, :file, :line
|
764
|
-
attr_accessor :nested_error
|
765
|
-
|
766
|
-
alias path file
|
767
|
-
|
768
|
-
def initialize(assertion, arguments, error_or_message, test, file, line)
|
769
|
-
|
770
|
-
@assertion = assertion
|
771
|
-
@arguments = arguments
|
772
|
-
|
773
|
-
@test = test
|
774
|
-
|
775
|
-
@file = file
|
776
|
-
@line = line
|
777
|
-
|
778
|
-
if error_or_message.is_a?(String)
|
779
|
-
@msg = error_or_message
|
780
|
-
else
|
781
|
-
@msg = "error while asserting: " + error_or_message.message
|
782
|
-
@nested_error = error_or_message
|
783
|
-
end
|
784
|
-
|
785
|
-
super(@msg)
|
786
|
-
end
|
787
|
-
|
788
|
-
def location
|
789
|
-
|
790
|
-
[ @file, @line ]
|
791
|
-
end
|
792
|
-
|
793
|
-
def loc
|
794
|
-
|
795
|
-
location.map(&:to_s).join(':')
|
796
|
-
end
|
797
|
-
|
798
|
-
def to_s
|
799
|
-
|
800
|
-
"#{self.class.name}: #{@msg}"
|
801
|
-
end
|
802
|
-
|
803
|
-
def trail
|
804
|
-
|
805
|
-
@test.trail + "\n" +
|
806
|
-
Probatio.c.red("#{' ' * (test.depth + 1)}#{loc} --> #{@msg}")
|
807
|
-
end
|
808
|
-
|
809
|
-
def source_line
|
810
|
-
|
811
|
-
@source_line ||=
|
812
|
-
File.readlines(@file)[@line - 1]
|
813
|
-
end
|
814
|
-
|
815
|
-
def source_lines
|
816
|
-
|
817
|
-
@source_lines ||=
|
818
|
-
Probatio::AssertionError.select_source_lines(@file, @line)
|
819
|
-
end
|
820
|
-
|
821
|
-
def summary(indent='')
|
822
|
-
|
823
|
-
tw = Probatio.term_width - 4 - indent.length
|
824
|
-
|
825
|
-
as =
|
826
|
-
@arguments.find { |a| a.inspect.length > tw } ?
|
827
|
-
@arguments.collect { |a|
|
828
|
-
if (s0 = a.inspect).length < tw
|
829
|
-
"\n#{indent} " + s0
|
830
|
-
else
|
831
|
-
s1 = StringIO.new; PP.pp(a, s1, tw)
|
832
|
-
qualify_argument(a) + "\n" +
|
833
|
-
indent + s1.string.gsub(/^(.*)$/) { " #{$1}" }
|
834
|
-
end } :
|
835
|
-
@arguments.collect(&:inspect)
|
836
|
-
|
837
|
-
s = StringIO.new
|
838
|
-
s << indent << @assertion << ':'
|
839
|
-
as.each_with_index { |a, i| s << "\n#{indent} %d: %s" % [ i, a ] }
|
840
|
-
|
841
|
-
s.string
|
842
|
-
end
|
843
|
-
|
844
|
-
class << self
|
845
|
-
|
846
|
-
def select_source_lines(path, line)
|
847
|
-
|
848
|
-
File.readlines(path).each_with_index.to_a[line - 1..-1]
|
849
|
-
.map { |l, i| [ i + 1, l.rstrip ] }
|
850
|
-
.take_while { |_, l|
|
851
|
-
l = l.strip
|
852
|
-
l.length > 0 && l != 'end' && l != '}' }
|
853
|
-
end
|
854
|
-
end
|
855
|
-
|
856
|
-
protected
|
857
|
-
|
858
|
-
def qualify_argument(a)
|
859
|
-
|
860
|
-
'<' +
|
861
|
-
a.class.to_s +
|
862
|
-
(a.respond_to?(:size) ? " size:#{a.size}" : '') +
|
863
|
-
'>'
|
864
|
-
end
|
865
|
-
end
|
866
|
-
|
867
|
-
module ExtraErrorMethods
|
868
|
-
|
869
|
-
attr_accessor :test
|
870
|
-
|
871
|
-
def path; test.path; end
|
872
|
-
def location; [ path, line ]; end
|
873
|
-
def loc; location.map(&:to_s).join(':'); end
|
874
|
-
|
875
|
-
def trail
|
876
|
-
|
877
|
-
msg = "#{self.class}: #{self.message.inspect}"
|
878
|
-
|
879
|
-
@test.trail + "\n" +
|
880
|
-
Probatio.c.red("#{' ' * (test.depth + 1)}#{loc} --> #{msg}")
|
881
|
-
end
|
882
|
-
|
883
|
-
def source_lines
|
884
|
-
|
885
|
-
@source_lines ||=
|
886
|
-
Probatio::AssertionError.select_source_lines(test.path, line)
|
887
|
-
end
|
888
|
-
|
889
|
-
def summary(indent='')
|
890
|
-
|
891
|
-
o = StringIO.new
|
892
|
-
|
893
|
-
o << self.class.name << ': ' << self.message.inspect << "\n"
|
894
|
-
|
895
|
-
i = backtrace.index { |l| l.match?(/\/lib\/probatio\.rb:/) } || -1
|
896
|
-
|
897
|
-
backtrace[0..i]
|
898
|
-
.inject(o) { |o, l| o << indent << l << "\n" }
|
899
|
-
|
900
|
-
o.string
|
901
|
-
end
|
902
|
-
|
903
|
-
def line
|
904
|
-
|
905
|
-
backtrace.each do |l|
|
906
|
-
|
907
|
-
ss = l.split(':')
|
908
|
-
|
909
|
-
next unless ss.find { |e| e == test.path }
|
910
|
-
return ss.find { |e| e.match?(/^\d+$/) }.to_i
|
911
|
-
end
|
912
|
-
|
913
|
-
-1
|
914
|
-
end
|
915
|
-
end
|
916
|
-
|
917
764
|
class Event
|
918
765
|
|
919
766
|
attr_reader :tstamp, :delta
|
data/probatio.gemspec
CHANGED
@@ -38,8 +38,9 @@ Test tools for floraison and flor. Somewhere between Minitest and Rspec, but not
|
|
38
38
|
"#{s.name}.gemspec",
|
39
39
|
]
|
40
40
|
|
41
|
+
s.add_runtime_dependency 'stringio'
|
42
|
+
s.add_runtime_dependency 'diff-lcs', '~> 1.6'
|
41
43
|
s.add_runtime_dependency 'colorato', '~> 1.0'
|
42
|
-
#s.add_runtime_dependency 'diff-lcs', '~> 1.5'
|
43
44
|
|
44
45
|
s.require_path = 'lib'
|
45
46
|
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: probatio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: stringio
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: diff-lcs
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: colorato
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,6 +68,7 @@ files:
|
|
40
68
|
- lib/probatio.rb
|
41
69
|
- lib/probatio/assertions.rb
|
42
70
|
- lib/probatio/debug.rb
|
71
|
+
- lib/probatio/errors.rb
|
43
72
|
- lib/probatio/examples/a_plugin.rb
|
44
73
|
- lib/probatio/examples/a_test.rb
|
45
74
|
- lib/probatio/helpers.rb
|