Class: Test::Unit::Fixture::HookPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/fixture.rb

Instance Method Summary collapse

Constructor Details

#initialize(default_options) ⇒ HookPoint

Returns a new instance of HookPoint.



71
72
73
74
75
76
# File 'lib/test/unit/fixture.rb', line 71

def initialize(default_options)
  @default_options = default_options
  @before_callbacks = []
  @after_callbacks = []
  @unregistered_callbacks = []
end

Instance Method Details

#after_callbacksObject



111
112
113
# File 'lib/test/unit/fixture.rb', line 111

def after_callbacks
  @after_callbacks - @unregistered_callbacks
end

#before_callbacksObject



107
108
109
# File 'lib/test/unit/fixture.rb', line 107

def before_callbacks
  @before_callbacks - @unregistered_callbacks
end

#register(method_name_or_callback, options = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/test/unit/fixture.rb', line 78

def register(method_name_or_callback, options=nil)
  options ||= {}
  unless valid_register_options?(options)
    message = "must be {:before => :prepend}, " +
      "{:before => :append}, {:after => :prepend} or " +
      "{:after => :append}: #{options.inspect}"
    raise ArgumentError, message
  end

  if options.empty?
    options = @default_options
  end
  before_how = options[:before]
  after_how = options[:after]
  if before_how
    @before_callbacks = add_callback(@before_callbacks,
                                     method_name_or_callback,
                                     before_how)
  else
    @after_callbacks = add_callback(@after_callbacks,
                                    method_name_or_callback,
                                    after_how)
  end
end

#unregister(method_name_or_callback) ⇒ Object



103
104
105
# File 'lib/test/unit/fixture.rb', line 103

def unregister(method_name_or_callback)
  @unregistered_callbacks << method_name_or_callback
end