class FlakeySpecCatcher::EventListener

EventListener class

Listens for events from RSpec and processes data from those events.

This event listener will receive example_failed and example_passed events from RSpec and will log those results into the provided result manager

Public Class Methods

new(result_manager) click to toggle source
# File lib/flakey_spec_catcher/event_listener.rb, line 13
def initialize(result_manager)
  @result_manager = result_manager
end

Public Instance Methods

example_failed(notification) click to toggle source
# File lib/flakey_spec_catcher/event_listener.rb, line 17
def example_failed(notification)
  description = notification.example.full_description.to_s.strip
  location = notification.example.location
  @result_manager.add_result(description, location, format_message(notification))
end
example_passed(notification) click to toggle source
# File lib/flakey_spec_catcher/event_listener.rb, line 23
def example_passed(notification)
  description = notification.example.full_description.to_s.strip
  location = notification.example.location
  @result_manager.add_result(description, location)
end

Private Instance Methods

format_message(notification) click to toggle source
# File lib/flakey_spec_catcher/event_listener.rb, line 31
def format_message(notification)
  exception = notification.example.execution_result.exception
  message = if exception.is_a?(RSpec::Core::MultipleExceptionError)
    exception.all_exceptions.join("\n").strip
  else
    exception.to_s.strip
  end

  message
end