minitest-ok 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -10
- data/Rakefile +46 -9
- data/lib/minitest/ok.rb +120 -18
- data/test/minitest/ok_test.rb +162 -26
- data/test/test_helper.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8da6c203333bd5267e00d76d25285c2e9c54e960d8cc4445230c5524bbb6c1c1
|
4
|
+
data.tar.gz: ded479a36c207e4c298e722a83e709234ff3b4a10c82513bbfc320ef771923ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31680ed69498d8d4eeaf1878af6bd3c8a20dab0e55cdb582837466c6b47efe3bc879479a53ac26b00bef3aca9dfc3960c204a7b0b97b4c4c1e78c3208ac93a84
|
7
|
+
data.tar.gz: 5f03eda1e5aa4a4846ad36d799f6bd77d1868668c8c9777b18f1851e9d92fba590f74091ddd3da168f6b6668b5bb1ea3ba86bb407f6ed752d742ffa30b26efe7
|
data/README.md
CHANGED
@@ -69,13 +69,21 @@ describe 'Minitest::Ok' do
|
|
69
69
|
ok {3.14159}.NOT.in_epsilon?(3.14, 0.0001) # same as refute_in_epsilon 3.14, 3.14159, 0.0001
|
70
70
|
|
71
71
|
## exception
|
72
|
-
|
73
|
-
ex = ok {
|
74
|
-
ex = ok {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
pr = proc { 1 / 0 }
|
73
|
+
ex = ok {pr}.raise?(ZeroDivisionError) # same as assert_raise(...)
|
74
|
+
ex = ok {pr}.raise?(ZeroDivisionError, "divided by 0")
|
75
|
+
ex = ok {pr}.raise?(ZeroDivisionError, /^divided by 0$/)
|
76
|
+
p ex #=> #<ZeroDivisionError>
|
77
|
+
ok {pr}.raise?(ZeroDivisionError, /^divided by 0$/) do |ex|
|
78
|
+
p ex # optional block will be yielded when exception raised
|
79
|
+
end
|
80
|
+
|
81
|
+
pr2 = proc { 1.0 / 0.0 }
|
82
|
+
ok {pr2}.raise_nothing?(Exception) # oktest >= 0.4
|
83
|
+
ok {pr2}.NOT.raise?(Exception)
|
84
|
+
|
85
|
+
pr3 = proc { throw :exit }
|
86
|
+
ok {pr3}.throw?(:exit) # same as assert_throws(:exit) {...}
|
79
87
|
|
80
88
|
## stdout and stderr
|
81
89
|
ok {proc {puts 'X'}}.output?("X\n") # same as assert_output {...}
|
@@ -85,8 +93,8 @@ describe 'Minitest::Ok' do
|
|
85
93
|
ok {123}.truthy? # similar to assert 123
|
86
94
|
ok {0}.truthy? # similar to assert 0
|
87
95
|
ok {""}.truthy? # similar to assert ""
|
88
|
-
ok {false}.
|
89
|
-
ok {nil}.
|
96
|
+
ok {false}.falsy? # similar to refute false
|
97
|
+
ok {nil}.falsy? # similar to refute nil
|
90
98
|
|
91
99
|
## predicates
|
92
100
|
ok {""}.empty? # same as assert_empty? ""
|
@@ -104,7 +112,7 @@ describe 'Minitest::Ok' do
|
|
104
112
|
obj.instance_variable_set('@x', 10)
|
105
113
|
ok {obj}.instance_variable_defined?('@x')
|
106
114
|
|
107
|
-
ok {'logo.png'}.end_with?('.png') # same as assert 'logon.png'.
|
115
|
+
ok {'logo.png'}.end_with?('.png') # same as assert 'logon.png'.end_with?('.png')
|
108
116
|
ok {[1,2,3]}.any? {|x| x % 2 == 0} # same as assert [1,2,3].any? {...}
|
109
117
|
ok {[1,2,3]}.NOT.all? {|x| x < 0 } # same as refute [1,2,3].all? {...}
|
110
118
|
|
@@ -138,6 +146,20 @@ $License: MIT License $
|
|
138
146
|
|
139
147
|
## History
|
140
148
|
|
149
|
+
|
150
|
+
### 2024-09-16: Release 0.4.0
|
151
|
+
|
152
|
+
* [enhance] `ok {x}.nil?` now calls `assert_nil?(x)`.
|
153
|
+
* [enhance] `ok {}.raise?()` now accepts optional block parameter yielded when exception raised.
|
154
|
+
* [enhance] `ok {}.raise_nothing?` defined which represens nothing raised.
|
155
|
+
* [bugfix] `ok {a}.eql?(e)` now calls `assert_true a.eql?(e)` instead of just calling `a.eql?(e)`.
|
156
|
+
|
157
|
+
|
158
|
+
### 2021-08-02: Release 0.3.3
|
159
|
+
|
160
|
+
* [bugfix] rename `ok {}.falthy?` to `ok {}.falsy?`.
|
161
|
+
|
162
|
+
|
141
163
|
### 2021-01-17: Release 0.3.2
|
142
164
|
|
143
165
|
* [bugfix] fix to work on Ruby 3.
|
data/Rakefile
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
rescue LoadError => exc
|
4
|
+
warn "[warning] failed to load '#{exc.path}'"
|
5
|
+
end
|
2
6
|
require "rake/testtask"
|
3
7
|
|
4
8
|
Rake::TestTask.new(:test) do |t|
|
@@ -7,11 +11,44 @@ Rake::TestTask.new(:test) do |t|
|
|
7
11
|
t.test_files = FileList['test/**/*_test.rb']
|
8
12
|
end
|
9
13
|
|
10
|
-
task :default => :test
|
11
14
|
|
15
|
+
desc "run test for multiple version of Ruby"
|
16
|
+
task :'test:all' do
|
17
|
+
vs_home = ENV['VS_HOME'] or
|
18
|
+
fail "$VS_HOME required."
|
19
|
+
failed = false
|
20
|
+
ruby_vers = %w[3.3 3.2 3.1 3.0 2.7 2.6 2.5 2.4 2.3]
|
21
|
+
ruby_vers.each do |ver|
|
22
|
+
puts "\e[33m========== Ruby #{ver} ==========\e[0m"
|
23
|
+
ruby_bin = Dir.glob("#{vs_home}/ruby/#{ver}.*/bin").last
|
24
|
+
if ! ruby_bin
|
25
|
+
$stderr.puts "\e[31m[ERROR] Ruby #{ver} not installed.\e[0m\n\n"
|
26
|
+
failed = true
|
27
|
+
next
|
28
|
+
end
|
29
|
+
sh "#{ruby_bin}/ruby test/minitest/ok_test.rb" do |status_ok|
|
30
|
+
failed = true unless status_ok
|
31
|
+
end
|
32
|
+
sleep 0.2
|
33
|
+
end
|
34
|
+
exit 1 if failed
|
35
|
+
end
|
12
36
|
|
13
|
-
|
37
|
+
|
38
|
+
task :default => :help
|
39
|
+
|
40
|
+
|
41
|
+
desc "list tasks"
|
14
42
|
task :help do
|
43
|
+
system "rake -T"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
desc "show how to release"
|
48
|
+
task :guide do
|
49
|
+
rel = ENV['rel'] or abort "rake help: required 'rel=X.X.X'"
|
50
|
+
rel =~ /(\d+\.\d+)/
|
51
|
+
branch = "rel-#{$1}"
|
15
52
|
puts <<END
|
16
53
|
How to release:
|
17
54
|
|
@@ -19,16 +56,16 @@ How to release:
|
|
19
56
|
$ git diff
|
20
57
|
$ which ruby
|
21
58
|
$ rake test # for confirmation
|
22
|
-
$ git checkout -b
|
23
|
-
$ rake edit rel
|
59
|
+
$ git checkout -b #{branch} # or git checkout #{branch}
|
60
|
+
$ rake edit rel=#{rel}
|
24
61
|
$ git diff
|
25
|
-
$ git commit -a -m "release preparation for
|
62
|
+
$ git commit -a -m "release preparation for #{rel}"
|
26
63
|
$ rake build # for confirmation
|
27
64
|
$ rake install # for confirmation
|
28
65
|
$ #rake release
|
29
|
-
$ gem push pkg/minitest-ok
|
30
|
-
$ git tag
|
31
|
-
$ git push -u origin
|
66
|
+
$ gem push pkg/minitest-ok-#{rel}.gem
|
67
|
+
$ git tag v#{rel}
|
68
|
+
$ git push -u origin #{branch}
|
32
69
|
$ git push --tags
|
33
70
|
END
|
34
71
|
|
data/lib/minitest/ok.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 0.
|
4
|
+
### $Release: 0.4.0 $
|
5
5
|
### $Copyright: copyright(c) 2015-2018 kuwata-lab.com all rights reserved $
|
6
6
|
### $License: MIT License $
|
7
7
|
###
|
@@ -34,7 +34,7 @@ module Minitest
|
|
34
34
|
## ok {1..9}.include?(5) # same as assert_includes 5, 1..9
|
35
35
|
## ok {1..9}.NOT.include?(0) # same as refute_includes 0, 1..9
|
36
36
|
## ok {""}.truthy? # same as assert true, !!""
|
37
|
-
## ok {nil}.
|
37
|
+
## ok {nil}.falsy? # same as assert false, !!""
|
38
38
|
##
|
39
39
|
## ex = ok { proc { 1 / 0 } }.raise?(ZeroDivisionError, "divided by 0")
|
40
40
|
## p ex #=> #<ZeroDivisionError: divided by 0>
|
@@ -59,7 +59,7 @@ module Minitest
|
|
59
59
|
|
60
60
|
module Ok
|
61
61
|
|
62
|
-
VERSION = '$Release: 0.
|
62
|
+
VERSION = '$Release: 0.4.0 $'.split()[1]
|
63
63
|
|
64
64
|
|
65
65
|
class Msg < Proc # :nodoc:
|
@@ -260,6 +260,81 @@ module Minitest
|
|
260
260
|
raise
|
261
261
|
end
|
262
262
|
|
263
|
+
##--
|
264
|
+
##
|
265
|
+
## Same as <tt>assert_predicate(<actual>, :equal?)</tt>.
|
266
|
+
##
|
267
|
+
#def eql?(expected)
|
268
|
+
# _mark_as_tested()
|
269
|
+
# __assert_predicate(:eql?, expected)
|
270
|
+
#rescue Minitest::Assertion => ex
|
271
|
+
# ex.backtrace.delete_if {|bt| bt.start_with?(__FILE__) }
|
272
|
+
# raise
|
273
|
+
#end
|
274
|
+
##++
|
275
|
+
|
276
|
+
##
|
277
|
+
## Same as <tt>assert_predicate()</tt>.
|
278
|
+
##
|
279
|
+
self.instance_methods().grep(/\?/).each do |x|
|
280
|
+
next if x == :equal?
|
281
|
+
next if x == :nil? || x == :frozen? || x == :respond_to?
|
282
|
+
next if x == :is_a? || x == :kind_of? || x == :instance_of?
|
283
|
+
next if x == :instance_variable_defined? || x == :tainted?
|
284
|
+
eval <<-END, binding(), __FILE__, __LINE__ + 1
|
285
|
+
def #{x}(*args, **kwargs, &block)
|
286
|
+
_mark_as_tested()
|
287
|
+
__assert_predicate(:#{x}, *args, **kwargs, &block)
|
288
|
+
rescue Minitest::Assertion => ex
|
289
|
+
#ex.backtrace.delete_if {|bt| bt.start_with?(__FILE__) }
|
290
|
+
raise
|
291
|
+
end
|
292
|
+
END
|
293
|
+
end
|
294
|
+
|
295
|
+
def __assert_predicate(symbol, *args, **kwargs, &block)
|
296
|
+
no_params = args.empty? && kwargs.empty? && ! block_given?()
|
297
|
+
if no_params
|
298
|
+
if ! @not
|
299
|
+
@context.assert_predicate(@actual, symbol)
|
300
|
+
else
|
301
|
+
@context.refute_predicate(@actual, symbol)
|
302
|
+
end
|
303
|
+
else
|
304
|
+
if RUBY_VERSION >= "2.7"
|
305
|
+
result = @actual.__send__(symbol, *args, **kwargs, &block)
|
306
|
+
elsif ! kwargs.empty?
|
307
|
+
s = "ok{}.#{symbol}(#{kwargs.inspect[1..-2]})"
|
308
|
+
raise ArgumentError, "#{s}: Keyword argument is not supported."
|
309
|
+
else
|
310
|
+
result = @actual.__send__(symbol, *args, &block)
|
311
|
+
end
|
312
|
+
if ! @not
|
313
|
+
@context.assert result, Msg.new { "Expected #{@actual.inspect}.#{symbol}(#{args.inspect[1..-2]}) but failed." }
|
314
|
+
else
|
315
|
+
@context.refute result, Msg.new { "Expected #{@actual.inspect}.#{symbol}(#{args.inspect[1..-2]}) to fail but succeeded." }
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
private :__assert_predicate
|
320
|
+
|
321
|
+
##
|
322
|
+
## Same as <tt>assert_il()</tt>.
|
323
|
+
##
|
324
|
+
## ok {nil}.nil? # Pass
|
325
|
+
## ok {" "}.nil? # Fail
|
326
|
+
## ok {" "}.NOT.nil? # Pass
|
327
|
+
##
|
328
|
+
def nil?()
|
329
|
+
_mark_as_tested()
|
330
|
+
@context.assert_nil @actual unless @not
|
331
|
+
@context.refute_nil @actual if @not
|
332
|
+
self
|
333
|
+
rescue Minitest::Assertion => ex
|
334
|
+
ex.backtrace.delete_if {|bt| bt.start_with?(__FILE__) }
|
335
|
+
raise
|
336
|
+
end
|
337
|
+
|
263
338
|
##
|
264
339
|
## Same as <tt>assert_kind_of()</tt>.
|
265
340
|
##
|
@@ -372,15 +447,19 @@ module Minitest
|
|
372
447
|
|
373
448
|
##
|
374
449
|
## Same as <tt>assert_raises()</tt>.
|
450
|
+
## Optional block will be yielded only when exception raised with exception raised.
|
375
451
|
##
|
376
452
|
## ex = ok { proc { 1/0 } }.raise?(ZeroDivisionError) # Pass
|
377
453
|
## p ex.class #=> ZeroDivisionError
|
378
|
-
## ex = ok { proc { 1/0 } }.raise?(ZeroDivisionError, "divided by
|
379
|
-
## ex = ok { proc { 1/0 } }.raise?(ZeroDivisionError, /^divided by
|
454
|
+
## ex = ok { proc { 1/0 } }.raise?(ZeroDivisionError, "divided by 0")
|
455
|
+
## ex = ok { proc { 1/0 } }.raise?(ZeroDivisionError, /^divided by 0$/)
|
456
|
+
## ok { proc { 1/0 } }.raise?(ZeroDivisionError) do |exc|
|
457
|
+
## ok {exc.message} =~ /^divided by 0$/
|
458
|
+
## end
|
380
459
|
##
|
381
460
|
## ok { proc { 1 / 1 } }.NOT.raise?(Exception) # Pass
|
382
461
|
##
|
383
|
-
def raise?(exception_class, message=nil)
|
462
|
+
def raise?(exception_class, message=nil, &b)
|
384
463
|
_mark_as_tested()
|
385
464
|
ex = nil
|
386
465
|
unless @not
|
@@ -392,6 +471,7 @@ module Minitest
|
|
392
471
|
@context.assert_equal message, ex.message
|
393
472
|
end
|
394
473
|
end
|
474
|
+
yield ex if block_given?()
|
395
475
|
else
|
396
476
|
begin
|
397
477
|
@actual.call
|
@@ -407,6 +487,29 @@ module Minitest
|
|
407
487
|
raise
|
408
488
|
end
|
409
489
|
|
490
|
+
##
|
491
|
+
## Asserts that a Proc object raises nothing.
|
492
|
+
## Not available with <tt>.NOT()</tt>.
|
493
|
+
## Optional block will be yielded when unexpected exception raised.
|
494
|
+
##
|
495
|
+
## pr = proc { 1.0 / 0.0 }
|
496
|
+
## ok {pr}.raise_nothing?
|
497
|
+
##
|
498
|
+
def raise_nothing?(&b)
|
499
|
+
_mark_as_tested()
|
500
|
+
! @not or
|
501
|
+
raise "`NOT.raise_nothing?` is not supported because double negation is difficult to understand."
|
502
|
+
@context.assert true # count up number of assertions
|
503
|
+
begin
|
504
|
+
@actual.call
|
505
|
+
rescue Exception => ex
|
506
|
+
yield ex if block_given?()
|
507
|
+
#@context.assert false, "Exception #{ex.class} raised unexpectedly."
|
508
|
+
ex.backtrace.delete_if {|bt| bt.start_with?(__FILE__) }
|
509
|
+
raise
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
410
513
|
##
|
411
514
|
## Same as <tt>assert_throws()</tt>.
|
412
515
|
##
|
@@ -571,7 +674,7 @@ module Minitest
|
|
571
674
|
## ok {'logo.jpg'}.end_with?('.jpg') # Pass
|
572
675
|
## ok {[1, 2, 3]}.all? {|x| x <= 3 } # Pass
|
573
676
|
##
|
574
|
-
def method_missing(symbol, *args, &block)
|
677
|
+
def method_missing(symbol, *args, **kwargs, &block)
|
575
678
|
unless symbol.to_s =~ /\?\z/
|
576
679
|
return super
|
577
680
|
end
|
@@ -582,8 +685,7 @@ module Minitest
|
|
582
685
|
begin
|
583
686
|
@context.__send__("assert_#{symbol.to_s[0..-2]}", @actual, *args, &block)
|
584
687
|
rescue NoMethodError
|
585
|
-
|
586
|
-
@context.assert result, Msg.new { "Expected #{@actual.inspect}.#{symbol}(#{args.inspect[1..-2]}) but failed." }
|
688
|
+
__assert_predicate(symbol, *args, **kwargs, &block)
|
587
689
|
end
|
588
690
|
else
|
589
691
|
## Try refute_xxxx() at first.
|
@@ -591,8 +693,7 @@ module Minitest
|
|
591
693
|
begin
|
592
694
|
@context.__send__("refute_#{symbol.to_s[0..-2]}", @actual, *args, &block)
|
593
695
|
rescue NoMethodError
|
594
|
-
|
595
|
-
@context.refute result, Msg.new { "Expected #{@actual.inspect}.#{symbol}(#{args.inspect[1..-2]}) to fail but succeeded." }
|
696
|
+
__assert_predicate(symbol, *args, **kwargs, &block)
|
596
697
|
end
|
597
698
|
end
|
598
699
|
self
|
@@ -629,14 +730,14 @@ module Minitest
|
|
629
730
|
##
|
630
731
|
## Tests whether actual is false or nil.
|
631
732
|
##
|
632
|
-
## ok {nil}.
|
633
|
-
## ok {false}.
|
634
|
-
## ok {true}.
|
635
|
-
## ok {0}.
|
636
|
-
## ok {""}.
|
637
|
-
## ok {[]}.
|
733
|
+
## ok {nil}.falsy? # Pass
|
734
|
+
## ok {false}.falsy? # Pass
|
735
|
+
## ok {true}.falsy? # Fail
|
736
|
+
## ok {0}.falsy? # Fail
|
737
|
+
## ok {""}.falsy? # Fail
|
738
|
+
## ok {[]}.falsy? # Fail
|
638
739
|
##
|
639
|
-
def
|
740
|
+
def falsy?
|
640
741
|
_mark_as_tested()
|
641
742
|
unless @not
|
642
743
|
@context.refute @actual, Msg.new { "Expected (!! #{@actual.inspect}) == false, but not." }
|
@@ -648,6 +749,7 @@ module Minitest
|
|
648
749
|
ex.backtrace.delete_if {|bt| bt.start_with?(__FILE__) }
|
649
750
|
raise
|
650
751
|
end
|
752
|
+
alias falthy? falsy?
|
651
753
|
|
652
754
|
##
|
653
755
|
## Tests attribute value.
|
data/test/minitest/ok_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 0.
|
4
|
+
### $Release: 0.4.0 $
|
5
5
|
### $Copyright: copyright(c) 2015-2018 kuwata-lab.com all rights reserved $
|
6
6
|
### $License: MIT License $
|
7
7
|
###
|
@@ -21,10 +21,10 @@ describe Minitest::Ok::AssertionObject do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def should_raise
|
24
|
+
def should_raise(exception_class=Minitest::Assertion)
|
25
25
|
begin
|
26
26
|
yield
|
27
|
-
rescue
|
27
|
+
rescue exception_class => ex
|
28
28
|
return ex
|
29
29
|
else
|
30
30
|
_called = caller(1).grep(/ok_test\.rb/).map {|x| " - #{x}" }.join("\n")
|
@@ -249,6 +249,25 @@ describe Minitest::Ok::AssertionObject do
|
|
249
249
|
end
|
250
250
|
|
251
251
|
|
252
|
+
describe '#nil?' do
|
253
|
+
|
254
|
+
it "calls assert_nil()." do
|
255
|
+
should_not_raise { ok {nil}.nil? }
|
256
|
+
ex = should_raise { ok {" "}.nil? }
|
257
|
+
msg = "Expected \" \" to be nil."
|
258
|
+
assert_equal msg, ex.message
|
259
|
+
end
|
260
|
+
|
261
|
+
it "calls refute_nil() after NOT() called." do
|
262
|
+
should_not_raise { ok {" "}.NOT.nil? }
|
263
|
+
ex = should_raise { ok {nil}.NOT.nil? }
|
264
|
+
msg = "Expected nil to not be nil."
|
265
|
+
assert_equal msg, ex.message
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
|
252
271
|
describe '#kind_of?' do
|
253
272
|
|
254
273
|
it "calls assert_kind_of()." do
|
@@ -392,18 +411,33 @@ describe Minitest::Ok::AssertionObject do
|
|
392
411
|
should_not_raise { ok {proc{1/0}}.raise?(ZeroDivisionError, "divided by 0") }
|
393
412
|
ex = should_raise { ok {proc{1/0}}.raise?(ZeroDivisionError, "foobar") }
|
394
413
|
#expected = "Expected: \"foobar\"\n Actual: \"divided by 0\""
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
414
|
+
if RUBY_VERSION >= "2.7"
|
415
|
+
expected = [
|
416
|
+
'--- expected',
|
417
|
+
'+++ actual',
|
418
|
+
'@@ -1 +1,3 @@',
|
419
|
+
'-"foobar"',
|
420
|
+
'+# encoding: ASCII-8BIT',
|
421
|
+
'+# valid: true',
|
422
|
+
'+"divided by 0"',
|
423
|
+
'',
|
424
|
+
].join("\n")
|
425
|
+
elsif RUBY_VERSION >= "2.4"
|
426
|
+
expected = [
|
427
|
+
'--- expected',
|
428
|
+
'+++ actual',
|
429
|
+
#'@@ -1 +1,3 @@',
|
430
|
+
'@@ -1 +1,2 @@',
|
431
|
+
'-"foobar"',
|
432
|
+
'+# encoding: ASCII-8BIT',
|
433
|
+
#'+# valid: true',
|
434
|
+
'+"divided by 0"',
|
435
|
+
'',
|
436
|
+
].join("\n")
|
437
|
+
else
|
438
|
+
expected = ("Expected: \"foobar\"\n"\
|
439
|
+
" Actual: \"divided by 0\"")
|
440
|
+
end
|
407
441
|
assert_equal expected, ex.message
|
408
442
|
end
|
409
443
|
|
@@ -411,12 +445,93 @@ describe Minitest::Ok::AssertionObject do
|
|
411
445
|
should_not_raise { ok {proc{1/0}}.raise?(ZeroDivisionError, /by [0]/) }
|
412
446
|
ex = should_raise { ok {proc{1/0}}.raise?(ZeroDivisionError, /by 99/) }
|
413
447
|
#expected = "Expected /by 99/ to match \"divided by 0\"."
|
414
|
-
|
415
|
-
|
416
|
-
|
448
|
+
if RUBY_VERSION >= "2.7"
|
449
|
+
expected = ("Expected /by 99/ to match # encoding: ASCII-8BIT\n"\
|
450
|
+
"# valid: true\n"\
|
451
|
+
"\"divided by 0\".")
|
452
|
+
elsif RUBY_VERSION >= "2.4"
|
453
|
+
expected = ("Expected /by 99/ to match # encoding: ASCII-8BIT\n"\
|
454
|
+
"\"divided by 0\".")
|
455
|
+
else
|
456
|
+
expected = "Expected /by 99/ to match \"divided by 0\"."
|
457
|
+
end
|
417
458
|
assert_equal expected, ex.message
|
418
459
|
end
|
419
460
|
|
461
|
+
it "can take optional block which is yielded only when exception raised." do
|
462
|
+
msg = /divided by (0|zero)/
|
463
|
+
called = false
|
464
|
+
ok { proc { 1 / 0 } }.raise?(ZeroDivisionError, msg) do |ex|
|
465
|
+
called = true
|
466
|
+
end
|
467
|
+
assert_equal true, called
|
468
|
+
#
|
469
|
+
begin
|
470
|
+
called = false
|
471
|
+
ok { proc {1.0 / 0.0} }.raise?(ZeroDivisionError, msg) do |ex|
|
472
|
+
called = true
|
473
|
+
end
|
474
|
+
assert false
|
475
|
+
rescue Minitest::Assertion => _ignore
|
476
|
+
end
|
477
|
+
assert_equal false, called
|
478
|
+
end
|
479
|
+
|
480
|
+
end
|
481
|
+
|
482
|
+
|
483
|
+
describe '#raise_nothing?' do
|
484
|
+
|
485
|
+
it "simply calls proc object, does nothing even if exception raised." do
|
486
|
+
should_not_raise { ok {proc{1.0/0.0}}.raise_nothing? }
|
487
|
+
ex = should_raise(ZeroDivisionError) { ok {proc{1/0}}.raise_nothing? }
|
488
|
+
assert_same ZeroDivisionError, ex.class
|
489
|
+
assert_equal "divided by 0", ex.message
|
490
|
+
end
|
491
|
+
|
492
|
+
it "counts number of assertion if nothing raised." do
|
493
|
+
n1 = self.assertions
|
494
|
+
ok { proc { 1.0 / 0.0 } }.raise_nothing?
|
495
|
+
n2 = self.assertions
|
496
|
+
assert_equal n1+1, n2
|
497
|
+
#
|
498
|
+
n3 = self.assertions
|
499
|
+
begin
|
500
|
+
ok { proc { 1 / 0 } }.raise_nothing?
|
501
|
+
raise "-- should not reach --"
|
502
|
+
rescue Exception
|
503
|
+
end
|
504
|
+
n4 = self.assertions
|
505
|
+
assert_equal n3+1, n4
|
506
|
+
end
|
507
|
+
|
508
|
+
it "yields optional block if any exception raised." do
|
509
|
+
called = false
|
510
|
+
ok { proc { 1.0 / 0.0 } }.raise_nothing? do
|
511
|
+
called = true
|
512
|
+
end
|
513
|
+
assert_equal false, called
|
514
|
+
#
|
515
|
+
begin
|
516
|
+
ok { proc { 1 / 0 } }.raise_nothing? do
|
517
|
+
called = true
|
518
|
+
end
|
519
|
+
assert false
|
520
|
+
rescue Exception
|
521
|
+
end
|
522
|
+
assert_equal true, called
|
523
|
+
end
|
524
|
+
|
525
|
+
it "deletes lines containing 'minitest/ok.rb' from backtrace of exception." do
|
526
|
+
begin
|
527
|
+
ok { proc { 1 / 0 } }.raise_nothing?
|
528
|
+
assert false
|
529
|
+
rescue ZeroDivisionError => ex
|
530
|
+
found = ex.backtrace.any? {|bt| bt.include?("minitest/ok.rb") }
|
531
|
+
assert !found
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
420
535
|
end
|
421
536
|
|
422
537
|
|
@@ -427,7 +542,7 @@ describe Minitest::Ok::AssertionObject do
|
|
427
542
|
ex = should_raise { ok {proc { throw :exit }}.throw?(:finish) }
|
428
543
|
msg = "Expected :finish to have been thrown, not :exit."
|
429
544
|
assert_equal msg, ex.message
|
430
|
-
ex = should_raise { ok {proc {
|
545
|
+
ex = should_raise { ok {proc { _var = 1 + 1 }}.throw?(:exit) }
|
431
546
|
msg = "Expected :exit to have been thrown."
|
432
547
|
assert_equal msg, ex.message
|
433
548
|
end
|
@@ -659,13 +774,26 @@ describe Minitest::Ok::AssertionObject do
|
|
659
774
|
(x = ok {nil}).append('bar')
|
660
775
|
end
|
661
776
|
x._mark_as_tested()
|
662
|
-
|
777
|
+
if RUBY_VERSION >= "3.3"
|
778
|
+
msg = /^undefined method `append' for an instance of Mini[tT]est::Ok::AssertionObject/
|
779
|
+
else
|
780
|
+
msg = /^undefined method `append' for \#<Mini[tT]est::Ok::AssertionObject:\w+/
|
781
|
+
end
|
663
782
|
assert_match msg, ex.message
|
664
783
|
#
|
665
784
|
ex = assert_raises(NoMethodError) do
|
666
785
|
ok {nil}.start_with?('bar')
|
667
786
|
end
|
668
|
-
|
787
|
+
if RUBY_VERSION >= "3.3"
|
788
|
+
msg = "undefined method `start_with?' for nil"
|
789
|
+
elsif RUBY_VERSION =~ /^3\.1\./
|
790
|
+
msg = ("undefined method `start_with?' for nil:NilClass\n"\
|
791
|
+
"\n"\
|
792
|
+
" result = @actual.__send__(symbol, *args, **kwargs, &block)\n"\
|
793
|
+
" ^^^^^^^^^")
|
794
|
+
else
|
795
|
+
msg = "undefined method `start_with?' for nil:NilClass"
|
796
|
+
end
|
669
797
|
assert_equal msg, ex.message
|
670
798
|
end
|
671
799
|
|
@@ -736,18 +864,18 @@ describe Minitest::Ok::AssertionObject do
|
|
736
864
|
end
|
737
865
|
|
738
866
|
|
739
|
-
describe '#
|
867
|
+
describe '#falsy?' do
|
740
868
|
|
741
869
|
it "calles refute()." do
|
742
|
-
should_not_raise { ok {nil}.
|
743
|
-
ex = should_raise { ok {123}.
|
870
|
+
should_not_raise { ok {nil}.falsy? }
|
871
|
+
ex = should_raise { ok {123}.falsy? }
|
744
872
|
msg = 'Expected (!! 123) == false, but not.'
|
745
873
|
assert_equal msg, ex.message
|
746
874
|
end
|
747
875
|
|
748
876
|
it "calles assert() after NOT() called." do
|
749
|
-
should_not_raise { ok {123}.NOT.
|
750
|
-
ex = should_raise { ok {nil}.NOT.
|
877
|
+
should_not_raise { ok {123}.NOT.falsy? }
|
878
|
+
ex = should_raise { ok {nil}.NOT.falsy? }
|
751
879
|
msg = 'Expected (!! nil) == true, but not.'
|
752
880
|
assert_equal msg, ex.message
|
753
881
|
end
|
@@ -947,4 +1075,12 @@ describe Minitest::Ok::AssertionObject do
|
|
947
1075
|
end
|
948
1076
|
|
949
1077
|
|
1078
|
+
it "predicate methods are handled by `assert_predicate()`." do
|
1079
|
+
should_not_raise { ok {1+1}.eql?(2) }
|
1080
|
+
ex = should_raise { ok {1+1}.eql?(0) }
|
1081
|
+
msg = "Expected 2.eql?(0) but failed."
|
1082
|
+
assert_equal msg, ex.message
|
1083
|
+
end
|
1084
|
+
|
1085
|
+
|
950
1086
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-ok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- makoto kuwata
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -48,7 +48,7 @@ homepage: https://github.com/kwatch/minitest-ok
|
|
48
48
|
licenses:
|
49
49
|
- MIT-License
|
50
50
|
metadata: {}
|
51
|
-
post_install_message:
|
51
|
+
post_install_message:
|
52
52
|
rdoc_options: []
|
53
53
|
require_paths:
|
54
54
|
- lib
|
@@ -63,8 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
67
|
-
signing_key:
|
66
|
+
rubygems_version: 3.5.11
|
67
|
+
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: "'ok {1+1} == 2' instead of 'assert_equal 2, 1+1'"
|
70
70
|
test_files: []
|