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.



44
45
46
47
# File 'lib/honeybadger/cli/test.rb', line 44

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.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/honeybadger/cli/test.rb', line 49

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