class TestUnitFixture::TestCleanup

Public Instance Methods

called(id) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 259
def called(id)
  called_ids << id
end
called_ids() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 255
def called_ids
  @called_ids ||= []
end
cleanup() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 263
def cleanup
  called(:cleanup)
  raise "cleanup"
end
custom_cleanup_method0() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 269
def custom_cleanup_method0
  called(:custom_cleanup_method0)
  raise "custom_cleanup_method0"
end
custom_cleanup_method1() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 280
def custom_cleanup_method1
  called(:custom_cleanup_method1)
  raise "custom_cleanup_method1"
end
test_nothing() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 290
def test_nothing
end
test_with_after_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 212
def test_with_after_option
  expected_cleanup_calls = [:cleanup,
                            :custom_cleanup_callback3,
                            :custom_cleanup_method3,
                            :custom_cleanup_method0,
                            :custom_cleanup_callback0,
                            :custom_cleanup_method1,
                            :custom_cleanup_callback1]
  test_case = assert_cleanup(expected_cleanup_calls,
                              [[{:after => :append}],
                               [{:after => :append}],
                               [{:after => :prepend}],
                               [{:after => :prepend}]])
  assert_inherited_cleanup(expected_cleanup_calls, test_case)

  assert_inherited_cleanup([:cleanup], nil)
  assert_called_fixtures(expected_cleanup_calls, test_case)
end
test_with_before_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 193
def test_with_before_option
  expected_cleanup_calls = [:custom_cleanup_callback3,
                            :custom_cleanup_method3,
                            :custom_cleanup_method0,
                            :custom_cleanup_callback0,
                            :custom_cleanup_method1,
                            :custom_cleanup_callback1,
                            :cleanup]
  test_case = assert_cleanup(expected_cleanup_calls,
                              [[{:before => :append}],
                               [{:before => :append}],
                               [{:before => :prepend}],
                               [{:before => :prepend}]])
  assert_inherited_cleanup(expected_cleanup_calls, test_case)

  assert_inherited_cleanup([:cleanup], nil)
  assert_called_fixtures(expected_cleanup_calls, test_case)
end
test_with_exception() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 253
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 cleanup
      called(:cleanup)
      raise "cleanup"
    end

    cleanup
    def custom_cleanup_method0
      called(:custom_cleanup_method0)
      raise "custom_cleanup_method0"
    end

    cleanup do
      called(:custom_cleanup_callback0)
      raise "custom_cleanup_callback0"
    end

    cleanup
    def custom_cleanup_method1
      called(:custom_cleanup_method1)
      raise "custom_cleanup_method1"
    end

    cleanup do
      called(:custom_cleanup_callback1)
      raise "custom_cleanup_callback1"
    end

    def test_nothing
    end
  end

  assert_called_fixtures([:custom_cleanup_callback1],
                         test_case)
end
test_with_invalid_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 231
def test_with_invalid_option
  assert_invalid_cleanup_option(:unknown => true)
  assert_invalid_cleanup_option(:before => :unknown)
  assert_invalid_cleanup_option(:after => :unknown)
end
test_with_option_to_inherited() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 237
def test_with_option_to_inherited
  expected_cleanup_calls = [:cleanup]
  test_case = assert_cleanup(expected_cleanup_calls, nil)
  assert_inherited_cleanup([:custom_cleanup_callback3,
                            :custom_cleanup_method3,
                            :custom_cleanup_callback1,
                            :custom_cleanup_method1,
                            :custom_cleanup_callback0,
                            :custom_cleanup_method0,
                            :cleanup],
                            test_case, [])

  assert_inherited_cleanup([:cleanup], nil)
  assert_called_fixtures(expected_cleanup_calls, test_case)
end
test_without_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 178
def test_without_option
  expected_cleanup_calls = [:custom_cleanup_callback3,
                            :custom_cleanup_method3,
                            :custom_cleanup_callback1,
                            :custom_cleanup_method1,
                            :custom_cleanup_callback0,
                            :custom_cleanup_method0,
                            :cleanup]
  test_case = assert_cleanup(expected_cleanup_calls, [])
  assert_inherited_cleanup(expected_cleanup_calls, test_case)

  assert_inherited_cleanup([:cleanup], nil)
  assert_called_fixtures(expected_cleanup_calls, test_case)
end

Private Instance Methods

assert_cleanup(expected, options) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 372
def assert_cleanup(expected, options)
  assert_cleanup_customizable(expected, nil, options)
  assert_cleanup_customizable(expected, nil, options) do |test_case, tag|
    test_case.send(:include, EmptyModule) if tag == :before
  end
end
assert_cleanup_customizable(expected, parent, options) { |self, :before| ... } click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 299
def assert_cleanup_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 cleanup
      called(:cleanup)
    end

    cleanup(*(options[0] || [])) if options
    def custom_cleanup_method0
      called(:custom_cleanup_method0)
    end

    if options
      cleanup(*(options[0] || [])) do
        called(:custom_cleanup_callback0)
      end
    end

    def custom_cleanup_method1
      called(:custom_cleanup_method1)
    end
    cleanup(*[:custom_cleanup_method1, *(options[1] || [])]) if options

    if options
      cleanup(*(options[1] || [])) do
        called(:custom_cleanup_callback1)
      end
    end

    cleanup(*(options[2] || [])) if options
    def custom_cleanup_method2
      called(:custom_cleanup_method2)
    end
    unregister_cleanup(:custom_cleanup_method2) if options

    if options
      callback = lambda do
        called(:custom_cleanup_callback2)
      end
      cleanup(*(options[2] || []), &callback)
      unregister_cleanup(callback)
    end

    cleanup(*(options[3] || [])) if options
    def custom_cleanup_method3
      called(:custom_cleanup_method3)
    end

    if options
      cleanup(*(options[3] || [])) do
        called(:custom_cleanup_callback3)
      end
    end

    def test_nothing
    end

    yield(self, :after) if block_given?
  end

  assert_called_fixtures(expected, test_case)
  test_case
end
assert_inherited_cleanup(expected, parent, options=nil) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 379
def assert_inherited_cleanup(expected, parent, options=nil)
  assert_cleanup_customizable(expected, parent, options)
  assert_cleanup_customizable(expected, parent, options) do |test_case, tag|
    test_case.send(:include, EmptyModule) if tag == :before
  end
end
assert_invalid_cleanup_option(option) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 386
def assert_invalid_cleanup_option(option)
  assert_invalid_option(:cleanup, option)
end
custom_cleanup_method2() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 338
def custom_cleanup_method2
  called(:custom_cleanup_method2)
end
custom_cleanup_method3() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 352
def custom_cleanup_method3
  called(:custom_cleanup_method3)
end