Class: TestMinitestRunnable

Inherits:
Minitest::Test show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb

Direct Known Subclasses

TestMinitestTest

Constant Summary

Constants inherited from Minitest::Test

Minitest::Test::PASSTHROUGH_EXCEPTIONS, Minitest::Test::SETUP_METHODS, Minitest::Test::TEARDOWN_METHODS

Constants included from Minitest::Assertions

Minitest::Assertions::E, Minitest::Assertions::UNDEFINED

Constants inherited from Minitest::Runnable

Minitest::Runnable::SIGNALS

Instance Attribute Summary

Attributes inherited from Minitest::Runnable

#assertions, #failures, #time

Instance Method Summary collapse

Methods inherited from Minitest::Test

#capture_exceptions, #class_name, #clean, i_suck_and_my_tests_are_order_dependent!, make_my_diffs_pretty!, #neuter_exception, #new_exception, parallelize_me!, #run, runnable_methods, #sanitize_exception, test_order, #with_empty_backtrace_filter, #with_info_handler

Methods included from Minitest::Guard

#jruby?, #maglev?, #mri?, #osx?, #rubinius?, #windows?

Methods included from Minitest::Test::LifecycleHooks

#after_setup, #after_teardown, #before_setup, #before_teardown, #setup, #teardown

Methods included from Minitest::Reportable

#class_name, #error?, #location, #passed?, #result_code, #skipped?

Methods included from Minitest::Assertions

#_synchronize, #assert, #assert_empty, #assert_equal, #assert_in_delta, #assert_in_epsilon, #assert_includes, #assert_instance_of, #assert_kind_of, #assert_match, #assert_mock, #assert_nil, #assert_operator, #assert_output, #assert_path_exists, #assert_predicate, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_silent, #assert_throws, #capture_io, #capture_subprocess_io, #diff, diff, diff=, #exception_details, #fail_after, #flunk, #message, #mu_pp, #mu_pp_for_diff, #pass, #refute, #refute_empty, #refute_equal, #refute_in_delta, #refute_in_epsilon, #refute_includes, #refute_instance_of, #refute_kind_of, #refute_match, #refute_nil, #refute_operator, #refute_path_exists, #refute_predicate, #refute_respond_to, #refute_same, #skip, #skip_until, #skipped?, #things_to_diff

Methods inherited from Minitest::Runnable

#failure, inherited, #initialize, #marshal_dump, #marshal_load, methods_matching, #name, #name=, on_signal, #passed?, reset, #result_code, run, #run, run_one_method, runnable_methods, runnables, #skipped?, #time_it, #whatever, with_info_handler

Constructor Details

This class inherits a constructor from Minitest::Runnable

Instance Method Details

#assert_marshal(expected_ivars) {|new_tc| ... } ⇒ Object

Yields:

  • (new_tc)


812
813
814
815
816
817
818
819
820
821
822
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 812

def assert_marshal expected_ivars
  new_tc = Marshal.load Marshal.dump @tc

  ivars = new_tc.instance_variables.map(&:to_s).sort
  assert_equal expected_ivars, ivars
  assert_equal "whatever",     new_tc.name
  assert_equal 42,             new_tc.assertions
  assert_equal ["a failure"],  new_tc.failures

  yield new_tc if block_given?
end

#setup_marshal(klass) {|tc| ... } ⇒ Object

Yields:

  • (tc)


797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 797

def setup_marshal klass
  tc = klass.new "whatever"
  tc.assertions = 42
  tc.failures << "a failure"

  yield tc if block_given?

  def tc.setup
    @blah = "blah"
  end
  tc.setup

  @tc = Minitest::Result.from tc
end

#test_marshalObject



824
825
826
827
828
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 824

def test_marshal
  setup_marshal Minitest::Runnable

  assert_marshal %w[@NAME @assertions @failures @klass @source_location @time]
end

#test_spec_marshalObject



830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 830

def test_spec_marshal
  klass = describe("whatever") { it("passes") { assert true } }
  rm = klass.runnable_methods.first

  # Run the test
  @tc = klass.new(rm).run

  assert_kind_of Minitest::Result, @tc

  # Pass it over the wire
  over_the_wire = Marshal.load Marshal.dump @tc

  assert_equal @tc.time,       over_the_wire.time
  assert_equal @tc.name,       over_the_wire.name
  assert_equal @tc.assertions, over_the_wire.assertions
  assert_equal @tc.failures,   over_the_wire.failures
  assert_equal @tc.klass,      over_the_wire.klass
end

#test_spec_marshal_with_exceptionObject



849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 849

def test_spec_marshal_with_exception
  klass = describe("whatever") {
    it("raises, badly") {
      raise Class.new(StandardError), "this is bad!"
    }
  }

  rm = klass.runnable_methods.first

  # Run the test
  @tc = klass.new(rm).run

  assert_kind_of Minitest::Result, @tc
  assert_instance_of Minitest::UnexpectedError, @tc.failure

  msg = @tc.failure.error.message
  assert_includes msg, "Neutered Exception #<Class:"
  assert_includes msg, "this is bad!"

  # Pass it over the wire
  over_the_wire = Marshal.load Marshal.dump @tc

  assert_equal @tc.time,       over_the_wire.time
  assert_equal @tc.name,       over_the_wire.name
  assert_equal @tc.assertions, over_the_wire.assertions
  assert_equal @tc.failures,   over_the_wire.failures
  assert_equal @tc.klass,      over_the_wire.klass
end

#test_spec_marshal_with_exception__better_error_typeerrorObject



916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 916

def test_spec_marshal_with_exception__better_error_typeerror
  klass = describe("whatever") {
    it("raises with binding") {
      raise BetterError, "boom"
    }
  }

  rm = klass.runnable_methods.first

  # Run the test
  @tc = with_runtime_error BetterError do
    klass.new(rm).run
  end

  assert_kind_of Minitest::Result, @tc
  assert_instance_of Minitest::UnexpectedError, @tc.failure

  msg = @tc.failure.error.message
  assert_equal "Neutered Exception BetterError: boom", msg

  # Pass it over the wire
  over_the_wire = Marshal.load Marshal.dump @tc

  assert_equal @tc.time,       over_the_wire.time
  assert_equal @tc.name,       over_the_wire.name
  assert_equal @tc.assertions, over_the_wire.assertions
  assert_equal @tc.failures,   over_the_wire.failures
  assert_equal @tc.klass,      over_the_wire.klass
end

#test_spec_marshal_with_exception__worse_error_typeerrorObject



946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 946

def test_spec_marshal_with_exception__worse_error_typeerror
  worse_error_klass = Class.new(StandardError) do
    # problem #1: anonymous subclass can'tmarshal, fails sanitize_exception
    def initialize(record = nil)

      super(record.first)
    end
  end

  klass = describe("whatever") {
    it("raises with NoMethodError") {
      # problem #2: instantiated with a NON-string argument
      #
      # problem #3: arg responds to #first, but it becomes message
      #             which gets passed back in via new_exception
      #             that passes a string to worse_error_klass#initialize
      #             which calls first on it, which raises NoMethodError
      raise worse_error_klass.new(["boom"])
    }
  }

  rm = klass.runnable_methods.first

  # Run the test
  @tc = klass.new(rm).run

  assert_kind_of Minitest::Result, @tc
  assert_instance_of Minitest::UnexpectedError, @tc.failure

  msg = @tc.failure.error.message.gsub(/0x[A-Fa-f0-9]+/, "0xXXX")

  assert_equal "Neutered Exception #<Class:0xXXX>: boom", msg

  # Pass it over the wire
  over_the_wire = Marshal.load Marshal.dump @tc

  assert_equal @tc.time,       over_the_wire.time
  assert_equal @tc.name,       over_the_wire.name
  assert_equal @tc.assertions, over_the_wire.assertions
  assert_equal @tc.failures,   over_the_wire.failures
  assert_equal @tc.klass,      over_the_wire.klass
end

#test_spec_marshal_with_exception_nameerrorObject



878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 878

def test_spec_marshal_with_exception_nameerror
  klass = describe("whatever") {
    it("raises nameerror") {
      NOPE::does_not_exist
    }
  }

  rm = klass.runnable_methods.first

  # Run the test
  @tc = klass.new(rm).run

  assert_kind_of Minitest::Result, @tc
  assert_instance_of Minitest::UnexpectedError, @tc.failure

  msg = @tc.failure.error.message
  assert_includes msg, "uninitialized constant TestMinitestRunnable::NOPE"

  # Pass it over the wire
  over_the_wire = Marshal.load Marshal.dump @tc

  assert_equal @tc.time,       over_the_wire.time
  assert_equal @tc.name,       over_the_wire.name
  assert_equal @tc.assertions, over_the_wire.assertions
  assert_equal @tc.failures,   over_the_wire.failures
  assert_equal @tc.klass,      over_the_wire.klass
end

#with_runtime_error(klass) ⇒ Object



906
907
908
909
910
911
912
913
914
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/test/minitest/test_minitest_test.rb', line 906

def with_runtime_error klass
  old_runtime = RuntimeError
  Object.send :remove_const, :RuntimeError
  Object.const_set :RuntimeError, klass
  yield
ensure
  Object.send :remove_const, :RuntimeError
  Object.const_set :RuntimeError, old_runtime
end