class TestMinitestAssertions
Constants
- RUBY18
do not call parallelize_me! - teardown accesses @tc._assertions which is not threadsafe. Nearly every method in here is an assertion test so it isn’t worth splitting it out further.
Public Class Methods
new(s;)
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 184 def initialize s; @name = s; end
Public Instance Methods
assert_deprecated(name) { || ... }
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 58 def assert_deprecated name dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+(?::.*)?/ dep = "" if $-w.nil? assert_output nil, dep do yield end end
assert_triggered(expected, klass = Minitest::Assertion) { || ... }
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 67 def assert_triggered expected, klass = Minitest::Assertion e = assert_raises klass do yield end msg = e.message.sub(/(---Backtrace---).*/m, '\1') msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)") msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform assert_msg = Regexp === expected ? :assert_match : :assert_equal self.send assert_msg, expected, msg end
clean(s)
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 80 def clean s s.gsub(/^ {6,10}/, "") end
non_verbose() { || ... }
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 84 def non_verbose orig_verbose = $VERBOSE $VERBOSE = false yield ensure $VERBOSE = orig_verbose end
setup()
click to toggle source
Calls superclass method
Minitest::Test::LifecycleHooks#setup
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 43 def setup super Minitest::Test.reset @tc = DummyTest.new @zomg = "zomg ponies!" # TODO: const @assertion_count = 1 end
teardown()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 53 def teardown assert_equal(@assertion_count, @tc.assertions, "expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") end
test_assert()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 93 def test_assert @assertion_count = 2 @tc.assert_equal true, @tc.assert(true), "returns true on success" end
test_assert__triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 99 def test_assert__triggered assert_triggered "Expected false to be truthy." do @tc.assert false end end
test_assert__triggered_lambda()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 111 def test_assert__triggered_lambda assert_triggered "whoops" do @tc.assert false, lambda { "whoops" } end end
test_assert__triggered_message()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 105 def test_assert__triggered_message assert_triggered @zomg do @tc.assert false, @zomg end end
test_assert_empty()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 117 def test_assert_empty @assertion_count = 2 @tc.assert_empty [] end
test_assert_empty_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 123 def test_assert_empty_triggered @assertion_count = 2 assert_triggered "Expected [1] to be empty." do @tc.assert_empty [1] end end
test_assert_equal()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 131 def test_assert_equal @tc.assert_equal 1, 1 end
test_assert_equal_different_collection_array_hex_invisible()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 135 def test_assert_equal_different_collection_array_hex_invisible object1 = Object.new object2 = Object.new msg = "No visible difference in the Array#inspect output. You should look at the implementation of #== on Array or its members. [#<Object:0xXXXXXX>]".gsub(/^ +/, "") assert_triggered msg do @tc.assert_equal [object1], [object2] end end
test_assert_equal_different_collection_hash_hex_invisible()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 146 def test_assert_equal_different_collection_hash_hex_invisible h1, h2 = {}, {} h1[1] = Object.new h2[1] = Object.new msg = "No visible difference in the Hash#inspect output. You should look at the implementation of #== on Hash or its members. {1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "") assert_triggered msg do @tc.assert_equal h1, h2 end end
test_assert_equal_different_diff_deactivated()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 159 def test_assert_equal_different_diff_deactivated without_diff do assert_triggered util_msg("haha" * 10, "blah" * 10) do o1 = "haha" * 10 o2 = "blah" * 10 @tc.assert_equal o1, o2 end end end
test_assert_equal_different_hex()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 182 def test_assert_equal_different_hex c = Class.new do def initialize s; @name = s; end end o1 = c.new "a" o2 = c.new "b" msg = clean <<-EOS --- expected +++ actual @@ -1 +1 @@ -#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\"> +#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\"> EOS assert_triggered msg do @tc.assert_equal o1, o2 end end
test_assert_equal_different_hex_invisible()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 202 def test_assert_equal_different_hex_invisible o1 = Object.new o2 = Object.new msg = "No visible difference in the Object#inspect output. You should look at the implementation of #== on Object or its members. #<Object:0xXXXXXX>".gsub(/^ +/, "") assert_triggered msg do @tc.assert_equal o1, o2 end end
test_assert_equal_different_lambda()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 176 def test_assert_equal_different_lambda assert_triggered "whoops.\nExpected: 1\n Actual: 2" do @tc.assert_equal 1, 2, lambda { "whoops" } end end
test_assert_equal_different_long()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 215 def test_assert_equal_different_long msg = "--- expected +++ actual @@ -1 +1 @@ -\"hahahahahahahahahahahahahahahahahahahaha\" +\"blahblahblahblahblahblahblahblahblahblah\" ".gsub(/^ +/, "") assert_triggered msg do o1 = "haha" * 10 o2 = "blah" * 10 @tc.assert_equal o1, o2 end end
test_assert_equal_different_long_invisible()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 231 def test_assert_equal_different_long_invisible msg = "No visible difference in the String#inspect output. You should look at the implementation of #== on String or its members. \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "") assert_triggered msg do o1 = "blah" * 10 o2 = "blah" * 10 def o1.== _ false end @tc.assert_equal o1, o2 end end
test_assert_equal_different_long_msg()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 246 def test_assert_equal_different_long_msg msg = "message. --- expected +++ actual @@ -1 +1 @@ -\"hahahahahahahahahahahahahahahahahahahaha\" +\"blahblahblahblahblahblahblahblahblahblah\" ".gsub(/^ +/, "") assert_triggered msg do o1 = "haha" * 10 o2 = "blah" * 10 @tc.assert_equal o1, o2, "message" end end
test_assert_equal_different_message()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 170 def test_assert_equal_different_message assert_triggered "whoops.\nExpected: 1\n Actual: 2" do @tc.assert_equal 1, 2, message { "whoops" } end end
test_assert_equal_different_short()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 262 def test_assert_equal_different_short assert_triggered util_msg(1, 2) do @tc.assert_equal 1, 2 end end
test_assert_equal_different_short_msg()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 268 def test_assert_equal_different_short_msg assert_triggered util_msg(1, 2, "message") do @tc.assert_equal 1, 2, "message" end end
test_assert_equal_different_short_multiline()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 274 def test_assert_equal_different_short_multiline msg = "--- expected\n+++ actual\n@@ -1,2 +1,2 @@\n \"a\n-b\"\n+c\"\n" assert_triggered msg do @tc.assert_equal "a\nb", "a\nc" end end
test_assert_equal_does_not_allow_lhs_nil()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 281 def test_assert_equal_does_not_allow_lhs_nil if Minitest::VERSION =~ /^6/ then warn "Time to strip the MT5 test" @assertion_count += 1 assert_triggered(/Use assert_nil if expecting nil/) do @tc.assert_equal nil, nil end else err_re = /Use assert_nil if expecting nil from .*test_minitest_\w+.rb/ err_re = "" if $-w.nil? assert_output "", err_re do @tc.assert_equal nil, nil end end end
test_assert_equal_does_not_allow_lhs_nil_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 299 def test_assert_equal_does_not_allow_lhs_nil_triggered assert_triggered "Expected: nil\n Actual: false" do @tc.assert_equal nil, false end end
test_assert_equal_string_both_escaped_unescaped_newlines()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 321 def test_assert_equal_string_both_escaped_unescaped_newlines msg = <<-EOM.gsub(/^ {10}/, "") --- expected +++ actual @@ -1,2 +1 @@ -\"A\\n -B\" +\"A\\n\\\\nB\" EOM assert_triggered msg do exp = "A\\nB" act = "A\n\\nB" @tc.assert_equal exp, act end end
test_assert_equal_string_bug791()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 305 def test_assert_equal_string_bug791 exp = <<-'EOF'.gsub(/^ {10}/, "") # note single quotes --- expected +++ actual @@ -1,2 +1 @@ -"\\n -" +"\\\" EOF exp = "Expected: \"\\\\n\"\n Actual: \"\\\\\"" assert_triggered exp do @tc.assert_equal "\\n", "\\" end end
test_assert_equal_string_encodings()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 339 def test_assert_equal_string_encodings msg = <<-EOM.gsub(/^ {10}/, "") --- expected +++ actual @@ -1,3 +1,3 @@ -# encoding: UTF-8 -# valid: false +# encoding: ASCII-8BIT +# valid: true "bad-utf8-\\xF1.txt" EOM assert_triggered msg do x = "bad-utf8-\xF1.txt" y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped @tc.assert_equal x, y end end
test_assert_equal_string_encodings_both_different()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 358 def test_assert_equal_string_encodings_both_different msg = <<-EOM.gsub(/^ {10}/, "") --- expected +++ actual @@ -1,3 +1,3 @@ -# encoding: US-ASCII -# valid: false +# encoding: ASCII-8BIT +# valid: true "bad-utf8-\\xF1.txt" EOM assert_triggered msg do x = "bad-utf8-\xF1.txt".force_encoding "ASCII" y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped @tc.assert_equal x, y end end
test_assert_equal_unescape_newlines()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 377 def test_assert_equal_unescape_newlines msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc --- expected +++ actual @@ -1,2 +1,2 @@ -"hello +"hello\n world" EOM assert_triggered msg do exp = "hello\nworld" act = 'hello\nworld' # notice single quotes @tc.assert_equal exp, act end end
test_assert_in_delta()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 395 def test_assert_in_delta @tc.assert_in_delta 0.0, 1.0 / 1000, 0.1 end
test_assert_in_delta_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 399 def test_assert_in_delta_triggered x = "1.0e-06" assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do @tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001 end end
test_assert_in_epsilon()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 406 def test_assert_in_epsilon @assertion_count = 10 @tc.assert_in_epsilon 10_000, 9991 @tc.assert_in_epsilon 9991, 10_000 @tc.assert_in_epsilon 1.0, 1.001 @tc.assert_in_epsilon 1.001, 1.0 @tc.assert_in_epsilon 10_000, 9999.1, 0.0001 @tc.assert_in_epsilon 9999.1, 10_000, 0.0001 @tc.assert_in_epsilon 1.0, 1.0001, 0.0001 @tc.assert_in_epsilon 1.0001, 1.0, 0.0001 @tc.assert_in_epsilon(-1, -1) @tc.assert_in_epsilon(-10_000, -9991) end
test_assert_in_epsilon_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 423 def test_assert_in_epsilon_triggered assert_triggered "Expected |10000 - 9990| (10) to be <= 9.99." do @tc.assert_in_epsilon 10_000, 9990 end end
test_assert_in_epsilon_triggered_negative_case()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 429 def test_assert_in_epsilon_triggered_negative_case x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx" y = "0.1" assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do @tc.assert_in_epsilon(-1.1, -1, 0.1) end end
test_assert_includes()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 437 def test_assert_includes @assertion_count = 2 @tc.assert_includes [true], true end
test_assert_includes_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 443 def test_assert_includes_triggered @assertion_count = 3 e = @tc.assert_raises Minitest::Assertion do @tc.assert_includes [true], false end expected = "Expected [true] to include false." assert_equal expected, e.message end
test_assert_instance_of()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 454 def test_assert_instance_of @tc.assert_instance_of String, "blah" end
test_assert_instance_of_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 458 def test_assert_instance_of_triggered assert_triggered 'Expected "blah" to be an instance of Array, not String.' do @tc.assert_instance_of Array, "blah" end end
test_assert_kind_of()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 464 def test_assert_kind_of @tc.assert_kind_of String, "blah" end
test_assert_kind_of_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 468 def test_assert_kind_of_triggered assert_triggered 'Expected "blah" to be a kind of Array, not String.' do @tc.assert_kind_of Array, "blah" end end
test_assert_match()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 474 def test_assert_match @assertion_count = 2 @tc.assert_match(/\w+/, "blah blah blah") end
test_assert_match_matchee_to_str()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 479 def test_assert_match_matchee_to_str @assertion_count = 2 obj = Object.new def obj.to_str; "blah" end @tc.assert_match "blah", obj end
test_assert_match_matcher_object()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 488 def test_assert_match_matcher_object @assertion_count = 2 pattern = Object.new def pattern.=~ _; true end @tc.assert_match pattern, 5 end
test_assert_match_object_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 497 def test_assert_match_object_triggered @assertion_count = 2 pattern = Object.new def pattern.=~ _; false end def pattern.inspect; "[Object]" end assert_triggered "Expected [Object] to match 5." do @tc.assert_match pattern, 5 end end
test_assert_match_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 509 def test_assert_match_triggered @assertion_count = 2 assert_triggered 'Expected /\d+/ to match "blah blah blah".' do @tc.assert_match(/\d+/, "blah blah blah") end end
test_assert_nil()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 516 def test_assert_nil @tc.assert_nil nil end
test_assert_nil_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 520 def test_assert_nil_triggered assert_triggered "Expected 42 to be nil." do @tc.assert_nil 42 end end
test_assert_operator()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 526 def test_assert_operator @tc.assert_operator 2, :>, 1 end
test_assert_operator_bad_object()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 530 def test_assert_operator_bad_object bad = Object.new def bad.== _; true end @tc.assert_operator bad, :equal?, bad end
test_assert_operator_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 537 def test_assert_operator_triggered assert_triggered "Expected 2 to be < 1." do @tc.assert_operator 2, :<, 1 end end
test_assert_output_both()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 543 def test_assert_output_both @assertion_count = 2 @tc.assert_output "yay", "blah" do print "yay" $stderr.print "blah" end end
test_assert_output_both_regexps()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 552 def test_assert_output_both_regexps @assertion_count = 4 @tc.assert_output(/y.y/, /bl.h/) do print "yay" $stderr.print "blah" end end
test_assert_output_err()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 561 def test_assert_output_err @tc.assert_output nil, "blah" do $stderr.print "blah" end end
test_assert_output_neither()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 567 def test_assert_output_neither @assertion_count = 0 @tc.assert_output do # do nothing end end
test_assert_output_out()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 575 def test_assert_output_out @tc.assert_output "blah" do print "blah" end end
test_assert_output_triggered_both()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 581 def test_assert_output_triggered_both assert_triggered util_msg("blah", "blah blah", "In stderr") do @tc.assert_output "yay", "blah" do print "boo" $stderr.print "blah blah" end end end
test_assert_output_triggered_err()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 590 def test_assert_output_triggered_err assert_triggered util_msg("blah", "blah blah", "In stderr") do @tc.assert_output nil, "blah" do $stderr.print "blah blah" end end end
test_assert_output_triggered_out()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 598 def test_assert_output_triggered_out assert_triggered util_msg("blah", "blah blah", "In stdout") do @tc.assert_output "blah" do print "blah blah" end end end
test_assert_output_without_block()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 606 def test_assert_output_without_block assert_triggered "assert_output requires a block to capture output." do @tc.assert_output "blah" end end
test_assert_path_exists()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 909 def test_assert_path_exists @tc.assert_path_exists __FILE__ end
test_assert_path_exists_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 913 def test_assert_path_exists_triggered assert_triggered "Expected path 'blah' to exist." do @tc.assert_path_exists "blah" end end
test_assert_predicate()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 612 def test_assert_predicate @tc.assert_predicate "", :empty? end
test_assert_predicate_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 616 def test_assert_predicate_triggered assert_triggered 'Expected "blah" to be empty?.' do @tc.assert_predicate "blah", :empty? end end
test_assert_raises()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 622 def test_assert_raises @tc.assert_raises RuntimeError do raise "blah" end end
test_assert_raises_default()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 628 def test_assert_raises_default @tc.assert_raises do raise StandardError, "blah" end end
test_assert_raises_default_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 634 def test_assert_raises_default_triggered e = assert_raises Minitest::Assertion do @tc.assert_raises do raise SomeError, "blah" end end expected = clean <<-EOM.chomp [StandardError] exception expected, not Class: <SomeError> Message: <\"blah\"> ---Backtrace--- FILE:LINE:in \`test_assert_raises_default_triggered\' --------------- EOM actual = e.message.gsub(/^.+:\d+/, "FILE:LINE") actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0" assert_equal expected, actual end
test_assert_raises_exit()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 656 def test_assert_raises_exit @tc.assert_raises SystemExit do exit 1 end end
test_assert_raises_module()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 662 def test_assert_raises_module @tc.assert_raises MyModule do raise AnError end end
test_assert_raises_signals()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 668 def test_assert_raises_signals @tc.assert_raises SignalException do raise SignalException, :INT end end
test_assert_raises_skip()
click to toggle source
svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 680 def test_assert_raises_skip @assertion_count = 0 assert_triggered "skipped", Minitest::Skip do @tc.assert_raises ArgumentError do begin raise "blah" rescue skip "skipped" end end end end
test_assert_raises_subclass()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 694 def test_assert_raises_subclass @tc.assert_raises StandardError do raise AnError end end
test_assert_raises_subclass_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 700 def test_assert_raises_subclass_triggered e = assert_raises Minitest::Assertion do @tc.assert_raises SomeError do raise AnError, "some message" end end expected = clean <<-EOM [SomeError] exception expected, not Class: <AnError> Message: <\"some message\"> ---Backtrace--- FILE:LINE:in \`test_assert_raises_subclass_triggered\' --------------- EOM actual = e.message.gsub(/^.+:\d+/, "FILE:LINE") actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0" assert_equal expected.chomp, actual end
test_assert_raises_triggered_different()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 722 def test_assert_raises_triggered_different e = assert_raises Minitest::Assertion do @tc.assert_raises RuntimeError do raise SyntaxError, "icky" end end expected = clean <<-EOM.chomp [RuntimeError] exception expected, not Class: <SyntaxError> Message: <\"icky\"> ---Backtrace--- FILE:LINE:in \`test_assert_raises_triggered_different\' --------------- EOM actual = e.message.gsub(/^.+:\d+/, "FILE:LINE") actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0" assert_equal expected, actual end
test_assert_raises_triggered_different_msg()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 744 def test_assert_raises_triggered_different_msg e = assert_raises Minitest::Assertion do @tc.assert_raises RuntimeError, "XXX" do raise SyntaxError, "icky" end end expected = clean <<-EOM XXX. [RuntimeError] exception expected, not Class: <SyntaxError> Message: <\"icky\"> ---Backtrace--- FILE:LINE:in \`test_assert_raises_triggered_different_msg\' --------------- EOM actual = e.message.gsub(/^.+:\d+/, "FILE:LINE") actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0" assert_equal expected.chomp, actual end
test_assert_raises_triggered_none()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 767 def test_assert_raises_triggered_none e = assert_raises Minitest::Assertion do @tc.assert_raises Minitest::Assertion do # do nothing end end expected = "Minitest::Assertion expected but nothing was raised." assert_equal expected, e.message end
test_assert_raises_triggered_none_msg()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 779 def test_assert_raises_triggered_none_msg e = assert_raises Minitest::Assertion do @tc.assert_raises Minitest::Assertion, "XXX" do # do nothing end end expected = "XXX.\nMinitest::Assertion expected but nothing was raised." assert_equal expected, e.message end
test_assert_raises_without_block()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 791 def test_assert_raises_without_block assert_triggered "assert_raises requires a block to capture errors." do @tc.assert_raises StandardError end end
test_assert_respond_to()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 797 def test_assert_respond_to @tc.assert_respond_to "blah", :empty? end
test_assert_respond_to_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 801 def test_assert_respond_to_triggered assert_triggered 'Expected "blah" (String) to respond to #rawr!.' do @tc.assert_respond_to "blah", :rawr! end end
test_assert_same()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 807 def test_assert_same @assertion_count = 3 o = "blah" @tc.assert_same 1, 1 @tc.assert_same :blah, :blah @tc.assert_same o, o end
test_assert_same_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 816 def test_assert_same_triggered @assertion_count = 2 assert_triggered "Expected 2 (oid=N) to be the same as 1 (oid=N)." do @tc.assert_same 1, 2 end s1 = "blah" s2 = "blah" assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do @tc.assert_same s1, s2 end end
test_assert_send()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 831 def test_assert_send assert_deprecated :assert_send do @tc.assert_send [1, :<, 2] end end
test_assert_send_bad()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 837 def test_assert_send_bad assert_deprecated :assert_send do assert_triggered "Expected 1.>(*[2]) to return true." do @tc.assert_send [1, :>, 2] end end end
test_assert_silent()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 845 def test_assert_silent @assertion_count = 2 @tc.assert_silent do # do nothing end end
test_assert_silent_triggered_err()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 853 def test_assert_silent_triggered_err assert_triggered util_msg("", "blah blah", "In stderr") do @tc.assert_silent do $stderr.print "blah blah" end end end
test_assert_silent_triggered_out()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 861 def test_assert_silent_triggered_out @assertion_count = 2 assert_triggered util_msg("", "blah blah", "In stdout") do @tc.assert_silent do print "blah blah" end end end
test_assert_throws()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 871 def test_assert_throws @tc.assert_throws :blah do throw :blah end end
test_assert_throws_argument_exception()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 877 def test_assert_throws_argument_exception @tc.assert_raises ArgumentError do @tc.assert_throws :blah do raise ArgumentError end end end
test_assert_throws_different()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 885 def test_assert_throws_different assert_triggered "Expected :blah to have been thrown, not :not_blah." do @tc.assert_throws :blah do throw :not_blah end end end
test_assert_throws_name_error()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 893 def test_assert_throws_name_error @tc.assert_raises NameError do @tc.assert_throws :blah do raise NameError end end end
test_assert_throws_unthrown()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 901 def test_assert_throws_unthrown assert_triggered "Expected :blah to have been thrown." do @tc.assert_throws :blah do # do nothing end end end
test_capture_io()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 919 def test_capture_io @assertion_count = 0 non_verbose do out, err = capture_io do puts "hi" $stderr.puts "bye!" end assert_equal "hi\n", out assert_equal "bye!\n", err end end
test_capture_subprocess_io()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 933 def test_capture_subprocess_io @assertion_count = 0 non_verbose do out, err = capture_subprocess_io do system("echo hi") system("echo bye! 1>&2") end assert_equal "hi\n", out assert_equal "bye!", err.strip end end
test_class_asserts_match_refutes()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 947 def test_class_asserts_match_refutes @assertion_count = 0 methods = Minitest::Assertions.public_instance_methods methods.map!(&:to_s) if Symbol === methods.first # These don't have corresponding refutes _on purpose_. They're # useless and will never be added, so don't bother. ignores = %w[assert_output assert_raises assert_send assert_silent assert_throws assert_mock] # These are test/unit methods. I'm not actually sure why they're still here ignores += %w[assert_no_match assert_not_equal assert_not_nil assert_not_same assert_nothing_raised assert_nothing_thrown assert_raise] asserts = methods.grep(/^assert/).sort - ignores refutes = methods.grep(/^refute/).sort - ignores assert_empty refutes.map { |n| n.sub(/^refute/, "assert") } - asserts assert_empty asserts.map { |n| n.sub(/^assert/, "refute") } - refutes end
test_delta_consistency()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 970 def test_delta_consistency @assertion_count = 2 @tc.assert_in_delta 0, 1, 1 assert_triggered "Expected |0 - 1| (1) to not be <= 1." do @tc.refute_in_delta 0, 1, 1 end end
test_epsilon_consistency()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 980 def test_epsilon_consistency @assertion_count = 2 @tc.assert_in_epsilon 1.0, 1.001 msg = "Expected |1.0 - 1.001| (0.000999xxx) to not be <= 0.001." assert_triggered msg do @tc.refute_in_epsilon 1.0, 1.001 end end
test_fail_after()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 991 def test_fail_after t = Time.now y, m, d = t.year, t.month, t.day assert_silent do @tc.fail_after y, m, d+1, "remove the deprecations" end assert_triggered "remove the deprecations" do @tc.fail_after y, m, d, "remove the deprecations" end end
test_flunk()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1004 def test_flunk assert_triggered "Epic Fail!" do @tc.flunk end end
test_flunk_message()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1010 def test_flunk_message assert_triggered @zomg do @tc.flunk @zomg end end
test_pass()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1016 def test_pass @tc.pass end
test_refute()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1020 def test_refute @assertion_count = 2 @tc.assert_equal false, @tc.refute(false), "returns false on success" end
test_refute_empty()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1026 def test_refute_empty @assertion_count = 2 @tc.refute_empty [1] end
test_refute_empty_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1032 def test_refute_empty_triggered @assertion_count = 2 assert_triggered "Expected [] to not be empty." do @tc.refute_empty [] end end
test_refute_equal()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1040 def test_refute_equal @tc.refute_equal "blah", "yay" end
test_refute_equal_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1044 def test_refute_equal_triggered assert_triggered 'Expected "blah" to not be equal to "blah".' do @tc.refute_equal "blah", "blah" end end
test_refute_in_delta()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1050 def test_refute_in_delta @tc.refute_in_delta 0.0, 1.0 / 1000, 0.000001 end
test_refute_in_delta_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1054 def test_refute_in_delta_triggered x = "0.1" assert_triggered "Expected |0.0 - 0.001| (0.001) to not be <= #{x}." do @tc.refute_in_delta 0.0, 1.0 / 1000, 0.1 end end
test_refute_in_epsilon()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1061 def test_refute_in_epsilon @tc.refute_in_epsilon 10_000, 9990-1 end
test_refute_in_epsilon_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1065 def test_refute_in_epsilon_triggered assert_triggered "Expected |10000 - 9990| (10) to not be <= 10.0." do @tc.refute_in_epsilon 10_000, 9990 flunk end end
test_refute_includes()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1072 def test_refute_includes @assertion_count = 2 @tc.refute_includes [true], false end
test_refute_includes_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1078 def test_refute_includes_triggered @assertion_count = 3 e = @tc.assert_raises Minitest::Assertion do @tc.refute_includes [true], true end expected = "Expected [true] to not include true." assert_equal expected, e.message end
test_refute_instance_of()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1089 def test_refute_instance_of @tc.refute_instance_of Array, "blah" end
test_refute_instance_of_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1093 def test_refute_instance_of_triggered assert_triggered 'Expected "blah" to not be an instance of String.' do @tc.refute_instance_of String, "blah" end end
test_refute_kind_of()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1099 def test_refute_kind_of @tc.refute_kind_of Array, "blah" end
test_refute_kind_of_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1103 def test_refute_kind_of_triggered assert_triggered 'Expected "blah" to not be a kind of String.' do @tc.refute_kind_of String, "blah" end end
test_refute_match()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1109 def test_refute_match @assertion_count = 2 @tc.refute_match(/\d+/, "blah blah blah") end
test_refute_match_matcher_object()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1114 def test_refute_match_matcher_object @assertion_count = 2 pattern = Object.new def pattern.=~ _; false end @tc.refute_match pattern, 5 end
test_refute_match_object_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1121 def test_refute_match_object_triggered @assertion_count = 2 pattern = Object.new def pattern.=~ _; true end def pattern.inspect; "[Object]" end assert_triggered "Expected [Object] to not match 5." do @tc.refute_match pattern, 5 end end
test_refute_match_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1133 def test_refute_match_triggered @assertion_count = 2 assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do @tc.refute_match(/\w+/, "blah blah blah") end end
test_refute_nil()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1140 def test_refute_nil @tc.refute_nil 42 end
test_refute_nil_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1144 def test_refute_nil_triggered assert_triggered "Expected nil to not be nil." do @tc.refute_nil nil end end
test_refute_operator()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1150 def test_refute_operator @tc.refute_operator 2, :<, 1 end
test_refute_operator_bad_object()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1154 def test_refute_operator_bad_object bad = Object.new def bad.== _; true end @tc.refute_operator true, :equal?, bad end
test_refute_operator_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1161 def test_refute_operator_triggered assert_triggered "Expected 2 to not be > 1." do @tc.refute_operator 2, :>, 1 end end
test_refute_path_exists()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1197 def test_refute_path_exists @tc.refute_path_exists "blah" end
test_refute_path_exists_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1201 def test_refute_path_exists_triggered assert_triggered "Expected path '#{__FILE__}' to not exist." do @tc.refute_path_exists __FILE__ end end
test_refute_predicate()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1167 def test_refute_predicate @tc.refute_predicate "42", :empty? end
test_refute_predicate_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1171 def test_refute_predicate_triggered assert_triggered 'Expected "" to not be empty?.' do @tc.refute_predicate "", :empty? end end
test_refute_respond_to()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1177 def test_refute_respond_to @tc.refute_respond_to "blah", :rawr! end
test_refute_respond_to_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1181 def test_refute_respond_to_triggered assert_triggered 'Expected "blah" to not respond to empty?.' do @tc.refute_respond_to "blah", :empty? end end
test_refute_same()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1187 def test_refute_same @tc.refute_same 1, 2 end
test_refute_same_triggered()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1191 def test_refute_same_triggered assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do @tc.refute_same 1, 1 end end
test_skip()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1207 def test_skip @assertion_count = 0 assert_triggered "haha!", Minitest::Skip do @tc.skip "haha!" end end
test_skip_until()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1215 def test_skip_until @assertion_count = 0 t = Time.now y, m, d = t.year, t.month, t.day assert_output "", /Stale skip_until \"not yet\" at .*?:\d+$/ do @tc.skip_until y, m, d, "not yet" end assert_triggered "not ready yet", Minitest::Skip do @tc.skip_until y, m, d+1, "not ready yet" end end
util_msg(exp, act, msg = nil)
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1230 def util_msg exp, act, msg = nil s = "Expected: #{exp.inspect}\n Actual: #{act.inspect}" s = "#{msg}.\n#{s}" if msg s end
without_diff() { || ... }
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_assertions.rb, line 1236 def without_diff old_diff = Minitest::Assertions.diff Minitest::Assertions.diff = nil yield ensure Minitest::Assertions.diff = old_diff end