Class: MinitestRollbar::RollbarReporter

Inherits:
Minitest::Reporters::BaseReporter
  • Object
show all
Defined in:
lib/minitest_rollbar/reporters.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RollbarReporter

Returns a new instance of RollbarReporter.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/minitest_rollbar/reporters.rb', line 10

def initialize(options = {})
  super
  @sequential_exception_count = 0
  # Inspect will return ExceptionType + Message.
  # E.g #<Selenium::WebDriver::Error::NoSuchWindowError: Window not found. The browser window may have been closed.>
  # Use this as a criteria of grouping
  @previous_exception_inspect_result = nil
  @previous_exception = nil

  raise 'Must set rollbar access token' if MinitestRollbar.access_token.nil?
  Rollbar.configure do |config|
    config.access_token = MinitestRollbar.access_token
  end
end

Instance Method Details

#record(result) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/minitest_rollbar/reporters.rb', line 25

def record(result)
  super
  if result.error?
    current_exception = result.failure.exception
    current_exception_inspect_result = current_exception.inspect

    # If there is no previous exception, start a fresh counter
    if @previous_exception_inspect_result.nil?
      record_new_error(current_exception)
      # Report or increment the count the previous errors if a new error occurs
    elsif current_exception_inspect_result == @previous_exception_inspect_result
      # Same error, increment counter
      increment_error_counting
    else
      # Different error, report previous errors and record new error
      report_error_to_rollbar
      record_new_error current_exception
    end
  else
    # Report previous errors if there is any
    unless @previous_exception.nil?
      report_error_to_rollbar
      reset_error_counting
    end
  end
end

#reportObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/minitest_rollbar/reporters.rb', line 52

def report
  super
  if @sequential_exception_count > 0
    notifier = Rollbar.scope(count: @sequential_exception_count)
    notifier.error(@previous_exception)

    @previous_exception_inspect_result = nil
    @previous_exception = nil
    @sequential_exception_count = 0

  end
end