class TestUnitFixture::TestTeardown

Public Instance Methods

called(id) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 473
def called(id)
  called_ids << id
end
called_ids() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 469
def called_ids
  @called_ids ||= []
end
custom_teardown_method0() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 483
def custom_teardown_method0
  called(:custom_teardown_method0)
  raise "custom_teardown_method0"
end
custom_teardown_method1() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 494
def custom_teardown_method1
  called(:custom_teardown_method1)
  raise "custom_teardown_method1"
end
setup1() { || ... } click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 549
def setup1
  called(:setup1)
  begin
    yield
    called(:setup1_after_yield)
  ensure
    called(:setup1_teardown)
  end
end
setup2() { || ... } click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 560
def setup2
  called(:setup2)
  begin
    yield
    called(:setup2_after_yield)
  ensure
    called(:setup2_teardown)
  end
end
teardown() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 477
def teardown
  called(:teardown)
  raise "teardown"
end
test_nested() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 516
def test_nested
  called = []
  parent_test_case = Class.new(Test::Unit::TestCase) do
    teardown do
      called << :parent
    end
  end

  child_test_case = Class.new(parent_test_case) do
    teardown do
      called << :child
    end

    def test_nothing
    end
  end

  run_test_nothing(child_test_case)
  assert_equal([:child, :parent],
               called)
end
test_nothing() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 504
def test_nothing
end
test_setup_with_block() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 538
def test_setup_with_block
  test_case = Class.new(Test::Unit::TestCase) do
    def called_ids
      @called_ids ||= []
    end

    def called(id)
      called_ids << id
    end

    setup
    def setup1
      called(:setup1)
      begin
        yield
        called(:setup1_after_yield)
      ensure
        called(:setup1_teardown)
      end
    end

    setup
    def setup2
      called(:setup2)
      begin
        yield
        called(:setup2_after_yield)
      ensure
        called(:setup2_teardown)
      end
    end

    def teardown
      called(:teardown)
    end

    def test_nothing
      called(:test)
      flunk
      called(:test_after_failure)
    end
  end

  assert_called_fixtures([
                           :setup1,
                           :setup2,
                           :test,
                           :setup2_teardown,
                           :setup1_teardown,
                           :teardown,
                         ],
                         test_case)
end
test_with_after_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 426
def test_with_after_option
  expected_teardown_calls = [:teardown,
                             :custom_teardown_callback3,
                             :custom_teardown_method3,
                             :custom_teardown_method0,
                             :custom_teardown_callback0,
                             :custom_teardown_method1,
                             :custom_teardown_callback1]
  test_case = assert_teardown(expected_teardown_calls,
                              [[{:after => :append}],
                               [{:after => :append}],
                               [{:after => :prepend}],
                               [{:after => :prepend}]])
  assert_inherited_teardown(expected_teardown_calls, test_case)

  assert_inherited_teardown([:teardown], nil)
  assert_called_fixtures(expected_teardown_calls, test_case)
end
test_with_before_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 407
def test_with_before_option
  expected_teardown_calls = [:custom_teardown_callback3,
                             :custom_teardown_method3,
                             :custom_teardown_method0,
                             :custom_teardown_callback0,
                             :custom_teardown_method1,
                             :custom_teardown_callback1,
                             :teardown]
  test_case = assert_teardown(expected_teardown_calls,
                              [[{:before => :append}],
                               [{:before => :append}],
                               [{:before => :prepend}],
                               [{:before => :prepend}]])
  assert_inherited_teardown(expected_teardown_calls, test_case)

  assert_inherited_teardown([:teardown], nil)
  assert_called_fixtures(expected_teardown_calls, test_case)
end
test_with_exception() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 467
def test_with_exception
  test_case = Class.new(Test::Unit::TestCase) do
    def called_ids
      @called_ids ||= []
    end

    def called(id)
      called_ids << id
    end

    def teardown
      called(:teardown)
      raise "teardown"
    end

    teardown
    def custom_teardown_method0
      called(:custom_teardown_method0)
      raise "custom_teardown_method0"
    end

    teardown do
      called(:custom_teardown_callback0)
      raise "custom_teardown_callback0"
    end

    teardown
    def custom_teardown_method1
      called(:custom_teardown_method1)
      raise "custom_teardown_method1"
    end

    teardown do
      called(:custom_teardown_callback1)
      raise "custom_teardown_callback1"
    end

    def test_nothing
    end
  end

  assert_called_fixtures([:custom_teardown_callback1,
                          :custom_teardown_method1,
                          :custom_teardown_callback0,
                          :custom_teardown_method0,
                          :teardown],
                         test_case)
end
test_with_invalid_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 445
def test_with_invalid_option
  assert_invalid_teardown_option(:unknown => true)
  assert_invalid_teardown_option(:before => :unknown)
  assert_invalid_teardown_option(:after => :unknown)
end
test_with_option_to_inherited() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 451
def test_with_option_to_inherited
  expected_teardown_calls = [:teardown]
  test_case = assert_teardown(expected_teardown_calls, nil)
  assert_inherited_teardown([:custom_teardown_callback3,
                             :custom_teardown_method3,
                             :custom_teardown_callback1,
                             :custom_teardown_method1,
                             :custom_teardown_callback0,
                             :custom_teardown_method0,
                             :teardown],
                            test_case, [])

  assert_inherited_teardown([:teardown], nil)
  assert_called_fixtures(expected_teardown_calls, test_case)
end
test_without_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 392
def test_without_option
  expected_teardown_calls = [:custom_teardown_callback3,
                             :custom_teardown_method3,
                             :custom_teardown_callback1,
                             :custom_teardown_method1,
                             :custom_teardown_callback0,
                             :custom_teardown_method0,
                             :teardown]
  test_case = assert_teardown(expected_teardown_calls, [])
  assert_inherited_teardown(expected_teardown_calls, test_case)

  assert_inherited_teardown([:teardown], nil)
  assert_called_fixtures(expected_teardown_calls, test_case)
end

Private Instance Methods

assert_inherited_teardown(expected, parent, options=nil) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 673
def assert_inherited_teardown(expected, parent, options=nil)
  assert_teardown_customizable(expected, parent, options)
  assert_teardown_customizable(expected, parent, options) do |test_case, tag|
    test_case.send(:include, EmptyModule) if tag == :before
  end
end
assert_invalid_teardown_option(option) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 680
def assert_invalid_teardown_option(option)
  assert_invalid_option(:teardown, option)
end
assert_teardown(expected, options) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 666
def assert_teardown(expected, options)
  assert_teardown_customizable(expected, nil, options)
  assert_teardown_customizable(expected, nil, options) do |test_case, tag|
    test_case.send(:include, EmptyModule) if tag == :before
  end
end
assert_teardown_customizable(expected, parent, options) { |self, :before| ... } click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 593
def assert_teardown_customizable(expected, parent, options)
  test_case = Class.new(parent || Test::Unit::TestCase) do
    yield(self, :before) if block_given?

    def called_ids
      @called_ids ||= []
    end

    def called(id)
      called_ids << id
    end

    def teardown
      called(:teardown)
    end

    teardown(*(options[0] || [])) if options
    def custom_teardown_method0
      called(:custom_teardown_method0)
    end

    if options
      teardown(*(options[0] || [])) do
        called(:custom_teardown_callback0)
      end
    end

    def custom_teardown_method1
      called(:custom_teardown_method1)
    end
    teardown(*[:custom_teardown_method1, *(options[1] || [])]) if options

    if options
      teardown(*(options[1] || [])) do
        called(:custom_teardown_callback1)
      end
    end

    teardown(*(options[2] || [])) if options
    def custom_teardown_method2
      called(:custom_teardown_method2)
    end
    unregister_teardown(:custom_teardown_method2) if options

    if options
      callback = lambda do
        called(:custom_teardown_callback2)
      end
      teardown(*(options[2] || []), &callback)
      unregister_teardown(callback)
    end

    teardown(*(options[3] || [])) if options
    def custom_teardown_method3
      called(:custom_teardown_method3)
    end

    if options
      teardown(*(options[3] || [])) do
        called(:custom_teardown_callback3)
      end
    end

    def test_nothing
    end

    yield(self, :after) if block_given?
  end

  assert_called_fixtures(expected, test_case)
  test_case
end
custom_teardown_method2() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 632
def custom_teardown_method2
  called(:custom_teardown_method2)
end
custom_teardown_method3() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 646
def custom_teardown_method3
  called(:custom_teardown_method3)
end