Skip to content

Commit 100e82a

Browse files
committed
+ Add a descriptive error if assert_output or assert_raises called without a block. (okuramasafumi)
[git-p4: depot-paths = "//src/minitest/dev/": change = 12124]
1 parent 2a9878b commit 100e82a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/minitest/assertions.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ def assert_operator o1, op, o2 = UNDEFINED, msg = nil
303303
# See also: #assert_silent
304304

305305
def assert_output stdout = nil, stderr = nil
306+
flunk "assert_output requires a block to capture output." unless
307+
block_given?
308+
306309
out, err = capture_io do
307310
yield
308311
end
@@ -339,6 +342,9 @@ def assert_predicate o1, op, msg = nil
339342
# passed.
340343

341344
def assert_raises *exp
345+
flunk "assert_raises requires a block to capture errors." unless
346+
block_given?
347+
342348
msg = "#{exp.pop}.\n" if String === exp.last
343349
exp << StandardError if exp.empty?
344350

test/minitest/test_minitest_assertions.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@ def test_assert_output_triggered_out
588588
end
589589
end
590590

591+
def test_assert_output_without_block
592+
assert_triggered "assert_output requires a block to capture output." do
593+
@tc.assert_output "blah"
594+
end
595+
end
596+
591597
def test_assert_predicate
592598
@tc.assert_predicate "", :empty?
593599
end
@@ -767,6 +773,12 @@ def test_assert_raises_triggered_none_msg
767773
assert_equal expected, e.message
768774
end
769775

776+
def test_assert_raises_without_block
777+
assert_triggered "assert_raises requires a block to capture errors." do
778+
@tc.assert_raises StandardError
779+
end
780+
end
781+
770782
def test_assert_respond_to
771783
@tc.assert_respond_to "blah", :empty?
772784
end

0 commit comments

Comments
 (0)