airbrake 3.1.6 → 11.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. data/lib/airbrake.rb +23 -150
  3. data/lib/airbrake/capistrano.rb +6 -42
  4. data/lib/airbrake/capistrano/capistrano2.rb +40 -0
  5. data/lib/airbrake/capistrano/capistrano3.rb +23 -0
  6. data/lib/airbrake/delayed_job.rb +66 -0
  7. data/lib/airbrake/logger.rb +103 -0
  8. data/lib/airbrake/rack.rb +30 -45
  9. data/lib/airbrake/rack/context_filter.rb +65 -0
  10. data/lib/airbrake/rack/http_headers_filter.rb +44 -0
  11. data/lib/airbrake/rack/http_params_filter.rb +27 -0
  12. data/lib/airbrake/rack/instrumentable.rb +136 -0
  13. data/lib/airbrake/rack/middleware.rb +102 -0
  14. data/lib/airbrake/rack/request_body_filter.rb +33 -0
  15. data/lib/airbrake/rack/request_store.rb +34 -0
  16. data/lib/airbrake/rack/route_filter.rb +51 -0
  17. data/lib/airbrake/rack/session_filter.rb +25 -0
  18. data/lib/airbrake/rack/user.rb +74 -0
  19. data/lib/airbrake/rack/user_filter.rb +25 -0
  20. data/lib/airbrake/rails.rb +25 -31
  21. data/lib/airbrake/rails/action_cable.rb +35 -0
  22. data/lib/airbrake/rails/action_cable/notify_callback.rb +22 -0
  23. data/lib/airbrake/rails/action_controller.rb +40 -0
  24. data/lib/airbrake/rails/action_controller_notify_subscriber.rb +32 -0
  25. data/lib/airbrake/rails/action_controller_performance_breakdown_subscriber.rb +51 -0
  26. data/lib/airbrake/rails/action_controller_route_subscriber.rb +33 -0
  27. data/lib/airbrake/rails/active_job.rb +50 -0
  28. data/lib/airbrake/rails/active_record.rb +36 -0
  29. data/lib/airbrake/rails/active_record_subscriber.rb +46 -0
  30. data/lib/airbrake/rails/app.rb +78 -0
  31. data/lib/airbrake/rails/backtrace_cleaner.rb +23 -0
  32. data/lib/airbrake/rails/curb.rb +32 -0
  33. data/lib/airbrake/rails/event.rb +81 -0
  34. data/lib/airbrake/rails/excon_subscriber.rb +25 -0
  35. data/lib/airbrake/rails/http.rb +14 -0
  36. data/lib/airbrake/rails/http_client.rb +16 -0
  37. data/lib/airbrake/rails/net_http.rb +18 -0
  38. data/lib/airbrake/rails/railtie.rb +151 -0
  39. data/lib/airbrake/rails/typhoeus.rb +16 -0
  40. data/lib/airbrake/rake.rb +65 -0
  41. data/lib/airbrake/rake/tasks.rb +112 -0
  42. data/lib/airbrake/resque.rb +61 -0
  43. data/lib/airbrake/shoryuken.rb +54 -0
  44. data/lib/airbrake/sidekiq.rb +55 -0
  45. data/lib/airbrake/sidekiq/retryable_jobs_filter.rb +53 -0
  46. data/lib/airbrake/sneakers.rb +72 -0
  47. data/lib/airbrake/version.rb +5 -1
  48. data/lib/generators/airbrake_generator.rb +25 -0
  49. data/lib/generators/airbrake_initializer.rb.erb +80 -0
  50. metadata +206 -259
  51. data/CHANGELOG +0 -944
  52. data/Gemfile +0 -3
  53. data/Guardfile +0 -6
  54. data/INSTALL +0 -20
  55. data/MIT-LICENSE +0 -22
  56. data/README.md +0 -556
  57. data/README_FOR_HEROKU_ADDON.md +0 -94
  58. data/Rakefile +0 -223
  59. data/SUPPORTED_RAILS_VERSIONS +0 -38
  60. data/TESTING.md +0 -41
  61. data/airbrake.gemspec +0 -40
  62. data/bin/airbrake +0 -12
  63. data/features/metal.feature +0 -18
  64. data/features/rack.feature +0 -60
  65. data/features/rails.feature +0 -272
  66. data/features/rails_with_js_notifier.feature +0 -97
  67. data/features/rake.feature +0 -27
  68. data/features/sinatra.feature +0 -29
  69. data/features/step_definitions/file_steps.rb +0 -10
  70. data/features/step_definitions/metal_steps.rb +0 -23
  71. data/features/step_definitions/rack_steps.rb +0 -23
  72. data/features/step_definitions/rails_application_steps.rb +0 -478
  73. data/features/step_definitions/rake_steps.rb +0 -17
  74. data/features/support/airbrake_shim.rb.template +0 -16
  75. data/features/support/env.rb +0 -18
  76. data/features/support/matchers.rb +0 -35
  77. data/features/support/rails.rb +0 -201
  78. data/features/support/rake/Rakefile +0 -68
  79. data/features/support/terminal.rb +0 -107
  80. data/features/user_informer.feature +0 -63
  81. data/generators/airbrake/airbrake_generator.rb +0 -94
  82. data/generators/airbrake/lib/insert_commands.rb +0 -34
  83. data/generators/airbrake/lib/rake_commands.rb +0 -24
  84. data/generators/airbrake/templates/airbrake_tasks.rake +0 -25
  85. data/generators/airbrake/templates/capistrano_hook.rb +0 -6
  86. data/generators/airbrake/templates/initializer.rb +0 -6
  87. data/install.rb +0 -1
  88. data/lib/airbrake/backtrace.rb +0 -108
  89. data/lib/airbrake/cli/client.rb +0 -68
  90. data/lib/airbrake/cli/options.rb +0 -41
  91. data/lib/airbrake/cli/printer.rb +0 -30
  92. data/lib/airbrake/cli/project.rb +0 -17
  93. data/lib/airbrake/cli/project_factory.rb +0 -36
  94. data/lib/airbrake/cli/runner.rb +0 -48
  95. data/lib/airbrake/cli/validator.rb +0 -8
  96. data/lib/airbrake/configuration.rb +0 -311
  97. data/lib/airbrake/extensions/blank.rb +0 -73
  98. data/lib/airbrake/notice.rb +0 -390
  99. data/lib/airbrake/rails/action_controller_catcher.rb +0 -30
  100. data/lib/airbrake/rails/controller_methods.rb +0 -87
  101. data/lib/airbrake/rails/error_lookup.rb +0 -33
  102. data/lib/airbrake/rails/javascript_notifier.rb +0 -47
  103. data/lib/airbrake/rails/middleware/exceptions_catcher.rb +0 -33
  104. data/lib/airbrake/rails3_tasks.rb +0 -98
  105. data/lib/airbrake/railtie.rb +0 -48
  106. data/lib/airbrake/rake_handler.rb +0 -71
  107. data/lib/airbrake/sender.rb +0 -128
  108. data/lib/airbrake/shared_tasks.rb +0 -47
  109. data/lib/airbrake/tasks.rb +0 -83
  110. data/lib/airbrake/user_informer.rb +0 -27
  111. data/lib/airbrake_tasks.rb +0 -64
  112. data/lib/rails/generators/airbrake/airbrake_generator.rb +0 -100
  113. data/lib/templates/javascript_notifier.erb +0 -15
  114. data/lib/templates/rescue.erb +0 -91
  115. data/rails/init.rb +0 -1
  116. data/resources/README.md +0 -34
  117. data/resources/ca-bundle.crt +0 -3376
  118. data/script/integration_test.rb +0 -38
  119. data/test/airbrake_2_3.xsd +0 -88
  120. data/test/airbrake_tasks_test.rb +0 -170
  121. data/test/backtrace_test.rb +0 -162
  122. data/test/capistrano_test.rb +0 -34
  123. data/test/catcher_test.rb +0 -333
  124. data/test/configuration_test.rb +0 -233
  125. data/test/helper.rb +0 -263
  126. data/test/javascript_notifier_test.rb +0 -51
  127. data/test/logger_test.rb +0 -79
  128. data/test/notice_test.rb +0 -490
  129. data/test/notifier_test.rb +0 -276
  130. data/test/rack_test.rb +0 -58
  131. data/test/rails_initializer_test.rb +0 -36
  132. data/test/recursion_test.rb +0 -10
  133. data/test/sender_test.rb +0 -288
  134. data/test/user_informer_test.rb +0 -29
@@ -1,34 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- require 'capistrano/configuration'
4
- require 'airbrake/capistrano'
5
-
6
- class CapistranoTest < Test::Unit::TestCase
7
- def setup
8
- super
9
- reset_config
10
-
11
- @configuration = Capistrano::Configuration.new
12
- Airbrake::Capistrano.load_into(@configuration)
13
- @configuration.dry_run = true
14
- end
15
-
16
- should "define airbrake:deploy task" do
17
- assert_not_nil @configuration.find_task('airbrake:deploy')
18
- end
19
-
20
- should "log when calling airbrake: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('airbrake:deploy')
30
-
31
- assert io.string.include?('** Notifying Airbrake of Deploy')
32
- assert io.string.include?('** Airbrake Notification Complete')
33
- end
34
- end
@@ -1,333 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- class ActionControllerCatcherTest < Test::Unit::TestCase
4
-
5
- include DefinesConstants
6
-
7
- def setup
8
- super
9
- reset_config
10
- Airbrake.sender = CollectingSender.new
11
- define_constant('RAILS_ROOT', '/path/to/rails/root')
12
- end
13
-
14
- def ignore(exception_class)
15
- Airbrake.configuration.ignore << exception_class
16
- end
17
-
18
- def build_controller_class(&definition)
19
- Class.new(ActionController::Base).tap do |klass|
20
- klass.__send__(:include, Airbrake::Rails::ActionControllerCatcher)
21
- klass.class_eval(&definition) if definition
22
- define_constant('AirbrakeTestController', klass)
23
- end
24
- end
25
-
26
- def assert_sent_hash(hash, xpath)
27
- hash.each do |key, value|
28
- next if key.match(/^airbrake\./) # We added this key.
29
-
30
- element_xpath = "#{xpath}/var[@key = '#{key}']"
31
- if value.respond_to?(:to_hash)
32
- assert_sent_hash value.to_hash, element_xpath
33
- else
34
- assert_sent_element value, element_xpath
35
- end
36
- end
37
- end
38
-
39
- def assert_sent_element(value, xpath)
40
- assert_valid_node last_sent_notice_document, xpath, stringify_array_elements(value).to_s
41
- end
42
-
43
- def stringify_array_elements(data)
44
- if data.respond_to?(:to_ary)
45
- data.collect do |value|
46
- stringify_array_elements(value)
47
- end
48
- else
49
- data.to_s
50
- end
51
- end
52
-
53
- def assert_sent_request_info_for(request)
54
- params = request.parameters.to_hash
55
- assert_sent_hash params, '/notice/request/params'
56
- assert_sent_element params['controller'], '/notice/request/component'
57
- assert_sent_element params['action'], '/notice/request/action'
58
- assert_sent_element url_from_request(request), '/notice/request/url'
59
- assert_sent_hash request.env, '/notice/request/cgi-data'
60
- end
61
-
62
- def url_from_request(request)
63
- url = "#{request.protocol}#{request.host}"
64
-
65
- unless [80, 443].include?(request.port)
66
- url << ":#{request.port}"
67
- end
68
-
69
- url << request.request_uri
70
- url
71
- end
72
-
73
- def sender
74
- Airbrake.sender
75
- end
76
-
77
- def last_sent_notice_xml
78
- sender.collected.last.to_xml
79
- end
80
-
81
- def last_sent_notice_document
82
- assert_not_nil xml = last_sent_notice_xml, "No xml was sent"
83
- Nokogiri::XML.parse(xml)
84
- end
85
-
86
- def process_action(opts = {}, &action)
87
- opts[:request] ||= ActionController::TestRequest.new
88
- opts[:response] ||= ActionController::TestResponse.new
89
- klass = build_controller_class do
90
- cattr_accessor :local
91
- define_method(:index, &action)
92
- def local_request?
93
- local
94
- end
95
- end
96
- if opts[:filters]
97
- klass.filter_parameter_logging *opts[:filters]
98
- end
99
- if opts[:user_agent]
100
- if opts[:request].respond_to?(:user_agent=)
101
- opts[:request].user_agent = opts[:user_agent]
102
- else
103
- opts[:request].env["HTTP_USER_AGENT"] = opts[:user_agent]
104
- end
105
- end
106
- if opts[:port]
107
- opts[:request].port = opts[:port]
108
- end
109
- klass.consider_all_requests_local = opts[:all_local]
110
- klass.local = opts[:local]
111
- controller = klass.new
112
- controller.stubs(:rescue_action_in_public_without_airbrake)
113
- opts[:request].query_parameters = opts[:request].query_parameters.merge(opts[:params] || {})
114
- opts[:request].session = ActionController::TestSession.new(opts[:session] || {})
115
- # Prevents request.fullpath from crashing Rails in tests
116
- opts[:request].env['REQUEST_URI'] = opts[:request].request_uri
117
- controller.process(opts[:request], opts[:response])
118
- controller
119
- end
120
-
121
- def process_action_with_manual_notification(args = {})
122
- process_action(args) do
123
- notify_airbrake(:error_message => 'fail')
124
- # Rails will raise a template error if we don't render something
125
- render :nothing => true
126
- end
127
- end
128
-
129
- def process_action_with_automatic_notification(args = {})
130
- process_action(args) { raise "Hello" }
131
- end
132
-
133
- should "deliver notices from exceptions raised in public requests" do
134
- process_action_with_automatic_notification
135
- assert_caught_and_sent
136
- end
137
-
138
- should "not deliver notices from exceptions in local requests" do
139
- process_action_with_automatic_notification(:local => true)
140
- assert_caught_and_not_sent
141
- end
142
-
143
- should "not deliver notices from exceptions when all requests are local" do
144
- process_action_with_automatic_notification(:all_local => true)
145
- assert_caught_and_not_sent
146
- end
147
-
148
- should "not deliver notices from actions that don't raise" do
149
- controller = process_action { render :text => 'Hello' }
150
- assert_caught_and_not_sent
151
- assert_equal 'Hello', controller.response.body
152
- end
153
-
154
- should "not deliver ignored exceptions raised by actions" do
155
- ignore(RuntimeError)
156
- process_action_with_automatic_notification
157
- assert_caught_and_not_sent
158
- end
159
-
160
- should "deliver ignored exception raised manually" do
161
- ignore(RuntimeError)
162
- process_action_with_manual_notification
163
- assert_caught_and_sent
164
- end
165
-
166
- should "deliver manually sent notices in public requests" do
167
- process_action_with_manual_notification
168
- assert_caught_and_sent
169
- end
170
-
171
- should "not deliver manually sent notices in local requests" do
172
- process_action_with_manual_notification(:local => true)
173
- assert_caught_and_not_sent
174
- end
175
-
176
- should "not deliver manually sent notices when all requests are local" do
177
- process_action_with_manual_notification(:all_local => true)
178
- assert_caught_and_not_sent
179
- end
180
-
181
- should "continue with default behavior after delivering an exception" do
182
- controller = process_action_with_automatic_notification(:public => true)
183
- # TODO: can we test this without stubbing?
184
- assert_received(controller, :rescue_action_in_public_without_airbrake)
185
- end
186
-
187
- should "not create actions from Airbrake methods" do
188
- controller = build_controller_class.new
189
- assert_equal [], Airbrake::Rails::ActionControllerCatcher.instance_methods
190
- end
191
-
192
- should "ignore exceptions when user agent is being ignored by regular expression" do
193
- Airbrake.configuration.ignore_user_agent_only = [/Ignored/]
194
- process_action_with_automatic_notification(:user_agent => 'ShouldBeIgnored')
195
- assert_caught_and_not_sent
196
- end
197
-
198
- should "ignore exceptions when user agent is being ignored by string" do
199
- Airbrake.configuration.ignore_user_agent_only = ['IgnoredUserAgent']
200
- process_action_with_automatic_notification(:user_agent => 'IgnoredUserAgent')
201
- assert_caught_and_not_sent
202
- end
203
-
204
- should "not ignore exceptions when user agent is not being ignored" do
205
- Airbrake.configuration.ignore_user_agent_only = ['IgnoredUserAgent']
206
- process_action_with_automatic_notification(:user_agent => 'NonIgnoredAgent')
207
- assert_caught_and_sent
208
- end
209
-
210
- should "send session data for manual notifications" do
211
- data = { 'one' => 'two' }
212
- process_action_with_manual_notification(:session => data)
213
- assert_sent_hash data, "/notice/request/session"
214
- end
215
-
216
- should "send session data for automatic notification" do
217
- data = { 'one' => 'two' }
218
- process_action_with_automatic_notification(:session => data)
219
- assert_sent_hash data, "/notice/request/session"
220
- end
221
-
222
- should "send request data for manual notification" do
223
- params = { 'controller' => "airbrake_test", 'action' => "index" }
224
- controller = process_action_with_manual_notification(:params => params)
225
- assert_sent_request_info_for controller.request
226
- end
227
-
228
- should "send request data for manual notification with non-standard port" do
229
- params = { 'controller' => "airbrake_test", 'action' => "index" }
230
- controller = process_action_with_manual_notification(:params => params, :port => 81)
231
- assert_sent_request_info_for controller.request
232
- end
233
-
234
- should "send request data for automatic notification" do
235
- params = { 'controller' => "airbrake_test", 'action' => "index" }
236
- controller = process_action_with_automatic_notification(:params => params)
237
- assert_sent_request_info_for controller.request
238
- end
239
-
240
- should "send request data for automatic notification with non-standard port" do
241
- params = { 'controller' => "airbrake_test", 'action' => "index" }
242
- controller = process_action_with_automatic_notification(:params => params, :port => 81)
243
- assert_sent_request_info_for controller.request
244
- end
245
-
246
- should "use standard rails logging filters on params and session and env" do
247
- filtered_params = { "abc" => "123",
248
- "def" => "456",
249
- "ghi" => "[FILTERED]" }
250
- filtered_session = { "abc" => "123",
251
- "ghi" => "[FILTERED]" }
252
- ENV['ghi'] = 'abc'
253
- filtered_env = { 'ghi' => '[FILTERED]' }
254
- filtered_cgi = { 'REQUEST_METHOD' => '[FILTERED]' }
255
-
256
- process_action_with_automatic_notification(:filters => [:ghi, :request_method],
257
- :params => { "abc" => "123",
258
- "def" => "456",
259
- "ghi" => "789" },
260
- :session => { "abc" => "123",
261
- "ghi" => "789" })
262
- assert_sent_hash filtered_params, '/notice/request/params'
263
- assert_sent_hash filtered_cgi, '/notice/request/cgi-data'
264
- assert_sent_hash filtered_session, '/notice/request/session'
265
- end
266
-
267
- context "for a local error with development lookup enabled" do
268
- setup do
269
- Airbrake.configuration.development_lookup = true
270
- Airbrake.stubs(:build_lookup_hash_for).returns({ :awesome => 2 })
271
-
272
- @controller = process_action_with_automatic_notification(:local => true)
273
- @response = @controller.response
274
- end
275
-
276
- should "append custom CSS and JS to response body for a local error" do
277
- assert_match /text\/css/, @response.body
278
- assert_match /text\/javascript/, @response.body
279
- end
280
-
281
- should "contain host, API key and notice JSON" do
282
- assert_match Airbrake.configuration.host.to_json, @response.body
283
- assert_match Airbrake.configuration.api_key.to_json, @response.body
284
- assert_match ({ :awesome => 2 }).to_json, @response.body
285
- end
286
- end
287
-
288
- context "for a local error with development lookup disabled" do
289
- setup do
290
- Airbrake.configuration.development_lookup = false
291
-
292
- @controller = process_action_with_automatic_notification(:local => true)
293
- @response = @controller.response
294
- end
295
-
296
- should "not append custom CSS and JS to response for a local error" do
297
- assert_no_match /text\/css/, @response.body
298
- assert_no_match /text\/javascript/, @response.body
299
- end
300
- end
301
-
302
- should "call session.to_hash if available" do
303
- hash_data = {:key => :value}
304
-
305
- session = ActionController::TestSession.new
306
- ActionController::TestSession.stubs(:new).returns(session)
307
- session.stubs(:to_hash).returns(hash_data)
308
-
309
- process_action_with_automatic_notification
310
- assert_received(session, :to_hash)
311
- assert_received(session, :data) { |expect| expect.never }
312
- assert_caught_and_sent
313
- end
314
-
315
- should "call session.data if session.to_hash is undefined" do
316
- hash_data = {:key => :value}
317
-
318
- session = ActionController::TestSession.new
319
- ActionController::TestSession.stubs(:new).returns(session)
320
- session.stubs(:data).returns(hash_data)
321
- if session.respond_to?(:to_hash)
322
- class << session
323
- undef to_hash
324
- end
325
- end
326
-
327
- process_action_with_automatic_notification
328
- assert_received(session, :to_hash) { |expect| expect.never }
329
- assert_received(session, :data) { |expect| expect.at_least_once }
330
- assert_caught_and_sent
331
- end
332
-
333
- end
@@ -1,233 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- class ConfigurationTest < Test::Unit::TestCase
4
-
5
- include DefinesConstants
6
-
7
- should "provide default values" do
8
- assert_config_default :proxy_host, nil
9
- assert_config_default :proxy_port, nil
10
- assert_config_default :proxy_user, nil
11
- assert_config_default :proxy_pass, nil
12
- assert_config_default :project_root, nil
13
- assert_config_default :environment_name, nil
14
- assert_config_default :logger, nil
15
- assert_config_default :notifier_version, Airbrake::VERSION
16
- assert_config_default :notifier_name, 'Airbrake Notifier'
17
- assert_config_default :notifier_url, 'https://github.com/airbrake/airbrake'
18
- assert_config_default :secure, false
19
- assert_config_default :host, 'api.airbrake.io'
20
- assert_config_default :http_open_timeout, 2
21
- assert_config_default :http_read_timeout, 5
22
- assert_config_default :ignore_by_filters, []
23
- assert_config_default :ignore_user_agent, []
24
- assert_config_default :params_filters,
25
- Airbrake::Configuration::DEFAULT_PARAMS_FILTERS
26
- assert_config_default :backtrace_filters,
27
- Airbrake::Configuration::DEFAULT_BACKTRACE_FILTERS
28
- assert_config_default :rake_environment_filters, []
29
- assert_config_default :ignore,
30
- Airbrake::Configuration::IGNORE_DEFAULT
31
- assert_config_default :development_lookup, true
32
- assert_config_default :framework, 'Standalone'
33
- assert_config_default :async, nil
34
- end
35
-
36
- should "set GirlFriday-callable for async=true" do
37
- config = Airbrake::Configuration.new
38
- config.async = true
39
- assert config.async.respond_to?(:call)
40
- end
41
-
42
- should "set provided-callable for async {}" do
43
- config = Airbrake::Configuration.new
44
- config.async {|notice| :ok}
45
- assert config.async.respond_to?(:call)
46
- assert_equal :ok, config.async.call
47
- end
48
-
49
- should "provide default values for secure connections" do
50
- config = Airbrake::Configuration.new
51
- config.secure = true
52
- assert_equal 443, config.port
53
- assert_equal 'https', config.protocol
54
- end
55
-
56
- should "provide default values for insecure connections" do
57
- config = Airbrake::Configuration.new
58
- config.secure = false
59
- assert_equal 80, config.port
60
- assert_equal 'http', config.protocol
61
- end
62
-
63
- should "not cache inferred ports" do
64
- config = Airbrake::Configuration.new
65
- config.secure = false
66
- config.port
67
- config.secure = true
68
- assert_equal 443, config.port
69
- end
70
-
71
- should "allow values to be overwritten" do
72
- assert_config_overridable :proxy_host
73
- assert_config_overridable :proxy_port
74
- assert_config_overridable :proxy_user
75
- assert_config_overridable :proxy_pass
76
- assert_config_overridable :secure
77
- assert_config_overridable :host
78
- assert_config_overridable :port
79
- assert_config_overridable :http_open_timeout
80
- assert_config_overridable :http_read_timeout
81
- assert_config_overridable :project_root
82
- assert_config_overridable :notifier_version
83
- assert_config_overridable :notifier_name
84
- assert_config_overridable :notifier_url
85
- assert_config_overridable :environment_name
86
- assert_config_overridable :development_lookup
87
- assert_config_overridable :logger
88
- assert_config_overridable :async
89
- end
90
-
91
- should "have an api key" do
92
- assert_config_overridable :api_key
93
- end
94
-
95
- should "act like a hash" do
96
- config = Airbrake::Configuration.new
97
- hash = config.to_hash
98
- [:api_key, :backtrace_filters, :development_environments,
99
- :environment_name, :host, :http_open_timeout,
100
- :http_read_timeout, :ignore, :ignore_by_filters, :ignore_user_agent,
101
- :notifier_name, :notifier_url, :notifier_version, :params_filters,
102
- :project_root, :port, :protocol, :proxy_host, :proxy_pass, :proxy_port,
103
- :proxy_user, :secure, :development_lookup, :async].each do |option|
104
- assert_equal config[option], hash[option], "Wrong value for #{option}"
105
- end
106
- end
107
-
108
- should "be mergable" do
109
- config = Airbrake::Configuration.new
110
- hash = config.to_hash
111
- assert_equal hash.merge(:key => 'value'), config.merge(:key => 'value')
112
- end
113
-
114
- should "allow param filters to be appended" do
115
- assert_appends_value :params_filters
116
- end
117
-
118
- should "allow rake environment filters to be appended" do
119
- assert_appends_value :rake_environment_filters
120
- end
121
-
122
- should "warn when attempting to write js_notifier" do
123
- config = Airbrake::Configuration.new
124
- config.
125
- expects(:warn).
126
- with(regexp_matches(/deprecated/i))
127
- config.js_notifier = true
128
- end
129
-
130
- should "allow ignored user agents to be appended" do
131
- assert_appends_value :ignore_user_agent
132
- end
133
-
134
- should "allow backtrace filters to be appended" do
135
- assert_appends_value(:backtrace_filters) do |config|
136
- new_filter = lambda {}
137
- config.filter_backtrace(&new_filter)
138
- new_filter
139
- end
140
- end
141
-
142
- should "allow ignore by filters to be appended" do
143
- assert_appends_value(:ignore_by_filters) do |config|
144
- new_filter = lambda {}
145
- config.ignore_by_filter(&new_filter)
146
- new_filter
147
- end
148
- end
149
-
150
- should "allow ignored exceptions to be appended" do
151
- config = Airbrake::Configuration.new
152
- original_filters = config.ignore.dup
153
- new_filter = 'hello'
154
- config.ignore << new_filter
155
- assert_same_elements original_filters + [new_filter], config.ignore
156
- end
157
-
158
- should "allow ignored exceptions to be replaced" do
159
- assert_replaces(:ignore, :ignore_only=)
160
- end
161
-
162
- should "allow ignored user agents to be replaced" do
163
- assert_replaces(:ignore_user_agent, :ignore_user_agent_only=)
164
- end
165
-
166
- should "use development and test as development environments by default" do
167
- config = Airbrake::Configuration.new
168
- assert_same_elements %w(development test cucumber), config.development_environments
169
- end
170
-
171
- should "be public in a public environment" do
172
- config = Airbrake::Configuration.new
173
- config.development_environments = %w(development)
174
- config.environment_name = 'production'
175
- assert config.public?
176
- end
177
-
178
- should "not be public in a development environment" do
179
- config = Airbrake::Configuration.new
180
- config.development_environments = %w(staging)
181
- config.environment_name = 'staging'
182
- assert !config.public?
183
- end
184
-
185
- should "be public without an environment name" do
186
- config = Airbrake::Configuration.new
187
- assert config.public?
188
- end
189
-
190
- should "use the assigned logger if set" do
191
- config = Airbrake::Configuration.new
192
- config.logger = "CUSTOM LOGGER"
193
- assert_equal "CUSTOM LOGGER", config.logger
194
- end
195
-
196
- should 'give a new instance if non defined' do
197
- Airbrake.configuration = nil
198
- assert_kind_of Airbrake::Configuration, Airbrake.configuration
199
- end
200
-
201
- def assert_config_default(option, default_value, config = nil)
202
- config ||= Airbrake::Configuration.new
203
- assert_equal default_value, config.send(option)
204
- end
205
-
206
- def assert_config_overridable(option, value = 'a value')
207
- config = Airbrake::Configuration.new
208
- config.send(:"#{option}=", value)
209
- assert_equal value, config.send(option)
210
- end
211
-
212
- def assert_appends_value(option, &block)
213
- config = Airbrake::Configuration.new
214
- original_values = config.send(option).dup
215
- block ||= lambda do |config|
216
- new_value = 'hello'
217
- config.send(option) << new_value
218
- new_value
219
- end
220
- new_value = block.call(config)
221
- assert_same_elements original_values + [new_value], config.send(option)
222
- end
223
-
224
- def assert_replaces(option, setter)
225
- config = Airbrake::Configuration.new
226
- new_value = 'hello'
227
- config.send(setter, [new_value])
228
- assert_equal [new_value], config.send(option)
229
- config.send(setter, new_value)
230
- assert_equal [new_value], config.send(option)
231
- end
232
-
233
- end