class TestMinitestStub
Public Class Methods
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 478 def self.method_missing meth, *args, &block if meth == :found false else super end end
respond_to?(meth)
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 474 def self.respond_to? meth meth == :found end
Public Instance Methods
assert_deprecated(re = /deprecated/) { || ... }
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 852 def assert_deprecated re = /deprecated/ assert_output "", re do yield end end
assert_stub(val_or_callable)
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 384 def assert_stub val_or_callable @assertion_count += 1 t = Time.now.to_i Time.stub :now, val_or_callable do @tc.assert_equal 42, Time.now end @tc.assert_operator Time.now.to_i, :>=, t end
fail_clap()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 412 def fail_clap raise :clap end
setup()
click to toggle source
Do not parallelize since we’re calling stub on class methods
Calls superclass method
Minitest::Test::LifecycleHooks#setup
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 365 def setup super Minitest::Test.reset @tc = Minitest::Test.new "fake tc" @assertion_count = 1 end
skip_stub6()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 858 def skip_stub6 skip "not yet" unless STUB6 end
teardown()
click to toggle source
Calls superclass method
Minitest::Test::LifecycleHooks#teardown
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 373 def teardown super assert_equal @assertion_count, @tc.assertions if self.passed? end
test_dynamic_method()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 470 def test_dynamic_method @assertion_count = 2 dynamic = Class.new do def self.respond_to? meth meth == :found end def self.method_missing meth, *args, &block if meth == :found false else super end end end val = dynamic.stub(:found, true) do |s| s.found end @tc.assert_equal true, val @tc.assert_equal false, dynamic.found end
test_mock_with_yield()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 506 def test_mock_with_yield mock = Minitest::Mock.new mock.expect(:write, true) do true end rs = nil File.stub :open, true, mock do File.open "foo.txt", "r" do |f| rs = f.write end end @tc.assert_equal true, rs end
test_stub_NameError()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 495 def test_stub_NameError e = @tc.assert_raises NameError do Time.stub :nope_nope_nope, 42 do # do nothing end end exp = /undefined method `nope_nope_nope' for( class)? `#{self.class}::Time'/ assert_match exp, e.message end
test_stub_block()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 434 def test_stub_block assert_stub lambda { 42 } end
test_stub_block_args()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 438 def test_stub_block_args @assertion_count += 1 t = Time.now.to_i Time.stub :now, lambda { |n| n * 2 } do @tc.assert_equal 42, Time.now(21) end @tc.assert_operator Time.now.to_i, :>=, t end
test_stub_callable()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 450 def test_stub_callable obj = Object.new def obj.call 42 end assert_stub obj end
test_stub_callable_block_5()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 594 def test_stub_callable_block_5 # from tenderlove @assertion_count += 1 Foo.stub5 :blocking, Bar.new do @tc.assert_output "hi\n", "" do Foo.blocking do @tc.flunk "shouldn't ever hit this" end end end end
test_stub_callable_block_6()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 605 def test_stub_callable_block_6 # from tenderlove skip_stub6 @assertion_count += 1 Foo.stub6 :blocking, Bar.new do @tc.assert_output "hi\n", "" do Foo.blocking do @tc.flunk "shouldn't ever hit this" end end end end
test_stub_lambda()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 618 def test_stub_lambda Thread.stub :new, lambda { 21+21 } do @tc.assert_equal 42, Thread.new end end
test_stub_lambda_args()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 624 def test_stub_lambda_args Thread.stub :new, lambda { 21+21 }, :wtf do @tc.assert_equal 42, Thread.new end end
test_stub_lambda_block_5()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 630 def test_stub_lambda_block_5 Thread.stub5 :new, lambda { 21+21 } do result = Thread.new do @tc.flunk "shouldn't ever hit this" end @tc.assert_equal 42, result end end
test_stub_lambda_block_6()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 639 def test_stub_lambda_block_6 skip_stub6 Thread.stub6 :new, lambda { 21+21 } do result = Thread.new do @tc.flunk "shouldn't ever hit this" end @tc.assert_equal 42, result end end
test_stub_lambda_block_args_5()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 650 def test_stub_lambda_block_args_5 @assertion_count += 1 Thingy.stub5 :identity, lambda { |y| @tc.assert_equal :nope, y; 21+21 }, :WTF? do result = Thingy.identity :nope do |x| @tc.flunk "shouldn't reach this" end @tc.assert_equal 42, result end end
test_stub_lambda_block_args_6()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 660 def test_stub_lambda_block_args_6 skip_stub6 @assertion_count += 1 Thingy.stub6 :identity, lambda { |y| @tc.assert_equal :nope, y; 21+21 }, :WTF? do result = Thingy.identity :nope do |x| @tc.flunk "shouldn't reach this" end @tc.assert_equal 42, result end end
test_stub_lambda_block_args_6_2()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 672 def test_stub_lambda_block_args_6_2 skip_stub6 @tc.assert_raises ArgumentError do Thingy.stub6_2 :identity, lambda { |y| :__not_run__ }, :WTF? do # doesn't matter end end end
test_stub_lambda_block_call_5()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 682 def test_stub_lambda_block_call_5 @assertion_count += 1 rs = nil io = StringIO.new "", "w" File.stub5 :open, lambda { |p, m, &blk| blk and blk.call io } do File.open "foo.txt", "r" do |f| rs = f && f.write("woot") end end @tc.assert_equal 4, rs @tc.assert_equal "woot", io.string end
test_stub_lambda_block_call_6()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 695 def test_stub_lambda_block_call_6 skip_stub6 @assertion_count += 1 rs = nil io = StringIO.new "", "w" File.stub6 :open, lambda { |p, m, &blk| blk.call io } do File.open "foo.txt", "r" do |f| rs = f.write("woot") end end @tc.assert_equal 4, rs @tc.assert_equal "woot", io.string end
test_stub_lambda_block_call_args_5()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 710 def test_stub_lambda_block_call_args_5 @assertion_count += 1 rs = nil io = StringIO.new "", "w" File.stub5(:open, lambda { |p, m, &blk| blk and blk.call io }, :WTF?) do File.open "foo.txt", "r" do |f| rs = f.write("woot") end end @tc.assert_equal 4, rs @tc.assert_equal "woot", io.string end
test_stub_lambda_block_call_args_6()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 723 def test_stub_lambda_block_call_args_6 skip_stub6 @assertion_count += 1 rs = nil io = StringIO.new "", "w" File.stub6(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do File.open "foo.txt", "r" do |f| rs = f.write("woot") end end @tc.assert_equal 4, rs @tc.assert_equal "woot", io.string end
test_stub_lambda_block_call_args_6_2()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 738 def test_stub_lambda_block_call_args_6_2 skip_stub6 @assertion_count += 2 rs = nil io = StringIO.new "", "w" @tc.assert_raises ArgumentError do File.stub6_2(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do File.open "foo.txt", "r" do |f| rs = f.write("woot") end end end @tc.assert_nil rs @tc.assert_equal "", io.string end
test_stub_private_module_method()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 396 def test_stub_private_module_method @assertion_count += 1 t0 = Time.now self.stub :sleep, nil do @tc.assert_nil sleep(10) end @tc.assert_operator Time.now - t0, :<=, 1 end
test_stub_private_module_method_indirect()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 408 def test_stub_private_module_method_indirect @assertion_count += 1 fail_clapper = Class.new do def fail_clap raise :clap end end.new fail_clapper.stub :raise, nil do |safe_clapper| @tc.assert_equal :clap, safe_clapper.fail_clap # either form works @tc.assert_equal :clap, fail_clapper.fail_clap # yay closures end end
test_stub_public_module_method()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 424 def test_stub_public_module_method Math.stub :log10, :stubbed do @tc.assert_equal :stubbed, Math.log10(1000) end end
test_stub_value()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 430 def test_stub_value assert_stub 42 end
Also aliased as: test_stub_value__old
test_stub_value_args()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 762 def test_stub_value_args Thread.stub :new, 42, :WTF? do result = Thread.new @tc.assert_equal 42, result end end
test_stub_value_block_5()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 769 def test_stub_value_block_5 @assertion_count += 1 Thread.stub5 :new, 42 do result = Thread.new do @tc.assert true end @tc.assert_equal 42, result end end
test_stub_value_block_6()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 779 def test_stub_value_block_6 skip_stub6 Thread.stub6 :new, 42 do result = Thread.new do @tc.flunk "shouldn't hit this" end @tc.assert_equal 42, result end end
test_stub_value_block_args_5()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 790 def test_stub_value_block_args_5 @assertion_count += 2 rs = nil io = StringIO.new "", "w" File.stub5 :open, :value, io do result = File.open "foo.txt", "r" do |f| rs = f.write("woot") end @tc.assert_equal :value, result end @tc.assert_equal 4, rs @tc.assert_equal "woot", io.string end
test_stub_value_block_args_5__break_if_not_passed()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 804 def test_stub_value_block_args_5__break_if_not_passed e = @tc.assert_raises NoMethodError do File.stub5 :open, :return_value do # intentionally bad setup w/ no args File.open "foo.txt", "r" do |f| f.write "woot" end end end exp = "undefined method `write' for nil:NilClass" assert_equal exp, e.message end
test_stub_value_block_args_6()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 816 def test_stub_value_block_args_6 skip_stub6 @assertion_count += 2 rs = nil io = StringIO.new "", "w" assert_deprecated do File.stub6 :open, :value, io do result = File.open "foo.txt", "r" do |f| rs = f.write("woot") end @tc.assert_equal :value, result end end @tc.assert_equal 4, rs @tc.assert_equal "woot", io.string end
test_stub_value_block_args_6_2()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 834 def test_stub_value_block_args_6_2 skip_stub6 @assertion_count += 2 rs = nil io = StringIO.new "", "w" @tc.assert_raises ArgumentError do File.stub6_2 :open, :value, io do result = File.open "foo.txt", "r" do |f| @tc.flunk "shouldn't hit this" end @tc.assert_equal :value, result end end @tc.assert_nil rs @tc.assert_equal "", io.string end
test_stub_yield_self()
click to toggle source
# File minitest-5.13.0/test/minitest/test_minitest_mock.rb, line 460 def test_stub_yield_self obj = "foo" val = obj.stub :to_s, "bar" do |s| s.to_s end @tc.assert_equal "bar", val end