honeybadger 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/Gemfile +13 -0
  2. data/Gemfile.lock +114 -0
  3. data/Guardfile +5 -0
  4. data/MIT-LICENSE +22 -0
  5. data/README.md +271 -0
  6. data/Rakefile +261 -0
  7. data/SUPPORTED_RAILS_VERSIONS +26 -0
  8. data/TESTING.md +33 -0
  9. data/features/metal.feature +18 -0
  10. data/features/rack.feature +56 -0
  11. data/features/rails.feature +211 -0
  12. data/features/rake.feature +27 -0
  13. data/features/sinatra.feature +29 -0
  14. data/features/step_definitions/file_steps.rb +10 -0
  15. data/features/step_definitions/metal_steps.rb +23 -0
  16. data/features/step_definitions/rack_steps.rb +23 -0
  17. data/features/step_definitions/rails_application_steps.rb +394 -0
  18. data/features/step_definitions/rake_steps.rb +17 -0
  19. data/features/support/env.rb +17 -0
  20. data/features/support/honeybadger_shim.rb.template +8 -0
  21. data/features/support/rails.rb +201 -0
  22. data/features/support/rake/Rakefile +68 -0
  23. data/features/support/terminal.rb +107 -0
  24. data/generators/honeybadger/honeybadger_generator.rb +94 -0
  25. data/generators/honeybadger/lib/insert_commands.rb +34 -0
  26. data/generators/honeybadger/lib/rake_commands.rb +24 -0
  27. data/generators/honeybadger/templates/capistrano_hook.rb +6 -0
  28. data/generators/honeybadger/templates/honeybadger_tasks.rake +25 -0
  29. data/generators/honeybadger/templates/initializer.rb +6 -0
  30. data/honeybadger.gemspec +109 -0
  31. data/lib/honeybadger.rb +162 -0
  32. data/lib/honeybadger/backtrace.rb +123 -0
  33. data/lib/honeybadger/capistrano.rb +43 -0
  34. data/lib/honeybadger/configuration.rb +273 -0
  35. data/lib/honeybadger/notice.rb +314 -0
  36. data/lib/honeybadger/rack.rb +55 -0
  37. data/lib/honeybadger/rails.rb +34 -0
  38. data/lib/honeybadger/rails/action_controller_catcher.rb +30 -0
  39. data/lib/honeybadger/rails/controller_methods.rb +69 -0
  40. data/lib/honeybadger/rails/middleware/exceptions_catcher.rb +29 -0
  41. data/lib/honeybadger/rails3_tasks.rb +84 -0
  42. data/lib/honeybadger/railtie.rb +45 -0
  43. data/lib/honeybadger/rake_handler.rb +65 -0
  44. data/lib/honeybadger/sender.rb +120 -0
  45. data/lib/honeybadger/shared_tasks.rb +36 -0
  46. data/lib/honeybadger/tasks.rb +82 -0
  47. data/lib/honeybadger_tasks.rb +65 -0
  48. data/lib/rails/generators/honeybadger/honeybadger_generator.rb +99 -0
  49. data/rails/init.rb +1 -0
  50. data/resources/README.md +34 -0
  51. data/resources/ca-bundle.crt +3376 -0
  52. data/script/integration_test.rb +38 -0
  53. data/test/test_helper.rb +143 -0
  54. data/test/unit/backtrace_test.rb +180 -0
  55. data/test/unit/capistrano_test.rb +34 -0
  56. data/test/unit/configuration_test.rb +201 -0
  57. data/test/unit/honeybadger_tasks_test.rb +163 -0
  58. data/test/unit/logger_test.rb +72 -0
  59. data/test/unit/notice_test.rb +406 -0
  60. data/test/unit/notifier_test.rb +245 -0
  61. data/test/unit/rack_test.rb +56 -0
  62. data/test/unit/rails/action_controller_catcher_test.rb +300 -0
  63. data/test/unit/rails_test.rb +35 -0
  64. data/test/unit/sender_test.rb +257 -0
  65. metadata +315 -0
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'logger'
4
+ require 'fileutils'
5
+
6
+ RAILS_ENV = "production"
7
+ RAILS_ROOT = FileUtils.pwd
8
+ RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
9
+
10
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ require 'honeybadger'
12
+ require 'rails/init'
13
+
14
+ fail "Please supply an API Key as the first argument" if ARGV.empty?
15
+
16
+ host = ARGV[1]
17
+ host ||= "api.honeybadger.io"
18
+
19
+ secure = (ARGV[2] == "secure")
20
+
21
+ exception = begin
22
+ raise "Testing honeybadger notifier with secure = #{secure}. If you can see this, it works."
23
+ rescue => foo
24
+ foo
25
+ end
26
+
27
+ Honeybadger.configure do |config|
28
+ config.secure = secure
29
+ config.host = host
30
+ config.api_key = ARGV.first
31
+ end
32
+ puts "Configuration:"
33
+ Honeybadger.configuration.to_hash.each do |key, value|
34
+ puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
35
+ end
36
+ puts "Sending #{secure ? "" : "in"}secure notification to project with key #{ARGV.first}"
37
+ Honeybadger.notify(exception)
38
+
@@ -0,0 +1,143 @@
1
+ require 'test/unit'
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'mocha'
6
+ require 'shoulda'
7
+ require 'bourne'
8
+ require 'rack'
9
+
10
+ require 'action_controller'
11
+ require 'action_controller/test_process'
12
+ require 'active_record'
13
+ require 'active_support'
14
+
15
+ require 'honeybadger'
16
+
17
+ class BacktracedException < Exception
18
+ attr_accessor :backtrace
19
+ def initialize(opts)
20
+ @backtrace = opts[:backtrace]
21
+ end
22
+ def set_backtrace(bt)
23
+ @backtrace = bt
24
+ end
25
+ end
26
+
27
+ module DefinesConstants
28
+ def setup
29
+ @defined_constants = []
30
+ end
31
+
32
+ def teardown
33
+ @defined_constants.each do |constant|
34
+ Object.__send__(:remove_const, constant)
35
+ end
36
+ end
37
+
38
+ def define_constant(name, value)
39
+ Object.const_set(name, value)
40
+ @defined_constants << name
41
+ end
42
+ end
43
+
44
+ class CollectingSender
45
+ attr_reader :collected
46
+
47
+ def initialize
48
+ @collected = []
49
+ end
50
+
51
+ def send_to_honeybadger(data)
52
+ @collected << data
53
+ end
54
+ end
55
+
56
+ module Honeybadger
57
+ class UnitTest < Test::Unit::TestCase
58
+ def assert_no_difference(expression, message = nil, &block)
59
+ assert_difference expression, 0, message, &block
60
+ end
61
+
62
+ def stub_sender
63
+ stub('sender', :send_to_honeybadger => nil)
64
+ end
65
+
66
+ def stub_sender!
67
+ Honeybadger.sender = stub_sender
68
+ end
69
+
70
+ def stub_notice
71
+ stub('notice', :to_json => 'some yaml', :ignore? => false)
72
+ end
73
+
74
+ def stub_notice!
75
+ stub_notice.tap do |notice|
76
+ Honeybadger::Notice.stubs(:new => notice)
77
+ end
78
+ end
79
+
80
+ def reset_config
81
+ Honeybadger.configuration = nil
82
+ Honeybadger.configure do |config|
83
+ config.api_key = 'abc123'
84
+ end
85
+ end
86
+
87
+ def build_notice_data(exception = nil)
88
+ exception ||= build_exception
89
+ {
90
+ :api_key => 'abc123',
91
+ :error_class => exception.class.name,
92
+ :error_message => "#{exception.class.name}: #{exception.message}",
93
+ :backtrace => exception.backtrace,
94
+ :environment => { 'PATH' => '/bin', 'REQUEST_URI' => '/users/1' },
95
+ :request => {
96
+ :params => { 'controller' => 'users', 'action' => 'show', 'id' => '1' },
97
+ :rails_root => '/path/to/application',
98
+ :url => "http://test.host/users/1"
99
+ },
100
+ :session => {
101
+ :key => '123abc',
102
+ :data => { 'user_id' => '5', 'flash' => { 'notice' => 'Logged in successfully' } }
103
+ }
104
+ }
105
+ end
106
+
107
+ def build_exception(opts = {})
108
+ backtrace = ["test/honeybadger/rack_test.rb:15:in `build_exception'",
109
+ "test/honeybadger/rack_test.rb:52:in `test_delivers_exception_from_rack'",
110
+ "/Users/josh/Developer/.rvm/gems/ruby-1.9.3-p0/gems/mocha-0.10.5/lib/mocha/integration/mini_test/version_230_to_262.rb:28:in `run'"]
111
+ opts = { :backtrace => backtrace }.merge(opts)
112
+ BacktracedException.new(opts)
113
+ end
114
+
115
+ def assert_array_starts_with(expected, actual)
116
+ assert_respond_to actual, :to_ary
117
+ array = actual.to_ary.reverse
118
+ expected.reverse.each_with_index do |value, i|
119
+ assert_equal value, array[i]
120
+ end
121
+ end
122
+
123
+ def assert_logged(expected)
124
+ assert_received(Honeybadger, :write_verbose_log) do |expect|
125
+ expect.with {|actual| actual =~ expected }
126
+ end
127
+ end
128
+
129
+ def assert_not_logged(expected)
130
+ assert_received(Honeybadger, :write_verbose_log) do |expect|
131
+ expect.with {|actual| actual =~ expected }.never
132
+ end
133
+ end
134
+
135
+ def assert_caught_and_sent
136
+ assert !Honeybadger.sender.collected.empty?
137
+ end
138
+
139
+ def assert_caught_and_not_sent
140
+ assert Honeybadger.sender.collected.empty?
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,180 @@
1
+ require 'test_helper'
2
+
3
+ class BacktraceTest < Honeybadger::UnitTest
4
+ should "parse a backtrace into lines" do
5
+ array = [
6
+ "app/models/user.rb:13:in `magic'",
7
+ "app/controllers/users_controller.rb:8:in `index'"
8
+ ]
9
+
10
+ backtrace = Honeybadger::Backtrace.parse(array)
11
+
12
+ line = backtrace.lines.first
13
+ assert_equal '13', line.number
14
+ assert_equal 'app/models/user.rb', line.file
15
+ assert_equal 'magic', line.method
16
+
17
+ line = backtrace.lines.last
18
+ assert_equal '8', line.number
19
+ assert_equal 'app/controllers/users_controller.rb', line.file
20
+ assert_equal 'index', line.method
21
+ end
22
+
23
+ should "parse a windows backtrace into lines" do
24
+ array = [
25
+ "C:/Program Files/Server/app/models/user.rb:13:in `magic'",
26
+ "C:/Program Files/Server/app/controllers/users_controller.rb:8:in `index'"
27
+ ]
28
+
29
+ backtrace = Honeybadger::Backtrace.parse(array)
30
+
31
+ line = backtrace.lines.first
32
+ assert_equal '13', line.number
33
+ assert_equal 'C:/Program Files/Server/app/models/user.rb', line.file
34
+ assert_equal 'magic', line.method
35
+
36
+ line = backtrace.lines.last
37
+ assert_equal '8', line.number
38
+ assert_equal 'C:/Program Files/Server/app/controllers/users_controller.rb', line.file
39
+ assert_equal 'index', line.method
40
+ end
41
+
42
+ should "be equal with equal lines" do
43
+ one = build_backtrace_array
44
+ two = one.dup
45
+
46
+ assert_equal Honeybadger::Backtrace.parse(one), Honeybadger::Backtrace.parse(two)
47
+ end
48
+
49
+ should "parse massive one-line exceptions into multiple lines" do
50
+ original_backtrace = Honeybadger::Backtrace.
51
+ parse(["one:1:in `one'\n two:2:in `two'\n three:3:in `three`"])
52
+ expected_backtrace = Honeybadger::Backtrace.
53
+ parse(["one:1:in `one'", "two:2:in `two'", "three:3:in `three`"])
54
+
55
+ assert_equal expected_backtrace, original_backtrace
56
+ end
57
+
58
+ context "with a project root" do
59
+ setup do
60
+ @project_root = '/some/path'
61
+ Honeybadger.configure {|config| config.project_root = @project_root }
62
+ end
63
+
64
+ teardown do
65
+ reset_config
66
+ end
67
+
68
+ should "filter out the project root" do
69
+ backtrace_with_root = Honeybadger::Backtrace.parse(
70
+ ["#{@project_root}/app/models/user.rb:7:in `latest'",
71
+ "#{@project_root}/app/controllers/users_controller.rb:13:in `index'",
72
+ "/lib/something.rb:41:in `open'"],
73
+ :filters => default_filters)
74
+ backtrace_without_root = Honeybadger::Backtrace.parse(
75
+ ["[PROJECT_ROOT]/app/models/user.rb:7:in `latest'",
76
+ "[PROJECT_ROOT]/app/controllers/users_controller.rb:13:in `index'",
77
+ "/lib/something.rb:41:in `open'"])
78
+
79
+ assert_equal backtrace_without_root, backtrace_with_root
80
+ end
81
+ end
82
+
83
+ context "with a project root equals to a part of file name" do
84
+ setup do
85
+ # Heroku-like
86
+ @project_root = '/app'
87
+ Honeybadger.configure {|config| config.project_root = @project_root }
88
+ end
89
+
90
+ teardown do
91
+ reset_config
92
+ end
93
+
94
+ should "filter out the project root" do
95
+ backtrace_with_root = Honeybadger::Backtrace.parse(
96
+ ["#{@project_root}/app/models/user.rb:7:in `latest'",
97
+ "#{@project_root}/app/controllers/users_controller.rb:13:in `index'",
98
+ "/lib/something.rb:41:in `open'"],
99
+ :filters => default_filters)
100
+ backtrace_without_root = Honeybadger::Backtrace.parse(
101
+ ["[PROJECT_ROOT]/app/models/user.rb:7:in `latest'",
102
+ "[PROJECT_ROOT]/app/controllers/users_controller.rb:13:in `index'",
103
+ "/lib/something.rb:41:in `open'"])
104
+
105
+ assert_equal backtrace_without_root, backtrace_with_root
106
+ end
107
+ end
108
+
109
+ context "with a blank project root" do
110
+ setup do
111
+ Honeybadger.configure {|config| config.project_root = '' }
112
+ end
113
+
114
+ teardown do
115
+ reset_config
116
+ end
117
+
118
+ should "not filter line numbers with respect to any project root" do
119
+ backtrace = ["/app/models/user.rb:7:in `latest'",
120
+ "/app/controllers/users_controller.rb:13:in `index'",
121
+ "/lib/something.rb:41:in `open'"]
122
+
123
+ backtrace_with_root =
124
+ Honeybadger::Backtrace.parse(backtrace, :filters => default_filters)
125
+
126
+ backtrace_without_root =
127
+ Honeybadger::Backtrace.parse(backtrace)
128
+
129
+ assert_equal backtrace_without_root, backtrace_with_root
130
+ end
131
+ end
132
+
133
+ should "remove notifier trace" do
134
+ inside_notifier = ['lib/honeybadger.rb:13:in `voodoo`']
135
+ outside_notifier = ['users_controller:8:in `index`']
136
+
137
+ without_inside = Honeybadger::Backtrace.parse(outside_notifier)
138
+ with_inside = Honeybadger::Backtrace.parse(inside_notifier + outside_notifier,
139
+ :filters => default_filters)
140
+
141
+ assert_equal without_inside, with_inside
142
+ end
143
+
144
+ should "run filters on the backtrace" do
145
+ filters = [lambda { |line| line.sub('foo', 'bar') }]
146
+ input = Honeybadger::Backtrace.parse(["foo:13:in `one'", "baz:14:in `two'"],
147
+ :filters => filters)
148
+ expected = Honeybadger::Backtrace.parse(["bar:13:in `one'", "baz:14:in `two'"])
149
+ assert_equal expected, input
150
+ end
151
+
152
+ should "alias #to_ary as #to_a" do
153
+ backtrace = Honeybadger::Backtrace.parse(build_backtrace_array)
154
+
155
+ assert_equal backtrace.to_a, backtrace.to_ary
156
+ end
157
+
158
+ should "generate json from to_array template" do
159
+ backtrace = Honeybadger::Backtrace.parse(build_backtrace_array)
160
+ array = [{'foo' => 'bar'}]
161
+ backtrace.expects(:to_ary).once.returns(array)
162
+ json = backtrace.to_json
163
+
164
+ payload = nil
165
+ assert_nothing_raised do
166
+ payload = JSON.parse(json)
167
+ end
168
+
169
+ assert_equal payload, array
170
+ end
171
+
172
+ def build_backtrace_array
173
+ ["app/models/user.rb:13:in `magic'",
174
+ "app/controllers/users_controller.rb:8:in `index'"]
175
+ end
176
+
177
+ def default_filters
178
+ Honeybadger::Configuration::DEFAULT_BACKTRACE_FILTERS
179
+ end
180
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ require 'capistrano/configuration'
4
+ require 'honeybadger/capistrano'
5
+
6
+ class CapistranoTest < Honeybadger::UnitTest
7
+ def setup
8
+ super
9
+ reset_config
10
+
11
+ @configuration = Capistrano::Configuration.new
12
+ Honeybadger::Capistrano.load_into(@configuration)
13
+ @configuration.dry_run = true
14
+ end
15
+
16
+ should "define honeybadger:deploy task" do
17
+ assert_not_nil @configuration.find_task('honeybadger:deploy')
18
+ end
19
+
20
+ should "log when calling honeybadger:deploy task" do
21
+ @configuration.set(:current_revision, '084505b1c0e0bcf1526e673bb6ac99fbcb18aecc')
22
+ @configuration.set(:repository, 'repository')
23
+ @configuration.set(:current_release, '/home/deploy/rails_app/hoptoad')
24
+ io = StringIO.new
25
+ logger = Capistrano::Logger.new(:output => io)
26
+ logger.level = Capistrano::Logger::MAX_LEVEL
27
+
28
+ @configuration.logger = logger
29
+ @configuration.find_and_execute_task('honeybadger:deploy')
30
+
31
+ assert io.string.include?('** Notifying Honeybadger of Deploy')
32
+ assert io.string.include?('** Honeybadger Notification Complete')
33
+ end
34
+ end
@@ -0,0 +1,201 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < Honeybadger::UnitTest
4
+ include DefinesConstants
5
+
6
+ should "provide default values" do
7
+ assert_config_default :proxy_host, nil
8
+ assert_config_default :proxy_port, nil
9
+ assert_config_default :proxy_user, nil
10
+ assert_config_default :proxy_pass, nil
11
+ assert_config_default :project_root, nil
12
+ assert_config_default :environment_name, nil
13
+ assert_config_default :logger, nil
14
+ assert_config_default :notifier_version, Honeybadger::VERSION
15
+ assert_config_default :notifier_name, 'Honeybadger Notifier'
16
+ assert_config_default :notifier_url, 'https://github.com/honeybadger/honeybadger'
17
+ assert_config_default :secure, false
18
+ assert_config_default :host, 'api.honeybadger.io'
19
+ assert_config_default :http_open_timeout, 2
20
+ assert_config_default :http_read_timeout, 5
21
+ assert_config_default :ignore_by_filters, []
22
+ assert_config_default :ignore_user_agent, []
23
+ assert_config_default :params_filters,
24
+ Honeybadger::Configuration::DEFAULT_PARAMS_FILTERS
25
+ assert_config_default :backtrace_filters,
26
+ Honeybadger::Configuration::DEFAULT_BACKTRACE_FILTERS
27
+ assert_config_default :ignore,
28
+ Honeybadger::Configuration::IGNORE_DEFAULT
29
+ assert_config_default :framework, 'Standalone'
30
+ end
31
+
32
+ should "provide default values for secure connections" do
33
+ config = Honeybadger::Configuration.new
34
+ config.secure = true
35
+ assert_equal 443, config.port
36
+ assert_equal 'https', config.protocol
37
+ end
38
+
39
+ should "provide default values for insecure connections" do
40
+ config = Honeybadger::Configuration.new
41
+ config.secure = false
42
+ assert_equal 80, config.port
43
+ assert_equal 'http', config.protocol
44
+ end
45
+
46
+ should "not cache inferred ports" do
47
+ config = Honeybadger::Configuration.new
48
+ config.secure = false
49
+ config.port
50
+ config.secure = true
51
+ assert_equal 443, config.port
52
+ end
53
+
54
+ should "allow values to be overwritten" do
55
+ assert_config_overridable :proxy_host
56
+ assert_config_overridable :proxy_port
57
+ assert_config_overridable :proxy_user
58
+ assert_config_overridable :proxy_pass
59
+ assert_config_overridable :secure
60
+ assert_config_overridable :host
61
+ assert_config_overridable :port
62
+ assert_config_overridable :http_open_timeout
63
+ assert_config_overridable :http_read_timeout
64
+ assert_config_overridable :project_root
65
+ assert_config_overridable :notifier_version
66
+ assert_config_overridable :notifier_name
67
+ assert_config_overridable :notifier_url
68
+ assert_config_overridable :environment_name
69
+ assert_config_overridable :logger
70
+ end
71
+
72
+ should "have an api key" do
73
+ assert_config_overridable :api_key
74
+ end
75
+
76
+ should "act like a hash" do
77
+ config = Honeybadger::Configuration.new
78
+ hash = config.to_hash
79
+ [:api_key, :backtrace_filters, :development_environments,
80
+ :environment_name, :host, :http_open_timeout,
81
+ :http_read_timeout, :ignore, :ignore_by_filters, :ignore_user_agent,
82
+ :notifier_name, :notifier_url, :notifier_version, :params_filters,
83
+ :project_root, :port, :protocol, :proxy_host, :proxy_pass, :proxy_port,
84
+ :proxy_user, :secure].each do |option|
85
+ assert_equal config[option], hash[option], "Wrong value for #{option}"
86
+ end
87
+ end
88
+
89
+ should "be mergable" do
90
+ config = Honeybadger::Configuration.new
91
+ hash = config.to_hash
92
+ assert_equal hash.merge(:key => 'value'), config.merge(:key => 'value')
93
+ end
94
+
95
+ should "allow param filters to be appended" do
96
+ assert_appends_value :params_filters
97
+ end
98
+
99
+ should "allow ignored user agents to be appended" do
100
+ assert_appends_value :ignore_user_agent
101
+ end
102
+
103
+ should "allow backtrace filters to be appended" do
104
+ assert_appends_value(:backtrace_filters) do |config|
105
+ new_filter = lambda {}
106
+ config.filter_backtrace(&new_filter)
107
+ new_filter
108
+ end
109
+ end
110
+
111
+ should "allow ignore by filters to be appended" do
112
+ assert_appends_value(:ignore_by_filters) do |config|
113
+ new_filter = lambda {}
114
+ config.ignore_by_filter(&new_filter)
115
+ new_filter
116
+ end
117
+ end
118
+
119
+ should "allow ignored exceptions to be appended" do
120
+ config = Honeybadger::Configuration.new
121
+ original_filters = config.ignore.dup
122
+ new_filter = 'hello'
123
+ config.ignore << new_filter
124
+ assert_same_elements original_filters + [new_filter], config.ignore
125
+ end
126
+
127
+ should "allow ignored exceptions to be replaced" do
128
+ assert_replaces(:ignore, :ignore_only=)
129
+ end
130
+
131
+ should "allow ignored user agents to be replaced" do
132
+ assert_replaces(:ignore_user_agent, :ignore_user_agent_only=)
133
+ end
134
+
135
+ should "use development and test as development environments by default" do
136
+ config = Honeybadger::Configuration.new
137
+ assert_same_elements %w(development test cucumber), config.development_environments
138
+ end
139
+
140
+ should "be public in a public environment" do
141
+ config = Honeybadger::Configuration.new
142
+ config.development_environments = %w(development)
143
+ config.environment_name = 'production'
144
+ assert config.public?
145
+ end
146
+
147
+ should "not be public in a development environment" do
148
+ config = Honeybadger::Configuration.new
149
+ config.development_environments = %w(staging)
150
+ config.environment_name = 'staging'
151
+ assert !config.public?
152
+ end
153
+
154
+ should "be public without an environment name" do
155
+ config = Honeybadger::Configuration.new
156
+ assert config.public?
157
+ end
158
+
159
+ should "use the assigned logger if set" do
160
+ config = Honeybadger::Configuration.new
161
+ config.logger = "CUSTOM LOGGER"
162
+ assert_equal "CUSTOM LOGGER", config.logger
163
+ end
164
+
165
+ should 'give a new instance if non defined' do
166
+ Honeybadger.configuration = nil
167
+ assert_kind_of Honeybadger::Configuration, Honeybadger.configuration
168
+ end
169
+
170
+ def assert_config_default(option, default_value, config = nil)
171
+ config ||= Honeybadger::Configuration.new
172
+ assert_equal default_value, config.send(option)
173
+ end
174
+
175
+ def assert_config_overridable(option, value = 'a value')
176
+ config = Honeybadger::Configuration.new
177
+ config.send(:"#{option}=", value)
178
+ assert_equal value, config.send(option)
179
+ end
180
+
181
+ def assert_appends_value(option, &block)
182
+ config = Honeybadger::Configuration.new
183
+ original_values = config.send(option).dup
184
+ block ||= lambda do |config|
185
+ new_value = 'hello'
186
+ config.send(option) << new_value
187
+ new_value
188
+ end
189
+ new_value = block.call(config)
190
+ assert_same_elements original_values + [new_value], config.send(option)
191
+ end
192
+
193
+ def assert_replaces(option, setter)
194
+ config = Honeybadger::Configuration.new
195
+ new_value = 'hello'
196
+ config.send(setter, [new_value])
197
+ assert_equal [new_value], config.send(option)
198
+ config.send(setter, new_value)
199
+ assert_equal [new_value], config.send(option)
200
+ end
201
+ end