honeybadger 1.8.1 → 1.9.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.md +14 -0
  2. data/Gemfile.lock +61 -19
  3. data/Guardfile +4 -4
  4. data/MIT-LICENSE +1 -0
  5. data/README.md +2 -2
  6. data/Rakefile +4 -14
  7. data/features/rails.feature +1 -1
  8. data/gemfiles/rack.gemfile.lock +62 -27
  9. data/gemfiles/rails2.3.gemfile.lock +73 -36
  10. data/gemfiles/rails3.0.gemfile.lock +59 -26
  11. data/gemfiles/rails3.1.gemfile.lock +59 -26
  12. data/gemfiles/rails3.2.gemfile.lock +63 -30
  13. data/gemfiles/rails4.gemfile.lock +69 -36
  14. data/gemfiles/rake.gemfile.lock +62 -27
  15. data/gemfiles/sinatra.gemfile.lock +62 -27
  16. data/honeybadger.gemspec +31 -17
  17. data/lib/honeybadger.rb +2 -3
  18. data/lib/honeybadger/array.rb +53 -0
  19. data/lib/honeybadger/configuration.rb +19 -2
  20. data/lib/honeybadger/monitor.rb +16 -0
  21. data/lib/honeybadger/monitor/railtie.rb +52 -0
  22. data/lib/honeybadger/monitor/sender.rb +33 -0
  23. data/lib/honeybadger/monitor/worker.rb +71 -0
  24. data/lib/honeybadger/railtie.rb +10 -0
  25. data/lib/honeybadger/sender.rb +60 -41
  26. data/{test/unit/backtrace_test.rb → spec/honeybadger/backtrace_spec.rb} +69 -71
  27. data/{test/unit/capistrano_test.rb → spec/honeybadger/capistrano_spec.rb} +8 -9
  28. data/{test/unit/configuration_test.rb → spec/honeybadger/configuration_spec.rb} +85 -59
  29. data/spec/honeybadger/logger_spec.rb +65 -0
  30. data/spec/honeybadger/monitor/worker_spec.rb +189 -0
  31. data/{test/unit/notice_test.rb → spec/honeybadger/notice_spec.rb} +169 -185
  32. data/spec/honeybadger/notifier_spec.rb +252 -0
  33. data/spec/honeybadger/rack_spec.rb +84 -0
  34. data/{test/unit/rails/action_controller_catcher_test.rb → spec/honeybadger/rails/action_controller_spec.rb} +65 -57
  35. data/{test/unit/rails_test.rb → spec/honeybadger/rails_spec.rb} +8 -8
  36. data/spec/honeybadger/sender_spec.rb +249 -0
  37. data/spec/honeybadger_tasks_spec.rb +165 -0
  38. data/spec/spec_helper.rb +18 -0
  39. data/spec/support/array_including.rb +31 -0
  40. data/spec/support/backtraced_exception.rb +9 -0
  41. data/spec/support/collected_sender.rb +12 -0
  42. data/spec/support/defines_constants.rb +18 -0
  43. data/{test/test_helper.rb → spec/support/helpers.rb} +8 -61
  44. metadata +93 -45
  45. data/test/unit/honeybadger_tasks_test.rb +0 -167
  46. data/test/unit/logger_test.rb +0 -74
  47. data/test/unit/notifier_test.rb +0 -265
  48. data/test/unit/rack_test.rb +0 -88
  49. data/test/unit/sender_test.rb +0 -290
@@ -1,167 +0,0 @@
1
- require 'test_helper'
2
- require 'rubygems'
3
-
4
- require File.expand_path('../../../lib/honeybadger_tasks', __FILE__)
5
- require 'fakeweb'
6
-
7
- FakeWeb.allow_net_connect = false
8
-
9
- class HoneybadgerTasksTest < Test::Unit::TestCase
10
- def successful_response(body = "")
11
- response = Net::HTTPSuccess.new('1.2', '200', 'OK')
12
- response.stubs(:body).returns(body)
13
- return response
14
- end
15
-
16
- def unsuccessful_response(body = "")
17
- response = Net::HTTPClientError.new('1.2', '200', 'OK')
18
- response.stubs(:body).returns(body)
19
- return response
20
- end
21
-
22
- context "being quiet" do
23
- setup { HoneybadgerTasks.stubs(:puts) }
24
-
25
- context "in a configured project" do
26
- setup { Honeybadger.configure { |config| config.api_key = "1234123412341234" } }
27
-
28
- context "on deploy({})" do
29
- setup { @output = HoneybadgerTasks.deploy({}) }
30
-
31
- before_should "complain about missing rails env" do
32
- HoneybadgerTasks.expects(:puts).with(regexp_matches(/which environment/i))
33
- end
34
-
35
- should "return false" do
36
- assert !@output
37
- end
38
- end
39
-
40
- context "given an optional HTTP proxy and valid options" do
41
- setup do
42
- @response = stub("response", :body => "stub body")
43
- @http_proxy = stub("proxy", :request => @response,
44
- :use_ssl= => nil,
45
- :ca_file= => nil,
46
- :verify_mode= => nil)
47
- @http_proxy_class = stub("proxy_class", :new => @http_proxy)
48
- @post = stub("post", :set_form_data => nil)
49
-
50
- @post.stubs(:[]=).with('X-API-Key', '1234123412341234').returns(true)
51
-
52
- Net::HTTP.expects(:Proxy).
53
- with(Honeybadger.configuration.proxy_host,
54
- Honeybadger.configuration.proxy_port,
55
- Honeybadger.configuration.proxy_user,
56
- Honeybadger.configuration.proxy_pass).
57
- returns(@http_proxy_class)
58
- Net::HTTP::Post.expects(:new).with("/v1/deploys").returns(@post)
59
-
60
- @options = { :environment => "staging", :dry_run => false }
61
- end
62
-
63
- context "performing a dry run" do
64
- setup { @output = HoneybadgerTasks.deploy(@options.merge(:dry_run => true)) }
65
-
66
- should "return true without performing any actual request" do
67
- assert_equal true, @output
68
- assert_received(@http_proxy, :request) do |expects|
69
- expects.never
70
- end
71
- end
72
- end
73
-
74
- context "on deploy(options)" do
75
- setup do
76
- @output = HoneybadgerTasks.deploy(@options)
77
- end
78
-
79
- before_should "post to https://api.honeybadger.io:443/v1/deploys" do
80
- @http_proxy_class.expects(:new).with("api.honeybadger.io", 443).returns(@http_proxy)
81
- @post.expects(:set_form_data).with(kind_of(Hash))
82
- @http_proxy.expects(:request).with(any_parameters).returns(successful_response)
83
- end
84
-
85
- before_should "use send the environment param" do
86
- @post.expects(:set_form_data).
87
- with(has_entries("deploy[environment]" => "staging"))
88
- end
89
-
90
- [:local_username, :repository, :revision].each do |key|
91
- before_should "use send the #{key} param if it's passed in." do
92
- @options[key] = "value"
93
- @post.expects(:set_form_data).
94
- with(has_entries("deploy[#{key}]" => "value"))
95
- end
96
- end
97
-
98
- before_should "puts the response body on success" do
99
- HoneybadgerTasks.expects(:puts).with("Succesfully recorded deployment")
100
- @http_proxy.expects(:request).with(any_parameters).returns(successful_response('body'))
101
- end
102
-
103
- before_should "puts the response body on failure" do
104
- HoneybadgerTasks.expects(:puts).with("body")
105
- @http_proxy.expects(:request).with(any_parameters).returns(unsuccessful_response('body'))
106
- end
107
-
108
- should "return false on failure", :before => lambda {
109
- @http_proxy.expects(:request).with(any_parameters).returns(unsuccessful_response('body'))
110
- } do
111
- assert !@output
112
- end
113
-
114
- should "return true on success", :before => lambda {
115
- @http_proxy.expects(:request).with(any_parameters).returns(successful_response('body'))
116
- } do
117
- assert @output
118
- end
119
- end
120
- end
121
- end
122
-
123
- context "in a configured project with custom host" do
124
- setup do
125
- Honeybadger.configure do |config|
126
- config.api_key = "1234123412341234"
127
- config.host = "custom.host"
128
- config.secure = false
129
- end
130
- end
131
-
132
- context "on deploy(:environment => 'staging')" do
133
- setup { @output = HoneybadgerTasks.deploy(:environment => "staging") }
134
-
135
- before_should "post to the custom host" do
136
- @post = stub("post", :set_form_data => nil)
137
- @http_proxy = stub("proxy", :request => @response)
138
-
139
- @post.stubs(:[]=).with('X-API-Key', '1234123412341234').returns(true)
140
-
141
- @http_proxy_class = stub("proxy_class", :new => @http_proxy)
142
- @http_proxy_class.expects(:new).with("custom.host", 80).returns(@http_proxy)
143
- Net::HTTP.expects(:Proxy).with(any_parameters).returns(@http_proxy_class)
144
- Net::HTTP::Post.expects(:new).with("/v1/deploys").returns(@post)
145
- @post.expects(:set_form_data).with(kind_of(Hash))
146
- @http_proxy.expects(:request).with(any_parameters).returns(successful_response)
147
- end
148
- end
149
- end
150
-
151
- context "when not configured" do
152
- setup { Honeybadger.configure { |config| config.api_key = "" } }
153
-
154
- context "on deploy(:environment => 'staging')" do
155
- setup { @output = HoneybadgerTasks.deploy(:environment => "staging") }
156
-
157
- before_should "complain about missing api key" do
158
- HoneybadgerTasks.expects(:puts).with(regexp_matches(/api key/i))
159
- end
160
-
161
- should "return false" do
162
- assert !@output
163
- end
164
- end
165
- end
166
- end
167
- end
@@ -1,74 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LoggerTest < Test::Unit::TestCase
4
- def stub_http(response, body = nil)
5
- response.stubs(:body => body) if body
6
- @http = stub(:post => response,
7
- :read_timeout= => nil,
8
- :open_timeout= => nil,
9
- :use_ssl= => nil,
10
- :ca_file= => nil,
11
- :verify_mode= => nil)
12
- Net::HTTP.stubs(:new).returns(@http)
13
- end
14
-
15
- def send_notice
16
- Honeybadger.sender.send_to_honeybadger('data')
17
- end
18
-
19
- def stub_verbose_log
20
- Honeybadger.stubs(:write_verbose_log)
21
- end
22
-
23
- def configure
24
- Honeybadger.configure { |config| }
25
- end
26
-
27
- should "report that notifier is ready when configured" do
28
- stub_verbose_log
29
- configure
30
- assert_logged /Notifier (.*) ready/
31
- end
32
-
33
- should "not report that notifier is ready when internally configured" do
34
- stub_verbose_log
35
- Honeybadger.configure(true) { |config| }
36
- assert_not_logged /.*/
37
- end
38
-
39
- should "print environment info a successful notification without a body" do
40
- reset_config
41
- stub_verbose_log
42
- stub_http(Net::HTTPSuccess)
43
- send_notice
44
- assert_logged /Environment Info:/
45
- assert_not_logged /Response from Honeybadger:/
46
- end
47
-
48
- should "print environment info on a failed notification without a body" do
49
- reset_config
50
- stub_verbose_log
51
- stub_http(Net::HTTPError)
52
- send_notice
53
- assert_logged /Environment Info:/
54
- assert_not_logged /Response from Honeybadger:/
55
- end
56
-
57
- should "print environment info and response on a success with a body" do
58
- reset_config
59
- stub_verbose_log
60
- stub_http(Net::HTTPSuccess, '{}')
61
- send_notice
62
- assert_logged /Environment Info:/
63
- assert_logged /Response from Honeybadger:/
64
- end
65
-
66
- should "print environment info and response on a failure with a body" do
67
- reset_config
68
- stub_verbose_log
69
- stub_http(Net::HTTPError, '{}')
70
- send_notice
71
- assert_logged /Environment Info:/
72
- assert_logged /Response from Honeybadger:/
73
- end
74
- end
@@ -1,265 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NotifierTest < Test::Unit::TestCase
4
- class OriginalException < Exception
5
- end
6
-
7
- class ContinuedException < Exception
8
- end
9
-
10
- def setup
11
- super
12
- reset_config
13
- end
14
-
15
- def assert_sent(notice, notice_args)
16
- assert_received(Honeybadger::Notice, :new) {|expect| expect.with(has_entries(notice_args)) }
17
- assert_received(Honeybadger.sender, :send_to_honeybadger) {|expect| expect.with(notice) }
18
- end
19
-
20
- def set_public_env
21
- Honeybadger.configure { |config| config.environment_name = 'production' }
22
- end
23
-
24
- def set_development_env
25
- Honeybadger.configure { |config| config.environment_name = 'development' }
26
- end
27
-
28
- should "yield and save a configuration when configuring" do
29
- yielded_configuration = nil
30
- Honeybadger.configure do |config|
31
- yielded_configuration = config
32
- end
33
-
34
- assert_kind_of Honeybadger::Configuration, yielded_configuration
35
- assert_equal yielded_configuration, Honeybadger.configuration
36
- end
37
-
38
- should "not remove existing config options when configuring twice" do
39
- first_config = nil
40
- Honeybadger.configure do |config|
41
- first_config = config
42
- end
43
- Honeybadger.configure do |config|
44
- assert_equal first_config, config
45
- end
46
- end
47
-
48
- should "configure the sender" do
49
- sender = stub_sender
50
- Honeybadger::Sender.stubs(:new => sender)
51
- configuration = nil
52
-
53
- Honeybadger.configure { |yielded_config| configuration = yielded_config }
54
-
55
- assert_received(Honeybadger::Sender, :new) { |expect| expect.with(configuration) }
56
- assert_equal sender, Honeybadger.sender
57
- end
58
-
59
- should "create and send a notice asynchronously" do
60
- set_public_env
61
- notice = stub_notice!
62
- notice_args = { :error_message => 'uh oh' }
63
-
64
- async_expectation = stub(:received => true)
65
- async_handler = Proc.new do |notice|
66
- async_expectation.received
67
- notice.deliver
68
- end
69
-
70
- Honeybadger.configure do |config|
71
- config.async = async_handler
72
- end
73
-
74
- stub_sender!
75
-
76
- Honeybadger.notify(notice_args)
77
-
78
- assert_received(async_expectation, :received)
79
- assert_sent(notice, notice_args)
80
- end
81
-
82
- should "create and send a notice for an exception" do
83
- set_public_env
84
- exception = build_exception
85
- stub_sender!
86
- notice = stub_notice!
87
-
88
- Honeybadger.notify(exception)
89
-
90
- assert_sent notice, :exception => exception
91
- end
92
-
93
- should "create and send a notice for a hash" do
94
- set_public_env
95
- notice = stub_notice!
96
- notice_args = { :error_message => 'uh oh' }
97
- stub_sender!
98
-
99
- Honeybadger.notify(notice_args)
100
-
101
- assert_sent(notice, notice_args)
102
- end
103
-
104
- should "not pass the hash as an exception when sending a notice for it" do
105
- set_public_env
106
- notice = stub_notice!
107
- notice_args = { :error_message => 'uh oh' }
108
- stub_sender!
109
-
110
- Honeybadger.notify(notice_args)
111
-
112
- assert_received(Honeybadger::Notice, :new) {|expect| expect.with(Not(has_key(:exception))) }
113
- end
114
-
115
- should "create and send a notice for an exception that responds to to_hash" do
116
- set_public_env
117
- exception = build_exception
118
- notice = stub_notice!
119
- notice_args = { :error_message => 'uh oh' }
120
- exception.stubs(:to_hash).returns(notice_args)
121
- stub_sender!
122
-
123
- Honeybadger.notify(exception)
124
-
125
- assert_sent(notice, notice_args.merge(:exception => exception))
126
- end
127
-
128
- should "create and sent a notice for an exception and hash" do
129
- set_public_env
130
- exception = build_exception
131
- notice = stub_notice!
132
- notice_args = { :error_message => 'uh oh' }
133
- stub_sender!
134
-
135
- Honeybadger.notify(exception, notice_args)
136
-
137
- assert_sent(notice, notice_args.merge(:exception => exception))
138
- end
139
-
140
- should "not create a notice in a development environment" do
141
- set_development_env
142
- sender = stub_sender!
143
-
144
- Honeybadger.notify(build_exception)
145
- Honeybadger.notify_or_ignore(build_exception)
146
-
147
- assert_received(sender, :send_to_honeybadger) {|expect| expect.never }
148
- end
149
-
150
- should "not deliver an ignored exception when notifying implicitly" do
151
- set_public_env
152
- exception = build_exception
153
- sender = stub_sender!
154
- notice = stub_notice!
155
- notice.stubs(:ignore? => true)
156
-
157
- Honeybadger.notify_or_ignore(exception)
158
-
159
- assert_received(sender, :send_to_honeybadger) {|expect| expect.never }
160
- end
161
-
162
- should "deliver an ignored exception when notifying manually" do
163
- set_public_env
164
- exception = build_exception
165
- sender = stub_sender!
166
- notice = stub_notice!
167
- notice.stubs(:ignore? => true)
168
-
169
- Honeybadger.notify(exception)
170
-
171
- assert_sent(notice, :exception => exception)
172
- end
173
-
174
- should "pass config to created notices" do
175
- exception = build_exception
176
- config_opts = { 'one' => 'two', 'three' => 'four' }
177
- notice = stub_notice!
178
- stub_sender!
179
- Honeybadger.configuration = stub('config', :merge => config_opts, :public? => true, :async? => false)
180
-
181
- Honeybadger.notify(exception)
182
-
183
- assert_received(Honeybadger::Notice, :new) do |expect|
184
- expect.with(has_entries(config_opts))
185
- end
186
- end
187
-
188
- context "building notice JSON for an exception" do
189
- setup do
190
- @params = { :controller => "users", :action => "create" }
191
- @exception = build_exception
192
- @hash = Honeybadger.build_lookup_hash_for(@exception, @params)
193
- end
194
-
195
- should "set action" do
196
- assert_equal @params[:action], @hash[:action]
197
- end
198
-
199
- should "set controller" do
200
- assert_equal @params[:controller], @hash[:component]
201
- end
202
-
203
- should "set line number" do
204
- assert @hash[:line_number] =~ /\d+/
205
- end
206
-
207
- should "set file" do
208
- assert_match /honeybadger\/rack_test\.rb$/, @hash[:file]
209
- end
210
-
211
- should "set environment_name to production" do
212
- assert_equal 'production', @hash[:environment_name]
213
- end
214
-
215
- should "set error class" do
216
- assert_equal @exception.class.to_s, @hash[:error_class]
217
- end
218
-
219
- should "not set file or line number with no backtrace" do
220
- @exception.stubs(:backtrace).returns([])
221
-
222
- @hash = Honeybadger.build_lookup_hash_for(@exception)
223
-
224
- assert_nil @hash[:line_number]
225
- assert_nil @hash[:file]
226
- end
227
-
228
- should "not set action or controller when not provided" do
229
- @hash = Honeybadger.build_lookup_hash_for(@exception)
230
-
231
- assert_nil @hash[:action]
232
- assert_nil @hash[:controller]
233
- end
234
-
235
- context "when an exception that provides #original_exception is raised" do
236
- setup do
237
- @exception.stubs(:original_exception).returns(begin
238
- raise NotifierTest::OriginalException.new
239
- rescue Exception => e
240
- e
241
- end)
242
- end
243
-
244
- should "unwrap exceptions that provide #original_exception" do
245
- @hash = Honeybadger.build_lookup_hash_for(@exception)
246
- assert_equal "NotifierTest::OriginalException", @hash[:error_class]
247
- end
248
- end
249
-
250
- context "when an exception that provides #continued_exception is raised" do
251
- setup do
252
- @exception.stubs(:continued_exception).returns(begin
253
- raise NotifierTest::ContinuedException.new
254
- rescue Exception => e
255
- e
256
- end)
257
- end
258
-
259
- should "unwrap exceptions that provide #continued_exception" do
260
- @hash = Honeybadger.build_lookup_hash_for(@exception)
261
- assert_equal "NotifierTest::ContinuedException", @hash[:error_class]
262
- end
263
- end
264
- end
265
- end