module Test::Unit::Fixture

Public Instance Methods

included(base) click to toggle source
# File 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

run_cleanup() click to toggle source
# File lib/test/unit/fixture.rb, line 245
def run_cleanup
  run_fixture(:cleanup)
end
run_fixture(type, options={}) click to toggle source
# File lib/test/unit/fixture.rb, line 211
def run_fixture(type, options={})
  [
    self.class.fixture.before_callbacks(type),
    type,
    self.class.fixture.after_callbacks(type),
  ].flatten.each do |method_name_or_callback|
    run_fixture_callback(method_name_or_callback, options)
  end
end
run_fixture_callback(method_name_or_callback, options) click to toggle source
# File lib/test/unit/fixture.rb, line 221
def run_fixture_callback(method_name_or_callback, options)
  if method_name_or_callback.respond_to?(:call)
    callback = lambda do
      instance_eval(&method_name_or_callback)
    end
  else
    return unless respond_to?(method_name_or_callback, true)
    callback = lambda do
      __send__(method_name_or_callback)
    end
  end

  begin
    callback.call
  rescue Exception
    raise unless options[:handle_exception]
    raise unless handle_exception($!)
  end
end
run_setup() click to toggle source
# File lib/test/unit/fixture.rb, line 241
def run_setup
  run_fixture(:setup)
end
run_teardown() click to toggle source
# File lib/test/unit/fixture.rb, line 249
def run_teardown
  run_fixture(:teardown, :handle_exception => true)
end