How to use test_skip method of MyModule Package

Best Minitest_ruby code snippet using MyModule.test_skip

test_minitest_test.rb

Source:test_minitest_test.rb Github

copy

Full Screen

...314 Class.new FakeNamedTest do315 def test_something316 assert true317 end318 def test_skip319 skip "not yet"320 end321 end322 expected = clean <<-EOM323 S.324 Finished in 0.00325 2 runs, 1 assertions, 0 failures, 0 errors, 1 skips326 You have skipped tests. Run with --verbose for details.327 EOM328 restore_env do329 assert_report expected330 end331 end332 def test_run_skip_verbose333 @tu =334 Class.new FakeNamedTest do335 def test_something336 assert true337 end338 def test_skip339 skip "not yet"340 end341 end342 expected = clean <<-EOM343 #<Class:0xXXX>#test_skip = 0.00 s = S344 #<Class:0xXXX>#test_something = 0.00 s = .345 Finished in 0.00346 1) Skipped:347 #<Class:0xXXX>#test_skip [FILE:LINE]:348 not yet349 2 runs, 1 assertions, 0 failures, 0 errors, 1 skips350 EOM351 assert_report expected, %w[--seed 42 --verbose]352 end353 def test_run_with_other_runner354 @tu =355 Class.new FakeNamedTest do356 def self.run reporter, options = {}357 @reporter = reporter358 before_my_suite359 super360 end361 def self.name; "wacky!" end362 def self.before_my_suite363 @reporter.io.puts "Running #{self.name} tests"364 @@foo = 1365 end366 def test_something367 assert_equal 1, @@foo368 end369 def test_something_else370 assert_equal 1, @@foo371 end372 end373 expected = clean <<-EOM374 Running wacky! tests375 ..376 Finished in 0.00377 2 runs, 2 assertions, 0 failures, 0 errors, 0 skips378 EOM379 assert_report expected380 end381 require "monitor"382 class Latch383 def initialize count = 1384 @count = count385 @lock = Monitor.new386 @cv = @lock.new_cond387 end388 def release389 @lock.synchronize do390 @count -= 1 if @count > 0391 @cv.broadcast if @count == 0392 end393 end394 def await395 @lock.synchronize { @cv.wait_while { @count > 0 } }396 end397 end398 def test_run_parallel399 skip "I don't have ParallelEach debugged yet" if maglev?400 test_count = 2401 test_latch = Latch.new test_count402 wait_latch = Latch.new test_count403 main_latch = Latch.new404 thread = Thread.new {405 Thread.current.abort_on_exception = true406 # This latch waits until both test latches have been released. Both407 # latches can't be released unless done in separate threads because408 # `main_latch` keeps the test method from finishing.409 test_latch.await410 main_latch.release411 }412 @tu =413 Class.new FakeNamedTest do414 parallelize_me!415 test_count.times do |i|416 define_method :"test_wait_on_main_thread_#{i}" do417 test_latch.release418 # This latch blocks until the "main thread" releases it. The main419 # thread can't release this latch until both test latches have420 # been released. This forces the latches to be released in separate421 # threads.422 main_latch.await423 assert true424 end425 end426 end427 expected = clean <<-EOM428 ..429 Finished in 0.00430 2 runs, 2 assertions, 0 failures, 0 errors, 0 skips431 EOM432 assert_report(expected) do |reporter|433 reporter.extend(Module.new {434 define_method("record") do |result|435 super(result)436 wait_latch.release437 end438 define_method("report") do439 wait_latch.await440 super()441 end442 })443 end444 assert thread.join445 end446end447class TestMinitestUnitOrder < MetaMetaMetaTestCase448 # do not parallelize this suite... it just can't handle it.449 def test_before_setup450 call_order = []451 @tu =452 Class.new FakeNamedTest do453 define_method :setup do454 super()455 call_order << :setup456 end457 define_method :before_setup do458 call_order << :before_setup459 end460 def test_omg; assert true; end461 end462 run_tu_with_fresh_reporter463 expected = [:before_setup, :setup]464 assert_equal expected, call_order465 end466 def test_after_teardown467 call_order = []468 @tu =469 Class.new FakeNamedTest do470 define_method :teardown do471 super()472 call_order << :teardown473 end474 define_method :after_teardown do475 call_order << :after_teardown476 end477 def test_omg; assert true; end478 end479 run_tu_with_fresh_reporter480 expected = [:teardown, :after_teardown]481 assert_equal expected, call_order482 end483 def test_all_teardowns_are_guaranteed_to_run484 call_order = []485 @tu =486 Class.new FakeNamedTest do487 define_method :after_teardown do488 super()489 call_order << :after_teardown490 raise491 end492 define_method :teardown do493 super()494 call_order << :teardown495 raise496 end497 define_method :before_teardown do498 super()499 call_order << :before_teardown500 raise501 end502 def test_omg; assert true; end503 end504 run_tu_with_fresh_reporter505 expected = [:before_teardown, :teardown, :after_teardown]506 assert_equal expected, call_order507 end508 def test_setup_and_teardown_survive_inheritance509 call_order = []510 @tu = Class.new FakeNamedTest do511 define_method :setup do512 call_order << :setup_method513 end514 define_method :teardown do515 call_order << :teardown_method516 end517 define_method :test_something do518 call_order << :test519 end520 end521 run_tu_with_fresh_reporter522 @tu = Class.new @tu523 run_tu_with_fresh_reporter524 # Once for the parent class, once for the child525 expected = [:setup_method, :test, :teardown_method] * 2526 assert_equal expected, call_order527 end528end529class TestMinitestRunnable < Minitest::Test530 def setup_marshal klass531 tc = klass.new "whatever"532 tc.assertions = 42533 tc.failures << "a failure"534 yield tc if block_given?535 def tc.setup536 @blah = "blah"537 end538 tc.setup539 @tc = tc540 end541 def assert_marshal expected_ivars542 new_tc = Marshal.load Marshal.dump @tc543 ivars = new_tc.instance_variables.map(&:to_s).sort544 assert_equal expected_ivars, ivars545 assert_equal "whatever", new_tc.name546 assert_equal 42, new_tc.assertions547 assert_equal ["a failure"], new_tc.failures548 yield new_tc if block_given?549 end550 def test_marshal551 setup_marshal Minitest::Runnable552 assert_marshal %w[@NAME @assertions @failures]553 end554end555class TestMinitestTest < TestMinitestRunnable556 def test_dup557 setup_marshal Minitest::Test do |tc|558 tc.time = 3.14559 end560 assert_marshal %w[@NAME @assertions @failures @time] do |new_tc|561 assert_in_epsilon 3.14, new_tc.time562 end563 end564end565class TestMinitestUnitTestCase < Minitest::Test566 # do not call parallelize_me! - teardown accesses @tc._assertions567 # which is not threadsafe. Nearly every method in here is an568 # assertion test so it isn't worth splitting it out further.569 RUBY18 = !defined? Encoding570 def setup571 super572 Minitest::Test.reset573 @tc = Minitest::Test.new "fake tc"574 @zomg = "zomg ponies!"575 @assertion_count = 1576 end577 def teardown578 assert_equal(@assertion_count, @tc.assertions,579 "expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") if @tc.passed?580 end581 def non_verbose582 orig_verbose = $VERBOSE583 $VERBOSE = false584 yield585 ensure586 $VERBOSE = orig_verbose587 end588 def test_assert589 @assertion_count = 2590 @tc.assert_equal true, @tc.assert(true), "returns true on success"591 end592 def test_assert__triggered593 assert_triggered "Expected false to be truthy." do594 @tc.assert false595 end596 end597 def test_assert__triggered_message598 assert_triggered @zomg do599 @tc.assert false, @zomg600 end601 end602 def test_assert_empty603 @assertion_count = 2604 @tc.assert_empty []605 end606 def test_assert_empty_triggered607 @assertion_count = 2608 assert_triggered "Expected [1] to be empty." do609 @tc.assert_empty [1]610 end611 end612 def test_assert_equal613 @tc.assert_equal 1, 1614 end615 def test_assert_equal_different_collection_array_hex_invisible616 object1 = Object.new617 object2 = Object.new618 msg = "No visible difference in the Array#inspect output.619 You should look at the implementation of #== on Array or its members.620 [#<Object:0xXXXXXX>]".gsub(/^ +/, "")621 assert_triggered msg do622 @tc.assert_equal [object1], [object2]623 end624 end625 def test_assert_equal_different_collection_hash_hex_invisible626 h1, h2 = {}, {}627 h1[1] = Object.new628 h2[1] = Object.new629 msg = "No visible difference in the Hash#inspect output.630 You should look at the implementation of #== on Hash or its members.631 {1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")632 assert_triggered msg do633 @tc.assert_equal h1, h2634 end635 end636 def test_assert_equal_string_encodings637 msg = <<-EOM.gsub(/^ {10}/, "")638 --- expected639 +++ actual640 @@ -1 +1,2 @@641 +# encoding: ASCII-8BIT642 "bad-utf8-\\xF1.txt"643 EOM644 assert_triggered msg do645 x = "bad-utf8-\xF1.txt"646 y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped647 @tc.assert_equal x, y648 end649 end unless RUBY18650 def test_assert_equal_string_encodings_both_different651 msg = <<-EOM.gsub(/^ {10}/, "")652 --- expected653 +++ actual654 @@ -1,2 +1,2 @@655 -# encoding: US-ASCII656 +# encoding: ASCII-8BIT657 "bad-utf8-\\xF1.txt"658 EOM659 assert_triggered msg do660 x = "bad-utf8-\xF1.txt".force_encoding "ASCII"661 y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped662 @tc.assert_equal x, y663 end664 end unless RUBY18665 def test_assert_equal_different_diff_deactivated666 skip "https://github.com/MagLev/maglev/issues/209" if maglev?667 without_diff do668 assert_triggered util_msg("haha" * 10, "blah" * 10) do669 o1 = "haha" * 10670 o2 = "blah" * 10671 @tc.assert_equal o1, o2672 end673 end674 end675 def test_assert_equal_different_hex676 c = Class.new do677 def initialize s; @name = s; end678 end679 o1 = c.new "a"680 o2 = c.new "b"681 msg = "--- expected682 +++ actual683 @@ -1 +1 @@684 -#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">685 +#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">686 ".gsub(/^ +/, "")687 assert_triggered msg do688 @tc.assert_equal o1, o2689 end690 end691 def test_assert_equal_different_hex_invisible692 o1 = Object.new693 o2 = Object.new694 msg = "No visible difference in the Object#inspect output.695 You should look at the implementation of #== on Object or its members.696 #<Object:0xXXXXXX>".gsub(/^ +/, "")697 assert_triggered msg do698 @tc.assert_equal o1, o2699 end700 end701 def test_assert_equal_different_long702 msg = "--- expected703 +++ actual704 @@ -1 +1 @@705 -\"hahahahahahahahahahahahahahahahahahahaha\"706 +\"blahblahblahblahblahblahblahblahblahblah\"707 ".gsub(/^ +/, "")708 assert_triggered msg do709 o1 = "haha" * 10710 o2 = "blah" * 10711 @tc.assert_equal o1, o2712 end713 end714 def test_assert_equal_different_long_invisible715 msg = "No visible difference in the String#inspect output.716 You should look at the implementation of #== on String or its members.717 \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")718 assert_triggered msg do719 o1 = "blah" * 10720 o2 = "blah" * 10721 def o1.== _722 false723 end724 @tc.assert_equal o1, o2725 end726 end727 def test_assert_equal_different_long_msg728 msg = "message.729 --- expected730 +++ actual731 @@ -1 +1 @@732 -\"hahahahahahahahahahahahahahahahahahahaha\"733 +\"blahblahblahblahblahblahblahblahblahblah\"734 ".gsub(/^ +/, "")735 assert_triggered msg do736 o1 = "haha" * 10737 o2 = "blah" * 10738 @tc.assert_equal o1, o2, "message"739 end740 end741 def test_assert_equal_different_short742 assert_triggered util_msg(1, 2) do743 @tc.assert_equal 1, 2744 end745 end746 def test_assert_equal_different_short_msg747 assert_triggered util_msg(1, 2, "message") do748 @tc.assert_equal 1, 2, "message"749 end750 end751 def test_assert_equal_different_short_multiline752 msg = "--- expected\n+++ actual\n@@ -1,2 +1,2 @@\n \"a\n-b\"\n+c\"\n"753 assert_triggered msg do754 @tc.assert_equal "a\nb", "a\nc"755 end756 end757 def test_assert_equal_does_not_allow_lhs_nil758 if Minitest::VERSION =~ /^6/ then759 warn "Time to strip the MT5 test"760 @assertion_count += 1761 assert_triggered(/Use assert_nil if expecting nil/) do762 @tc.assert_equal nil, nil763 end764 else765 err_re = /Use assert_nil if expecting nil from .*test_minitest_test.rb/766 assert_output "", err_re do767 @tc.assert_equal nil, nil768 end769 end770 end771 def test_assert_equal_does_not_allow_lhs_nil_triggered772 assert_triggered "Expected: nil\n Actual: false" do773 @tc.assert_equal nil, false774 end775 end776 def test_assert_in_delta777 @tc.assert_in_delta 0.0, 1.0 / 1000, 0.1778 end779 def test_delta_consistency780 @assertion_count = 2781 @tc.assert_in_delta 0, 1, 1782 assert_triggered "Expected |0 - 1| (1) to not be <= 1." do783 @tc.refute_in_delta 0, 1, 1784 end785 end786 def test_assert_in_delta_triggered787 x = maglev? ? "9.999999xxxe-07" : "1.0e-06"788 assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do789 @tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001790 end791 end792 def test_assert_in_epsilon793 @assertion_count = 10794 @tc.assert_in_epsilon 10_000, 9991795 @tc.assert_in_epsilon 9991, 10_000796 @tc.assert_in_epsilon 1.0, 1.001797 @tc.assert_in_epsilon 1.001, 1.0798 @tc.assert_in_epsilon 10_000, 9999.1, 0.0001799 @tc.assert_in_epsilon 9999.1, 10_000, 0.0001800 @tc.assert_in_epsilon 1.0, 1.0001, 0.0001801 @tc.assert_in_epsilon 1.0001, 1.0, 0.0001802 @tc.assert_in_epsilon(-1, -1)803 @tc.assert_in_epsilon(-10_000, -9991)804 end805 def test_epsilon_consistency806 @assertion_count = 2807 @tc.assert_in_epsilon 1.0, 1.001808 msg = "Expected |1.0 - 1.001| (0.000999xxx) to not be <= 0.001."809 assert_triggered msg do810 @tc.refute_in_epsilon 1.0, 1.001811 end812 end813 def test_assert_in_epsilon_triggered814 assert_triggered "Expected |10000 - 9990| (10) to be <= 9.99." do815 @tc.assert_in_epsilon 10_000, 9990816 end817 end818 def test_assert_in_epsilon_triggered_negative_case819 x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"820 y = maglev? ? "0.100000xxx" : "0.1"821 assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do822 @tc.assert_in_epsilon(-1.1, -1, 0.1)823 end824 end825 def test_assert_includes826 @assertion_count = 2827 @tc.assert_includes [true], true828 end829 def test_assert_includes_triggered830 @assertion_count = 3831 e = @tc.assert_raises Minitest::Assertion do832 @tc.assert_includes [true], false833 end834 expected = "Expected [true] to include false."835 assert_equal expected, e.message836 end837 def test_assert_instance_of838 @tc.assert_instance_of String, "blah"839 end840 def test_assert_instance_of_triggered841 assert_triggered 'Expected "blah" to be an instance of Array, not String.' do842 @tc.assert_instance_of Array, "blah"843 end844 end845 def test_assert_kind_of846 @tc.assert_kind_of String, "blah"847 end848 def test_assert_kind_of_triggered849 assert_triggered 'Expected "blah" to be a kind of Array, not String.' do850 @tc.assert_kind_of Array, "blah"851 end852 end853 def test_assert_match854 @assertion_count = 2855 @tc.assert_match(/\w+/, "blah blah blah")856 end857 def test_assert_match_matcher_object858 @assertion_count = 2859 pattern = Object.new860 def pattern.=~ _; true end861 @tc.assert_match pattern, 5862 end863 def test_assert_match_matchee_to_str864 @assertion_count = 2865 obj = Object.new866 def obj.to_str; "blah" end867 @tc.assert_match "blah", obj868 end869 def test_assert_match_object_triggered870 @assertion_count = 2871 pattern = Object.new872 def pattern.=~ _; false end873 def pattern.inspect; "[Object]" end874 assert_triggered "Expected [Object] to match 5." do875 @tc.assert_match pattern, 5876 end877 end878 def test_assert_match_triggered879 @assertion_count = 2880 assert_triggered 'Expected /\d+/ to match "blah blah blah".' do881 @tc.assert_match(/\d+/, "blah blah blah")882 end883 end884 def test_assert_nil885 @tc.assert_nil nil886 end887 def test_assert_nil_triggered888 assert_triggered "Expected 42 to be nil." do889 @tc.assert_nil 42890 end891 end892 def test_assert_operator893 @tc.assert_operator 2, :>, 1894 end895 def test_assert_operator_bad_object896 bad = Object.new897 def bad.== _; true end898 @tc.assert_operator bad, :equal?, bad899 end900 def test_assert_operator_triggered901 assert_triggered "Expected 2 to be < 1." do902 @tc.assert_operator 2, :<, 1903 end904 end905 def test_assert_output_both906 @assertion_count = 2907 @tc.assert_output "yay", "blah" do908 print "yay"909 $stderr.print "blah"910 end911 end912 def test_assert_output_both_regexps913 @assertion_count = 4914 @tc.assert_output(/y.y/, /bl.h/) do915 print "yay"916 $stderr.print "blah"917 end918 end919 def test_assert_output_err920 @tc.assert_output nil, "blah" do921 $stderr.print "blah"922 end923 end924 def test_assert_output_neither925 @assertion_count = 0926 @tc.assert_output do927 # do nothing928 end929 end930 def test_assert_output_out931 @tc.assert_output "blah" do932 print "blah"933 end934 end935 def test_assert_output_triggered_both936 assert_triggered util_msg("blah", "blah blah", "In stderr") do937 @tc.assert_output "yay", "blah" do938 print "boo"939 $stderr.print "blah blah"940 end941 end942 end943 def test_assert_output_triggered_err944 assert_triggered util_msg("blah", "blah blah", "In stderr") do945 @tc.assert_output nil, "blah" do946 $stderr.print "blah blah"947 end948 end949 end950 def test_assert_output_triggered_out951 assert_triggered util_msg("blah", "blah blah", "In stdout") do952 @tc.assert_output "blah" do953 print "blah blah"954 end955 end956 end957 def test_assert_predicate958 @tc.assert_predicate "", :empty?959 end960 def test_assert_predicate_triggered961 assert_triggered 'Expected "blah" to be empty?.' do962 @tc.assert_predicate "blah", :empty?963 end964 end965 def test_assert_raises966 @tc.assert_raises RuntimeError do967 raise "blah"968 end969 end970 def test_assert_raises_default971 @tc.assert_raises do972 raise StandardError, "blah"973 end974 end975 def test_assert_raises_default_triggered976 e = assert_raises Minitest::Assertion do977 @tc.assert_raises do978 raise SomeError, "blah"979 end980 end981 expected = clean <<-EOM.chomp982 [StandardError] exception expected, not983 Class: <SomeError>984 Message: <\"blah\">985 ---Backtrace---986 FILE:LINE:in \`test_assert_raises_default_triggered\'987 ---------------988 EOM989 actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")990 actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"991 assert_equal expected, actual992 end993 def test_assert_raises_module994 @tc.assert_raises MyModule do995 raise AnError996 end997 end998 ##999 # *sigh* This is quite an odd scenario, but it is from real (albeit1000 # ugly) test code in ruby-core:1001 #1002 # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=292591003 def test_assert_raises_skip1004 @assertion_count = 01005 assert_triggered "skipped", Minitest::Skip do1006 @tc.assert_raises ArgumentError do1007 begin1008 raise "blah"1009 rescue1010 skip "skipped"1011 end1012 end1013 end1014 end1015 def test_assert_raises_triggered_different1016 e = assert_raises Minitest::Assertion do1017 @tc.assert_raises RuntimeError do1018 raise SyntaxError, "icky"1019 end1020 end1021 expected = clean <<-EOM.chomp1022 [RuntimeError] exception expected, not1023 Class: <SyntaxError>1024 Message: <\"icky\">1025 ---Backtrace---1026 FILE:LINE:in \`test_assert_raises_triggered_different\'1027 ---------------1028 EOM1029 actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")1030 actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"1031 assert_equal expected, actual1032 end1033 def test_assert_raises_triggered_different_msg1034 e = assert_raises Minitest::Assertion do1035 @tc.assert_raises RuntimeError, "XXX" do1036 raise SyntaxError, "icky"1037 end1038 end1039 expected = clean <<-EOM1040 XXX.1041 [RuntimeError] exception expected, not1042 Class: <SyntaxError>1043 Message: <\"icky\">1044 ---Backtrace---1045 FILE:LINE:in \`test_assert_raises_triggered_different_msg\'1046 ---------------1047 EOM1048 actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")1049 actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"1050 assert_equal expected.chomp, actual1051 end1052 def test_assert_raises_triggered_none1053 e = assert_raises Minitest::Assertion do1054 @tc.assert_raises Minitest::Assertion do1055 # do nothing1056 end1057 end1058 expected = "Minitest::Assertion expected but nothing was raised."1059 assert_equal expected, e.message1060 end1061 def test_assert_raises_triggered_none_msg1062 e = assert_raises Minitest::Assertion do1063 @tc.assert_raises Minitest::Assertion, "XXX" do1064 # do nothing1065 end1066 end1067 expected = "XXX.\nMinitest::Assertion expected but nothing was raised."1068 assert_equal expected, e.message1069 end1070 def test_assert_raises_subclass1071 @tc.assert_raises StandardError do1072 raise AnError1073 end1074 end1075 def test_assert_raises_subclass_triggered1076 e = assert_raises Minitest::Assertion do1077 @tc.assert_raises SomeError do1078 raise AnError, "some message"1079 end1080 end1081 expected = clean <<-EOM1082 [SomeError] exception expected, not1083 Class: <AnError>1084 Message: <\"some message\">1085 ---Backtrace---1086 FILE:LINE:in \`test_assert_raises_subclass_triggered\'1087 ---------------1088 EOM1089 actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")1090 actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"1091 assert_equal expected.chomp, actual1092 end1093 def test_assert_raises_exit1094 @tc.assert_raises SystemExit do1095 exit 11096 end1097 end1098 def test_assert_raises_signals1099 @tc.assert_raises SignalException do1100 raise SignalException, :INT1101 end1102 end1103 def test_assert_respond_to1104 @tc.assert_respond_to "blah", :empty?1105 end1106 def test_assert_respond_to_triggered1107 assert_triggered 'Expected "blah" (String) to respond to #rawr!.' do1108 @tc.assert_respond_to "blah", :rawr!1109 end1110 end1111 def test_assert_same1112 @assertion_count = 31113 o = "blah"1114 @tc.assert_same 1, 11115 @tc.assert_same :blah, :blah1116 @tc.assert_same o, o1117 end1118 def test_assert_same_triggered1119 @assertion_count = 21120 assert_triggered "Expected 2 (oid=N) to be the same as 1 (oid=N)." do1121 @tc.assert_same 1, 21122 end1123 s1 = "blah"1124 s2 = "blah"1125 assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do1126 @tc.assert_same s1, s21127 end1128 end1129 def assert_deprecated name1130 dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+:.*?/1131 assert_output nil, dep do1132 yield1133 end1134 end1135 def test_assert_send1136 assert_deprecated :assert_send do1137 @tc.assert_send [1, :<, 2]1138 end1139 end1140 def test_assert_send_bad1141 assert_deprecated :assert_send do1142 assert_triggered "Expected 1.>(*[2]) to return true." do1143 @tc.assert_send [1, :>, 2]1144 end1145 end1146 end1147 def test_assert_silent1148 @assertion_count = 21149 @tc.assert_silent do1150 # do nothing1151 end1152 end1153 def test_assert_silent_triggered_err1154 assert_triggered util_msg("", "blah blah", "In stderr") do1155 @tc.assert_silent do1156 $stderr.print "blah blah"1157 end1158 end1159 end1160 def test_assert_silent_triggered_out1161 @assertion_count = 21162 assert_triggered util_msg("", "blah blah", "In stdout") do1163 @tc.assert_silent do1164 print "blah blah"1165 end1166 end1167 end1168 def test_assert_throws1169 @tc.assert_throws :blah do1170 throw :blah1171 end1172 end1173 def test_assert_throws_name_error1174 @tc.assert_raises NameError do1175 @tc.assert_throws :blah do1176 raise NameError1177 end1178 end1179 end1180 def test_assert_throws_argument_exception1181 @tc.assert_raises ArgumentError do1182 @tc.assert_throws :blah do1183 raise ArgumentError1184 end1185 end1186 end1187 def test_assert_throws_different1188 assert_triggered "Expected :blah to have been thrown, not :not_blah." do1189 @tc.assert_throws :blah do1190 throw :not_blah1191 end1192 end1193 end1194 def test_assert_throws_unthrown1195 assert_triggered "Expected :blah to have been thrown." do1196 @tc.assert_throws :blah do1197 # do nothing1198 end1199 end1200 end1201 def test_capture_io1202 @assertion_count = 01203 non_verbose do1204 out, err = capture_io do1205 puts "hi"1206 $stderr.puts "bye!"1207 end1208 assert_equal "hi\n", out1209 assert_equal "bye!\n", err1210 end1211 end1212 def test_capture_subprocess_io1213 @assertion_count = 01214 non_verbose do1215 out, err = capture_subprocess_io do1216 system("echo hi")1217 system("echo bye! 1>&2")1218 end1219 assert_equal "hi\n", out1220 assert_equal "bye!", err.strip1221 end1222 end1223 def test_class_asserts_match_refutes1224 @assertion_count = 01225 methods = Minitest::Assertions.public_instance_methods1226 methods.map!(&:to_s) if Symbol === methods.first1227 # These don't have corresponding refutes _on purpose_. They're1228 # useless and will never be added, so don't bother.1229 ignores = %w[assert_output assert_raises assert_send1230 assert_silent assert_throws assert_mock]1231 # These are test/unit methods. I'm not actually sure why they're still here1232 ignores += %w[assert_no_match assert_not_equal assert_not_nil1233 assert_not_same assert_nothing_raised1234 assert_nothing_thrown assert_raise]1235 asserts = methods.grep(/^assert/).sort - ignores1236 refutes = methods.grep(/^refute/).sort - ignores1237 assert_empty refutes.map { |n| n.sub(/^refute/, "assert") } - asserts1238 assert_empty asserts.map { |n| n.sub(/^assert/, "refute") } - refutes1239 end1240 def test_flunk1241 assert_triggered "Epic Fail!" do1242 @tc.flunk1243 end1244 end1245 def test_flunk_message1246 assert_triggered @zomg do1247 @tc.flunk @zomg1248 end1249 end1250 def test_message1251 @assertion_count = 01252 assert_equal "blah2.", @tc.message { "blah2" }.call1253 assert_equal "blah2.", @tc.message("") { "blah2" }.call1254 assert_equal "blah1.\nblah2.", @tc.message(:blah1) { "blah2" }.call1255 assert_equal "blah1.\nblah2.", @tc.message("blah1") { "blah2" }.call1256 message = proc { "blah1" }1257 assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call1258 message = @tc.message { "blah1" }1259 assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call1260 end1261 def test_message_message1262 assert_triggered "whoops.\nExpected: 1\n Actual: 2" do1263 @tc.assert_equal 1, 2, message { "whoops" }1264 end1265 end1266 def test_message_lambda1267 assert_triggered "whoops.\nExpected: 1\n Actual: 2" do1268 @tc.assert_equal 1, 2, lambda { "whoops" }1269 end1270 end1271 def test_message_deferred1272 @assertion_count, var = 0, nil1273 msg = message { var = "blah" }1274 assert_nil var1275 msg.call1276 assert_equal "blah", var1277 end1278 def test_pass1279 @tc.pass1280 end1281 def test_prints1282 printer = Class.new { extend Minitest::Assertions }1283 @tc.assert_equal '"test"', printer.mu_pp(ImmutableString.new "test")1284 end1285 def test_refute1286 @assertion_count = 21287 @tc.assert_equal false, @tc.refute(false), "returns false on success"1288 end1289 def test_refute_empty1290 @assertion_count = 21291 @tc.refute_empty [1]1292 end1293 def test_refute_empty_triggered1294 @assertion_count = 21295 assert_triggered "Expected [] to not be empty." do1296 @tc.refute_empty []1297 end1298 end1299 def test_refute_equal1300 @tc.refute_equal "blah", "yay"1301 end1302 def test_refute_equal_triggered1303 assert_triggered 'Expected "blah" to not be equal to "blah".' do1304 @tc.refute_equal "blah", "blah"1305 end1306 end1307 def test_refute_in_delta1308 @tc.refute_in_delta 0.0, 1.0 / 1000, 0.0000011309 end1310 def test_refute_in_delta_triggered1311 x = maglev? ? "0.100000xxx" : "0.1"1312 assert_triggered "Expected |0.0 - 0.001| (0.001) to not be <= #{x}." do1313 @tc.refute_in_delta 0.0, 1.0 / 1000, 0.11314 end1315 end1316 def test_refute_in_epsilon1317 @tc.refute_in_epsilon 10_000, 9990-11318 end1319 def test_refute_in_epsilon_triggered1320 assert_triggered "Expected |10000 - 9990| (10) to not be <= 10.0." do1321 @tc.refute_in_epsilon 10_000, 99901322 flunk1323 end1324 end1325 def test_refute_includes1326 @assertion_count = 21327 @tc.refute_includes [true], false1328 end1329 def test_refute_includes_triggered1330 @assertion_count = 31331 e = @tc.assert_raises Minitest::Assertion do1332 @tc.refute_includes [true], true1333 end1334 expected = "Expected [true] to not include true."1335 assert_equal expected, e.message1336 end1337 def test_refute_instance_of1338 @tc.refute_instance_of Array, "blah"1339 end1340 def test_refute_instance_of_triggered1341 assert_triggered 'Expected "blah" to not be an instance of String.' do1342 @tc.refute_instance_of String, "blah"1343 end1344 end1345 def test_refute_kind_of1346 @tc.refute_kind_of Array, "blah"1347 end1348 def test_refute_kind_of_triggered1349 assert_triggered 'Expected "blah" to not be a kind of String.' do1350 @tc.refute_kind_of String, "blah"1351 end1352 end1353 def test_refute_match1354 @assertion_count = 21355 @tc.refute_match(/\d+/, "blah blah blah")1356 end1357 def test_refute_match_matcher_object1358 @assertion_count = 21359 @tc.refute_match Object.new, 5 # default #=~ returns false1360 end1361 def test_refute_match_object_triggered1362 @assertion_count = 21363 pattern = Object.new1364 def pattern.=~ _; true end1365 def pattern.inspect; "[Object]" end1366 assert_triggered "Expected [Object] to not match 5." do1367 @tc.refute_match pattern, 51368 end1369 end1370 def test_refute_match_triggered1371 @assertion_count = 21372 assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do1373 @tc.refute_match(/\w+/, "blah blah blah")1374 end1375 end1376 def test_refute_nil1377 @tc.refute_nil 421378 end1379 def test_refute_nil_triggered1380 assert_triggered "Expected nil to not be nil." do1381 @tc.refute_nil nil1382 end1383 end1384 def test_refute_predicate1385 @tc.refute_predicate "42", :empty?1386 end1387 def test_refute_predicate_triggered1388 assert_triggered 'Expected "" to not be empty?.' do1389 @tc.refute_predicate "", :empty?1390 end1391 end1392 def test_refute_operator1393 @tc.refute_operator 2, :<, 11394 end1395 def test_refute_operator_bad_object1396 bad = Object.new1397 def bad.== _; true end1398 @tc.refute_operator true, :equal?, bad1399 end1400 def test_refute_operator_triggered1401 assert_triggered "Expected 2 to not be > 1." do1402 @tc.refute_operator 2, :>, 11403 end1404 end1405 def test_refute_respond_to1406 @tc.refute_respond_to "blah", :rawr!1407 end1408 def test_refute_respond_to_triggered1409 assert_triggered 'Expected "blah" to not respond to empty?.' do1410 @tc.refute_respond_to "blah", :empty?1411 end1412 end1413 def test_refute_same1414 @tc.refute_same 1, 21415 end1416 def test_refute_same_triggered1417 assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do1418 @tc.refute_same 1, 11419 end1420 end1421 def test_skip1422 @assertion_count = 01423 assert_triggered "haha!", Minitest::Skip do1424 @tc.skip "haha!"1425 end1426 end1427 def test_runnable_methods_random1428 @assertion_count = 01429 sample_test_case = Class.new FakeNamedTest do1430 def self.test_order; :random; end1431 def test_test1; assert "does not matter" end1432 def test_test2; assert "does not matter" end1433 def test_test3; assert "does not matter" end1434 end1435 srand 42...

Full Screen

Full Screen

test_minitest_unit.rb

Source:test_minitest_unit.rb Github

copy

Full Screen

...259 tc = Class.new(MiniTest::Unit::TestCase) do260 def test_something261 assert true262 end263 def test_skip264 skip "not yet"265 end266 end267 Object.const_set(:ATestCase, tc)268 @tu.run %w[--seed 42]269 expected = "Run options: --seed 42270# Running tests:271S.272Finished tests in 0.002732 tests, 1 assertions, 0 failures, 0 errors, 1 skips274"275 assert_report expected276 end277 def test_run_skip_verbose278 tc = Class.new(MiniTest::Unit::TestCase) do279 def test_something280 assert true281 end282 def test_skip283 skip "not yet"284 end285 end286 Object.const_set(:ATestCase, tc)287 @tu.run %w[--seed 42 --verbose]288 expected = "Run options: --seed 42 --verbose289# Running tests:290ATestCase#test_skip = 0.00 s = S291ATestCase#test_something = 0.00 s = .292Finished tests in 0.00293 1) Skipped:294test_skip(ATestCase) [FILE:LINE]:295not yet2962 tests, 1 assertions, 0 failures, 0 errors, 1 skips297"298 assert_report expected299 end300 def test_default_runner_is_minitest_unit301 assert_instance_of MiniTest::Unit, MiniTest::Unit.runner302 end303 def test_run_with_other_runner304 runner = Class.new(MiniTest::Unit) do305 # Run once before each suite306 def _run_suite(suite, type)307 begin308 suite.before_suite309 super(suite, type)310 end311 end312 end313 tc = Class.new(MiniTest::Unit::TestCase) do314 def self.before_suite315 MiniTest::Unit.output.puts "Running #{self.name} tests"316 @@foo = 1317 end318 def test_something319 assert_equal 1, @@foo320 end321 def test_something_else322 assert_equal 1, @@foo323 end324 end325 Object.const_set(:ATestCase, tc)326 MiniTest::Unit.runner = runner.new327 @tu.run %w[--seed 42]328 # We should only see 'running ATestCase tests' once329 expected = "Run options: --seed 42330# Running tests:331Running ATestCase tests332..333Finished tests in 0.003342 tests, 2 assertions, 0 failures, 0 errors, 0 skips335"336 assert_report expected337 end338 def with_overridden_include339 Class.class_eval do340 def inherited_with_hacks klass341 throw :inherited_hook342 end343 alias inherited_without_hacks inherited344 alias inherited inherited_with_hacks345 alias IGNORE_ME! inherited # 1.8 bug. god I love venture bros346 end347 yield348 ensure349 Class.class_eval do350 alias inherited inherited_without_hacks351 undef_method :inherited_with_hacks352 undef_method :inherited_without_hacks353 end354 refute_respond_to Class, :inherited_with_hacks355 refute_respond_to Class, :inherited_without_hacks356 end357 def test_inherited_hook_plays_nice_with_others358 with_overridden_include do359 assert_throws :inherited_hook do360 Class.new MiniTest::Unit::TestCase361 end362 end363 end364 def test_setup_hooks365 call_order = []366 tc = Class.new(MiniTest::Unit::TestCase) do367 define_method :setup do368 super()369 call_order << :method370 end371 define_method :test2 do372 call_order << :test2373 end374 define_method :test1 do375 call_order << :test1376 end377 end378 tc.add_setup_hook lambda { call_order << :proc }379 argument = nil380 tc.add_setup_hook do |arg|381 argument = arg382 call_order << :block383 end384 @tu.run %w[--seed 42]385 assert_kind_of tc, argument386 expected = [:method, :proc, :block, :test1,387 :method, :proc, :block, :test2]388 assert_equal expected, call_order389 end390 def test_teardown_hooks391 call_order = []392 tc = Class.new(MiniTest::Unit::TestCase) do393 define_method :teardown do394 super()395 call_order << :method396 end397 define_method :test2 do398 call_order << :test2399 end400 define_method :test1 do401 call_order << :test1402 end403 end404 tc.add_teardown_hook lambda { call_order << :proc }405 argument = nil406 tc.add_teardown_hook do |arg|407 argument = arg408 call_order << :block409 end410 @tu.run %w[--seed 42]411 assert_kind_of tc, argument412 expected = [:test1, :block, :proc, :method,413 :test2, :block, :proc, :method]414 assert_equal expected, call_order415 end416 def test_setup_and_teardown_hooks_survive_inheritance417 call_order = []418 parent = Class.new(MiniTest::Unit::TestCase) do419 define_method :setup do420 super()421 call_order << :setup_method422 end423 define_method :teardown do424 super()425 call_order << :teardown_method426 end427 define_method :test_something do428 call_order << :test429 end430 end431 parent.add_setup_hook { call_order << :setup_hook }432 parent.add_teardown_hook { call_order << :teardown_hook }433 _ = Class.new parent434 parent.add_setup_hook { call_order << :setup_after }435 parent.add_teardown_hook { call_order << :teardown_after }436 @tu.run %w[--seed 42]437 # Once for the parent class, once for the child438 expected = [:setup_method, :setup_hook, :setup_after, :test,439 :teardown_after, :teardown_hook, :teardown_method] * 2440 assert_equal expected, call_order441 end442 def util_expand_bt bt443 if RUBY_VERSION =~ /^1\.9/ then444 bt.map { |f| (f =~ /^\./) ? File.expand_path(f) : f }445 else446 bt447 end448 end449end450class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase451 def setup452 MiniTest::Unit::TestCase.reset453 @tc = MiniTest::Unit::TestCase.new 'fake tc'454 @zomg = "zomg ponies!"455 @assertion_count = 1456 end457 def teardown458 assert_equal(@assertion_count, @tc._assertions,459 "expected #{@assertion_count} assertions to be fired during the test, not #{@tc._assertions}") if @tc._assertions460 Object.send :remove_const, :ATestCase if defined? ATestCase461 end462 def test_assert463 @assertion_count = 2464 @tc.assert_equal true, @tc.assert(true), "returns true on success"465 end466 def test_assert__triggered467 util_assert_triggered "Failed assertion, no message given." do468 @tc.assert false469 end470 end471 def test_assert__triggered_message472 util_assert_triggered @zomg do473 @tc.assert false, @zomg474 end475 end476 def test_assert_block477 @tc.assert_block do478 true479 end480 end481 def test_assert_block_triggered482 util_assert_triggered "blah.\nExpected block to return true value." do483 @tc.assert_block "blah" do484 false485 end486 end487 end488 def test_assert_empty489 @assertion_count = 2490 @tc.assert_empty []491 end492 def test_assert_empty_triggered493 @assertion_count = 2494 util_assert_triggered "Expected [1] to be empty." do495 @tc.assert_empty [1]496 end497 end498 def test_assert_equal499 @tc.assert_equal 1, 1500 end501 def test_assert_equal_different_diff_deactivated502 without_diff do503 util_assert_triggered util_msg("haha" * 10, "blah" * 10) do504 o1 = "haha" * 10505 o2 = "blah" * 10506 @tc.assert_equal o1, o2507 end508 end509 end510 def test_assert_equal_different_hex511 c = Class.new do512 def initialize s; @name = s; end513 end514 o1 = c.new "a"515 o2 = c.new "b"516 msg = "--- expected517 +++ actual518 @@ -1 +1 @@519 -#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">520 +#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">521 ".gsub(/^ +/, "")522 util_assert_triggered msg do523 @tc.assert_equal o1, o2524 end525 end526 def test_assert_equal_different_hex_invisible527 o1 = Object.new528 o2 = Object.new529 msg = "No visible difference.530 You should look at your implementation of Object#==.531 #<Object:0xXXXXXX>".gsub(/^ +/, "")532 util_assert_triggered msg do533 @tc.assert_equal o1, o2534 end535 end536 def test_assert_equal_different_long537 msg = "--- expected538 +++ actual539 @@ -1 +1 @@540 -\"hahahahahahahahahahahahahahahahahahahaha\"541 +\"blahblahblahblahblahblahblahblahblahblah\"542 ".gsub(/^ +/, "")543 util_assert_triggered msg do544 o1 = "haha" * 10545 o2 = "blah" * 10546 @tc.assert_equal o1, o2547 end548 end549 def test_assert_equal_different_long_invisible550 msg = "No visible difference.551 You should look at your implementation of String#==.552 \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")553 util_assert_triggered msg do554 o1 = "blah" * 10555 o2 = "blah" * 10556 def o1.== o557 false558 end559 @tc.assert_equal o1, o2560 end561 end562 def test_assert_equal_different_long_msg563 msg = "message.564 --- expected565 +++ actual566 @@ -1 +1 @@567 -\"hahahahahahahahahahahahahahahahahahahaha\"568 +\"blahblahblahblahblahblahblahblahblahblah\"569 ".gsub(/^ +/, "")570 util_assert_triggered msg do571 o1 = "haha" * 10572 o2 = "blah" * 10573 @tc.assert_equal o1, o2, "message"574 end575 end576 def test_assert_equal_different_short577 util_assert_triggered util_msg(1, 2) do578 @tc.assert_equal 1, 2579 end580 end581 def test_assert_equal_different_short_msg582 util_assert_triggered util_msg(1, 2, "message") do583 @tc.assert_equal 1, 2, "message"584 end585 end586 def test_assert_equal_different_short_multiline587 msg = "--- expected\n+++ actual\n@@ -1,2 +1,2 @@\n \"a\n-b\"\n+c\"\n"588 util_assert_triggered msg do589 @tc.assert_equal "a\nb", "a\nc"590 end591 end592 def test_assert_in_delta593 @tc.assert_in_delta 0.0, 1.0 / 1000, 0.1594 end595 def test_assert_in_delta_triggered596 util_assert_triggered 'Expected 0.0 - 0.001 (0.001) to be < 1.0e-06.' do597 @tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001598 end599 end600 def test_assert_in_epsilon601 @assertion_count = 8602 @tc.assert_in_epsilon 10000, 9991603 @tc.assert_in_epsilon 9991, 10000604 @tc.assert_in_epsilon 1.0, 1.001605 @tc.assert_in_epsilon 1.001, 1.0606 @tc.assert_in_epsilon 10000, 9999.1, 0.0001607 @tc.assert_in_epsilon 9999.1, 10000, 0.0001608 @tc.assert_in_epsilon 1.0, 1.0001, 0.0001609 @tc.assert_in_epsilon 1.0001, 1.0, 0.0001610 end611 def test_assert_in_epsilon_triggered612 util_assert_triggered 'Expected 10000 - 9990 (10) to be < 9.99.' do613 @tc.assert_in_epsilon 10000, 9990614 end615 end616 def test_assert_includes617 @assertion_count = 2618 @tc.assert_includes [true], true619 end620 def test_assert_includes_triggered621 @assertion_count = 3622 e = @tc.assert_raises MiniTest::Assertion do623 @tc.assert_includes [true], false624 end625 expected = "Expected [true] to include false."626 assert_equal expected, e.message627 end628 def test_assert_instance_of629 @tc.assert_instance_of String, "blah"630 end631 def test_assert_instance_of_triggered632 util_assert_triggered 'Expected "blah" to be an instance of Array, not String.' do633 @tc.assert_instance_of Array, "blah"634 end635 end636 def test_assert_kind_of637 @tc.assert_kind_of String, "blah"638 end639 def test_assert_kind_of_triggered640 util_assert_triggered 'Expected "blah" to be a kind of Array, not String.' do641 @tc.assert_kind_of Array, "blah"642 end643 end644 def test_assert_match645 @assertion_count = 2646 @tc.assert_match(/\w+/, "blah blah blah")647 end648 def test_assert_match_object649 @assertion_count = 2650 pattern = Object.new651 def pattern.=~(other) true end652 @tc.assert_match pattern, 5653 end654 def test_assert_match_object_triggered655 @assertion_count = 2656 pattern = Object.new657 def pattern.=~(other) false end658 def pattern.inspect; "[Object]" end659 util_assert_triggered 'Expected [Object] to match 5.' do660 @tc.assert_match pattern, 5661 end662 end663 def test_assert_match_triggered664 @assertion_count = 2665 util_assert_triggered 'Expected /\d+/ to match "blah blah blah".' do666 @tc.assert_match(/\d+/, "blah blah blah")667 end668 end669 def test_assert_nil670 @tc.assert_nil nil671 end672 def test_assert_nil_triggered673 util_assert_triggered 'Expected 42 to be nil.' do674 @tc.assert_nil 42675 end676 end677 def test_assert_operator678 @tc.assert_operator 2, :>, 1679 end680 def test_assert_operator_triggered681 util_assert_triggered "Expected 2 to be < 1." do682 @tc.assert_operator 2, :<, 1683 end684 end685 def test_assert_output_both686 @assertion_count = 2687 @tc.assert_output "yay", "blah" do688 print "yay"689 $stderr.print "blah"690 end691 end692 def test_assert_output_err693 @tc.assert_output nil, "blah" do694 $stderr.print "blah"695 end696 end697 def test_assert_output_neither698 @assertion_count = 0699 @tc.assert_output do700 # do nothing701 end702 end703 def test_assert_output_out704 @tc.assert_output "blah" do705 print "blah"706 end707 end708 def test_assert_output_triggered_both709 util_assert_triggered util_msg("yay", "boo", "In stdout") do710 @tc.assert_output "yay", "blah" do711 print "boo"712 $stderr.print "blah blah"713 end714 end715 end716 def test_assert_output_triggered_err717 util_assert_triggered util_msg("blah", "blah blah", "In stderr") do718 @tc.assert_output nil, "blah" do719 $stderr.print "blah blah"720 end721 end722 end723 def test_assert_output_triggered_out724 util_assert_triggered util_msg("blah", "blah blah", "In stdout") do725 @tc.assert_output "blah" do726 print "blah blah"727 end728 end729 end730 def test_assert_raises731 @tc.assert_raises RuntimeError do732 raise "blah"733 end734 end735 ##736 # *sigh* This is quite an odd scenario, but it is from real (albeit737 # ugly) test code in ruby-core:738 #739 # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259740 def test_assert_raises_skip741 @assertion_count = 0742 util_assert_triggered "skipped", MiniTest::Skip do743 @tc.assert_raises ArgumentError do744 begin745 raise "blah"746 rescue747 skip "skipped"748 end749 end750 end751 end752 def test_assert_raises_module753 @tc.assert_raises MyModule do754 raise AnError755 end756 end757 def test_assert_raises_triggered_different758 e = assert_raises MiniTest::Assertion do759 @tc.assert_raises RuntimeError do760 raise SyntaxError, "icky"761 end762 end763 expected = "[RuntimeError] exception expected, not764Class: <SyntaxError>765Message: <\"icky\">766---Backtrace---767FILE:LINE:in `test_assert_raises_triggered_different'768---------------"769 actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')770 actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/771 assert_equal expected, actual772 end773 def test_assert_raises_triggered_different_msg774 e = assert_raises MiniTest::Assertion do775 @tc.assert_raises RuntimeError, "XXX" do776 raise SyntaxError, "icky"777 end778 end779 expected = "XXX780[RuntimeError] exception expected, not781Class: <SyntaxError>782Message: <\"icky\">783---Backtrace---784FILE:LINE:in `test_assert_raises_triggered_different_msg'785---------------"786 actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')787 actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/788 assert_equal expected, actual789 end790 def test_assert_raises_triggered_none791 e = assert_raises MiniTest::Assertion do792 @tc.assert_raises MiniTest::Assertion do793 # do nothing794 end795 end796 expected = "MiniTest::Assertion expected but nothing was raised."797 assert_equal expected, e.message798 end799 def test_assert_raises_triggered_none_msg800 e = assert_raises MiniTest::Assertion do801 @tc.assert_raises MiniTest::Assertion, "XXX" do802 # do nothing803 end804 end805 expected = "XXX\nMiniTest::Assertion expected but nothing was raised."806 assert_equal expected, e.message807 end808 def test_assert_raises_triggered_subclass809 e = assert_raises MiniTest::Assertion do810 @tc.assert_raises StandardError do811 raise AnError812 end813 end814 expected = "[StandardError] exception expected, not815Class: <AnError>816Message: <\"AnError\">817---Backtrace---818FILE:LINE:in `test_assert_raises_triggered_subclass'819---------------"820 actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE')821 actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/822 assert_equal expected, actual823 end824 def test_assert_respond_to825 @tc.assert_respond_to "blah", :empty?826 end827 def test_assert_respond_to_triggered828 util_assert_triggered 'Expected "blah" (String) to respond to #rawr!.' do829 @tc.assert_respond_to "blah", :rawr!830 end831 end832 def test_assert_same833 @assertion_count = 3834 o = "blah"835 @tc.assert_same 1, 1836 @tc.assert_same :blah, :blah837 @tc.assert_same o, o838 end839 def test_assert_same_triggered840 @assertion_count = 2841 util_assert_triggered 'Expected 2 (oid=N) to be the same as 1 (oid=N).' do842 @tc.assert_same 1, 2843 end844 s1 = "blah"845 s2 = "blah"846 util_assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do847 @tc.assert_same s1, s2848 end849 end850 def test_assert_send851 @tc.assert_send [1, :<, 2]852 end853 def test_assert_send_bad854 util_assert_triggered "Expected 1.>(*[2]) to return true." do855 @tc.assert_send [1, :>, 2]856 end857 end858 def test_assert_silent859 @assertion_count = 2860 @tc.assert_silent do861 # do nothing862 end863 end864 def test_assert_silent_triggered_err865 @assertion_count = 2866 util_assert_triggered util_msg("", "blah blah", "In stderr") do867 @tc.assert_silent do868 $stderr.print "blah blah"869 end870 end871 end872 def test_assert_silent_triggered_out873 util_assert_triggered util_msg("", "blah blah", "In stdout") do874 @tc.assert_silent do875 print "blah blah"876 end877 end878 end879 def test_assert_throws880 @tc.assert_throws(:blah) do881 throw :blah882 end883 end884 def test_assert_throws_different885 util_assert_triggered 'Expected :blah to have been thrown, not :not_blah.' do886 @tc.assert_throws(:blah) do887 throw :not_blah888 end889 end890 end891 def test_assert_throws_unthrown892 util_assert_triggered 'Expected :blah to have been thrown.' do893 @tc.assert_throws(:blah) do894 # do nothing895 end896 end897 end898 def test_capture_io899 @assertion_count = 0900 orig_verbose = $VERBOSE901 $VERBOSE = false902 out, err = capture_io do903 puts 'hi'904 warn 'bye!'905 end906 assert_equal "hi\n", out907 assert_equal "bye!\n", err908 ensure909 $VERBOSE = orig_verbose910 end911 def test_class_asserts_match_refutes912 @assertion_count = 0913 methods = MiniTest::Assertions.public_instance_methods914 methods.map! { |m| m.to_s } if Symbol === methods.first915 ignores = %w(assert_block assert_no_match assert_not_equal916 assert_not_nil assert_not_same assert_nothing_raised917 assert_nothing_thrown assert_output assert_raise918 assert_raises assert_send assert_silent assert_throws)919 asserts = methods.grep(/^assert/).sort - ignores920 refutes = methods.grep(/^refute/).sort - ignores921 assert_empty refutes.map { |n| n.sub(/^refute/, 'assert') } - asserts922 assert_empty asserts.map { |n| n.sub(/^assert/, 'refute') } - refutes923 end924 def test_class_inherited925 @assertion_count = 0926 Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))927 assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites928 end929 def test_class_test_suites930 @assertion_count = 0931 Object.const_set(:ATestCase, Class.new(MiniTest::Unit::TestCase))932 assert_equal 1, MiniTest::Unit::TestCase.test_suites.size933 assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites934 end935 def test_flunk936 util_assert_triggered 'Epic Fail!' do937 @tc.flunk938 end939 end940 def test_flunk_message941 util_assert_triggered @zomg do942 @tc.flunk @zomg943 end944 end945 def test_message946 @assertion_count = 0947 assert_equal "blah2.", @tc.message { "blah2" }.call948 assert_equal "blah2.", @tc.message("") { "blah2" }.call949 assert_equal "blah1.\nblah2.", @tc.message(:blah1) { "blah2" }.call950 assert_equal "blah1.\nblah2.", @tc.message("blah1") { "blah2" }.call951 end952 def test_pass953 @tc.pass954 end955 def test_prints956 printer = Class.new { extend MiniTest::Assertions }957 @tc.assert_equal '"test"', printer.mu_pp(ImmutableString.new 'test')958 end959 def test_refute960 @assertion_count = 2961 @tc.assert_equal false, @tc.refute(false), "returns false on success"962 end963 def test_refute_empty964 @assertion_count = 2965 @tc.refute_empty [1]966 end967 def test_refute_empty_triggered968 @assertion_count = 2969 util_assert_triggered "Expected [] to not be empty." do970 @tc.refute_empty []971 end972 end973 def test_refute_equal974 @tc.refute_equal "blah", "yay"975 end976 def test_refute_equal_triggered977 util_assert_triggered 'Expected "blah" to not be equal to "blah".' do978 @tc.refute_equal "blah", "blah"979 end980 end981 def test_refute_in_delta982 @tc.refute_in_delta 0.0, 1.0 / 1000, 0.000001983 end984 def test_refute_in_delta_triggered985 util_assert_triggered 'Expected 0.0 - 0.001 (0.001) to not be < 0.1.' do986 @tc.refute_in_delta 0.0, 1.0 / 1000, 0.1987 end988 end989 def test_refute_in_epsilon990 @tc.refute_in_epsilon 10000, 9990991 end992 def test_refute_in_epsilon_triggered993 util_assert_triggered 'Expected 10000 - 9991 (9) to not be < 10.0.' do994 @tc.refute_in_epsilon 10000, 9991995 fail996 end997 end998 def test_refute_includes999 @assertion_count = 21000 @tc.refute_includes [true], false1001 end1002 def test_refute_includes_triggered1003 @assertion_count = 31004 e = @tc.assert_raises MiniTest::Assertion do1005 @tc.refute_includes [true], true1006 end1007 expected = "Expected [true] to not include true."1008 assert_equal expected, e.message1009 end1010 def test_refute_instance_of1011 @tc.refute_instance_of Array, "blah"1012 end1013 def test_refute_instance_of_triggered1014 util_assert_triggered 'Expected "blah" to not be an instance of String.' do1015 @tc.refute_instance_of String, "blah"1016 end1017 end1018 def test_refute_kind_of1019 @tc.refute_kind_of Array, "blah"1020 end1021 def test_refute_kind_of_triggered1022 util_assert_triggered 'Expected "blah" to not be a kind of String.' do1023 @tc.refute_kind_of String, "blah"1024 end1025 end1026 def test_refute_match1027 @assertion_count = 21028 @tc.refute_match(/\d+/, "blah blah blah")1029 end1030 def test_refute_match_object1031 @assertion_count = 21032 @tc.refute_match Object.new, 5 # default #=~ returns false1033 end1034 def test_refute_match_object_triggered1035 @assertion_count = 21036 pattern = Object.new1037 def pattern.=~(other) true end1038 def pattern.inspect; "[Object]" end1039 util_assert_triggered 'Expected [Object] to not match 5.' do1040 @tc.refute_match pattern, 51041 end1042 end1043 def test_refute_match_triggered1044 @assertion_count = 21045 util_assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do1046 @tc.refute_match(/\w+/, "blah blah blah")1047 end1048 end1049 def test_refute_nil1050 @tc.refute_nil 421051 end1052 def test_refute_nil_triggered1053 util_assert_triggered 'Expected nil to not be nil.' do1054 @tc.refute_nil nil1055 end1056 end1057 def test_refute_operator1058 @tc.refute_operator 2, :<, 11059 end1060 def test_refute_operator_triggered1061 util_assert_triggered "Expected 2 to not be > 1." do1062 @tc.refute_operator 2, :>, 11063 end1064 end1065 def test_refute_respond_to1066 @tc.refute_respond_to "blah", :rawr!1067 end1068 def test_refute_respond_to_triggered1069 util_assert_triggered 'Expected "blah" to not respond to empty?.' do1070 @tc.refute_respond_to "blah", :empty?1071 end1072 end1073 def test_refute_same1074 @tc.refute_same 1, 21075 end1076 def test_refute_same_triggered1077 util_assert_triggered 'Expected 1 (oid=N) to not be the same as 1 (oid=N).' do1078 @tc.refute_same 1, 11079 end1080 end1081 def test_skip1082 @assertion_count = 01083 util_assert_triggered "haha!", MiniTest::Skip do1084 @tc.skip "haha!"1085 end1086 end1087 def test_test_methods_random1088 @assertion_count = 01089 sample_test_case = Class.new(MiniTest::Unit::TestCase) do1090 def test_test1; assert "does not matter" end1091 def test_test2; assert "does not matter" end1092 def test_test3; assert "does not matter" end1093 end1094 srand 421095 expected = %w(test_test2 test_test1 test_test3)...

Full Screen

Full Screen

test_skip

Using AI Code Generation

copy

Full Screen

1 skip("test_skip")2 def skip(message)3 def skip(message)4 skip("test_skip")5Your name to display (optional):6Your name to display (optional):

Full Screen

Full Screen

test_skip

Using AI Code Generation

copy

Full Screen

1 skip("skip this test")2 def skip(message)3Traceback (most recent call last):41.rb:5:in `<class:TestMyModule>': undefined method `skip' for TestMyModule:Class (NoMethodError)

Full Screen

Full Screen

test_skip

Using AI Code Generation

copy

Full Screen

1 test_skip("This test is skipped")2 def test_skip(message)3 skip("This test is skipped")4 skip("This test is skipped")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Minitest_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful