Skip to content

Commit

Permalink
+ Add a descriptive error if assert_output or assert_raises called wi…
Browse files Browse the repository at this point in the history
…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 100e82a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/minitest/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?

Expand Down
12 changes: 12 additions & 0 deletions test/minitest/test_minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 100e82a

Please sign in to comment.