123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::Fixture::Fixture

Relationships & Source Files
Inherits: Object
Defined in: lib/test/unit/fixture.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(test_case) ⇒ Fixture

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 25

def initialize(test_case)
  @test_case = test_case
  @setup = HookPoint.new(:after => :append)
  @cleanup = HookPoint.new(:before => :prepend)
  @teardown = HookPoint.new(:before => :prepend)
end

Instance Attribute Details

#cleanup (readonly)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 23

attr_reader :cleanup

#setup (readonly)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 22

attr_reader :setup

#teardown (readonly)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 24

attr_reader :teardown

Instance Method Details

#[](type)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 32

def [](type)
  case type
  when :setup
    @setup
  when :cleanup
    @cleanup
  when :teardown
    @teardown
  end
end

#after_callbacks(type)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 54

def 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

#before_callbacks(type)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 43

def 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 (private)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 70

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) (private)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 79

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 (private)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 66

def target_test_cases
  @cached_target_test_cases ||= collect_target_test_cases
end