class Test::Unit::Fixture::Fixture

Attributes

cleanup[R]
setup[R]
teardown[R]

Public Class Methods

new(test_case) click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 25
def initialize(test_case)
  @test_case = test_case
  @setup = HookPoint.new(@test_case, :setup, :after => :append)
  @cleanup = HookPoint.new(@test_case, :cleanup, :before => :prepend)
  @teardown = HookPoint.new(@test_case, :teardown, :before => :prepend)
  @cached_before_callbacks = {}
  @cached_after_callbacks = {}
end

Public Instance Methods

[](type) click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 34
def [](type)
  case type
  when :setup
    @setup
  when :cleanup
    @cleanup
  when :teardown
    @teardown
  end
end
after_callbacks(type) click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 49
def after_callbacks(type)
  @cached_after_callbacks[type] ||= collect_after_callbacks(type)
end
before_callbacks(type) click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 45
def before_callbacks(type)
  @cached_before_callbacks[type] ||= collect_before_callbacks(type)
end

Private Instance Methods

collect_after_callbacks(type) click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 69
def collect_after_callbacks(type)
  prepend_callbacks = []
  append_callbacks = []
  target_test_cases.each do |ancestor|
    prepend_callbacks << ancestor.fixture[type].after_prepend_callbacks
    append_callbacks << ancestor.fixture[type].after_append_callbacks
  end

  merge_callbacks(prepend_callbacks, append_callbacks)
end
collect_before_callbacks(type) click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 58
def collect_before_callbacks(type)
  prepend_callbacks = []
  append_callbacks = []
  target_test_cases.each do |ancestor|
    prepend_callbacks << ancestor.fixture[type].before_prepend_callbacks
    append_callbacks << ancestor.fixture[type].before_append_callbacks
  end

  merge_callbacks(prepend_callbacks, append_callbacks)
end
collect_target_test_cases() click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 80
def collect_target_test_cases
  ancestors = @test_case.ancestors
  base_index = ancestors.index(::Test::Unit::Fixture)
  interested_ancestors = ancestors[0, base_index].find_all do |ancestor|
    ancestor.is_a?(Class)
  end
  interested_ancestors.reverse
end
merge_callbacks(prepend_callbacks, append_callbacks) click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 89
def merge_callbacks(prepend_callbacks, append_callbacks)
  all_callbacks = []
  prepend_callbacks.reverse_each do |callbacks|
    all_callbacks.concat(callbacks)
  end
  append_callbacks.each do |callbacks|
    all_callbacks.concat(callbacks)
  end
  all_callbacks
end
target_test_cases() click to toggle source
# File test-unit-3.6.4/lib/test/unit/fixture.rb, line 54
def target_test_cases
  @cached_target_test_cases ||= collect_target_test_cases
end