module Test::Unit::Fixture

Public Class 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 |fixture|
    observer = lambda do |test_case, _, _, value, callback|
      if value.nil?
        test_case.send("unregister_#{fixture}_callback", callback)
      else
        test_case.send("register_#{fixture}_callback", callback, value)
      end
    end
    base.register_attribute_observer(fixture, &observer)
  end
end

Private Instance Methods

run_cleanup() click to toggle source
# File lib/test/unit/fixture.rb, line 218
def run_cleanup
  run_fixture(:cleanup)
end
run_fixture(fixture, options={}) click to toggle source
# File lib/test/unit/fixture.rb, line 184
def run_fixture(fixture, options={})
  [
   self.class.send("before_#{fixture}_callbacks"),
   fixture,
   self.class.send("after_#{fixture}_callbacks")
  ].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 194
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 214
def run_setup
  run_fixture(:setup)
end
run_teardown() click to toggle source
# File lib/test/unit/fixture.rb, line 222
def run_teardown
  run_fixture(:teardown, :handle_exception => true)
end