Skip to content
Permalink
Browse files

+ Add a descriptive error if assert_output or assert_raises called wi…

…thout a block. (okuramasafumi)

[git-p4: depot-paths = "//src/minitest/dev/": change = 12124]
  • Loading branch information...
zenspider committed Jun 11, 2019
1 parent 2a9878b commit 100e82a4de148348fc87a6b09292079635eb9503
Showing with 18 additions and 0 deletions.
  1. +6 −0 lib/minitest/assertions.rb
  2. +12 −0 test/minitest/test_minitest_assertions.rb
@@ -303,6 +303,9 @@ def assert_operator o1, op, o2 = UNDEFINED, msg = nil
# See also: #assert_silent

def assert_output stdout = nil, stderr = nil
flunk "assert_output requires a block to capture output." unless
block_given?

out, err = capture_io do
yield
end
@@ -339,6 +342,9 @@ def assert_predicate o1, op, msg = nil
# passed.

def assert_raises *exp
flunk "assert_raises requires a block to capture errors." unless
block_given?

msg = "#{exp.pop}.\n" if String === exp.last
exp << StandardError if exp.empty?

@@ -588,6 +588,12 @@ def test_assert_output_triggered_out
end
end

def test_assert_output_without_block
assert_triggered "assert_output requires a block to capture output." do
@tc.assert_output "blah"
end
end

def test_assert_predicate
@tc.assert_predicate "", :empty?
end
@@ -767,6 +773,12 @@ def test_assert_raises_triggered_none_msg
assert_equal expected, e.message
end

def test_assert_raises_without_block
assert_triggered "assert_raises requires a block to capture errors." do
@tc.assert_raises StandardError
end
end

def test_assert_respond_to
@tc.assert_respond_to "blah", :empty?
end

0 comments on commit 100e82a

Please sign in to comment.
You can’t perform that action at this time.