test/minitest/test_minitest_assertions.rb in minitest-5.17.0 vs test/minitest/test_minitest_assertions.rb in minitest-5.18.0
- old
+ new
@@ -1060,10 +1060,70 @@
assert_triggered "Expected path 'blah' to exist." do
@tc.assert_path_exists "blah"
end
end
+ def test_assert_pattern
+ if RUBY_VERSION > "3" then
+ @tc.assert_pattern do
+ exp = if RUBY_VERSION.start_with? "3.0"
+ "(eval):1: warning: One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!\n"
+ else
+ ""
+ end
+ assert_output nil, exp do
+ eval "[1,2,3] => [Integer, Integer, Integer]" # eval to escape parser for ruby<3
+ end
+ end
+ else
+ @assertion_count = 0
+
+ assert_raises NotImplementedError do
+ @tc.assert_pattern do
+ # do nothing
+ end
+ end
+ end
+ end
+
+ def test_assert_pattern_traps_nomatchingpatternerror
+ skip unless RUBY_VERSION > "3"
+ exp = if RUBY_VERSION.start_with? "3.0" then
+ "[1, 2, 3]" # terrible error message!
+ else
+ /length mismatch/
+ end
+
+ assert_triggered exp do
+ @tc.assert_pattern do
+ capture_io do # 3.0 is noisy
+ eval "[1,2,3] => [Integer, Integer]" # eval to escape parser for ruby<3
+ end
+ end
+ end
+ end
+
+ def test_assert_pattern_raises_other_exceptions
+ skip unless RUBY_VERSION >= "3.0"
+
+ @assertion_count = 0
+
+ assert_raises RuntimeError do
+ @tc.assert_pattern do
+ raise "boom"
+ end
+ end
+ end
+
+ def test_assert_pattern_with_no_block
+ skip unless RUBY_VERSION >= "3.0"
+
+ assert_triggered "assert_pattern requires a block to capture errors." do
+ @tc.assert_pattern
+ end
+ end
+
def test_capture_io
@assertion_count = 0
non_verbose do
out, err = capture_io do
@@ -1309,9 +1369,59 @@
end
def test_refute_operator_triggered
assert_triggered "Expected 2 to not be > 1." do
@tc.refute_operator 2, :>, 1
+ end
+ end
+
+ def test_refute_pattern
+ if RUBY_VERSION >= "3.0"
+ @tc.refute_pattern do
+ capture_io do # 3.0 is noisy
+ eval "[1,2,3] => [Integer, Integer, String]"
+ end
+ end
+ else
+ @assertion_count = 0
+
+ assert_raises NotImplementedError do
+ @tc.refute_pattern do
+ eval "[1,2,3] => [Integer, Integer, String]"
+ end
+ end
+ end
+ end
+
+ def test_refute_pattern_expects_nomatchingpatternerror
+ skip unless RUBY_VERSION > "3"
+
+ assert_triggered(/NoMatchingPatternError expected, but nothing was raised./) do
+ @tc.refute_pattern do
+ capture_io do # 3.0 is noisy
+ eval "[1,2,3] => [Integer, Integer, Integer]"
+ end
+ end
+ end
+ end
+
+ def test_refute_pattern_raises_other_exceptions
+ skip unless RUBY_VERSION >= "3.0"
+
+ @assertion_count = 0
+
+ assert_raises RuntimeError do
+ @tc.refute_pattern do
+ raise "boom"
+ end
+ end
+ end
+
+ def test_refute_pattern_with_no_block
+ skip unless RUBY_VERSION >= "3.0"
+
+ assert_triggered "refute_pattern requires a block to capture errors." do
+ @tc.refute_pattern
end
end
def test_refute_predicate
@tc.refute_predicate "42", :empty?