ae 1.9.0 → 1.9.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/HISTORY.md +52 -0
- data/README.md +9 -1
- data/demo/03_assert.md +110 -8
- data/demo/05_expect.md +36 -4
- data/demo/07_matchers.md +2 -2
- data/demo/09_legacy.md +122 -0
- data/demo/10_adapters.md +48 -0
- data/lib/ae/adapter.rb +3 -4
- data/lib/ae/adapters/minitest.rb +35 -31
- data/lib/ae/adapters/testunit.rb +25 -8
- data/lib/ae/ansi.rb +9 -7
- data/lib/ae/assert.rb +1 -2
- data/lib/ae/assertor.rb +118 -57
- data/lib/ae/check.rb +14 -6
- data/lib/ae/core_ext/helpers.rb +21 -19
- data/lib/ae/legacy.rb +38 -28
- data/lib/ae/must.rb +2 -2
- data/lib/ae/pry.rb +8 -11
- data/lib/ae/should.rb +2 -2
- data/lib/ae/version.rb +1 -1
- metadata +31 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 07e5fefa83c88e06d6d8a94bdc072d9eea673ef345edbe75db64ab173f1e71fc
|
|
4
|
+
data.tar.gz: baad7c8b171ddf06a6382d8ce2da3394229290867bf3c0bd697d119eb94421ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78893c43cd04011a98d2bc73bbde6652f536f1fd0c8f5107ab7b6b13dd6ac9ff0f1d530a5e58b1b3c2889366d4591ee691b46a0d5dbf61d573cb767204ad8496
|
|
7
|
+
data.tar.gz: 9dab4ff9008cf59f9f544617a496b079341d0f86adfc19334a429807db9bd46fae29b1a4e41875c1721cb06d028d9e3451967bb17027845f7b1a6a34035dc065
|
data/HISTORY.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# RELEASE HISTORY
|
|
2
2
|
|
|
3
|
+
## 1.9.1 / 2026-11-10
|
|
4
|
+
|
|
5
|
+
This release fixes assertions that checked nothing, or less than they
|
|
6
|
+
appeared to. So some tests that passed before may now fail, but each
|
|
7
|
+
of those was not checking what it said.
|
|
8
|
+
|
|
9
|
+
Changes:
|
|
10
|
+
|
|
11
|
+
* Fix `x.assert.equal?(y)`, which always passed. Ruby's BasicObject,
|
|
12
|
+
Assertor's superclass, has its own public `equal?`, so the call
|
|
13
|
+
never became an assertion. Now it does, like `==`, `!=` and `!`.
|
|
14
|
+
* `x.assert.instance_eval { ... }` and `instance_exec` go to the
|
|
15
|
+
object, so the block's result is the assertion. They used to run in
|
|
16
|
+
the Assertor and check nothing.
|
|
17
|
+
* Warn about `x.assert.size == 3`, which checks only that `size` is
|
|
18
|
+
truthy. The warning comes when a method called with no arguments
|
|
19
|
+
returns something other than true, false or nil. Write
|
|
20
|
+
`x.size.assert == 3` instead.
|
|
21
|
+
* Pass keyword arguments on as keywords.
|
|
22
|
+
* `assert(expected) { ... }` and `expect(expected) { ... }` compare
|
|
23
|
+
with any expected value, including `false` and `nil`.
|
|
24
|
+
* A Hash or Symbol is no longer used as a proc because it has
|
|
25
|
+
`#to_proc`, so `refute({a: 1})` fails. A lambda that takes no
|
|
26
|
+
arguments works as a matcher.
|
|
27
|
+
* Fix `flunk`, which raised NoMethodError, and passed when negated.
|
|
28
|
+
* Fix `expect` with a block that takes the receiver, and with an
|
|
29
|
+
exception instance. It no longer catches an interrupt or an exit.
|
|
30
|
+
* Fix the legacy Test::Unit assertions: `assert(false)` never failed,
|
|
31
|
+
`assert_block` was inverted, `assert_raises` and `assert_throws`
|
|
32
|
+
were broken, and `assert_instance_of` accepted a subclass. They are
|
|
33
|
+
counted now, and raise the test framework's assertion error.
|
|
34
|
+
* The minitest and test-unit adapters add AE's assertions to the
|
|
35
|
+
test's count, and `ae/adapter` finds current minitest, which no
|
|
36
|
+
longer defines `MiniTest`.
|
|
37
|
+
* Build failure messages only for failures. A passing `==` on two
|
|
38
|
+
1000-element arrays took five seconds. A broken `#inspect` no
|
|
39
|
+
longer breaks the message, and very large color diffs are skipped.
|
|
40
|
+
* Color diffs are on only when standard output is a terminal and
|
|
41
|
+
NO_COLOR is not set. `AE.ansi = true` or `false` still decides.
|
|
42
|
+
* `Kernel#pry` no longer caches, which mixed up equal objects and
|
|
43
|
+
kept them all alive. It passes keywords, and sends `==` and the
|
|
44
|
+
like to the object.
|
|
45
|
+
* Fix `in_epsilon?` for negative numbers, `match?` for objects without
|
|
46
|
+
`=~`, and `throws?`, `thrown?` and `send?`, which hid errors raised
|
|
47
|
+
by the code under test.
|
|
48
|
+
* Fix `AE::Check.define` and `Check::Proc#message`, and report a failed
|
|
49
|
+
`ok` or `no` at the line that called it.
|
|
50
|
+
* Add demos for the legacy assertions and the adapters, and fix demos
|
|
51
|
+
that asserted nothing.
|
|
52
|
+
* Test on Ruby 4.0.
|
|
53
|
+
|
|
54
|
+
|
|
3
55
|
## 1.9.0 / 2026-03-30
|
|
4
56
|
|
|
5
57
|
Maintenance release. Modernized project tooling and cleaned up documentation.
|
data/README.md
CHANGED
|
@@ -29,7 +29,7 @@ intended for reuse by any TDD, BDD or similar system.
|
|
|
29
29
|
## Synopsis
|
|
30
30
|
|
|
31
31
|
AE defines the method `assert`. It is compatible with the method
|
|
32
|
-
as defined by Test::Unit and
|
|
32
|
+
as defined by Test::Unit and Minitest, which verifies truth of a
|
|
33
33
|
single argument (and can accept an optional failure message).
|
|
34
34
|
|
|
35
35
|
assert(true)
|
|
@@ -64,6 +64,14 @@ to make an assertion. Eg.
|
|
|
64
64
|
|
|
65
65
|
"Daffy Duck".assert.daffy?
|
|
66
66
|
|
|
67
|
+
The method's result is what gets asserted, so to compare a result,
|
|
68
|
+
call the method before `assert`:
|
|
69
|
+
|
|
70
|
+
x.size.assert == 3
|
|
71
|
+
|
|
72
|
+
Written as `x.assert.size == 3`, it would check only that `size`
|
|
73
|
+
is truthy, and AE warns about that.
|
|
74
|
+
|
|
67
75
|
When an assertion fails an Assertion exception is raised. Any test
|
|
68
76
|
framework can catch this exception and process it accordingly.
|
|
69
77
|
Technically the framework should check to see that the exception
|
data/demo/03_assert.md
CHANGED
|
@@ -39,6 +39,16 @@ into the block as a block argument.
|
|
|
39
39
|
/h/ =~ s
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
Given an argument as well, `assert` compares it to the block's result
|
|
43
|
+
using `#==`. Any argument counts, even `false` or `nil`.
|
|
44
|
+
|
|
45
|
+
assert(5) { 2 + 3 }
|
|
46
|
+
assert(nil) { nil }
|
|
47
|
+
|
|
48
|
+
Assertion.assert.raised? do
|
|
49
|
+
assert(false) { true }
|
|
50
|
+
end
|
|
51
|
+
|
|
42
52
|
|
|
43
53
|
## Antonyms for Assert
|
|
44
54
|
|
|
@@ -67,9 +77,22 @@ create reusable assertions.
|
|
|
67
77
|
|
|
68
78
|
"abracarba".assert palindrome
|
|
69
79
|
|
|
80
|
+
A lambda that takes no arguments is called without the receiver.
|
|
81
|
+
|
|
82
|
+
"abracarba".assert lambda { true }
|
|
83
|
+
|
|
70
84
|
The message for a failed assertion will come from calling `#to_s` on the
|
|
71
85
|
object.
|
|
72
86
|
|
|
87
|
+
A Hash or a Symbol is a value like any other, even though each has
|
|
88
|
+
`#to_proc`, so here `assert` and `refute` check only that it is truthy.
|
|
89
|
+
|
|
90
|
+
assert({a: 1})
|
|
91
|
+
|
|
92
|
+
Assertion.assert.raised? do
|
|
93
|
+
refute({a: 1})
|
|
94
|
+
end
|
|
95
|
+
|
|
73
96
|
## RSpec-style Assertion Matchers
|
|
74
97
|
|
|
75
98
|
If an object passed to assert responds to `#matches?` then AE will handle
|
|
@@ -91,12 +114,26 @@ message methods will be used if they are defined.
|
|
|
91
114
|
Rather then the general form.
|
|
92
115
|
|
|
93
116
|
x = 10
|
|
94
|
-
x.assert
|
|
117
|
+
x.object_id.assert == x.object_id
|
|
95
118
|
|
|
96
119
|
We can use Ruby's own `equal?`> method.
|
|
97
120
|
|
|
98
121
|
x.assert.equal?(x)
|
|
99
122
|
|
|
123
|
+
It fails for an equal but separate object.
|
|
124
|
+
|
|
125
|
+
Assertion.assert.raised? do
|
|
126
|
+
"abc".assert.equal?("abc".dup)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
And the opposite.
|
|
130
|
+
|
|
131
|
+
x.refute.equal?(11)
|
|
132
|
+
|
|
133
|
+
Assertion.assert.raised? do
|
|
134
|
+
x.refute.equal?(x)
|
|
135
|
+
end
|
|
136
|
+
|
|
100
137
|
AE provides `identical?`> method as an alternative
|
|
101
138
|
to make it a bit more clear.
|
|
102
139
|
|
|
@@ -205,6 +242,12 @@ necessary. Assert combined with +instance_eval+ makes it easy too.
|
|
|
205
242
|
@a == 1
|
|
206
243
|
end
|
|
207
244
|
|
|
245
|
+
Assertion.assert.raised? do
|
|
246
|
+
x.assert.instance_eval do
|
|
247
|
+
@a == 2
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
208
251
|
|
|
209
252
|
## Catch/Try Assertions
|
|
210
253
|
|
|
@@ -247,6 +290,57 @@ AE adds `true?` and `false?` which acts accordingly.
|
|
|
247
290
|
false.assert.false?
|
|
248
291
|
|
|
249
292
|
|
|
293
|
+
## Keyword Arguments
|
|
294
|
+
|
|
295
|
+
Keyword arguments are passed on to the method as keywords.
|
|
296
|
+
|
|
297
|
+
class Gate
|
|
298
|
+
def open?(strict: false)
|
|
299
|
+
!strict
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
Gate.new.assert.open?(strict: false)
|
|
304
|
+
Gate.new.refute.open?(strict: true)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
## Comparing a Method's Result
|
|
308
|
+
|
|
309
|
+
A method called on `assert` makes the assertion itself, so its result
|
|
310
|
+
can't be compared afterwards. Here `size` returns 2, which is truthy, so
|
|
311
|
+
the assertion passes. The comparison with 3 is then made with the
|
|
312
|
+
assertion's own result, and checks nothing.
|
|
313
|
+
|
|
314
|
+
require 'stringio'
|
|
315
|
+
$stderr, stderr = StringIO.new, $stderr
|
|
316
|
+
|
|
317
|
+
[1, 2].assert.size == 3
|
|
318
|
+
|
|
319
|
+
warning, $stderr = $stderr.string, stderr
|
|
320
|
+
|
|
321
|
+
To compare a result, call the method first.
|
|
322
|
+
|
|
323
|
+
[1, 2].size.assert == 2
|
|
324
|
+
|
|
325
|
+
Because this is an easy mistake to make, AE warns when a method called
|
|
326
|
+
without arguments returns something other than true, false or nil.
|
|
327
|
+
|
|
328
|
+
warning.assert.include?("`size` returned 2")
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
## Flunk
|
|
332
|
+
|
|
333
|
+
`flunk` always fails, negated or not.
|
|
334
|
+
|
|
335
|
+
Assertion.assert.raised? do
|
|
336
|
+
flunk "not done yet"
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
Assertion.assert.raised? do
|
|
340
|
+
10.refute.flunk
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
|
|
250
344
|
## Send Assertions
|
|
251
345
|
|
|
252
346
|
Assert that a method can be successfully called.
|
|
@@ -259,11 +353,16 @@ Assert that a method can be successfully called.
|
|
|
259
353
|
You may wish to assert that a numeric value is with some
|
|
260
354
|
range.
|
|
261
355
|
|
|
262
|
-
3.in_delta?(1,5)
|
|
356
|
+
3.assert.in_delta?(1,5)
|
|
357
|
+
|
|
358
|
+
Or minimum range, relative to the smaller of the two magnitudes.
|
|
263
359
|
|
|
264
|
-
|
|
360
|
+
3.assert.in_epsilon?(3,5)
|
|
361
|
+
-100.0.assert.in_epsilon?(-100.05, 0.01)
|
|
265
362
|
|
|
266
|
-
|
|
363
|
+
Assertion.assert.raised? do
|
|
364
|
+
-100.0.assert.in_epsilon?(-101.5, 0.01)
|
|
365
|
+
end
|
|
267
366
|
|
|
268
367
|
|
|
269
368
|
## Verifying Object State
|
|
@@ -282,11 +381,14 @@ can be used in conjunction with +assert+.
|
|
|
282
381
|
@a.assert == 4
|
|
283
382
|
end
|
|
284
383
|
|
|
285
|
-
|
|
286
|
-
|
|
384
|
+
Calling #instance_eval on #assert works too, as shown under "Assertions
|
|
385
|
+
on Object State" above: the block runs in the object, and its result
|
|
386
|
+
is the assertion.
|
|
287
387
|
|
|
288
|
-
|
|
289
|
-
|
|
388
|
+
Assertion.assert.raised? do
|
|
389
|
+
x.assert.instance_eval do
|
|
390
|
+
@a == "obviously wrong"
|
|
391
|
+
end
|
|
290
392
|
end
|
|
291
393
|
|
|
292
394
|
AE offers an optional helper method for times when testing underlying private
|
data/demo/05_expect.md
CHANGED
|
@@ -18,11 +18,27 @@ than #assert. For example we can test for a subclass.
|
|
|
18
18
|
3
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
Assertion.assert.raised? do
|
|
22
|
+
expect Numeric do
|
|
23
|
+
"3"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Any expected value counts, even `nil` or `false`.
|
|
28
|
+
|
|
29
|
+
expect nil do
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
Assertion.assert.raised? do
|
|
34
|
+
"abc".expect nil do
|
|
35
|
+
"abc"
|
|
36
|
+
end
|
|
24
37
|
end
|
|
25
|
-
|
|
38
|
+
|
|
39
|
+
A block that takes an argument is given the receiver.
|
|
40
|
+
|
|
41
|
+
"abc".expect(3) { |s| s.size }
|
|
26
42
|
|
|
27
43
|
|
|
28
44
|
## Exception Expectation
|
|
@@ -38,6 +54,22 @@ then #expect will check to see if the block raises that kind of exception.
|
|
|
38
54
|
expect(nil)
|
|
39
55
|
end
|
|
40
56
|
|
|
57
|
+
An instance of an Exception class stands for its class.
|
|
58
|
+
|
|
59
|
+
expect ArgumentError.new do
|
|
60
|
+
raise ArgumentError
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
An exception of another kind fails the expectation, but an interrupt or
|
|
64
|
+
an exit is never caught, so it isn't mistaken for a failure, or for
|
|
65
|
+
a pass when negated.
|
|
66
|
+
|
|
67
|
+
expect SystemExit do
|
|
68
|
+
expect! ArgumentError do
|
|
69
|
+
exit
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
41
73
|
This is an important distinction to note because it means `#expect` can not be used
|
|
42
74
|
if verify instances of Exception classes.
|
|
43
75
|
|
data/demo/07_matchers.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Matchers are simply Procs or objects with the proper interface that can be
|
|
4
4
|
passed to #assert or #refute (or other Assertor) as an ecapsulated test.
|
|
5
5
|
|
|
6
|
-
## Proc or #
|
|
6
|
+
## Proc or #call
|
|
7
7
|
|
|
8
|
-
Passing a Proc object or
|
|
8
|
+
Passing a Proc object, or any object that responds to `#call`, will use it
|
|
9
9
|
as if it were a block of the method. This allows for a simple way to quickly
|
|
10
10
|
create reusable assertions.
|
|
11
11
|
|
data/demo/09_legacy.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Legacy Assertions
|
|
2
|
+
|
|
3
|
+
The optional `ae/legacy` library provides Test::Unit's assertion
|
|
4
|
+
methods, for an easier move from Test::Unit to AE. They are defined
|
|
5
|
+
in the `AE::Legacy::Assertions` module, which `AE::World` includes.
|
|
6
|
+
|
|
7
|
+
require 'ae/legacy'
|
|
8
|
+
|
|
9
|
+
class LegacyTest
|
|
10
|
+
include AE::Legacy::Assertions
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
t = LegacyTest.new
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Assert
|
|
17
|
+
|
|
18
|
+
With an argument, `assert` checks that it is true, with an optional
|
|
19
|
+
message.
|
|
20
|
+
|
|
21
|
+
t.assert(true)
|
|
22
|
+
t.assert(1 == 1, "one is one")
|
|
23
|
+
|
|
24
|
+
Assertion.assert.raised? do
|
|
25
|
+
t.assert(false, "must fail")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Assertion.assert.raised? do
|
|
29
|
+
t.assert(nil)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
With a block instead, it works like `assert_block`.
|
|
33
|
+
|
|
34
|
+
t.assert { true }
|
|
35
|
+
|
|
36
|
+
Assertion.assert.raised? do
|
|
37
|
+
t.assert { false }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Assert Block
|
|
42
|
+
|
|
43
|
+
t.assert_block { true }
|
|
44
|
+
|
|
45
|
+
Assertion.assert.raised? do
|
|
46
|
+
t.assert_block { false }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Equality and Type
|
|
51
|
+
|
|
52
|
+
t.assert_equal 2, 1 + 1
|
|
53
|
+
|
|
54
|
+
Assertion.assert.raised? do
|
|
55
|
+
t.assert_equal 2, 3
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
`assert_instance_of` wants the exact class, while `assert_kind_of`
|
|
59
|
+
accepts a superclass too.
|
|
60
|
+
|
|
61
|
+
t.assert_instance_of Integer, 1
|
|
62
|
+
t.assert_kind_of Numeric, 1
|
|
63
|
+
|
|
64
|
+
Assertion.assert.raised? do
|
|
65
|
+
t.assert_instance_of Numeric, 1
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Raises
|
|
70
|
+
|
|
71
|
+
`assert_raises` passes if the block raises one of the given exceptions,
|
|
72
|
+
or a subclass of one, and returns the exception.
|
|
73
|
+
|
|
74
|
+
e = t.assert_raises(ArgumentError) { raise ArgumentError, "bad" }
|
|
75
|
+
e.message.assert == "bad"
|
|
76
|
+
|
|
77
|
+
t.assert_raises(StandardError) { raise ArgumentError }
|
|
78
|
+
|
|
79
|
+
It fails if nothing is raised, or something else is.
|
|
80
|
+
|
|
81
|
+
Assertion.assert.raised? do
|
|
82
|
+
t.assert_raises(ArgumentError) { }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
Assertion.assert.raised? do
|
|
86
|
+
t.assert_raises(ArgumentError) { raise TypeError }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## Throws
|
|
91
|
+
|
|
92
|
+
t.assert_throws(:done) { throw :done }
|
|
93
|
+
|
|
94
|
+
Assertion.assert.raised? do
|
|
95
|
+
t.assert_throws(:done) { throw :other }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
Assertion.assert.raised? do
|
|
99
|
+
t.assert_throws(:done) { }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Messages
|
|
104
|
+
|
|
105
|
+
Each assertion has a default message.
|
|
106
|
+
|
|
107
|
+
message = begin
|
|
108
|
+
t.assert_operator 1, :>, 2
|
|
109
|
+
rescue Assertion => e
|
|
110
|
+
e.message
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
message.assert.include?("Expected 1.>(2) to be true")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## Counts
|
|
117
|
+
|
|
118
|
+
Legacy assertions are counted like any other.
|
|
119
|
+
|
|
120
|
+
before = AE::Assertor.counts[:total]
|
|
121
|
+
t.assert_equal 1, 1
|
|
122
|
+
AE::Assertor.counts[:total].assert == before + 1
|
data/demo/10_adapters.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Framework Adapters
|
|
2
|
+
|
|
3
|
+
AE works within other test frameworks by way of adapters. An adapter
|
|
4
|
+
makes AE raise the framework's own assertion error, so a failed AE
|
|
5
|
+
assertion is reported as a failure rather than an error, and it adds
|
|
6
|
+
each AE assertion to the framework's count. Requiring `ae/adapter`
|
|
7
|
+
loads the adapter for whichever framework is already loaded.
|
|
8
|
+
|
|
9
|
+
To see them at work, we run a small test under each framework in a
|
|
10
|
+
separate Ruby process.
|
|
11
|
+
|
|
12
|
+
require 'rbconfig'
|
|
13
|
+
|
|
14
|
+
lib = File.dirname($LOADED_FEATURES.grep(%r{/ae\.rb\z}).first)
|
|
15
|
+
|
|
16
|
+
run = lambda do |code|
|
|
17
|
+
IO.popen([RbConfig.ruby, '-I', lib, '-e', code, err: [:child, :out]], &:read)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Minitest
|
|
22
|
+
|
|
23
|
+
output = run.call <<~'RUBY'
|
|
24
|
+
require 'minitest/autorun'
|
|
25
|
+
require 'ae/adapter'
|
|
26
|
+
|
|
27
|
+
class ExampleTest < Minitest::Test
|
|
28
|
+
def test_pass; 5.assert == 5; end
|
|
29
|
+
def test_fail; 5.assert == 6; end
|
|
30
|
+
end
|
|
31
|
+
RUBY
|
|
32
|
+
|
|
33
|
+
output.assert.include?("2 runs, 2 assertions, 1 failures, 0 errors")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Test::Unit
|
|
37
|
+
|
|
38
|
+
output = run.call <<~'RUBY'
|
|
39
|
+
require 'test/unit'
|
|
40
|
+
require 'ae/adapter'
|
|
41
|
+
|
|
42
|
+
class ExampleTest < Test::Unit::TestCase
|
|
43
|
+
def test_pass; 5.assert == 5; end
|
|
44
|
+
def test_fail; 5.assert == 6; end
|
|
45
|
+
end
|
|
46
|
+
RUBY
|
|
47
|
+
|
|
48
|
+
output.assert.include?("2 tests, 2 assertions, 1 failures, 0 errors")
|
data/lib/ae/adapter.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
if defined?(::
|
|
1
|
+
if defined?(::Minitest::Test)
|
|
2
2
|
require 'ae/adapters/minitest'
|
|
3
|
-
elsif defined?(::Test::Unit)
|
|
3
|
+
elsif defined?(::Test::Unit::TestCase)
|
|
4
4
|
require 'ae/adapters/testunit'
|
|
5
|
-
elsif defined?(::RSpec)
|
|
5
|
+
elsif defined?(::RSpec::Expectations)
|
|
6
6
|
require 'ae/adapters/rspec'
|
|
7
7
|
end
|
|
8
|
-
|
data/lib/ae/adapters/minitest.rb
CHANGED
|
@@ -2,40 +2,44 @@ require 'ae'
|
|
|
2
2
|
|
|
3
3
|
AE.assertion_error = ::Minitest::Assertion
|
|
4
4
|
|
|
5
|
-
module
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
module AE
|
|
6
|
+
# Minitest adapter. AE raises Minitest::Assertion, so failures are
|
|
7
|
+
# reported as failures, and each AE assertion is added to the
|
|
8
|
+
# running test's assertion count.
|
|
9
|
+
module MinitestAdapter
|
|
10
|
+
# Notes the running test, and reports any other exception that
|
|
11
|
+
# says it is an assertion as a failure rather than an error.
|
|
12
|
+
module Test
|
|
13
|
+
def capture_exceptions
|
|
14
|
+
previous = ::Thread.current[:ae_minitest_test]
|
|
15
|
+
::Thread.current[:ae_minitest_test] = self
|
|
16
|
+
super do
|
|
17
|
+
begin
|
|
18
|
+
yield
|
|
19
|
+
rescue ::Minitest::Assertion
|
|
20
|
+
raise
|
|
21
|
+
rescue ::Exception => e
|
|
22
|
+
raise unless e.respond_to?(:assertion?) && e.assertion?
|
|
23
|
+
failure = ::Minitest::Assertion.new(e.message)
|
|
24
|
+
failure.set_backtrace(e.backtrace)
|
|
25
|
+
raise failure
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
ensure
|
|
29
|
+
::Thread.current[:ae_minitest_test] = previous
|
|
24
30
|
end
|
|
25
31
|
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
else
|
|
37
|
-
counts[:fail] += 1
|
|
33
|
+
# Adds each AE assertion to the running test's count.
|
|
34
|
+
module Counts
|
|
35
|
+
def increment_counts(pass)
|
|
36
|
+
test = ::Thread.current[:ae_minitest_test]
|
|
37
|
+
test.assertions += 1 if test
|
|
38
|
+
super
|
|
39
|
+
end
|
|
38
40
|
end
|
|
39
|
-
return counts
|
|
40
41
|
end
|
|
41
42
|
end
|
|
43
|
+
|
|
44
|
+
Minitest::Test.prepend(AE::MinitestAdapter::Test)
|
|
45
|
+
AE::Assertor.singleton_class.prepend(AE::MinitestAdapter::Counts)
|
data/lib/ae/adapters/testunit.rb
CHANGED
|
@@ -27,14 +27,31 @@ module Test #:nodoc:
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
module AE
|
|
31
|
+
# Test::Unit adapter. Each AE assertion is added to the running
|
|
32
|
+
# test's assertion count.
|
|
33
|
+
module TestUnitAdapter
|
|
34
|
+
# Notes the running test.
|
|
35
|
+
module Test
|
|
36
|
+
def run(*args, **kw, &block)
|
|
37
|
+
previous = ::Thread.current[:ae_testunit_test]
|
|
38
|
+
::Thread.current[:ae_testunit_test] = self
|
|
39
|
+
super
|
|
40
|
+
ensure
|
|
41
|
+
::Thread.current[:ae_testunit_test] = previous
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Adds each AE assertion to the running test's count.
|
|
46
|
+
module Counts
|
|
47
|
+
def increment_counts(pass)
|
|
48
|
+
test = ::Thread.current[:ae_testunit_test]
|
|
49
|
+
test.__send__(:add_assertion) if test
|
|
50
|
+
super
|
|
51
|
+
end
|
|
37
52
|
end
|
|
38
|
-
return counts
|
|
39
53
|
end
|
|
40
54
|
end
|
|
55
|
+
|
|
56
|
+
Test::Unit::TestCase.prepend(AE::TestUnitAdapter::Test)
|
|
57
|
+
AE::Assertor.singleton_class.prepend(AE::TestUnitAdapter::Counts)
|
data/lib/ae/ansi.rb
CHANGED
|
@@ -2,25 +2,27 @@ require 'ansi/diff'
|
|
|
2
2
|
|
|
3
3
|
module AE
|
|
4
4
|
|
|
5
|
-
#
|
|
6
|
-
|
|
5
|
+
# ANSI mode is automatic until it is set: on when standard output is
|
|
6
|
+
# a terminal and the NO_COLOR environment variable is not set.
|
|
7
|
+
@ansi = nil
|
|
7
8
|
|
|
8
9
|
# ANSI mode.
|
|
9
10
|
#
|
|
10
11
|
# @return [Boolean] ANSI mode.
|
|
11
12
|
def self.ansi?
|
|
12
|
-
@ansi
|
|
13
|
+
return @ansi unless @ansi.nil?
|
|
14
|
+
$stdout.respond_to?(:tty?) && $stdout.tty? && ENV.fetch('NO_COLOR', '').empty?
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
# To turn
|
|
16
|
-
# ansi to +false+ in your test helper.
|
|
17
|
+
# To turn ANSI colorized error messages on or off, set
|
|
18
|
+
# ansi to +true+ or +false+ in your test helper. Set it to
|
|
19
|
+
# +nil+ to go back to the automatic setting.
|
|
17
20
|
#
|
|
18
21
|
# @example
|
|
19
22
|
# AE.ansi = false
|
|
20
23
|
#
|
|
21
24
|
def self.ansi=(boolean)
|
|
22
|
-
@ansi = boolean
|
|
25
|
+
@ansi = boolean.nil? ? nil : !!boolean
|
|
23
26
|
end
|
|
24
27
|
|
|
25
28
|
end
|
|
26
|
-
|
data/lib/ae/assert.rb
CHANGED
|
@@ -73,8 +73,7 @@ module AE
|
|
|
73
73
|
# @raise [Assertion]
|
|
74
74
|
# Assertion error with given `message`.
|
|
75
75
|
def flunk(message=nil, backtrace=nil)
|
|
76
|
-
|
|
77
|
-
Assertor.assert(false, message, backtrace || caller)
|
|
76
|
+
Assertor.assert(false, message, false, backtrace || caller)
|
|
78
77
|
end
|
|
79
78
|
|
|
80
79
|
end
|