module Test::Unit::Fixture

Public Class Methods

included(base) click to toggle source
# File test-unit-3.3.4/lib/test/unit/fixture.rb, line 5
def included(base)
  base.extend(ClassMethods)

  [:setup, :cleanup, :teardown].each do |type|
    observer = lambda do |test_case, _, _, value, callback|
      if value.nil?
        test_case.fixture[type].unregister(callback)
      else
        test_case.fixture[type].register(callback, value)
      end
    end
    base.register_attribute_observer(type, &observer)
  end
end

Private Instance Methods

create_fixtures_runner(fixtures, options, &block) click to toggle source
# File test-unit-3.3.4/lib/test/unit/fixture.rb, line 259
def create_fixtures_runner(fixtures, options, &block)
  if fixtures.empty?
    block
  else
    last_fixture = fixtures.pop
    create_fixtures_runner(fixtures, options) do
      block_is_called = false
      run_fixture_callback(last_fixture, options) do
        block_is_called = true
        block.call
      end
      block.call unless block_is_called
    end
  end
end
run_cleanup() click to toggle source
# File test-unit-3.3.4/lib/test/unit/fixture.rb, line 289
def run_cleanup
  run_fixture(:cleanup)
end
run_fixture(type, options={}, &block) click to toggle source
# File test-unit-3.3.4/lib/test/unit/fixture.rb, line 243
def run_fixture(type, options={}, &block)
  fixtures = [
    self.class.fixture.before_callbacks(type),
    type,
    self.class.fixture.after_callbacks(type),
  ].flatten
  if block
    runner = create_fixtures_runner(fixtures, options, &block)
    runner.call
  else
    fixtures.each do |method_name|
      run_fixture_callback(method_name, options)
    end
  end
end
run_fixture_callback(method_name, options, &block) click to toggle source
# File test-unit-3.3.4/lib/test/unit/fixture.rb, line 275
def run_fixture_callback(method_name, options, &block)
  return unless respond_to?(method_name, true)
  begin
    __send__(method_name, &block)
  rescue Exception
    raise unless options[:handle_exception]
    raise unless handle_exception($!)
  end
end
run_setup(&block) click to toggle source
# File test-unit-3.3.4/lib/test/unit/fixture.rb, line 285
def run_setup(&block)
  run_fixture(:setup, &block)
end
run_teardown() click to toggle source
# File test-unit-3.3.4/lib/test/unit/fixture.rb, line 293
def run_teardown
  run_fixture(:teardown, :handle_exception => true)
end