airbrake 4.3.8 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/lib/airbrake/capistrano/tasks.rb +64 -0
  3. data/lib/airbrake/delayed_job/plugin.rb +48 -0
  4. data/lib/airbrake/rack/middleware.rb +45 -0
  5. data/lib/airbrake/rack/notice_builder.rb +80 -0
  6. data/lib/airbrake/rack/user.rb +51 -0
  7. data/lib/airbrake/rails/action_controller.rb +35 -0
  8. data/lib/airbrake/rails/active_job.rb +23 -0
  9. data/lib/airbrake/rails/active_record.rb +40 -0
  10. data/lib/airbrake/rails/railtie.rb +61 -0
  11. data/lib/airbrake/rake/task_ext.rb +61 -0
  12. data/lib/airbrake/rake/tasks.rb +93 -0
  13. data/lib/airbrake/resque/failure.rb +19 -0
  14. data/lib/airbrake/sidekiq/error_handler.rb +35 -0
  15. data/lib/airbrake/version.rb +4 -1
  16. data/lib/airbrake.rb +16 -185
  17. data/lib/generators/airbrake_generator.rb +25 -0
  18. data/lib/generators/airbrake_initializer.rb.erb +55 -0
  19. data/spec/airbrake_spec.rb +0 -0
  20. data/spec/apps/rack/dummy_app.rb +17 -0
  21. data/spec/apps/rails/dummy_app.rb +150 -0
  22. data/spec/apps/rails/dummy_task.rake +20 -0
  23. data/spec/apps/rails/logs/32.log +13358 -0
  24. data/spec/apps/rails/logs/40.log +6854 -0
  25. data/spec/apps/rails/logs/41.log +3170 -0
  26. data/spec/apps/rails/logs/42.log +23919 -0
  27. data/spec/apps/rails/logs/50.log +10976 -0
  28. data/spec/apps/sinatra/dummy_app.rb +12 -0
  29. data/spec/integration/rack/rack_spec.rb +17 -0
  30. data/spec/integration/rails/rails_spec.rb +135 -0
  31. data/spec/integration/rails/rake_spec.rb +160 -0
  32. data/spec/integration/shared_examples/rack_examples.rb +106 -0
  33. data/spec/integration/sinatra/sinatra_spec.rb +15 -0
  34. data/spec/spec_helper.rb +127 -0
  35. data/spec/unit/rack/middleware_spec.rb +80 -0
  36. data/spec/unit/rack/notice_builder_spec.rb +35 -0
  37. data/spec/unit/rack/user_spec.rb +78 -0
  38. data/spec/unit/rake/tasks_spec.rb +40 -0
  39. data/spec/unit/sidekiq/error_handler_spec.rb +29 -0
  40. metadata +108 -323
  41. data/CHANGELOG +0 -1716
  42. data/Gemfile +0 -3
  43. data/Guardfile +0 -6
  44. data/INSTALL +0 -20
  45. data/LICENSE +0 -61
  46. data/README.md +0 -148
  47. data/README_FOR_HEROKU_ADDON.md +0 -102
  48. data/Rakefile +0 -179
  49. data/TESTED_AGAINST +0 -7
  50. data/airbrake.gemspec +0 -41
  51. data/bin/airbrake +0 -12
  52. data/features/metal.feature +0 -34
  53. data/features/rack.feature +0 -60
  54. data/features/rails.feature +0 -324
  55. data/features/rake.feature +0 -33
  56. data/features/sinatra.feature +0 -126
  57. data/features/step_definitions/file_steps.rb +0 -14
  58. data/features/step_definitions/rack_steps.rb +0 -27
  59. data/features/step_definitions/rails_application_steps.rb +0 -267
  60. data/features/step_definitions/rake_steps.rb +0 -22
  61. data/features/support/airbrake_shim.rb.template +0 -11
  62. data/features/support/aruba.rb +0 -5
  63. data/features/support/env.rb +0 -39
  64. data/features/support/matchers.rb +0 -35
  65. data/features/support/rails.rb +0 -156
  66. data/features/support/rake/Rakefile +0 -77
  67. data/features/user_informer.feature +0 -57
  68. data/generators/airbrake/airbrake_generator.rb +0 -94
  69. data/generators/airbrake/lib/insert_commands.rb +0 -34
  70. data/generators/airbrake/lib/rake_commands.rb +0 -24
  71. data/generators/airbrake/templates/airbrake_tasks.rake +0 -25
  72. data/generators/airbrake/templates/capistrano_hook.rb +0 -6
  73. data/generators/airbrake/templates/initializer.rb +0 -4
  74. data/install.rb +0 -1
  75. data/lib/airbrake/backtrace.rb +0 -103
  76. data/lib/airbrake/capistrano.rb +0 -103
  77. data/lib/airbrake/capistrano3.rb +0 -3
  78. data/lib/airbrake/cli/client.rb +0 -76
  79. data/lib/airbrake/cli/options.rb +0 -45
  80. data/lib/airbrake/cli/printer.rb +0 -33
  81. data/lib/airbrake/cli/project.rb +0 -17
  82. data/lib/airbrake/cli/project_factory.rb +0 -33
  83. data/lib/airbrake/cli/runner.rb +0 -49
  84. data/lib/airbrake/cli/validator.rb +0 -8
  85. data/lib/airbrake/configuration.rb +0 -366
  86. data/lib/airbrake/jobs/send_job.rb +0 -7
  87. data/lib/airbrake/notice.rb +0 -411
  88. data/lib/airbrake/rack.rb +0 -64
  89. data/lib/airbrake/rails/action_controller_catcher.rb +0 -32
  90. data/lib/airbrake/rails/controller_methods.rb +0 -146
  91. data/lib/airbrake/rails/error_lookup.rb +0 -35
  92. data/lib/airbrake/rails/middleware.rb +0 -63
  93. data/lib/airbrake/rails.rb +0 -45
  94. data/lib/airbrake/rails3_tasks.rb +0 -126
  95. data/lib/airbrake/railtie.rb +0 -46
  96. data/lib/airbrake/rake_handler.rb +0 -75
  97. data/lib/airbrake/response.rb +0 -29
  98. data/lib/airbrake/sender.rb +0 -213
  99. data/lib/airbrake/shared_tasks.rb +0 -59
  100. data/lib/airbrake/sidekiq.rb +0 -8
  101. data/lib/airbrake/sinatra.rb +0 -40
  102. data/lib/airbrake/tasks/airbrake.cap +0 -28
  103. data/lib/airbrake/tasks.rb +0 -81
  104. data/lib/airbrake/user_informer.rb +0 -36
  105. data/lib/airbrake/utils/params_cleaner.rb +0 -141
  106. data/lib/airbrake/utils/rack_filters.rb +0 -45
  107. data/lib/airbrake_tasks.rb +0 -62
  108. data/lib/rails/generators/airbrake/airbrake_generator.rb +0 -155
  109. data/lib/templates/rescue.erb +0 -91
  110. data/rails/init.rb +0 -1
  111. data/resources/README.md +0 -34
  112. data/resources/airbrake_2_4.xsd +0 -89
  113. data/resources/airbrake_3_0.json +0 -52
  114. data/resources/ca-bundle.crt +0 -3376
  115. data/script/integration_test.rb +0 -35
  116. data/test/airbrake_tasks_test.rb +0 -161
  117. data/test/backtrace_test.rb +0 -215
  118. data/test/capistrano_test.rb +0 -44
  119. data/test/configuration_test.rb +0 -303
  120. data/test/controller_methods_test.rb +0 -230
  121. data/test/helper.rb +0 -233
  122. data/test/integration/catcher_test.rb +0 -371
  123. data/test/integration.rb +0 -13
  124. data/test/logger_test.rb +0 -79
  125. data/test/notice_test.rb +0 -494
  126. data/test/notifier_test.rb +0 -288
  127. data/test/params_cleaner_test.rb +0 -204
  128. data/test/rack_test.rb +0 -62
  129. data/test/rails_initializer_test.rb +0 -36
  130. data/test/recursion_test.rb +0 -10
  131. data/test/response_test.rb +0 -18
  132. data/test/sender_test.rb +0 -335
  133. data/test/support/response_shim.xml +0 -4
  134. data/test/user_informer_test.rb +0 -29
@@ -1,267 +0,0 @@
1
- require 'uri'
2
-
3
- require 'active_support/core_ext/string/inflections'
4
-
5
- Given /^Airbrake server is not responding$/ do
6
- content = <<-CONTENT
7
- require 'sham_rack'
8
-
9
- ShamRack.at("api.airbrake.io") {["500", { "Content-type" => "text/xml" }, ["Internal server error"]]}
10
-
11
- CONTENT
12
- target = File.join(rails_root, 'config', 'initializers', 'airbrake_shim.rb')
13
- File.open(target,"w") { |f| f.write content }
14
- end
15
-
16
- Then /^I should (?:(not ))?receive a Airbrake notification$/ do |negator|
17
- steps %{
18
- Then the output should #{negator}contain "** [Airbrake] Response from Airbrake:"
19
- And the output should #{negator}contain "b6817316-9c45-ed26-45eb-780dbb86aadb"
20
- And the output should #{negator}contain "http://airbrake.io/locate/b6817316-9c45-ed26-45eb-780dbb86aadb"
21
- }
22
- end
23
-
24
- Then /^I should receive two Airbrake notifications$/ do
25
- step %{the output should match /\[Airbrake\] Response from Airbrake:/}
26
- end
27
-
28
- When /^I configure the Airbrake shim$/ do
29
- shim_file = File.join(PROJECT_ROOT, 'features', 'support', 'airbrake_shim.rb.template')
30
- target = File.join(rails_root, 'config', 'initializers', 'airbrake_shim.rb')
31
- FileUtils.cp(shim_file, target)
32
- end
33
-
34
- When /^I configure the notifier to use "([^\"]*)" as an API key$/ do |api_key|
35
- steps %{
36
- When I configure the notifier to use the following configuration lines:
37
- """
38
- config.api_key = #{api_key.inspect}
39
- """
40
- }
41
- end
42
-
43
- When /^I configure the notifier to use the following configuration lines:$/ do |configuration_lines|
44
- initializer_code = <<-EOF
45
- Airbrake.configure do |config|
46
- config.test_mode = true
47
- #{configuration_lines}
48
- end
49
- EOF
50
-
51
- File.open(rails_initializer_file, 'w') { |file| file.write(initializer_code) }
52
- end
53
-
54
- def rails_initializer_file
55
- File.join(rails_root, 'config', 'initializers', 'airbrake.rb')
56
- end
57
-
58
- def rails_non_initializer_airbrake_config_file
59
- File.join(rails_root, 'config', 'airbrake.rb')
60
- end
61
-
62
- Then /^I should (?:(not ))?see "([^\"]*)"$/ do |negator,expected_text|
63
- step %{the output should #{negator}contain "#{expected_text}"}
64
- end
65
-
66
- When /^I install the "([^\"]*)" plugin$/ do |plugin_name|
67
- FileUtils.mkdir_p("#{rails_root}/vendor/plugins/#{plugin_name}")
68
- end
69
-
70
- When /^I define a response for "([^\"]*)":$/ do |controller_and_action, definition|
71
- controller_class_name, action = controller_and_action.split('#')
72
- controller_name = controller_class_name.underscore
73
- controller_file_name = File.join(rails_root, 'app', 'controllers', "#{controller_name}.rb")
74
- File.open(controller_file_name, "w") do |file|
75
- file.puts "class #{controller_class_name} < ApplicationController"
76
- file.puts "def consider_all_requests_local; false; end"
77
- file.puts "def local_request?; false; end"
78
- file.puts "def #{action}"
79
- file.puts definition
80
- file.puts "end"
81
- file.puts "end"
82
- end
83
- end
84
-
85
- When /^I perform a request to "([^\"]*)"$/ do |uri|
86
- perform_request(uri)
87
- step %{I run `bundle exec rails runner request.rb`}
88
- end
89
-
90
- When /^I perform a request to "([^\"]*)" in the "([^\"]*)" environment$/ do |uri, environment|
91
- perform_request(uri,environment)
92
- step %{I run `bundle exec rails runner -e #{environment} request.rb`}
93
- end
94
-
95
- Given /^the response page for a "([^\"]*)" error is$/ do |error, html|
96
- File.open(File.join(rails_root, "public", "#{error}.html"), "w") do |file|
97
- file.write(html)
98
- end
99
- end
100
-
101
- Then /^I should see the Rails version$/ do
102
- step %{I should see "Rails: #{ENV["RAILS_VERSION"]}"}
103
- end
104
-
105
- Then /^I should see that "([^\"]*)" is not considered a framework gem$/ do |gem_name|
106
- step %{I should not see "[R] #{gem_name}"}
107
- end
108
-
109
- When /^I route "([^\"]*)" to "([^\"]*)"$/ do |path, controller_action_pair|
110
- route = %(get "#{path}", :to => "#{controller_action_pair}")
111
- routes_file = File.join(rails_root, "config", "routes.rb")
112
- File.open(routes_file, "r+") do |file|
113
- content = file.read
114
- content.gsub!(/^end$/, " #{route}\nend")
115
- file.rewind
116
- file.write(content)
117
- end
118
- end
119
-
120
- Then /^"([^\"]*)" should not contain "([^\"]*)"$/ do |file_path, text|
121
- actual_text = IO.read(File.join(rails_root, file_path))
122
- if actual_text.include?(text)
123
- raise "Didn't expect text:\n#{actual_text}\nTo include:\n#{text}"
124
- end
125
- end
126
-
127
- Then /^my Airbrake configuration should contain the following line:$/ do |line|
128
- configuration_file = rails_initializer_file
129
-
130
- configuration = File.read(configuration_file)
131
- if ! configuration.include?(line.strip)
132
- raise "Expected text:\n#{configuration}\nTo include:\n#{line}\nBut it didn't."
133
- end
134
- end
135
-
136
- When /^I configure the Heroku shim with "([^\"]*)"( and multiple app support)?$/ do |api_key, multi_app|
137
- heroku_script_bin = File.join(TEMP_DIR, "bin")
138
- FileUtils.mkdir_p(heroku_script_bin)
139
- heroku_script = File.join(heroku_script_bin, "heroku")
140
- heroku_env_vars = <<-VARS
141
- AIRBRAKE_API_KEY => myapikey
142
- APP_NAME => cold-moon-2929
143
- BUNDLE_WITHOUT => development:test
144
- COMMIT_HASH => lj32j42ss9332jfa2
145
- DATABASE_URL => postgres://fchovwjcyb:QLPVWmBBbf4hCG_YMrtV@ec3-107-28-193-23.compute-1.amazonaws.com/fhcvojwwcyb
146
- LANG => en_US.UTF-8
147
- LAST_GIT_BY => kensa
148
- RACK_ENV => production
149
- SHARED_DATABASE_URL => postgres://fchovwjcyb:QLPVwMbbbF8Hcg_yMrtV@ec2-94-29-181-224.compute-1.amazonaws.com/fhcvojcwwyb
150
- STACK => bamboo-mri-1.9.2
151
- URL => cold-moon-2929.heroku.com
152
- VARS
153
- single_app_script = <<-SINGLE
154
- #!/bin/bash
155
- if [ $1 == 'config' ]
156
- then
157
- echo "#{heroku_env_vars}"
158
- fi
159
- SINGLE
160
-
161
- multi_app_script = <<-MULTI
162
- #!/bin/bash
163
- if [[ $1 == 'config' && $2 == '--app' ]]
164
- then
165
- echo "#{heroku_env_vars}"
166
- fi
167
- MULTI
168
-
169
- File.open(heroku_script, "w") do |f|
170
- if multi_app
171
- f.puts multi_app_script
172
- else
173
- f.puts single_app_script
174
- end
175
- end
176
- FileUtils.chmod(0755, heroku_script)
177
- prepend_path(heroku_script_bin)
178
- end
179
-
180
- When /^I configure the application to filter parameter "([^\"]*)"$/ do |parameter|
181
- application_filename = File.join(rails_root, 'config', 'application.rb')
182
- application_lines = File.open(application_filename).readlines
183
-
184
- application_definition_line = application_lines.detect { |line| line =~ /Application/ }
185
- application_definition_line_index = application_lines.index(application_definition_line)
186
-
187
- parameter = (parameter == "block" ? "lambda { |x,y| x }" : parameter.inspect)
188
- application_lines.insert(application_definition_line_index + 1, " config.filter_parameters += [#{parameter}]")
189
-
190
- File.open(application_filename, "w") do |file|
191
- file.puts application_lines.join("\n")
192
- end
193
- end
194
-
195
- When /^I have set up authentication system in my app that uses "([^\"]*)"$/ do |current_user|
196
- application_controller = File.join(rails_root, 'app', 'controllers', "application_controller.rb")
197
- definition =
198
- """
199
- class ApplicationController < ActionController::Base
200
- def consider_all_requests_local; false; end
201
- def local_request?; false; end
202
-
203
- # this is the ultimate authentication system, devise is history
204
- def #{current_user}
205
- Struct.new(:id, :name, :email, :username, :class_name).new(1, 'Bender', 'bender@beer.com', 'b3nd0r', 'User')
206
- end
207
- end
208
- """
209
- File.open(application_controller, "w") {|file| file.puts definition }
210
- end
211
-
212
- Then /^the Airbrake notification should contain "([^\"]*)"$/ do |content|
213
- step %{the last notice sent should contain "#{content}"}
214
- end
215
-
216
- Then /^the Airbrake notification should not contain "([^\"]*)"$/ do |content|
217
- step %{the last notice sent should not contain "#{content}"}
218
- end
219
-
220
- Then /^the Airbrake notification should contain the custom user details$/ do
221
- step %{the last notice sent should contain "<name>Bender</name>"}
222
- step %{the last notice sent should contain "<email>bender@beer.com</email>"}
223
- step %{the last notice sent should contain "<username>b3nd0r</username>"}
224
- end
225
-
226
- Then /^the Airbrake notification should contain user details$/ do
227
- step %{the last notice sent should contain "<id>1</id>"}
228
- end
229
-
230
- Then /^the Airbrake notification should not contain any of the sensitive Rack variables$/ do
231
- sensitive_rack_data_regex = FILTERED_RACK_VARS.map do |var|
232
- var.instance_of?(Regexp) ? var : Regexp.quote(var)
233
- end.join("|")
234
- step %{the last notice sent should not contain keys with "#{sensitive_rack_data_regex}"}
235
- end
236
-
237
- Then /^the last notice sent should contain "([^\"]*)"$/ do |data|
238
- last_notice = File.read(LAST_NOTICE)
239
- last_notice.should match(%r{#{data}})
240
- end
241
-
242
- Then /^the last notice sent should not contain "([^\"]*)"$/ do |data|
243
- last_notice = File.read(LAST_NOTICE)
244
- last_notice.should_not match(%r{#{data}})
245
- end
246
-
247
- Then /^the last notice sent should not contain keys with "([^\"]*)"$/ do |data|
248
- last_notice = File.read(LAST_NOTICE)
249
- last_notice.should_not match(%r{key\=\"(#{data})\"})
250
- end
251
-
252
- Then /^the Airbrake notification should contain the framework information$/ do
253
- step %{the last notice sent should contain "Rails: #{ENV["RAILS_VERSION"]}"}
254
- end
255
-
256
- When /^I list the application's middleware and save it into a file$/ do
257
- step %{I run `bash -c 'bundle exec rake middleware > middleware.dump'`}
258
- end
259
-
260
- Then /^the Airbrake middleware should be placed correctly$/ do
261
- middleware_file = File.join(LOCAL_RAILS_ROOT, 'middleware.dump')
262
- middleware = File.read(middleware_file).split(/\n/)
263
- airbrake_index = middleware.rindex("use Airbrake::Rails::Middleware")
264
- middleware_index = middleware.rindex("use ActionDispatch::DebugExceptions") ||
265
- middleware.rindex("use ActionDispatch::ShowExceptions")
266
- (airbrake_index > middleware_index).should be_true
267
- end
@@ -1,22 +0,0 @@
1
- Given /I've prepared the Rakefile/ do
2
- rakefile = File.join(PROJECT_ROOT, 'features', 'support', 'rake', 'Rakefile')
3
- target = File.join(TEMP_DIR, 'Rakefile')
4
- FileUtils.cp(rakefile, target)
5
- end
6
-
7
- When /I run rake with (.+)/ do |command|
8
- command = "rake #{command.gsub(' ','_')}"
9
- step %{I run `#{command}`}
10
- end
11
-
12
- Then "Airbrake should not catch the exception" do
13
- step %{I should not see "[airbrake]"}
14
- end
15
-
16
- Then "Airbrake should catch the exception" do
17
- step %{I should see "[airbrake]"}
18
- end
19
-
20
- Then /^command "(.*?)" should be reported$/ do |command_name|
21
- step %{the output should contain "[airbrake] rake #{command_name}"}
22
- end
@@ -1,11 +0,0 @@
1
- require 'sham_rack'
2
-
3
- ShamRack.at("api.airbrake.io") do |env|
4
- response = <<-end_xml
5
- <notice>
6
- <id>b6817316-9c45-ed26-45eb-780dbb86aadb</id>
7
- <url>http://airbrake.io/locate/b6817316-9c45-ed26-45eb-780dbb86aadb</url>
8
- </notice>
9
- end_xml
10
- ["200 OK", { "Content-type" => "text/xml" }, [response]]
11
- end
@@ -1,5 +0,0 @@
1
- Before do
2
- @aruba_timeout_seconds = 30
3
- @aruba_io_wait_seconds = 5
4
- @dirs = ["tmp"]
5
- end
@@ -1,39 +0,0 @@
1
- require 'active_support'
2
- require 'nokogiri'
3
- require 'rspec'
4
- require 'aruba/cucumber'
5
- require 'pry'
6
-
7
- PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
8
- TEMP_DIR = File.join(PROJECT_ROOT, 'tmp').freeze
9
- LOCAL_RAILS_ROOT = File.join(TEMP_DIR, 'rails_root').freeze
10
- RACK_FILE = File.join(TEMP_DIR, 'rack_app.rb').freeze
11
- LAST_NOTICE = File.join(PROJECT_ROOT, 'resources', 'notice.xml')
12
- ORIGINAL_RACK_FILTERS = File.join(PROJECT_ROOT, 'lib', 'airbrake', 'utils', 'rack_filters.rb')
13
-
14
- Before do
15
- FileUtils.rm_rf(LOCAL_RAILS_ROOT)
16
-
17
- reload_rack_filters
18
- end
19
-
20
- When /^I reset Bundler environment variable$/ do
21
- BUNDLE_ENV_VARS.each do |key|
22
- ENV[key] = nil
23
- end
24
- end
25
-
26
- def prepend_path(path)
27
- ENV['PATH'] = path + ":" + ENV['PATH']
28
- end
29
-
30
- def reload_rack_filters
31
- original_filters = File.read(ORIGINAL_RACK_FILTERS)
32
-
33
- Dir.mkdir(TEMP_DIR) unless Dir.exist?(TEMP_DIR)
34
-
35
- File.write(File.join(TEMP_DIR, "rack_filters.rb"),
36
- original_filters.lines.to_a[1..-2].join("\n"))
37
-
38
- require File.join(TEMP_DIR, "rack_filters.rb")
39
- end
@@ -1,35 +0,0 @@
1
- RSpec::Matchers.define :have_content do |xpath, content|
2
- match do |document|
3
- @elements = document.search(xpath)
4
-
5
- if @elements.empty?
6
- false
7
- else
8
- element_with_content = document.at("#{xpath}[contains(.,'#{content}')]")
9
-
10
- if element_with_content.nil?
11
- @found = @elements.collect { |element| element.content }
12
-
13
- false
14
- else
15
- true
16
- end
17
- end
18
- end
19
-
20
- failure_message_for_should do |document|
21
- if @elements.empty?
22
- "In XML:\n#{document}\nNo element at #{xpath}"
23
- else
24
- "In XML:\n#{document}\nGot content #{@found.inspect} at #{xpath} instead of #{content.inspect}"
25
- end
26
- end
27
-
28
- failure_message_for_should_not do |document|
29
- unless @elements.empty?
30
- "In XML:\n#{document}\nExpcted no content #{content.inspect} at #{xpath}"
31
- end
32
- end
33
- end
34
-
35
- World(RSpec::Matchers)
@@ -1,156 +0,0 @@
1
- BUNDLE_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE)
2
- ORIGINAL_BUNDLE_VARS = Hash[ENV.select{ |key,value| BUNDLE_ENV_VARS.include?(key) }]
3
-
4
- ENV['RAILS_ENV'] = 'test'
5
-
6
- Before do
7
- ENV['BUNDLE_GEMFILE'] = File.join(Dir.pwd, ENV['BUNDLE_GEMFILE']) unless ENV['BUNDLE_GEMFILE'].start_with?(Dir.pwd)
8
- @framework_version = nil
9
- end
10
-
11
- After do |s|
12
- ORIGINAL_BUNDLE_VARS.each_pair do |key, value|
13
- ENV[key] = value
14
- end
15
- Cucumber.wants_to_quit = true if s.failed?
16
- end
17
-
18
- module RailsHelpers
19
- def rails_root_exists?
20
- File.exists?(environment_path)
21
- end
22
-
23
- def application_controller_filename
24
- controller_filename = File.join(rails_root, 'app', 'controllers', "application_controller.rb")
25
- end
26
-
27
- def rails_3_or_4?
28
- rails_version =~ /\A[34]/
29
- end
30
-
31
- def rails_root
32
- LOCAL_RAILS_ROOT
33
- end
34
-
35
- def rails_uses_rack?
36
- rails_3_or_4? || rails_version =~ /^2\.3/
37
- end
38
-
39
- def rails_version
40
- @rails_version ||= begin
41
- if ENV["RAILS_VERSION"]
42
- ENV["RAILS_VERSION"]
43
- elsif bundler_manages_gems?
44
- rails_version = open(gemfile_path).read.match(/gem.*rails["'].*["'](.+)["']/)[1]
45
- else
46
- environment_file = File.join(rails_root, 'config', 'environment.rb')
47
- rails_version = `grep RAILS_GEM_VERSION #{environment_file}`.match(/[\d.]+/)[0]
48
- end
49
- end
50
- end
51
-
52
- def bundler_manages_gems?
53
- File.exists?(gemfile_path)
54
- end
55
-
56
- def gemfile_path
57
- gemfile = File.join(rails_root, 'Gemfile')
58
- end
59
-
60
- def rails_manages_gems?
61
- rails_version =~ /\A2\.[123]/
62
- end
63
-
64
- def rails_supports_initializers?
65
- rails_3_or_4? || rails_version =~ /\A2\./
66
- end
67
-
68
- def rails_finds_generators_in_gems?
69
- rails_3_or_4? || rails_version =~ /\A2\./
70
- end
71
-
72
- def version_string
73
- ENV['RAILS_VERSION'] || `tail -n 1 SUPPORTED_RAILS_VERSIONS` # use latest version if ENV["RAILS_VERSION"] is undefined
74
- end
75
-
76
- def environment_path
77
- File.join(rails_root, 'config', 'environment.rb')
78
- end
79
-
80
- def rakefile_path
81
- File.join(rails_root, 'Rakefile')
82
- end
83
-
84
- def config_gem(gem_name, version = nil)
85
- run = "Rails::Initializer.run do |config|"
86
- insert = " config.gem '#{gem_name}'"
87
- insert += ", :version => '#{version}'" if version
88
- content = File.read(environment_path)
89
- content = "require 'thread'\n#{content}"
90
- if content.sub!(run, "#{run}\n#{insert}")
91
- File.open(environment_path, 'wb') { |file| file.write(content) }
92
- else
93
- raise "Couldn't find #{run.inspect} in #{environment_path}"
94
- end
95
- end
96
-
97
- def config_gem_dependencies
98
- insert = <<-END
99
- if Gem::VERSION >= "1.3.6"
100
- module Rails
101
- class GemDependency
102
- def requirement
103
- r = super
104
- (r == Gem::Requirement.default) ? nil : r
105
- end
106
- end
107
- end
108
- end
109
- END
110
- run = "Rails::Initializer.run do |config|"
111
- content = File.read(environment_path)
112
- if content.sub!(run, "#{insert}\n#{run}")
113
- File.open(environment_path, 'wb') { |file| file.write(content) }
114
- else
115
- raise "Couldn't find #{run.inspect} in #{environment_path}"
116
- end
117
- end
118
-
119
- def require_thread
120
- content = File.read(rakefile_path)
121
- content = "require 'thread'\n#{content}"
122
- File.open(rakefile_path, 'wb') { |file| file.write(content) }
123
- end
124
-
125
- def perform_request(uri, environment = 'production')
126
- request_script = <<-SCRIPT
127
- require File.expand_path('../config/environment', __FILE__)
128
-
129
- env = Rack::MockRequest.env_for(#{uri.inspect})
130
- response = RailsRoot::Application.call(env)
131
-
132
- response = response.last if response.last.is_a?(ActionDispatch::Response)
133
-
134
- if response.is_a?(Array)
135
- puts "Status: " + response.first.to_s
136
- puts "Headers: " + response.second.to_s
137
- if response.last.respond_to?(:each)
138
- # making it work even with Rack::BodyProxy
139
- body = ""
140
- response.last.each do |chunk|
141
- body << chunk
142
- end
143
- response.pop
144
- response << body
145
- end
146
- puts "Body: " + response.last.to_s
147
- else
148
- puts response.body
149
- end
150
- SCRIPT
151
- File.open(File.join(rails_root, 'request.rb'), 'w') { |file| file.write(request_script) }
152
- end
153
-
154
- end
155
-
156
- World(RailsHelpers)
@@ -1,77 +0,0 @@
1
- # A test harness for RakeHandler
2
- #
3
- require 'rake'
4
- require 'rubygems'
5
- require 'airbrake'
6
- require 'airbrake/rake_handler'
7
-
8
- class IgnoredException < StandardError; end
9
-
10
- Airbrake.configure do |c|
11
- c.ignore_rake_only = ["IgnoredException"]
12
- end
13
-
14
- # Should catch exception
15
- task :airbrake do
16
- Airbrake.configuration.rescue_rake_exceptions = true
17
- stub_tty_output(true)
18
- raise_exception
19
- end
20
-
21
- # Should not catch exception
22
- task :airbrake_disabled do
23
- Airbrake.configuration.rescue_rake_exceptions = false
24
- stub_tty_output(true)
25
- raise_exception
26
- end
27
-
28
- # Should ignore the exception
29
- task :airbrake_ignored do
30
- Airbrake.configuration.rescue_rake_exceptions = true
31
- stub_tty_output(true)
32
- raise_exception(IgnoredException)
33
- end
34
-
35
- # Should not catch exception as tty_output is true
36
- task :airbrake_autodetect_from_terminal do
37
- Airbrake.configuration.rescue_rake_exceptions = nil
38
- stub_tty_output(true)
39
- raise_exception
40
- end
41
-
42
- # Should catch exception as tty_output is false
43
- task :airbrake_autodetect_not_from_terminal do
44
- Airbrake.configuration.rescue_rake_exceptions = nil
45
- stub_tty_output(false)
46
- raise_exception
47
- end
48
-
49
- task :airbrake_not_yet_configured do
50
- Airbrake.configuration.rescue_rake_exceptions = true
51
- stub_tty_output(true)
52
- stub_empty_sender
53
- raise_exception
54
- end
55
-
56
- module Airbrake
57
- def self.send_notice(notice)
58
- $stderr.puts "[airbrake] #{notice.component}"
59
- end
60
- end
61
-
62
- def stub_empty_sender
63
- Airbrake.sender = nil
64
- end
65
-
66
- def stub_tty_output(value)
67
- Rake.application.instance_eval do
68
- @tty_output_stub = value
69
- def tty_output?
70
- @tty_output_stub
71
- end
72
- end
73
- end
74
-
75
- def raise_exception(exception_class = StandardError)
76
- raise exception_class.new('TEST')
77
- end
@@ -1,57 +0,0 @@
1
- Feature: Inform the user of the airbrake notice that was just created
2
-
3
- Background:
4
- Given I successfully run `rails new rails_root -O --skip-gemfile`
5
- And I cd to "rails_root"
6
- And I configure the Airbrake shim
7
-
8
- Scenario: Rescue an exception in a controller
9
- When I run `rails generate airbrake -k myapikey`
10
- And I define a response for "TestController#index":
11
- """
12
- raise RuntimeError, "some message"
13
- """
14
- And the response page for a "500" error is
15
- """
16
- <!-- AIRBRAKE ERROR -->
17
- """
18
- And I route "/test/index" to "test#index"
19
- And I perform a request to "http://example.com:123/test/index?param=value" in the "production" environment
20
- Then I should see "Airbrake Error b6817316-9c45-ed26-45eb-780dbb86aadb"
21
-
22
- Scenario: Rescue an exception in a controller with a custom error string
23
- When I configure the notifier to use the following configuration lines:
24
- """
25
- config.api_key = "myapikey"
26
- config.user_information = 'Error #{{ error_id }}'
27
- """
28
- And I run `rails generate airbrake -k myapikey`
29
- And I define a response for "TestController#index":
30
- """
31
- raise RuntimeError, "some message"
32
- """
33
- And the response page for a "500" error is
34
- """
35
- <!-- AIRBRAKE ERROR -->
36
- """
37
- And I route "/test/index" to "test#index"
38
- And I perform a request to "http://example.com:123/test/index?param=value" in the "production" environment
39
- Then I should see "Error #b6817316-9c45-ed26-45eb-780dbb86aadb"
40
-
41
- Scenario: Don't inform the user
42
- When I configure the notifier to use the following configuration lines:
43
- """
44
- config.user_information = false
45
- """
46
- And I run `rails generate airbrake -k myapikey`
47
- And I define a response for "TestController#index":
48
- """
49
- raise RuntimeError, "some message"
50
- """
51
- And the response page for a "500" error is
52
- """
53
- <!-- AIRBRAKE ERROR -->
54
- """
55
- And I route "/test/index" to "test#index"
56
- And I perform a request to "http://example.com:123/test/index?param=value" in the "production" environment
57
- Then I should not see "Airbrake Error b6817316-9c45-ed26-45eb-780dbb86aadb"