Permalink
Browse files

+ TestCase#message can now take another proc to defer custom message …

…cost. (ordinaryzelig/bhenderson)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8102]
  • Loading branch information...
1 parent 1dde8a3 commit fa1591a003a64925226a3a8926fd70dc1193a575 @zenspider zenspider committed Jan 7, 2013
Showing with 31 additions and 0 deletions.
  1. +1 −0 lib/minitest/unit.rb
  2. +30 −0 test/minitest/test_minitest_unit.rb
View
@@ -558,6 +558,7 @@ def flunk msg = nil
def message msg = nil, ending = ".", &default
proc {
+ msg = msg.call.chomp(".") if Proc === msg
custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
"#{custom_message}#{default.call}#{ending}"
}
@@ -1418,6 +1418,36 @@ def test_message
assert_equal "blah2.", @tc.message("") { "blah2" }.call
assert_equal "blah1.\nblah2.", @tc.message(:blah1) { "blah2" }.call
assert_equal "blah1.\nblah2.", @tc.message("blah1") { "blah2" }.call
+
+ message = proc { "blah1" }
+ assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call
+
+ message = @tc.message { "blah1" }
+ assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call
+ end
+
+ def test_message_message
+ util_assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
+ @tc.assert_equal 1, 2, message { "whoops" }
+ end
+ end
+
+ def test_message_lambda
+ util_assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
+ @tc.assert_equal 1, 2, lambda { "whoops" }
+ end
+ end
+
+ def test_message_deferred
+ @assertion_count, var = 0, nil
+
+ msg = message { var = "blah" }
+
+ assert_nil var
+
+ msg.call
+
+ assert_equal "blah", var
end
def test_pass

0 comments on commit fa1591a

Please sign in to comment.