Class: Honeybadger::CLI::Test Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/honeybadger/cli/test.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: TestBackend

Constant Summary collapse

TEST_EXCEPTION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

begin
  exception_name = ENV['EXCEPTION'] || 'HoneybadgerTestingException'
  Object.const_get(exception_name)
rescue
  Object.const_set(exception_name, Class.new(Exception))
end.new('Testing honeybadger via "honeybadger test". If you can see this, it works.')

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Test

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Test.



34
35
36
37
# File 'lib/honeybadger/cli/test.rb', line 34

def initialize(options)
  @options = options
  @shell = ::Thor::Base.shell.new
end

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/honeybadger/cli/test.rb', line 39

def run
  begin
    require File.join(Dir.pwd, 'config', 'environment.rb')
    raise LoadError unless defined?(::Rails.application)
    say("Detected Rails #{Rails::VERSION::STRING}")
  rescue LoadError
    require 'honeybadger/init/ruby'
  end

  if Honeybadger.config.get(:api_key).to_s =~ BLANK
    say("Unable to send test: Honeybadger API key is missing.", :red)
    exit(1)
  end

  Honeybadger.config.set(:report_data, !options[:dry_run])
  test_backend = TestBackend.new(Honeybadger.config.backend)
  Honeybadger.config.backend = test_backend

  at_exit do
    # Exceptions will already be reported when exiting.
    verify_test unless $!
  end

  run_test
end