123456789_123456789_123456789_123456789_123456789_

Module: Test::Unit::Fixture

Relationships & Source Files
Namespace Children
Modules:
Classes:
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/test/unit/fixture.rb

Class Method Summary

Instance Method Summary

Class Method Details

.included(base)

[ GitHub ]

  
# 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

Instance Method Details

#run_cleanup (private)

[ GitHub ]

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

def run_cleanup
  run_fixture(:cleanup)
end

#run_fixture(type, options = {}) (private)

[ GitHub ]

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

[ GitHub ]

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

[ GitHub ]

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

def run_setup
  run_fixture(:setup)
end

#run_teardown (private)

[ GitHub ]

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

def run_teardown
  run_fixture(:teardown, :handle_exception => true)
end