class Aruba::EventBus


to subscribe to different events that fire as your tests are executed.
Implements and in-process pub-sub events broadcaster allowing multiple observers
Event bus

def initialize(resolver)

Parameters:
  • resolver (#transform) --
def initialize(resolver)
  @resolver = resolver
  @handlers = Hash.new { |h, k| h[k] = [] }
end

def notify(event)

Parameters:
  • event (Object) --
def notify(event)
  raise NoEventError, "Please pass an event object, not a class" if event.is_a?(Class)
  @handlers[event.class.to_s].each { |handler| handler.call(event) }
end

def register(event_ids, handler_object = nil, &handler_proc)

Other tags:
    Yield: -

Parameters:
  • handler_object (#call) --
  • event_ids (String, Symbol, Class, Array) --
def register(event_ids, handler_object = nil, &handler_proc)
  handler = handler_proc || handler_object
  if handler.nil? || !handler.respond_to?(:call)
    raise ArgumentError, "Please pass either an object#call or a handler block"
  end
  Array(event_ids).flatten.each do |id|
    @handlers[
      @resolver.transform(id).to_s
    ] << handler
  end
  nil
end