airbrake 3.1.6 → 11.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/airbrake.rb +23 -150
- data/lib/airbrake/capistrano.rb +6 -42
- data/lib/airbrake/capistrano/capistrano2.rb +40 -0
- data/lib/airbrake/capistrano/capistrano3.rb +23 -0
- data/lib/airbrake/delayed_job.rb +66 -0
- data/lib/airbrake/logger.rb +103 -0
- data/lib/airbrake/rack.rb +30 -45
- data/lib/airbrake/rack/context_filter.rb +65 -0
- data/lib/airbrake/rack/http_headers_filter.rb +44 -0
- data/lib/airbrake/rack/http_params_filter.rb +27 -0
- data/lib/airbrake/rack/instrumentable.rb +136 -0
- data/lib/airbrake/rack/middleware.rb +102 -0
- data/lib/airbrake/rack/request_body_filter.rb +33 -0
- data/lib/airbrake/rack/request_store.rb +34 -0
- data/lib/airbrake/rack/route_filter.rb +51 -0
- data/lib/airbrake/rack/session_filter.rb +25 -0
- data/lib/airbrake/rack/user.rb +74 -0
- data/lib/airbrake/rack/user_filter.rb +25 -0
- data/lib/airbrake/rails.rb +25 -31
- data/lib/airbrake/rails/action_cable.rb +35 -0
- data/lib/airbrake/rails/action_cable/notify_callback.rb +22 -0
- data/lib/airbrake/rails/action_controller.rb +40 -0
- data/lib/airbrake/rails/action_controller_notify_subscriber.rb +32 -0
- data/lib/airbrake/rails/action_controller_performance_breakdown_subscriber.rb +51 -0
- data/lib/airbrake/rails/action_controller_route_subscriber.rb +33 -0
- data/lib/airbrake/rails/active_job.rb +50 -0
- data/lib/airbrake/rails/active_record.rb +36 -0
- data/lib/airbrake/rails/active_record_subscriber.rb +46 -0
- data/lib/airbrake/rails/app.rb +78 -0
- data/lib/airbrake/rails/backtrace_cleaner.rb +23 -0
- data/lib/airbrake/rails/curb.rb +32 -0
- data/lib/airbrake/rails/event.rb +81 -0
- data/lib/airbrake/rails/excon_subscriber.rb +25 -0
- data/lib/airbrake/rails/http.rb +14 -0
- data/lib/airbrake/rails/http_client.rb +16 -0
- data/lib/airbrake/rails/net_http.rb +18 -0
- data/lib/airbrake/rails/railtie.rb +151 -0
- data/lib/airbrake/rails/typhoeus.rb +16 -0
- data/lib/airbrake/rake.rb +65 -0
- data/lib/airbrake/rake/tasks.rb +112 -0
- data/lib/airbrake/resque.rb +61 -0
- data/lib/airbrake/shoryuken.rb +54 -0
- data/lib/airbrake/sidekiq.rb +55 -0
- data/lib/airbrake/sidekiq/retryable_jobs_filter.rb +53 -0
- data/lib/airbrake/sneakers.rb +72 -0
- data/lib/airbrake/version.rb +5 -1
- data/lib/generators/airbrake_generator.rb +25 -0
- data/lib/generators/airbrake_initializer.rb.erb +80 -0
- metadata +206 -259
- data/CHANGELOG +0 -944
- data/Gemfile +0 -3
- data/Guardfile +0 -6
- data/INSTALL +0 -20
- data/MIT-LICENSE +0 -22
- data/README.md +0 -556
- data/README_FOR_HEROKU_ADDON.md +0 -94
- data/Rakefile +0 -223
- data/SUPPORTED_RAILS_VERSIONS +0 -38
- data/TESTING.md +0 -41
- data/airbrake.gemspec +0 -40
- data/bin/airbrake +0 -12
- data/features/metal.feature +0 -18
- data/features/rack.feature +0 -60
- data/features/rails.feature +0 -272
- data/features/rails_with_js_notifier.feature +0 -97
- data/features/rake.feature +0 -27
- data/features/sinatra.feature +0 -29
- data/features/step_definitions/file_steps.rb +0 -10
- data/features/step_definitions/metal_steps.rb +0 -23
- data/features/step_definitions/rack_steps.rb +0 -23
- data/features/step_definitions/rails_application_steps.rb +0 -478
- data/features/step_definitions/rake_steps.rb +0 -17
- data/features/support/airbrake_shim.rb.template +0 -16
- data/features/support/env.rb +0 -18
- data/features/support/matchers.rb +0 -35
- data/features/support/rails.rb +0 -201
- data/features/support/rake/Rakefile +0 -68
- data/features/support/terminal.rb +0 -107
- data/features/user_informer.feature +0 -63
- data/generators/airbrake/airbrake_generator.rb +0 -94
- data/generators/airbrake/lib/insert_commands.rb +0 -34
- data/generators/airbrake/lib/rake_commands.rb +0 -24
- data/generators/airbrake/templates/airbrake_tasks.rake +0 -25
- data/generators/airbrake/templates/capistrano_hook.rb +0 -6
- data/generators/airbrake/templates/initializer.rb +0 -6
- data/install.rb +0 -1
- data/lib/airbrake/backtrace.rb +0 -108
- data/lib/airbrake/cli/client.rb +0 -68
- data/lib/airbrake/cli/options.rb +0 -41
- data/lib/airbrake/cli/printer.rb +0 -30
- data/lib/airbrake/cli/project.rb +0 -17
- data/lib/airbrake/cli/project_factory.rb +0 -36
- data/lib/airbrake/cli/runner.rb +0 -48
- data/lib/airbrake/cli/validator.rb +0 -8
- data/lib/airbrake/configuration.rb +0 -311
- data/lib/airbrake/extensions/blank.rb +0 -73
- data/lib/airbrake/notice.rb +0 -390
- data/lib/airbrake/rails/action_controller_catcher.rb +0 -30
- data/lib/airbrake/rails/controller_methods.rb +0 -87
- data/lib/airbrake/rails/error_lookup.rb +0 -33
- data/lib/airbrake/rails/javascript_notifier.rb +0 -47
- data/lib/airbrake/rails/middleware/exceptions_catcher.rb +0 -33
- data/lib/airbrake/rails3_tasks.rb +0 -98
- data/lib/airbrake/railtie.rb +0 -48
- data/lib/airbrake/rake_handler.rb +0 -71
- data/lib/airbrake/sender.rb +0 -128
- data/lib/airbrake/shared_tasks.rb +0 -47
- data/lib/airbrake/tasks.rb +0 -83
- data/lib/airbrake/user_informer.rb +0 -27
- data/lib/airbrake_tasks.rb +0 -64
- data/lib/rails/generators/airbrake/airbrake_generator.rb +0 -100
- data/lib/templates/javascript_notifier.erb +0 -15
- data/lib/templates/rescue.erb +0 -91
- data/rails/init.rb +0 -1
- data/resources/README.md +0 -34
- data/resources/ca-bundle.crt +0 -3376
- data/script/integration_test.rb +0 -38
- data/test/airbrake_2_3.xsd +0 -88
- data/test/airbrake_tasks_test.rb +0 -170
- data/test/backtrace_test.rb +0 -162
- data/test/capistrano_test.rb +0 -34
- data/test/catcher_test.rb +0 -333
- data/test/configuration_test.rb +0 -233
- data/test/helper.rb +0 -263
- data/test/javascript_notifier_test.rb +0 -51
- data/test/logger_test.rb +0 -79
- data/test/notice_test.rb +0 -490
- data/test/notifier_test.rb +0 -276
- data/test/rack_test.rb +0 -58
- data/test/rails_initializer_test.rb +0 -36
- data/test/recursion_test.rb +0 -10
- data/test/sender_test.rb +0 -288
- data/test/user_informer_test.rb +0 -29
data/test/helper.rb
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
SimpleCov.start
|
3
|
-
require 'test/unit'
|
4
|
-
require 'rubygems'
|
5
|
-
|
6
|
-
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
7
|
-
|
8
|
-
require 'thread'
|
9
|
-
|
10
|
-
require 'shoulda'
|
11
|
-
require 'mocha'
|
12
|
-
|
13
|
-
require 'action_controller'
|
14
|
-
require 'action_controller/test_process'
|
15
|
-
require 'active_record'
|
16
|
-
require 'active_support'
|
17
|
-
require 'nokogiri'
|
18
|
-
require 'rack'
|
19
|
-
require 'bourne'
|
20
|
-
require 'sham_rack'
|
21
|
-
|
22
|
-
require "airbrake"
|
23
|
-
|
24
|
-
begin require 'redgreen'; rescue LoadError; end
|
25
|
-
|
26
|
-
module TestMethods
|
27
|
-
def rescue_action e
|
28
|
-
raise e
|
29
|
-
end
|
30
|
-
|
31
|
-
def do_raise
|
32
|
-
raise "Airbrake"
|
33
|
-
end
|
34
|
-
|
35
|
-
def do_not_raise
|
36
|
-
render :text => "Success"
|
37
|
-
end
|
38
|
-
|
39
|
-
def do_raise_ignored
|
40
|
-
raise ActiveRecord::RecordNotFound.new("404")
|
41
|
-
end
|
42
|
-
|
43
|
-
def do_raise_not_ignored
|
44
|
-
raise ActiveRecord::StatementInvalid.new("Statement invalid")
|
45
|
-
end
|
46
|
-
|
47
|
-
def manual_notify
|
48
|
-
notify_airbrake(Exception.new)
|
49
|
-
render :text => "Success"
|
50
|
-
end
|
51
|
-
|
52
|
-
def manual_notify_ignored
|
53
|
-
notify_airbrake(ActiveRecord::RecordNotFound.new("404"))
|
54
|
-
render :text => "Success"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class Test::Unit::TestCase
|
59
|
-
def request(action = nil, method = :get, user_agent = nil, params = {})
|
60
|
-
@request = ActionController::TestRequest.new
|
61
|
-
@request.action = action ? action.to_s : ""
|
62
|
-
|
63
|
-
if user_agent
|
64
|
-
if @request.respond_to?(:user_agent=)
|
65
|
-
@request.user_agent = user_agent
|
66
|
-
else
|
67
|
-
@request.env["HTTP_USER_AGENT"] = user_agent
|
68
|
-
end
|
69
|
-
end
|
70
|
-
@request.query_parameters = @request.query_parameters.merge(params)
|
71
|
-
@response = ActionController::TestResponse.new
|
72
|
-
@controller.process(@request, @response)
|
73
|
-
end
|
74
|
-
|
75
|
-
# Borrowed from ActiveSupport 2.3.2
|
76
|
-
def assert_difference(expression, difference = 1, message = nil, &block)
|
77
|
-
b = block.send(:binding)
|
78
|
-
exps = Array.wrap(expression)
|
79
|
-
before = exps.map { |e| eval(e, b) }
|
80
|
-
|
81
|
-
yield
|
82
|
-
|
83
|
-
exps.each_with_index do |e, i|
|
84
|
-
error = "#{e.inspect} didn't change by #{difference}"
|
85
|
-
error = "#{message}.\n#{error}" if message
|
86
|
-
assert_equal(before[i] + difference, eval(e, b), error)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def assert_no_difference(expression, message = nil, &block)
|
91
|
-
assert_difference expression, 0, message, &block
|
92
|
-
end
|
93
|
-
|
94
|
-
def stub_sender
|
95
|
-
stub('sender', :send_to_airbrake => nil)
|
96
|
-
end
|
97
|
-
|
98
|
-
def stub_sender!
|
99
|
-
Airbrake.sender = stub_sender
|
100
|
-
end
|
101
|
-
|
102
|
-
def stub_notice
|
103
|
-
stub('notice', :to_xml => 'some yaml', :ignore? => false)
|
104
|
-
end
|
105
|
-
|
106
|
-
def stub_notice!
|
107
|
-
stub_notice.tap do |notice|
|
108
|
-
Airbrake::Notice.stubs(:new => notice)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def create_dummy
|
113
|
-
Airbrake::DummySender.new
|
114
|
-
end
|
115
|
-
|
116
|
-
def reset_config
|
117
|
-
Airbrake.configuration = nil
|
118
|
-
Airbrake.configure do |config|
|
119
|
-
config.api_key = 'abc123'
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def clear_backtrace_filters
|
124
|
-
Airbrake.configuration.backtrace_filters.clear
|
125
|
-
end
|
126
|
-
|
127
|
-
def build_exception(opts = {})
|
128
|
-
backtrace = ["airbrake/test/helper.rb:132:in `build_exception'",
|
129
|
-
"airbrake/test/backtrace.rb:4:in `build_notice_data'",
|
130
|
-
"/var/lib/gems/1.8/gems/airbrake-2.4.5/rails/init.rb:2:in `send_exception'"]
|
131
|
-
opts = {:backtrace => backtrace}.merge(opts)
|
132
|
-
BacktracedException.new(opts)
|
133
|
-
end
|
134
|
-
|
135
|
-
def build_notice_data(exception = nil)
|
136
|
-
exception ||= build_exception
|
137
|
-
{
|
138
|
-
:api_key => 'abc123',
|
139
|
-
:error_class => exception.class.name,
|
140
|
-
:error_message => "#{exception.class.name}: #{exception.message}",
|
141
|
-
:backtrace => exception.backtrace,
|
142
|
-
:environment => { 'PATH' => '/bin', 'REQUEST_URI' => '/users/1' },
|
143
|
-
:request => {
|
144
|
-
:params => { 'controller' => 'users', 'action' => 'show', 'id' => '1' },
|
145
|
-
:rails_root => '/path/to/application',
|
146
|
-
:url => "http://test.host/users/1"
|
147
|
-
},
|
148
|
-
:session => {
|
149
|
-
:key => '123abc',
|
150
|
-
:data => { 'user_id' => '5', 'flash' => { 'notice' => 'Logged in successfully' } }
|
151
|
-
}
|
152
|
-
}
|
153
|
-
end
|
154
|
-
|
155
|
-
def assert_caught_and_sent
|
156
|
-
assert !Airbrake.sender.collected.empty?
|
157
|
-
end
|
158
|
-
|
159
|
-
def assert_caught_and_not_sent
|
160
|
-
assert Airbrake.sender.collected.empty?
|
161
|
-
end
|
162
|
-
|
163
|
-
def assert_array_starts_with(expected, actual)
|
164
|
-
assert_respond_to actual, :to_ary
|
165
|
-
array = actual.to_ary.reverse
|
166
|
-
expected.reverse.each_with_index do |value, i|
|
167
|
-
assert_equal value, array[i]
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def assert_valid_node(document, xpath, content)
|
172
|
-
nodes = document.xpath(xpath)
|
173
|
-
assert nodes.any?{|node| node.content == content },
|
174
|
-
"Expected xpath #{xpath} to have content #{content}, " +
|
175
|
-
"but found #{nodes.map { |n| n.content }} in #{nodes.size} matching nodes." +
|
176
|
-
"Document:\n#{document.to_s}"
|
177
|
-
end
|
178
|
-
|
179
|
-
def assert_logged(expected)
|
180
|
-
assert_received(Airbrake, :write_verbose_log) do |expect|
|
181
|
-
expect.with {|actual| actual =~ expected }
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def assert_not_logged(expected)
|
186
|
-
assert_received(Airbrake, :write_verbose_log) do |expect|
|
187
|
-
expect.with {|actual| actual =~ expected }.never
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
end
|
193
|
-
|
194
|
-
module DefinesConstants
|
195
|
-
def setup
|
196
|
-
@defined_constants = []
|
197
|
-
end
|
198
|
-
|
199
|
-
def teardown
|
200
|
-
@defined_constants.each do |constant|
|
201
|
-
Object.__send__(:remove_const, constant)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def define_constant(name, value)
|
206
|
-
Object.const_set(name, value)
|
207
|
-
@defined_constants << name
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
# Also stolen from AS 2.3.2
|
212
|
-
class Array
|
213
|
-
# Wraps the object in an Array unless it's an Array. Converts the
|
214
|
-
# object to an Array using #to_ary if it implements that.
|
215
|
-
def self.wrap(object)
|
216
|
-
case object
|
217
|
-
when nil
|
218
|
-
[]
|
219
|
-
when self
|
220
|
-
object
|
221
|
-
else
|
222
|
-
if object.respond_to?(:to_ary)
|
223
|
-
object.to_ary
|
224
|
-
else
|
225
|
-
[object]
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|
231
|
-
|
232
|
-
class CollectingSender
|
233
|
-
attr_reader :collected
|
234
|
-
|
235
|
-
def initialize
|
236
|
-
@collected = []
|
237
|
-
end
|
238
|
-
|
239
|
-
def send_to_airbrake(data)
|
240
|
-
@collected << data
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
class FakeLogger
|
245
|
-
def info(*args); end
|
246
|
-
def debug(*args); end
|
247
|
-
def warn(*args); end
|
248
|
-
def error(*args); end
|
249
|
-
def fatal(*args); end
|
250
|
-
end
|
251
|
-
|
252
|
-
class BacktracedException < Exception
|
253
|
-
attr_accessor :backtrace
|
254
|
-
def initialize(opts)
|
255
|
-
@backtrace = opts[:backtrace]
|
256
|
-
end
|
257
|
-
def set_backtrace(bt)
|
258
|
-
@backtrace = bt
|
259
|
-
end
|
260
|
-
def message
|
261
|
-
"Something went wrong. Did you press the red button?"
|
262
|
-
end
|
263
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.expand_path '../helper', __FILE__
|
2
|
-
require 'airbrake/rails/javascript_notifier'
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
|
-
class JavascriptNotifierTest < Test::Unit::TestCase
|
6
|
-
module FakeRenderer
|
7
|
-
def javascript_tag(text)
|
8
|
-
"<script>#{text}</script>"
|
9
|
-
end
|
10
|
-
def escape_javascript(text)
|
11
|
-
"ESC#{text}ESC"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class FakeController
|
16
|
-
def self.helper_method(*args)
|
17
|
-
end
|
18
|
-
|
19
|
-
include Airbrake::Rails::JavascriptNotifier
|
20
|
-
|
21
|
-
def action_name
|
22
|
-
"action"
|
23
|
-
end
|
24
|
-
|
25
|
-
def controller_name
|
26
|
-
"controller"
|
27
|
-
end
|
28
|
-
|
29
|
-
def request
|
30
|
-
@request ||= OpenStruct.new
|
31
|
-
end
|
32
|
-
|
33
|
-
def render_to_string(options)
|
34
|
-
context = OpenStruct.new(options[:locals])
|
35
|
-
context.extend(FakeRenderer)
|
36
|
-
context.instance_eval do
|
37
|
-
erb = ERB.new(IO.read(options[:file]))
|
38
|
-
erb.result(binding)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
should "make sure escape_javacript is called on the request.url" do
|
44
|
-
Airbrake.configure do
|
45
|
-
end
|
46
|
-
controller = FakeController.new
|
47
|
-
controller.request.url = "bad_javascript"
|
48
|
-
assert controller.send(:airbrake_javascript_notifier)['"ESCbad_javascriptESC"']
|
49
|
-
assert ! controller.send(:airbrake_javascript_notifier)['"bad_javascript"']
|
50
|
-
end
|
51
|
-
end
|
data/test/logger_test.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require File.expand_path '../helper', __FILE__
|
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
|
-
Net::HTTP.stubs(:new).returns(@http)
|
11
|
-
end
|
12
|
-
|
13
|
-
def send_notice
|
14
|
-
Airbrake.sender.send_to_airbrake({'foo' => "bar"})
|
15
|
-
end
|
16
|
-
|
17
|
-
def stub_verbose_log
|
18
|
-
Airbrake.stubs(:write_verbose_log)
|
19
|
-
end
|
20
|
-
|
21
|
-
def configure
|
22
|
-
Airbrake.configure { |config| }
|
23
|
-
end
|
24
|
-
|
25
|
-
should "report that notifier is ready when configured" do
|
26
|
-
stub_verbose_log
|
27
|
-
configure
|
28
|
-
assert_logged /Notifier (.*) ready/
|
29
|
-
end
|
30
|
-
|
31
|
-
should "not report that notifier is ready when internally configured" do
|
32
|
-
stub_verbose_log
|
33
|
-
Airbrake.configure(true) { |config| }
|
34
|
-
assert_not_logged /.*/
|
35
|
-
end
|
36
|
-
|
37
|
-
should "print environment info a successful notification without a body" do
|
38
|
-
reset_config
|
39
|
-
stub_verbose_log
|
40
|
-
stub_http(Net::HTTPSuccess)
|
41
|
-
send_notice
|
42
|
-
assert_logged /Environment Info:/
|
43
|
-
assert_not_logged /Response from Airbrake:/
|
44
|
-
end
|
45
|
-
|
46
|
-
should "print environment info on a failed notification without a body" do
|
47
|
-
reset_config
|
48
|
-
stub_verbose_log
|
49
|
-
stub_http(Net::HTTPError)
|
50
|
-
send_notice
|
51
|
-
assert_logged /Environment Info:/
|
52
|
-
assert_not_logged /Response from Airbrake:/
|
53
|
-
end
|
54
|
-
|
55
|
-
should "print environment info and response on a success with a body" do
|
56
|
-
reset_config
|
57
|
-
stub_verbose_log
|
58
|
-
stub_http(Net::HTTPSuccess, 'test')
|
59
|
-
send_notice
|
60
|
-
assert_logged /Environment Info:/
|
61
|
-
assert_logged /Response from Airbrake:/
|
62
|
-
end
|
63
|
-
|
64
|
-
should "print environment info and response on a failure with a body" do
|
65
|
-
reset_config
|
66
|
-
stub_verbose_log
|
67
|
-
stub_http(Net::HTTPError, 'test')
|
68
|
-
send_notice
|
69
|
-
assert_logged /Environment Info:/
|
70
|
-
assert_logged /Response from Airbrake:/
|
71
|
-
end
|
72
|
-
|
73
|
-
should "print information about the notice when Airbrake server fails" do
|
74
|
-
stub_verbose_log
|
75
|
-
stub_http(Net::HTTPError, "test")
|
76
|
-
send_notice
|
77
|
-
assert_logged /Notice details:/
|
78
|
-
end
|
79
|
-
end
|
data/test/notice_test.rb
DELETED
@@ -1,490 +0,0 @@
|
|
1
|
-
require File.expand_path '../helper', __FILE__
|
2
|
-
|
3
|
-
class NoticeTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include DefinesConstants
|
6
|
-
|
7
|
-
def configure
|
8
|
-
Airbrake::Configuration.new.tap do |config|
|
9
|
-
config.api_key = 'abc123def456'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def build_notice(args = {})
|
14
|
-
configuration = args.delete(:configuration) || configure
|
15
|
-
Airbrake::Notice.new(configuration.merge(args))
|
16
|
-
end
|
17
|
-
|
18
|
-
def stub_request(attrs = {})
|
19
|
-
stub('request', { :parameters => { 'one' => 'two' },
|
20
|
-
:protocol => 'http',
|
21
|
-
:host => 'some.host',
|
22
|
-
:request_uri => '/some/uri',
|
23
|
-
:session => { :to_hash => { 'a' => 'b' } },
|
24
|
-
:env => { 'three' => 'four' } }.update(attrs))
|
25
|
-
end
|
26
|
-
|
27
|
-
def assert_accepts_exception_attribute(attribute, args = {}, &block)
|
28
|
-
exception = build_exception
|
29
|
-
block ||= lambda { exception.send(attribute) }
|
30
|
-
value = block.call(exception)
|
31
|
-
|
32
|
-
notice_from_exception = build_notice(args.merge(:exception => exception))
|
33
|
-
|
34
|
-
assert_equal notice_from_exception.send(attribute),
|
35
|
-
value,
|
36
|
-
"#{attribute} was not correctly set from an exception"
|
37
|
-
|
38
|
-
notice_from_hash = build_notice(args.merge(attribute => value))
|
39
|
-
assert_equal notice_from_hash.send(attribute),
|
40
|
-
value,
|
41
|
-
"#{attribute} was not correctly set from a hash"
|
42
|
-
end
|
43
|
-
|
44
|
-
def assert_serializes_hash(attribute)
|
45
|
-
[File.open(__FILE__), Proc.new { puts "boo!" }, Module.new].each do |object|
|
46
|
-
hash = {
|
47
|
-
:strange_object => object,
|
48
|
-
:sub_hash => {
|
49
|
-
:sub_object => object
|
50
|
-
},
|
51
|
-
:array => [object]
|
52
|
-
}
|
53
|
-
notice = build_notice(attribute => hash)
|
54
|
-
hash = notice.send(attribute)
|
55
|
-
assert_equal object.to_s, hash[:strange_object], "objects should be serialized"
|
56
|
-
assert_kind_of Hash, hash[:sub_hash], "subhashes should be kept"
|
57
|
-
assert_equal object.to_s, hash[:sub_hash][:sub_object], "subhash members should be serialized"
|
58
|
-
assert_kind_of Array, hash[:array], "arrays should be kept"
|
59
|
-
assert_equal object.to_s, hash[:array].first, "array members should be serialized"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def assert_valid_notice_document(document)
|
64
|
-
xsd_path = File.join(File.dirname(__FILE__), "airbrake_2_3.xsd")
|
65
|
-
schema = Nokogiri::XML::Schema.new(IO.read(xsd_path))
|
66
|
-
errors = schema.validate(document)
|
67
|
-
assert errors.empty?, errors.collect{|e| e.message }.join
|
68
|
-
end
|
69
|
-
|
70
|
-
def assert_filters_hash(attribute)
|
71
|
-
filters = ["abc", :def]
|
72
|
-
original = { 'abc' => "123", 'def' => "456", 'ghi' => "789", 'nested' => { 'abc' => '100' },
|
73
|
-
'something_with_abc' => 'match the entire string'}
|
74
|
-
filtered = { 'abc' => "[FILTERED]",
|
75
|
-
'def' => "[FILTERED]",
|
76
|
-
'something_with_abc' => "match the entire string",
|
77
|
-
'ghi' => "789",
|
78
|
-
'nested' => { 'abc' => '[FILTERED]' } }
|
79
|
-
|
80
|
-
notice = build_notice(:params_filters => filters, attribute => original)
|
81
|
-
|
82
|
-
assert_equal(filtered,
|
83
|
-
notice.send(attribute))
|
84
|
-
end
|
85
|
-
|
86
|
-
def build_backtrace_array
|
87
|
-
["app/models/user.rb:13:in `magic'",
|
88
|
-
"app/controllers/users_controller.rb:8:in `index'"]
|
89
|
-
end
|
90
|
-
|
91
|
-
def hostname
|
92
|
-
`hostname`.chomp
|
93
|
-
end
|
94
|
-
|
95
|
-
def user
|
96
|
-
Struct.new(:email,:id,:name).
|
97
|
-
new("darth@vader.com",1,"Anakin Skywalker")
|
98
|
-
end
|
99
|
-
|
100
|
-
should "set the api key" do
|
101
|
-
api_key = 'key'
|
102
|
-
notice = build_notice(:api_key => api_key)
|
103
|
-
assert_equal api_key, notice.api_key
|
104
|
-
end
|
105
|
-
|
106
|
-
should "accept a project root" do
|
107
|
-
project_root = '/path/to/project'
|
108
|
-
notice = build_notice(:project_root => project_root)
|
109
|
-
assert_equal project_root, notice.project_root
|
110
|
-
end
|
111
|
-
|
112
|
-
should "accept a component" do
|
113
|
-
assert_equal 'users_controller', build_notice(:component => 'users_controller').controller
|
114
|
-
end
|
115
|
-
|
116
|
-
should "alias the component as controller" do
|
117
|
-
assert_equal 'users_controller', build_notice(:controller => 'users_controller').component
|
118
|
-
assert_equal 'users_controller', build_notice(:component => 'users_controller').controller
|
119
|
-
end
|
120
|
-
|
121
|
-
should "accept a action" do
|
122
|
-
assert_equal 'index', build_notice(:action => 'index').action
|
123
|
-
end
|
124
|
-
|
125
|
-
should "accept a url" do
|
126
|
-
url = 'http://some.host/uri'
|
127
|
-
notice = build_notice(:url => url)
|
128
|
-
assert_equal url, notice.url
|
129
|
-
end
|
130
|
-
|
131
|
-
should "set the host name" do
|
132
|
-
notice = build_notice
|
133
|
-
assert_equal hostname, notice.hostname
|
134
|
-
end
|
135
|
-
|
136
|
-
should "accept a backtrace from an exception or hash" do
|
137
|
-
array = ["user.rb:34:in `crazy'"]
|
138
|
-
exception = build_exception
|
139
|
-
exception.set_backtrace array
|
140
|
-
backtrace = Airbrake::Backtrace.parse(array)
|
141
|
-
notice_from_exception = build_notice(:exception => exception)
|
142
|
-
|
143
|
-
|
144
|
-
assert_equal backtrace,
|
145
|
-
notice_from_exception.backtrace,
|
146
|
-
"backtrace was not correctly set from an exception"
|
147
|
-
|
148
|
-
notice_from_hash = build_notice(:backtrace => array)
|
149
|
-
assert_equal backtrace,
|
150
|
-
notice_from_hash.backtrace,
|
151
|
-
"backtrace was not correctly set from a hash"
|
152
|
-
end
|
153
|
-
|
154
|
-
should "accept user" do
|
155
|
-
assert_equal user.id, build_notice(:user => user).user.id
|
156
|
-
assert_equal user.email, build_notice(:user => user).user.email
|
157
|
-
assert_equal user.name, build_notice(:user => user).user.name
|
158
|
-
end
|
159
|
-
|
160
|
-
should "pass its backtrace filters for parsing" do
|
161
|
-
backtrace_array = ['my/file/backtrace:3']
|
162
|
-
exception = build_exception
|
163
|
-
exception.set_backtrace(backtrace_array)
|
164
|
-
Airbrake::Backtrace.expects(:parse).with(backtrace_array, {:filters => 'foo'})
|
165
|
-
|
166
|
-
notice = Airbrake::Notice.new({:exception => exception, :backtrace_filters => 'foo'})
|
167
|
-
end
|
168
|
-
|
169
|
-
should "set the error class from an exception or hash" do
|
170
|
-
assert_accepts_exception_attribute :error_class do |exception|
|
171
|
-
exception.class.name
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
should "set the error message from an exception or hash" do
|
176
|
-
assert_accepts_exception_attribute :error_message do |exception|
|
177
|
-
"#{exception.class.name}: #{exception.message}"
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
should "accept parameters from a request or hash" do
|
182
|
-
parameters = { 'one' => 'two' }
|
183
|
-
notice_from_hash = build_notice(:parameters => parameters)
|
184
|
-
assert_equal notice_from_hash.parameters, parameters
|
185
|
-
end
|
186
|
-
|
187
|
-
should "accept session data from a session[:data] hash" do
|
188
|
-
data = { 'one' => 'two' }
|
189
|
-
notice = build_notice(:session => { :data => data })
|
190
|
-
assert_equal data, notice.session_data
|
191
|
-
end
|
192
|
-
|
193
|
-
should "accept session data from a session_data hash" do
|
194
|
-
data = { 'one' => 'two' }
|
195
|
-
notice = build_notice(:session_data => data)
|
196
|
-
assert_equal data, notice.session_data
|
197
|
-
end
|
198
|
-
|
199
|
-
should "accept an environment name" do
|
200
|
-
assert_equal 'development', build_notice(:environment_name => 'development').environment_name
|
201
|
-
end
|
202
|
-
|
203
|
-
should "accept CGI data from a hash" do
|
204
|
-
data = { 'string' => 'value' }
|
205
|
-
notice = build_notice(:cgi_data => data)
|
206
|
-
assert_equal data, notice.cgi_data, "should take CGI data from a hash"
|
207
|
-
end
|
208
|
-
|
209
|
-
should "accept notifier information" do
|
210
|
-
params = { :notifier_name => 'a name for a notifier',
|
211
|
-
:notifier_version => '1.0.5',
|
212
|
-
:notifier_url => 'http://notifiers.r.us/download' }
|
213
|
-
notice = build_notice(params)
|
214
|
-
assert_equal params[:notifier_name], notice.notifier_name
|
215
|
-
assert_equal params[:notifier_version], notice.notifier_version
|
216
|
-
assert_equal params[:notifier_url], notice.notifier_url
|
217
|
-
end
|
218
|
-
|
219
|
-
should "set sensible defaults without an exception" do
|
220
|
-
backtrace = Airbrake::Backtrace.parse(build_backtrace_array)
|
221
|
-
notice = build_notice(:backtrace => build_backtrace_array)
|
222
|
-
|
223
|
-
assert_equal 'Notification', notice.error_message
|
224
|
-
assert_array_starts_with backtrace.lines, notice.backtrace.lines
|
225
|
-
assert_equal({}, notice.parameters)
|
226
|
-
assert_equal({}, notice.session_data)
|
227
|
-
end
|
228
|
-
|
229
|
-
should "use the caller as the backtrace for an exception without a backtrace" do
|
230
|
-
filters = Airbrake::Configuration.new.backtrace_filters
|
231
|
-
backtrace = Airbrake::Backtrace.parse(caller, :filters => filters)
|
232
|
-
notice = build_notice(:exception => StandardError.new('error'), :backtrace => nil)
|
233
|
-
|
234
|
-
assert_array_starts_with backtrace.lines, notice.backtrace.lines
|
235
|
-
end
|
236
|
-
|
237
|
-
should "convert unserializable objects to strings" do
|
238
|
-
assert_serializes_hash(:parameters)
|
239
|
-
assert_serializes_hash(:cgi_data)
|
240
|
-
assert_serializes_hash(:session_data)
|
241
|
-
end
|
242
|
-
|
243
|
-
should "filter parameters" do
|
244
|
-
assert_filters_hash(:parameters)
|
245
|
-
end
|
246
|
-
|
247
|
-
should "filter cgi data" do
|
248
|
-
assert_filters_hash(:cgi_data)
|
249
|
-
end
|
250
|
-
|
251
|
-
should "filter session" do
|
252
|
-
assert_filters_hash(:session_data)
|
253
|
-
end
|
254
|
-
|
255
|
-
should "remove rack.request.form_vars" do
|
256
|
-
original = {
|
257
|
-
"rack.request.form_vars" => "story%5Btitle%5D=The+TODO+label",
|
258
|
-
"abc" => "123"
|
259
|
-
}
|
260
|
-
|
261
|
-
notice = build_notice(:cgi_data => original)
|
262
|
-
assert_equal({"abc" => "123"}, notice.cgi_data)
|
263
|
-
end
|
264
|
-
|
265
|
-
context "a Notice turned into XML" do
|
266
|
-
setup do
|
267
|
-
Airbrake.configure do |config|
|
268
|
-
config.api_key = "1234567890"
|
269
|
-
end
|
270
|
-
|
271
|
-
@exception = build_exception
|
272
|
-
|
273
|
-
@notice = build_notice({
|
274
|
-
:notifier_name => 'a name',
|
275
|
-
:notifier_version => '1.2.3',
|
276
|
-
:notifier_url => 'http://some.url/path',
|
277
|
-
:exception => @exception,
|
278
|
-
:controller => "controller",
|
279
|
-
:action => "action",
|
280
|
-
:url => "http://url.com",
|
281
|
-
:parameters => { "paramskey" => "paramsvalue",
|
282
|
-
"nestparentkey" => { "nestkey" => "nestvalue" } },
|
283
|
-
:session_data => { "sessionkey" => "sessionvalue" },
|
284
|
-
:cgi_data => { "cgikey" => "cgivalue" },
|
285
|
-
:project_root => "RAILS_ROOT",
|
286
|
-
:environment_name => "RAILS_ENV"
|
287
|
-
})
|
288
|
-
|
289
|
-
@xml = @notice.to_xml
|
290
|
-
|
291
|
-
@document = Nokogiri::XML::Document.parse(@xml)
|
292
|
-
end
|
293
|
-
|
294
|
-
should "validate against the XML schema" do
|
295
|
-
assert_valid_notice_document @document
|
296
|
-
end
|
297
|
-
|
298
|
-
should "serialize a Notice to XML when sent #to_xml" do
|
299
|
-
assert_valid_node(@document, "//api-key", @notice.api_key)
|
300
|
-
|
301
|
-
assert_valid_node(@document, "//notifier/name", @notice.notifier_name)
|
302
|
-
assert_valid_node(@document, "//notifier/version", @notice.notifier_version)
|
303
|
-
assert_valid_node(@document, "//notifier/url", @notice.notifier_url)
|
304
|
-
|
305
|
-
assert_valid_node(@document, "//error/class", @notice.error_class)
|
306
|
-
assert_valid_node(@document, "//error/message", @notice.error_message)
|
307
|
-
|
308
|
-
assert_valid_node(@document, "//error/backtrace/line/@number", @notice.backtrace.lines.first.number)
|
309
|
-
assert_valid_node(@document, "//error/backtrace/line/@file", @notice.backtrace.lines.first.file)
|
310
|
-
assert_valid_node(@document, "//error/backtrace/line/@method", @notice.backtrace.lines.first.method)
|
311
|
-
|
312
|
-
assert_valid_node(@document, "//request/url", @notice.url)
|
313
|
-
assert_valid_node(@document, "//request/component", @notice.controller)
|
314
|
-
assert_valid_node(@document, "//request/action", @notice.action)
|
315
|
-
|
316
|
-
assert_valid_node(@document, "//request/params/var/@key", "paramskey")
|
317
|
-
assert_valid_node(@document, "//request/params/var", "paramsvalue")
|
318
|
-
assert_valid_node(@document, "//request/params/var/@key", "nestparentkey")
|
319
|
-
assert_valid_node(@document, "//request/params/var/var/@key", "nestkey")
|
320
|
-
assert_valid_node(@document, "//request/params/var/var", "nestvalue")
|
321
|
-
assert_valid_node(@document, "//request/session/var/@key", "sessionkey")
|
322
|
-
assert_valid_node(@document, "//request/session/var", "sessionvalue")
|
323
|
-
assert_valid_node(@document, "//request/cgi-data/var/@key", "cgikey")
|
324
|
-
assert_valid_node(@document, "//request/cgi-data/var", "cgivalue")
|
325
|
-
|
326
|
-
assert_valid_node(@document, "//server-environment/project-root", "RAILS_ROOT")
|
327
|
-
assert_valid_node(@document, "//server-environment/environment-name", "RAILS_ENV")
|
328
|
-
assert_valid_node(@document, "//server-environment/hostname", hostname)
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
should "not send empty request data" do
|
333
|
-
notice = build_notice
|
334
|
-
assert_nil notice.url
|
335
|
-
assert_nil notice.controller
|
336
|
-
assert_nil notice.action
|
337
|
-
|
338
|
-
xml = notice.to_xml
|
339
|
-
document = Nokogiri::XML.parse(xml)
|
340
|
-
assert_nil document.at('//request/url')
|
341
|
-
assert_nil document.at('//request/component')
|
342
|
-
assert_nil document.at('//request/action')
|
343
|
-
|
344
|
-
assert_valid_notice_document document
|
345
|
-
end
|
346
|
-
|
347
|
-
%w(url controller action).each do |var|
|
348
|
-
should "send a request if #{var} is present" do
|
349
|
-
notice = build_notice(var.to_sym => 'value')
|
350
|
-
xml = notice.to_xml
|
351
|
-
document = Nokogiri::XML.parse(xml)
|
352
|
-
assert_not_nil document.at('//request')
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
%w(parameters cgi_data session_data).each do |var|
|
357
|
-
should "send a request if #{var} is present" do
|
358
|
-
notice = build_notice(var.to_sym => { 'key' => 'value' })
|
359
|
-
xml = notice.to_xml
|
360
|
-
document = Nokogiri::XML.parse(xml)
|
361
|
-
assert_not_nil document.at('//request')
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
should "not ignore an exception not matching ignore filters" do
|
366
|
-
notice = build_notice(:error_class => 'ArgumentError',
|
367
|
-
:ignore => ['Argument'],
|
368
|
-
:ignore_by_filters => [lambda { |notice| false }])
|
369
|
-
assert !notice.ignore?
|
370
|
-
end
|
371
|
-
|
372
|
-
should "ignore an exception with a matching error class" do
|
373
|
-
notice = build_notice(:error_class => 'ArgumentError',
|
374
|
-
:ignore => [ArgumentError])
|
375
|
-
assert notice.ignore?
|
376
|
-
end
|
377
|
-
|
378
|
-
should "ignore an exception with a matching error class name" do
|
379
|
-
notice = build_notice(:error_class => 'ArgumentError',
|
380
|
-
:ignore => ['ArgumentError'])
|
381
|
-
assert notice.ignore?
|
382
|
-
end
|
383
|
-
|
384
|
-
should "ignore an exception with a matching filter" do
|
385
|
-
filter = lambda {|notice| notice.error_class == 'ArgumentError' }
|
386
|
-
notice = build_notice(:error_class => 'ArgumentError',
|
387
|
-
:ignore_by_filters => [filter])
|
388
|
-
assert notice.ignore?
|
389
|
-
end
|
390
|
-
|
391
|
-
should "not raise without an ignore list" do
|
392
|
-
notice = build_notice(:ignore => nil, :ignore_by_filters => nil)
|
393
|
-
assert_nothing_raised do
|
394
|
-
notice.ignore?
|
395
|
-
end
|
396
|
-
end
|
397
|
-
|
398
|
-
ignored_error_classes = Airbrake::Configuration::IGNORE_DEFAULT
|
399
|
-
|
400
|
-
ignored_error_classes.each do |ignored_error_class|
|
401
|
-
should "ignore #{ignored_error_class} error by default" do
|
402
|
-
notice = build_notice(:error_class => ignored_error_class)
|
403
|
-
assert notice.ignore?
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
should "act like a hash" do
|
408
|
-
notice = build_notice(:error_message => 'some message')
|
409
|
-
assert_equal notice.error_message, notice[:error_message]
|
410
|
-
end
|
411
|
-
|
412
|
-
should "return params on notice[:request][:params]" do
|
413
|
-
params = { 'one' => 'two' }
|
414
|
-
notice = build_notice(:parameters => params)
|
415
|
-
assert_equal params, notice[:request][:params]
|
416
|
-
end
|
417
|
-
|
418
|
-
should "ensure #to_hash is called on objects that support it" do
|
419
|
-
assert_nothing_raised do
|
420
|
-
build_notice(:session => { :object => stub(:to_hash => {}) })
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
should "ensure #to_ary is called on objects that support it" do
|
425
|
-
assert_nothing_raised do
|
426
|
-
build_notice(:session => { :object => stub(:to_ary => {}) })
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
should "extract data from a rack environment hash" do
|
431
|
-
url = "https://subdomain.happylane.com:100/test/file.rb?var=value&var2=value2"
|
432
|
-
parameters = { 'var' => 'value', 'var2' => 'value2' }
|
433
|
-
env = Rack::MockRequest.env_for(url)
|
434
|
-
|
435
|
-
notice = build_notice(:rack_env => env)
|
436
|
-
|
437
|
-
assert_equal url, notice.url
|
438
|
-
assert_equal parameters, notice.parameters
|
439
|
-
assert_equal 'GET', notice.cgi_data['REQUEST_METHOD']
|
440
|
-
end
|
441
|
-
|
442
|
-
should "show a nice warning when rack environment exceeds rack keyspace" do
|
443
|
-
# simulate exception for too big query
|
444
|
-
Rack::Request.any_instance.expects(:params).raises(RangeError.new("exceeded available parameter key space"))
|
445
|
-
|
446
|
-
url = "https://subdomain.happylane.com:100/test/file.rb?var=x"
|
447
|
-
env = Rack::MockRequest.env_for(url)
|
448
|
-
|
449
|
-
notice = build_notice(:rack_env => env)
|
450
|
-
|
451
|
-
assert_equal url, notice.url
|
452
|
-
assert_equal({:message => "failed to call params on Rack::Request -- exceeded available parameter key space"}, notice.parameters)
|
453
|
-
assert_equal 'GET', notice.cgi_data['REQUEST_METHOD']
|
454
|
-
end
|
455
|
-
|
456
|
-
should "extract data from a rack environment hash with action_dispatch info" do
|
457
|
-
params = { 'controller' => 'users', 'action' => 'index', 'id' => '7' }
|
458
|
-
env = Rack::MockRequest.env_for('/', { 'action_dispatch.request.parameters' => params })
|
459
|
-
|
460
|
-
notice = build_notice(:rack_env => env)
|
461
|
-
|
462
|
-
assert_equal params, notice.parameters
|
463
|
-
assert_equal params['controller'], notice.component
|
464
|
-
assert_equal params['action'], notice.action
|
465
|
-
end
|
466
|
-
|
467
|
-
should "extract session data from a rack environment" do
|
468
|
-
session_data = { 'something' => 'some value' }
|
469
|
-
env = Rack::MockRequest.env_for('/', 'rack.session' => session_data)
|
470
|
-
|
471
|
-
notice = build_notice(:rack_env => env)
|
472
|
-
|
473
|
-
assert_equal session_data, notice.session_data
|
474
|
-
end
|
475
|
-
|
476
|
-
should "prefer passed session data to rack session data" do
|
477
|
-
session_data = { 'something' => 'some value' }
|
478
|
-
env = Rack::MockRequest.env_for('/')
|
479
|
-
|
480
|
-
notice = build_notice(:rack_env => env, :session_data => session_data)
|
481
|
-
|
482
|
-
assert_equal session_data, notice.session_data
|
483
|
-
end
|
484
|
-
|
485
|
-
should "prefer passed error_message to exception message" do
|
486
|
-
exception = build_exception
|
487
|
-
notice = build_notice(:exception => exception,:error_message => "Random ponies")
|
488
|
-
assert_equal "BacktracedException: Random ponies", notice.error_message
|
489
|
-
end
|
490
|
-
end
|