class TestUnitFixture::TestSetup

Public Instance Methods

test_with_after_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 40
def test_with_after_option
  expected_setup_calls = [:setup,
                          :custom_setup_callback3,
                          :custom_setup_method3,
                          :custom_setup_method0,
                          :custom_setup_callback0,
                          :custom_setup_method1,
                          :custom_setup_callback1]
  test_case = assert_setup(expected_setup_calls,
                           [[{:after => :append}],
                            [{:after => :append}],
                            [{:after => :prepend}],
                            [{:after => :prepend}]])
  assert_inherited_setup(expected_setup_calls, test_case)

  assert_inherited_setup([:setup], nil)
  assert_called_fixtures(expected_setup_calls, test_case)
end
test_with_before_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 21
def test_with_before_option
  expected_setup_calls = [:custom_setup_callback3,
                          :custom_setup_method3,
                          :custom_setup_method0,
                          :custom_setup_callback0,
                          :custom_setup_method1,
                          :custom_setup_callback1,
                          :setup]
  test_case = assert_setup(expected_setup_calls,
                           [[{:before => :append}],
                            [{:before => :append}],
                            [{:before => :prepend}],
                            [{:before => :prepend}]])
  assert_inherited_setup(expected_setup_calls, test_case)

  assert_inherited_setup([:setup], nil)
  assert_called_fixtures(expected_setup_calls, test_case)
end
test_with_invalid_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 59
def test_with_invalid_option
  assert_invalid_setup_option(:unknown => true)
  assert_invalid_setup_option(:before => :unknown)
  assert_invalid_setup_option(:after => :unknown)
end
test_with_option_to_inherited() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 65
def test_with_option_to_inherited
  expected_setup_calls = [:setup]
  test_case = assert_setup(expected_setup_calls, nil)
  assert_inherited_setup([:setup,
                          :custom_setup_method0,
                          :custom_setup_callback0,
                          :custom_setup_method1,
                          :custom_setup_callback1,
                          :custom_setup_method3,
                          :custom_setup_callback3],
                         test_case,
                         [])

  assert_inherited_setup([:setup], nil)
  assert_called_fixtures(expected_setup_calls, test_case)
end
test_without_option() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 6
def test_without_option
  expected_setup_calls = [:setup,
                          :custom_setup_method0,
                          :custom_setup_callback0,
                          :custom_setup_method1,
                          :custom_setup_callback1,
                          :custom_setup_method3,
                          :custom_setup_callback3]
  test_case = assert_setup(expected_setup_calls, [])
  assert_inherited_setup(expected_setup_calls, test_case)

  assert_inherited_setup([:setup], nil)
  assert_called_fixtures(expected_setup_calls, test_case)
end

Private Instance Methods

assert_inherited_setup(expected, parent, options=nil) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 164
def assert_inherited_setup(expected, parent, options=nil)
  _test_case = assert_setup_customizable(expected, parent, options)
  assert_setup_customizable(expected, parent, options) do |test_case, tag|
    test_case.send(:include, EmptyModule) if tag == :before
  end
  _test_case
end
assert_invalid_setup_option(option) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 172
def assert_invalid_setup_option(option)
  assert_invalid_option(:setup, option)
end
assert_setup(expected, options) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 156
def assert_setup(expected, options)
  _test_case = assert_setup_customizable(expected, nil, options)
  assert_setup_customizable(expected, nil, options) do |test_case, tag|
    test_case.send(:include, EmptyModule) if tag == :before
  end
  _test_case
end
assert_setup_customizable(expected, parent, options) { |self, :before| ... } click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 83
def assert_setup_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 setup
      called(:setup)
    end

    setup(*(options[0] || [])) if options
    def custom_setup_method0
      called(:custom_setup_method0)
    end

    if options
      setup(*(options[0] || [])) do
        called(:custom_setup_callback0)
      end
    end

    def custom_setup_method1
      called(:custom_setup_method1)
    end
    setup(*[:custom_setup_method1, *(options[1] || [])]) if options

    if options
      setup(*(options[1] || [])) do
        called(:custom_setup_callback1)
      end
    end

    setup(*(options[2] || [])) if options
    def custom_setup_method2
      called(:custom_setup_method2)
    end
    unregister_setup(:custom_setup_method2) if options

    if options
      callback = lambda do
        called(:custom_setup_callback2)
      end
      setup(*(options[2] || []), &callback)
      unregister_setup(callback)
    end

    setup(*(options[3] || [])) if options
    def custom_setup_method3
      called(:custom_setup_method3)
    end

    if options
      setup(*(options[3] || [])) do
        called(:custom_setup_callback3)
      end
    end

    def test_nothing
    end

    yield(self, :after) if block_given?
  end

  assert_called_fixtures(expected, test_case)
  test_case
end
called(id) click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 91
def called(id)
  called_ids << id
end
called_ids() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 87
def called_ids
  @called_ids ||= []
end
custom_setup_method0() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 100
def custom_setup_method0
  called(:custom_setup_method0)
end
custom_setup_method1() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 110
def custom_setup_method1
  called(:custom_setup_method1)
end
custom_setup_method2() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 122
def custom_setup_method2
  called(:custom_setup_method2)
end
custom_setup_method3() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 136
def custom_setup_method3
  called(:custom_setup_method3)
end
setup() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 95
def setup
  called(:setup)
end
test_nothing() click to toggle source
# File test-unit-3.3.4/test/test-fixture.rb, line 146
def test_nothing
end