honeybadger 1.16.7 → 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +19 -0
  3. data/README.md +37 -16
  4. data/bin/honeybadger +5 -0
  5. data/lib/honeybadger.rb +167 -191
  6. data/lib/honeybadger/agent.rb +136 -0
  7. data/lib/honeybadger/backend.rb +26 -0
  8. data/lib/honeybadger/backend/base.rb +66 -0
  9. data/lib/honeybadger/backend/debug.rb +12 -0
  10. data/lib/honeybadger/backend/null.rb +16 -0
  11. data/lib/honeybadger/backend/server.rb +51 -0
  12. data/lib/honeybadger/backend/test.rb +24 -0
  13. data/lib/honeybadger/backtrace.rb +29 -24
  14. data/lib/honeybadger/cli.rb +367 -0
  15. data/lib/honeybadger/config.rb +333 -0
  16. data/lib/honeybadger/config/callbacks.rb +70 -0
  17. data/lib/honeybadger/config/defaults.rb +175 -0
  18. data/lib/honeybadger/config/env.rb +40 -0
  19. data/lib/honeybadger/config/yaml.rb +43 -0
  20. data/lib/honeybadger/const.rb +28 -0
  21. data/lib/honeybadger/init/rails.rb +84 -0
  22. data/lib/honeybadger/init/sinatra.rb +27 -0
  23. data/lib/honeybadger/logging.rb +133 -0
  24. data/lib/honeybadger/notice.rb +243 -280
  25. data/lib/honeybadger/plugin.rb +110 -0
  26. data/lib/honeybadger/plugins/delayed_job.rb +22 -0
  27. data/lib/honeybadger/{integrations → plugins}/delayed_job/plugin.rb +6 -7
  28. data/lib/honeybadger/{integrations → plugins}/local_variables.rb +7 -8
  29. data/lib/honeybadger/{integrations → plugins}/net_http.rb +10 -8
  30. data/lib/honeybadger/plugins/passenger.rb +24 -0
  31. data/lib/honeybadger/plugins/rails.rb +61 -0
  32. data/lib/honeybadger/plugins/sidekiq.rb +35 -0
  33. data/lib/honeybadger/{integrations → plugins}/thor.rb +9 -8
  34. data/lib/honeybadger/{integrations → plugins}/unicorn.rb +10 -9
  35. data/lib/honeybadger/rack/error_notifier.rb +44 -27
  36. data/lib/honeybadger/rack/metrics_reporter.rb +41 -0
  37. data/lib/honeybadger/rack/request_hash.rb +50 -0
  38. data/lib/honeybadger/rack/user_feedback.rb +15 -10
  39. data/lib/honeybadger/rack/user_informer.rb +14 -3
  40. data/lib/honeybadger/trace.rb +185 -0
  41. data/lib/honeybadger/util/http.rb +79 -0
  42. data/lib/honeybadger/util/request_sanitizer.rb +35 -0
  43. data/lib/honeybadger/util/sanitizer.rb +71 -0
  44. data/lib/honeybadger/util/stats.rb +31 -0
  45. data/lib/honeybadger/version.rb +4 -0
  46. data/lib/honeybadger/worker.rb +224 -0
  47. data/lib/honeybadger/worker/batch.rb +50 -0
  48. data/lib/honeybadger/worker/metered_queue.rb +80 -0
  49. data/lib/honeybadger/worker/metrics_collection.rb +61 -0
  50. data/lib/honeybadger/worker/metrics_collector.rb +96 -0
  51. data/{lib/honeybadger/capistrano.rb → vendor/capistrano-honeybadger/lib/capistrano/honeybadger.rb} +1 -3
  52. data/vendor/capistrano-honeybadger/lib/capistrano/tasks/deploy.cap +76 -0
  53. data/vendor/capistrano-honeybadger/lib/honeybadger/capistrano.rb +2 -0
  54. data/{lib → vendor/capistrano-honeybadger/lib}/honeybadger/capistrano/legacy.rb +16 -15
  55. data/vendor/thor/lib/thor.rb +484 -0
  56. data/vendor/thor/lib/thor/actions.rb +319 -0
  57. data/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  58. data/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  59. data/vendor/thor/lib/thor/actions/directory.rb +118 -0
  60. data/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  61. data/vendor/thor/lib/thor/actions/file_manipulation.rb +316 -0
  62. data/vendor/thor/lib/thor/actions/inject_into_file.rb +107 -0
  63. data/vendor/thor/lib/thor/base.rb +656 -0
  64. data/vendor/thor/lib/thor/command.rb +133 -0
  65. data/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  66. data/vendor/thor/lib/thor/core_ext/io_binary_read.rb +10 -0
  67. data/vendor/thor/lib/thor/core_ext/ordered_hash.rb +98 -0
  68. data/vendor/thor/lib/thor/error.rb +32 -0
  69. data/vendor/thor/lib/thor/group.rb +281 -0
  70. data/vendor/thor/lib/thor/invocation.rb +178 -0
  71. data/vendor/thor/lib/thor/line_editor.rb +17 -0
  72. data/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  73. data/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  74. data/vendor/thor/lib/thor/parser.rb +4 -0
  75. data/vendor/thor/lib/thor/parser/argument.rb +73 -0
  76. data/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  77. data/vendor/thor/lib/thor/parser/option.rb +125 -0
  78. data/vendor/thor/lib/thor/parser/options.rb +218 -0
  79. data/vendor/thor/lib/thor/rake_compat.rb +71 -0
  80. data/vendor/thor/lib/thor/runner.rb +322 -0
  81. data/vendor/thor/lib/thor/shell.rb +81 -0
  82. data/vendor/thor/lib/thor/shell/basic.rb +421 -0
  83. data/vendor/thor/lib/thor/shell/color.rb +149 -0
  84. data/vendor/thor/lib/thor/shell/html.rb +126 -0
  85. data/vendor/thor/lib/thor/util.rb +267 -0
  86. data/vendor/thor/lib/thor/version.rb +3 -0
  87. metadata +97 -305
  88. data/Appraisals +0 -95
  89. data/CHANGELOG.md +0 -422
  90. data/Gemfile +0 -8
  91. data/Gemfile.lock +0 -136
  92. data/Guardfile +0 -5
  93. data/MIT-LICENSE +0 -32
  94. data/Rakefile +0 -159
  95. data/features/metal.feature +0 -20
  96. data/features/rack.feature +0 -55
  97. data/features/rails.feature +0 -343
  98. data/features/rails3.x.feature +0 -26
  99. data/features/rake.feature +0 -25
  100. data/features/sinatra.feature +0 -27
  101. data/features/standalone.feature +0 -73
  102. data/features/step_definitions/metal_steps.rb +0 -24
  103. data/features/step_definitions/rack_steps.rb +0 -18
  104. data/features/step_definitions/rails_steps.rb +0 -270
  105. data/features/step_definitions/rake_steps.rb +0 -17
  106. data/features/step_definitions/standalone_steps.rb +0 -12
  107. data/features/step_definitions/thor_steps.rb +0 -4
  108. data/features/support/env.rb +0 -22
  109. data/features/support/honeybadger_failure_shim.rb.template +0 -5
  110. data/features/support/honeybadger_shim.rb.template +0 -6
  111. data/features/support/rails.rb +0 -202
  112. data/features/support/rake/Rakefile +0 -68
  113. data/features/support/test.thor +0 -22
  114. data/features/thor.feature +0 -5
  115. data/gemfiles/binding_of_caller.gemfile +0 -13
  116. data/gemfiles/delayed_job.gemfile +0 -13
  117. data/gemfiles/rack.gemfile +0 -13
  118. data/gemfiles/rails.gemfile +0 -16
  119. data/gemfiles/rails2.3.gemfile +0 -15
  120. data/gemfiles/rails3.0.gemfile +0 -16
  121. data/gemfiles/rails3.1.gemfile +0 -16
  122. data/gemfiles/rails3.2.gemfile +0 -16
  123. data/gemfiles/rails4.0.gemfile +0 -16
  124. data/gemfiles/rails4.1.gemfile +0 -16
  125. data/gemfiles/rake.gemfile +0 -13
  126. data/gemfiles/sinatra.gemfile +0 -13
  127. data/gemfiles/standalone.gemfile +0 -12
  128. data/gemfiles/thor.gemfile +0 -13
  129. data/generators/honeybadger/honeybadger_generator.rb +0 -95
  130. data/generators/honeybadger/lib/insert_commands.rb +0 -34
  131. data/generators/honeybadger/lib/rake_commands.rb +0 -24
  132. data/generators/honeybadger/templates/capistrano_hook.rb +0 -6
  133. data/generators/honeybadger/templates/honeybadger_tasks.rake +0 -25
  134. data/generators/honeybadger/templates/initializer.rb +0 -6
  135. data/honeybadger.gemspec +0 -174
  136. data/lib/honeybadger/array.rb +0 -53
  137. data/lib/honeybadger/capistrano/tasks.rake +0 -73
  138. data/lib/honeybadger/configuration.rb +0 -397
  139. data/lib/honeybadger/dependency.rb +0 -65
  140. data/lib/honeybadger/integrations.rb +0 -9
  141. data/lib/honeybadger/integrations/delayed_job.rb +0 -20
  142. data/lib/honeybadger/integrations/passenger.rb +0 -18
  143. data/lib/honeybadger/integrations/sidekiq.rb +0 -37
  144. data/lib/honeybadger/monitor.rb +0 -17
  145. data/lib/honeybadger/monitor/railtie.rb +0 -53
  146. data/lib/honeybadger/monitor/sender.rb +0 -44
  147. data/lib/honeybadger/monitor/trace.rb +0 -187
  148. data/lib/honeybadger/monitor/worker.rb +0 -169
  149. data/lib/honeybadger/payload.rb +0 -101
  150. data/lib/honeybadger/rack.rb +0 -12
  151. data/lib/honeybadger/rails.rb +0 -45
  152. data/lib/honeybadger/rails/action_controller_catcher.rb +0 -30
  153. data/lib/honeybadger/rails/controller_methods.rb +0 -78
  154. data/lib/honeybadger/rails/middleware/exceptions_catcher.rb +0 -29
  155. data/lib/honeybadger/rails3_tasks.rb +0 -94
  156. data/lib/honeybadger/railtie.rb +0 -52
  157. data/lib/honeybadger/rake_handler.rb +0 -66
  158. data/lib/honeybadger/sender.rb +0 -185
  159. data/lib/honeybadger/shared_tasks.rb +0 -56
  160. data/lib/honeybadger/stats.rb +0 -29
  161. data/lib/honeybadger/tasks.rb +0 -95
  162. data/lib/honeybadger/user_feedback.rb +0 -8
  163. data/lib/honeybadger/user_informer.rb +0 -8
  164. data/lib/honeybadger_tasks.rb +0 -69
  165. data/lib/rails/generators/honeybadger/honeybadger_generator.rb +0 -99
  166. data/rails/init.rb +0 -1
  167. data/resources/README.md +0 -34
  168. data/script/integration_test.rb +0 -38
  169. data/spec/allocation_stats.rb +0 -32
  170. data/spec/honeybadger/backtrace_spec.rb +0 -242
  171. data/spec/honeybadger/capistrano_spec.rb +0 -36
  172. data/spec/honeybadger/configuration_spec.rb +0 -328
  173. data/spec/honeybadger/dependency_spec.rb +0 -134
  174. data/spec/honeybadger/integrations/delayed_job_spec.rb +0 -82
  175. data/spec/honeybadger/integrations/local_variables_spec.rb +0 -60
  176. data/spec/honeybadger/integrations/net_http_spec.rb +0 -29
  177. data/spec/honeybadger/integrations/passenger_spec.rb +0 -29
  178. data/spec/honeybadger/integrations/sidekiq_spec.rb +0 -60
  179. data/spec/honeybadger/integrations/thor_spec.rb +0 -32
  180. data/spec/honeybadger/integrations/unicorn_spec.rb +0 -40
  181. data/spec/honeybadger/logger_spec.rb +0 -79
  182. data/spec/honeybadger/monitor/trace_spec.rb +0 -65
  183. data/spec/honeybadger/monitor/worker_spec.rb +0 -274
  184. data/spec/honeybadger/notice_spec.rb +0 -669
  185. data/spec/honeybadger/notifier_spec.rb +0 -328
  186. data/spec/honeybadger/payload_spec.rb +0 -162
  187. data/spec/honeybadger/rack_spec.rb +0 -85
  188. data/spec/honeybadger/rails/action_controller_spec.rb +0 -328
  189. data/spec/honeybadger/rails_spec.rb +0 -37
  190. data/spec/honeybadger/sender_spec.rb +0 -317
  191. data/spec/honeybadger/stats_spec.rb +0 -57
  192. data/spec/honeybadger/user_feedback_spec.rb +0 -80
  193. data/spec/honeybadger/user_informer_spec.rb +0 -30
  194. data/spec/honeybadger_tasks_spec.rb +0 -171
  195. data/spec/spec_helper.rb +0 -24
  196. data/spec/support/array_including.rb +0 -31
  197. data/spec/support/backtraced_exception.rb +0 -9
  198. data/spec/support/collected_sender.rb +0 -12
  199. data/spec/support/defines_constants.rb +0 -18
  200. data/spec/support/helpers.rb +0 -101
@@ -1,317 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Honeybadger::Sender do
4
- before { reset_config }
5
- let(:http) { stub_http }
6
-
7
- it "makes a single request when sending notices" do
8
- http.should_receive(:post).with(Honeybadger::Sender::NOTICES_URI, kind_of(String), kind_of(Hash))
9
- Honeybadger.notify(RuntimeError.new('oops!'))
10
- end
11
-
12
- it "sends a user agent with version number" do
13
- http = stub_http
14
- http.should_receive(:post).with(kind_of(String), kind_of(String), hash_including({'User-Agent' => "HB-Ruby #{Honeybadger::VERSION}; #{RUBY_VERSION}; #{RUBY_PLATFORM}"}))
15
- send_exception
16
- end
17
-
18
- it "posts to Honeybadger when using an HTTP proxy" do
19
- http = stub_http
20
- proxy = double(:new => http)
21
- Net::HTTP.stub(:Proxy).and_return(proxy)
22
-
23
- http.should_receive(:post).with(Honeybadger::Sender::NOTICES_URI, kind_of(String), Honeybadger::HEADERS.merge({ 'X-API-Key' => 'abc123'}))
24
- Net::HTTP.should_receive(:Proxy).with('some.host', 88, 'login', 'passwd')
25
-
26
- send_exception(:proxy_host => 'some.host',
27
- :proxy_port => 88,
28
- :proxy_user => 'login',
29
- :proxy_pass => 'passwd',
30
- :notice => 'asdf')
31
- end
32
-
33
- it "returns the created group's id on successful posting" do
34
- stub_http(:body => '{"id":"3799307"}')
35
- expect(send_exception(:secure => false)).to eq '3799307'
36
- end
37
-
38
- it "returns nil on failed posting" do
39
- stub_http(:response => Net::HTTPError)
40
- expect(send_exception(:secure => false)).to be_nil
41
- end
42
-
43
- describe '#api_key' do
44
- context 'api_key is missing' do
45
- it "logs missing API key and return nil" do
46
- sender = build_sender(:api_key => nil)
47
- sender.should_receive(:log).with(:error, /API key/)
48
- expect(send_exception(:sender => sender, :secure => false)).to be_nil
49
- end
50
- end
51
-
52
- context 'notice is a hash' do
53
- it 'uses api_key from hash when present' do
54
- sender = build_sender(:api_key => 'asdf')
55
- http.should_receive(:post).with(Honeybadger::Sender::NOTICES_URI, kind_of(String), hash_including('X-API-Key' => 'zxcv'))
56
- send_exception(:sender => sender, :notice => { 'api_key' => 'zxcv' })
57
- end
58
- end
59
-
60
- context 'notice is a Honeybadger::Notice' do
61
- it 'uses api_key from notice when present' do
62
- sender = build_sender(:api_key => 'asdf')
63
- http.should_receive(:post).with(Honeybadger::Sender::NOTICES_URI, kind_of(String), hash_including('X-API-Key' => 'zxcv'))
64
- send_exception(:sender => sender, :notice => Honeybadger::Notice.new(:api_key => 'zxcv'))
65
- end
66
- end
67
- end
68
-
69
- context "success response from server" do
70
- let(:sender) { build_sender }
71
-
72
- before { stub_http }
73
-
74
- it "logs success" do
75
- sender.should_receive(:log).with(:debug, /Success/, kind_of(Net::HTTPSuccess), kind_of(String))
76
- send_exception(:sender => sender, :secure => false)
77
- end
78
-
79
- it "doesn't change features" do
80
- expect { send_exception(:sender => sender, :secure => false) }.not_to change { Honeybadger.configuration.features }
81
- end
82
- end
83
-
84
- context "403 response from server" do
85
- it "deactivates notices on 403" do
86
- stub_http(:response => Net::HTTPForbidden.new('1.2', '403', 'Forbidden'))
87
- sender = build_sender
88
- expect { send_exception(:sender => sender, :secure => false) }.to change { Honeybadger.configuration.features['notices'] }.to false
89
- end
90
- end
91
-
92
- it "logs failure" do
93
- stub_http(:response => Net::HTTPServerError.new('1.2', '500', 'Internal Error'))
94
- sender = build_sender
95
- sender.should_receive(:log).with(:error, /Failure/, kind_of(Net::HTTPServerError), kind_of(String))
96
- send_exception(:sender => sender, :secure => false)
97
- end
98
-
99
- context "when encountering exceptions" do
100
- # TODO: Figure out why nested groups aren't running
101
- context "HTTP connection setup problems" do
102
- it "should not be rescued" do
103
- proxy = double()
104
- proxy.stub(:new).and_raise(NoMemoryError)
105
- Net::HTTP.stub(:Proxy).and_return(proxy)
106
- expect { build_sender.send(:setup_http_connection) }.to raise_error(NoMemoryError)
107
- end
108
-
109
- it "should be logged" do
110
- proxy = double()
111
- proxy.stub(:new).and_raise(RuntimeError)
112
- Net::HTTP.stub(:Proxy).and_return(proxy)
113
-
114
- sender = build_sender
115
- sender.should_receive(:log).with(:error, /Failure initializing the HTTP connection/)
116
-
117
- expect { sender.send(:setup_http_connection) }.to raise_error(RuntimeError)
118
- end
119
- end
120
-
121
- context "unexpected exception sending problems" do
122
- it "should be logged" do
123
- sender = build_sender
124
- sender.should_receive(:setup_http_connection).and_raise(RuntimeError)
125
-
126
- sender.should_receive(:log).with(:error, /Error/)
127
- sender.send_to_honeybadger("stuff")
128
- end
129
-
130
- it "should log the exception on any error" do
131
- Honeybadger.configuration.log_exception_on_send_failure = true
132
- notice = Honeybadger::Notice.new(:exception => Exception.new("bad things"))
133
- sender = build_sender
134
- sender.should_receive(:setup_http_connection).and_raise(RuntimeError)
135
- sender.stub(:log)
136
-
137
- Honeybadger.should_receive(:write_verbose_log).with(/Original Exception:.*bad things/, :error)
138
- sender.send_to_honeybadger(notice)
139
- end
140
-
141
- it "should not log the exception on any error by default" do
142
- notice = Honeybadger::Notice.new(:exception => Exception.new("bad things"))
143
- sender = build_sender
144
- sender.should_receive(:setup_http_connection).and_raise(RuntimeError)
145
- sender.stub(:log)
146
-
147
- Honeybadger.should_not_receive(:write_verbose_log).with(/Original Exception:.*bad things/, :error)
148
- sender.send_to_honeybadger(notice)
149
- end
150
-
151
- it "should log the exception on a non-successful HTTP response" do
152
- Honeybadger.configuration.log_exception_on_send_failure = true
153
- stub_http(:response => Net::HTTPError)
154
- notice = Honeybadger::Notice.new(:exception => Exception.new("bad things"))
155
- sender = build_sender
156
- sender.stub(:log)
157
-
158
- Honeybadger.should_receive(:write_verbose_log).with(/Original Exception:.*bad things/, :error)
159
- sender.send_to_honeybadger(notice)
160
- end
161
-
162
-
163
- it "returns nil no matter what" do
164
- sender = build_sender
165
- sender.should_receive(:setup_http_connection).and_raise(LocalJumpError)
166
-
167
- expect { sender.send_to_honeybadger("stuff").should be_nil }.not_to raise_error
168
- end
169
- end
170
-
171
- it "returns nil on failed posting" do
172
- http = stub_http
173
- http.should_receive(:post).and_raise(Errno::ECONNREFUSED)
174
- expect(send_exception(:secure => false)).to be_nil
175
- end
176
-
177
- it "not fail when posting and a timeout exception occurs" do
178
- http = stub_http
179
- http.should_receive(:post).and_raise(TimeoutError)
180
- expect { send_exception(:secure => false) }.not_to raise_error
181
- end
182
-
183
- it "not fail when posting and a connection refused exception occurs" do
184
- http = stub_http
185
- http.should_receive(:post).and_raise(Errno::ECONNREFUSED)
186
- expect { send_exception(:secure => false) }.not_to raise_error
187
- end
188
-
189
- it "not fail when posting any http exception occurs" do
190
- http = stub_http
191
- Honeybadger::Sender::HTTP_ERRORS.each do |error|
192
- http.stub(:post).and_raise(error)
193
- expect { send_exception(:secure => false) }.not_to raise_error
194
- end
195
- end
196
- end
197
-
198
- context "SSL" do
199
- it "posts to the right url for non-ssl" do
200
- http = stub_http
201
- url = "http://api.honeybadger.io:80#{Honeybadger::Sender::NOTICES_URI}"
202
- uri = URI.parse(url)
203
- http.should_receive(:post).with(uri.path, anything, Honeybadger::HEADERS.merge({ 'X-API-Key' => 'abc123'}))
204
- send_exception(:secure => false)
205
- end
206
-
207
- it "post to the right path for ssl" do
208
- http = stub_http
209
- http.should_receive(:post).with(Honeybadger::Sender::NOTICES_URI, anything, Honeybadger::HEADERS.merge({ 'X-API-Key' => 'abc123'}))
210
- send_exception(:secure => true)
211
- end
212
-
213
- it "verifies the SSL peer when the use_ssl option is set to true" do
214
- url = "https://api.honeybadger.io#{Honeybadger::Sender::NOTICES_URI}"
215
- uri = URI.parse(url)
216
-
217
- real_http = Net::HTTP.new(uri.host, uri.port)
218
- real_http.stub(:post => nil)
219
- proxy = double(:new => real_http)
220
- Net::HTTP.stub(:Proxy => proxy)
221
-
222
- File.stub(:exist?).with(OpenSSL::X509::DEFAULT_CERT_FILE).and_return(false)
223
-
224
- send_exception(:secure => true)
225
-
226
- expect(real_http.use_ssl?).to be_true
227
- expect(real_http.verify_mode).to eq OpenSSL::SSL::VERIFY_PEER
228
- expect(real_http.ca_file).to eq Honeybadger.configuration.local_cert_path
229
- end
230
-
231
- it "uses the default DEFAULT_CERT_FILE if asked to" do
232
- File.should_receive(:exist?).with(OpenSSL::X509::DEFAULT_CERT_FILE).and_return(true)
233
-
234
- Honeybadger.configure do |config|
235
- config.secure = true
236
- config.use_system_ssl_cert_chain = true
237
- end
238
-
239
- sender = Honeybadger::Sender.new(Honeybadger.configuration)
240
-
241
- expect(sender.use_system_ssl_cert_chain?).to be_true
242
-
243
- http = sender.send(:setup_http_connection)
244
- expect(http.ca_file).not_to eq Honeybadger.configuration.local_cert_path
245
- end
246
-
247
- it "verifies the connection when the use_ssl option is set (VERIFY_PEER)" do
248
- sender = build_sender(:secure => true)
249
- http = sender.send(:setup_http_connection)
250
- expect(http.verify_mode).to eq OpenSSL::SSL::VERIFY_PEER
251
- end
252
-
253
- it "uses the default cert (OpenSSL::X509::DEFAULT_CERT_FILE) only if explicitly told to" do
254
- sender = build_sender(:secure => true)
255
- http = sender.send(:setup_http_connection)
256
-
257
- expect(http.ca_file).to eq Honeybadger.configuration.local_cert_path
258
-
259
- File.stub(:exist?).with(OpenSSL::X509::DEFAULT_CERT_FILE).and_return(true)
260
- sender = build_sender(:secure => true, :use_system_ssl_cert_chain => true)
261
- http = sender.send(:setup_http_connection)
262
-
263
- expect(http.ca_file).not_to eq Honeybadger.configuration.local_cert_path
264
- expect(http.ca_file).to eq OpenSSL::X509::DEFAULT_CERT_FILE
265
- end
266
-
267
- it "uses ssl if secure" do
268
- sender = build_sender(:secure => true)
269
- http = sender.send(:setup_http_connection)
270
- expect(http.port).to eq 443
271
- end
272
-
273
- it "does not use ssl if not secure" do
274
- sender = build_sender(:secure => false)
275
- http = sender.send(:setup_http_connection)
276
- expect(http.port).to eq 80
277
- end
278
- end
279
-
280
- context "network timeouts" do
281
- it "default the open timeout to 2 seconds" do
282
- http = stub_http
283
- http.should_receive(:open_timeout=).with(2)
284
- send_exception
285
- end
286
-
287
- it "default the read timeout to 5 seconds" do
288
- http = stub_http
289
- http.should_receive(:read_timeout=).with(5)
290
- send_exception
291
- end
292
-
293
- it "allow override of the open timeout" do
294
- http = stub_http
295
- http.should_receive(:open_timeout=).with(4)
296
- send_exception(:http_open_timeout => 4)
297
- end
298
-
299
- it "allow override of the read timeout" do
300
- http = stub_http
301
- http.should_receive(:read_timeout=).with(10)
302
- send_exception(:http_read_timeout => 10)
303
- end
304
- end
305
-
306
- def build_sender(opts = {})
307
- Honeybadger.configure do |conf|
308
- opts.each {|opt, value| conf.send(:"#{opt}=", value) }
309
- end
310
- end
311
-
312
- def send_exception(args = {})
313
- notice = args.delete(:notice) || build_notice_data
314
- sender = args.delete(:sender) || build_sender(args)
315
- sender.send_to_honeybadger(notice)
316
- end
317
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Honeybadger::Stats do
4
- describe '.memory' do
5
- subject { Honeybadger::Stats.memory }
6
-
7
- before do
8
- stub_const('Honeybadger::Stats::HAS_MEM', true)
9
- IO.stub(:readlines).with('/proc/meminfo').and_return(["MemTotal: 35125476 kB\n", "MemFree: 1671436 kB\n", "Buffers: 2242812 kB\n", "Cached: 11791596 kB\n", "SwapCached: 164256 kB\n", "Active: 15891800 kB\n", "Inactive: 13593872 kB\n"])
10
- end
11
-
12
- describe '.keys' do
13
- subject { Honeybadger::Stats.memory.keys }
14
- its(:length) { should eq 5 }
15
- end
16
-
17
- it 'converts KB to MB' do
18
- expect(Honeybadger::Stats.memory[:total]).to eq 34302.22265625
19
- expect(Honeybadger::Stats.memory[:free]).to eq 1632.26171875
20
- expect(Honeybadger::Stats.memory[:buffers]).to eq 2190.24609375
21
- expect(Honeybadger::Stats.memory[:cached]).to eq 11515.23046875
22
- end
23
-
24
- it 'sums non-totals for free_total' do
25
- expect(Honeybadger::Stats.memory[:free_total]).to eq 15337.73828125
26
- end
27
-
28
- context 'when mathn is required' do
29
- before(:all) { require 'mathn' }
30
-
31
- it 'converts Rational to Float' do
32
- expect(Honeybadger::Stats.memory[:total]).to be_a Float
33
- expect(Honeybadger::Stats.memory[:free]).to be_a Float
34
- expect(Honeybadger::Stats.memory[:buffers]).to be_a Float
35
- expect(Honeybadger::Stats.memory[:cached]).to be_a Float
36
- end
37
- end
38
- end
39
-
40
- describe '.load' do
41
- subject { Honeybadger::Stats.load }
42
-
43
- before do
44
- stub_const('Honeybadger::Stats::HAS_LOAD', true)
45
- IO.stub(:read).with('/proc/loadavg').and_return('22.58 19.66 15.96 20/2019 2')
46
- end
47
-
48
- describe '.keys' do
49
- subject { Honeybadger::Stats.load.keys }
50
- its(:length) { should eq 3 }
51
- end
52
-
53
- specify { expect(subject[:one]).to eq 22.58 }
54
- specify { expect(subject[:five]).to eq 19.66 }
55
- specify { expect(subject[:fifteen]).to eq 15.96 }
56
- end
57
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
- require 'sham_rack'
3
-
4
- describe Honeybadger::Rack::UserFeedback do
5
- let(:main_app) do
6
- lambda do |env|
7
- env['honeybadger.error_id'] = honeybadger_id if defined?(honeybadger_id)
8
- [200, {}, ["<!-- HONEYBADGER FEEDBACK -->"]]
9
- end
10
- end
11
- let(:informer_app) { Honeybadger::Rack::UserFeedback.new(main_app) }
12
- let(:response) { Net::HTTP.get_response(URI.parse("http://example.com/")) }
13
-
14
- before do
15
- reset_config
16
- ShamRack.mount(informer_app, "example.com")
17
- end
18
-
19
- context "feedback feature is disabled by ping" do
20
- it "does not modify the output" do
21
- expect(response.body).to eq '<!-- HONEYBADGER FEEDBACK -->'
22
- end
23
- end
24
-
25
- context "feedback feature is enabled by ping" do
26
- before do
27
- Honeybadger.configuration.features['feedback'] = true
28
- end
29
-
30
- context "there is a honeybadger id" do
31
- let(:honeybadger_id) { 1 }
32
-
33
- it "modifies output" do
34
- rendered_length = informer_app.render_form(1).size
35
- expect(response.body).to match(/honeybadger_feedback_token/)
36
- expect(response["Content-Length"].to_i).to eq rendered_length
37
- end
38
-
39
- context "a project root is configured" do
40
- let(:tmp_dir) { File.expand_path('../../../tmp', __FILE__) }
41
- let(:template_dir) { File.join(tmp_dir, 'lib', 'honeybadger', 'templates') }
42
- let(:template_file) { File.join(template_dir, 'feedback_form.erb') }
43
-
44
- before do
45
- FileUtils.mkdir_p(template_dir)
46
- FileUtils.rm_f(template_file)
47
- Honeybadger.configure(true) do |config|
48
- config.project_root = tmp_dir
49
- end
50
- end
51
-
52
- context "custom template is implemented" do
53
- before do
54
- File.open(template_file, 'w') { |f| f.write 'custom feedback form' }
55
- end
56
-
57
- it "renders with custom template" do
58
- expect(response.body).to match(/custom feedback form/)
59
- end
60
- end
61
- end
62
-
63
- context "feedback feature is disabled by customer" do
64
- before do
65
- Honeybadger.configuration.feedback = false
66
- end
67
-
68
- it "does not modify the output" do
69
- expect(response.body).to eq '<!-- HONEYBADGER FEEDBACK -->'
70
- end
71
- end
72
- end
73
-
74
- context "there is no honeybadger id" do
75
- it "does not modify the output" do
76
- expect(response.body).to eq '<!-- HONEYBADGER FEEDBACK -->'
77
- end
78
- end
79
- end
80
- end