Class: Test::Unit::Fixture::HookPoint
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/test/unit/fixture.rb |
Class Method Summary
Instance Method Summary
- #after_append_callbacks
- #after_prepend_callbacks
- #before_append_callbacks
- #before_prepend_callbacks
- #register(method_name_or_callback, options = nil)
- #unregister(method_name_or_callback)
- #add_callback(method_name_or_callback, before_how, after_how) private
- #callback_method_name(callback) private
- #valid_register_options?(options) ⇒ Boolean private
Constructor Details
.new(test_case, type, default_options) ⇒ HookPoint
# File 'lib/test/unit/fixture.rb', line 102
def initialize(test_case, type, ) @test_case = test_case @type = type @default_options = @before_prepend_callbacks = [] @before_append_callbacks = [] @after_prepend_callbacks = [] @after_append_callbacks = [] @unregistered_callbacks = [] end
Instance Method Details
#add_callback(method_name_or_callback, before_how, after_how) (private)
[ GitHub ]# File 'lib/test/unit/fixture.rb', line 180
def add_callback(method_name_or_callback, before_how, after_how) case before_how when :prepend @before_prepend_callbacks = [method_name_or_callback] | @before_prepend_callbacks when :append @before_append_callbacks |= [method_name_or_callback] else case after_how when :prepend @after_prepend_callbacks = [method_name_or_callback] | @after_prepend_callbacks when :append @after_append_callbacks |= [method_name_or_callback] end end end
#after_append_callbacks
[ GitHub ]# File 'lib/test/unit/fixture.rb', line 162
def after_append_callbacks @after_append_callbacks - @unregistered_callbacks end
#after_prepend_callbacks
[ GitHub ]# File 'lib/test/unit/fixture.rb', line 158
def after_prepend_callbacks @after_prepend_callbacks - @unregistered_callbacks end
#before_append_callbacks
[ GitHub ]# File 'lib/test/unit/fixture.rb', line 154
def before_append_callbacks @before_append_callbacks - @unregistered_callbacks end
#before_prepend_callbacks
[ GitHub ]# File 'lib/test/unit/fixture.rb', line 150
def before_prepend_callbacks @before_prepend_callbacks - @unregistered_callbacks end
#callback_method_name(callback) (private)
[ GitHub ]# File 'lib/test/unit/fixture.rb', line 176
def callback_method_name(callback) "#{@type}_#{callback.object_id}" end
#register(method_name_or_callback, options = nil)
[ GitHub ]# File 'lib/test/unit/fixture.rb', line 113
def register(method_name_or_callback, =nil) ||= {} unless ( ) = "must be {:before => :prepend}, " + "{:before => :append}, {:after => :prepend} or " + "{:after => :append}: #{ .inspect}" raise ArgumentError, end if .empty? = @default_options end before_how = [:before] after_how = [:after] if method_name_or_callback.respond_to?(:call) callback = method_name_or_callback method_name = callback_method_name(callback) @test_case.attribute(:source_location, callback.source_location, method_name) @test_case.__send__(:define_method, method_name, &callback) else method_name = method_name_or_callback end add_callback(method_name, before_how, after_how) end
#unregister(method_name_or_callback)
[ GitHub ]# File 'lib/test/unit/fixture.rb', line 140
def unregister(method_name_or_callback) if method_name_or_callback.respond_to?(:call) callback = method_name_or_callback method_name = callback_method_name(callback) else method_name = method_name_or_callback end @unregistered_callbacks << method_name end
#valid_register_options?(options) ⇒ Boolean
(private)
# File 'lib/test/unit/fixture.rb', line 167
def ( ) return true if .empty? return false if .size > 1 key = .keys.first [:before, :after].include?(key) and [:prepend, :append].include?( [key]) end