airbrake 3.1.6 → 3.1.7

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 (58) hide show
  1. data/CHANGELOG +116 -0
  2. data/LICENSE +61 -0
  3. data/README.md +28 -478
  4. data/README_FOR_HEROKU_ADDON.md +13 -5
  5. data/Rakefile +26 -103
  6. data/TESTED_AGAINST +6 -0
  7. data/airbrake.gemspec +13 -14
  8. data/features/metal.feature +27 -12
  9. data/features/rack.feature +59 -59
  10. data/features/rails.feature +79 -100
  11. data/features/rails_with_js_notifier.feature +9 -21
  12. data/features/rake.feature +6 -4
  13. data/features/sinatra.feature +32 -6
  14. data/features/step_definitions/file_steps.rb +4 -0
  15. data/features/step_definitions/rack_steps.rb +9 -5
  16. data/features/step_definitions/rails_application_steps.rb +46 -278
  17. data/features/step_definitions/rake_steps.rb +16 -11
  18. data/features/support/airbrake_shim.rb.template +0 -2
  19. data/features/support/aruba.rb +5 -0
  20. data/features/support/env.rb +12 -6
  21. data/features/support/rails.rb +30 -73
  22. data/features/support/rake/Rakefile +1 -2
  23. data/features/user_informer.feature +12 -19
  24. data/generators/airbrake/airbrake_generator.rb +1 -1
  25. data/lib/airbrake.rb +9 -8
  26. data/lib/airbrake/cli/project_factory.rb +6 -3
  27. data/lib/airbrake/configuration.rb +7 -0
  28. data/lib/airbrake/notice.rb +52 -3
  29. data/lib/airbrake/rack.rb +16 -7
  30. data/lib/airbrake/rails/action_controller_catcher.rb +5 -3
  31. data/lib/airbrake/rails/controller_methods.rb +6 -6
  32. data/lib/airbrake/rails/error_lookup.rb +4 -2
  33. data/lib/airbrake/rails/javascript_notifier.rb +7 -3
  34. data/lib/airbrake/rails/middleware.rb +65 -0
  35. data/lib/airbrake/rails3_tasks.rb +16 -21
  36. data/lib/airbrake/railtie.rb +9 -16
  37. data/lib/airbrake/rake_handler.rb +2 -2
  38. data/lib/airbrake/sender.rb +57 -6
  39. data/lib/airbrake/shared_tasks.rb +24 -11
  40. data/lib/airbrake/sinatra.rb +34 -0
  41. data/lib/airbrake/user_informer.rb +9 -0
  42. data/lib/airbrake/version.rb +1 -1
  43. data/lib/rails/generators/airbrake/airbrake_generator.rb +10 -10
  44. data/{test/airbrake_2_3.xsd → resources/airbrake_2_4.xsd} +1 -0
  45. data/resources/airbrake_3_0.json +52 -0
  46. data/test/catcher_test.rb +198 -240
  47. data/test/configuration_test.rb +2 -0
  48. data/test/helper.rb +123 -53
  49. data/test/notice_test.rb +45 -1
  50. data/test/sender_test.rb +63 -32
  51. metadata +60 -79
  52. data/MIT-LICENSE +0 -22
  53. data/SUPPORTED_RAILS_VERSIONS +0 -38
  54. data/TESTING.md +0 -41
  55. data/features/step_definitions/metal_steps.rb +0 -23
  56. data/features/support/terminal.rb +0 -107
  57. data/lib/airbrake/extensions/blank.rb +0 -73
  58. data/lib/airbrake/rails/middleware/exceptions_catcher.rb +0 -33
@@ -1,12 +1,11 @@
1
1
  Feature: Install the Gem in a Rails application and enable the JavaScript notifier
2
2
 
3
3
  Background:
4
- Given I have built and installed the "airbrake" gem
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
5
7
 
6
8
  Scenario: Include the Javascript notifier when enabled
7
- When I generate a new Rails application
8
- And I configure the Airbrake shim
9
- And I configure my application to require the "airbrake" gem
10
9
  When I configure the notifier to use the following configuration lines:
11
10
  """
12
11
  config.api_key = "myapikey"
@@ -16,7 +15,7 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
16
15
  render :inline => '<html><head profile="http://example.com"><%= airbrake_javascript_notifier %></head><body></body></html>'
17
16
  """
18
17
  And I route "/test/index" to "test#index"
19
- And I perform a request to "http://example.com:123/test/index"
18
+ And I perform a request to "http://example.com:123/test/index" in the "production" environment
20
19
  Then I should see the notifier JavaScript for the following:
21
20
  | api_key | environment | host |
22
21
  | myapikey | production | api.airbrake.io |
@@ -25,11 +24,9 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
25
24
  | http://example.com:123/test/index | test | index |
26
25
 
27
26
  Scenario: Include the Javascript notifier when enabled using custom configuration settings
28
- When I generate a new Rails application
29
- And I configure the Airbrake shim
30
- And I configure my application to require the "airbrake" gem
31
27
  When I configure the notifier to use the following configuration lines:
32
28
  """
29
+ config.development_environments = []
33
30
  config.api_key = "myapikey!"
34
31
  config.host = "myairbrake.com"
35
32
  config.port = 3001
@@ -42,12 +39,9 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
42
39
  And I perform a request to "http://example.com:123/test/index"
43
40
  Then I should see the notifier JavaScript for the following:
44
41
  | api_key | environment | host |
45
- | myapikey! | production | myairbrake.com:3001 |
42
+ | myapikey! | test | myairbrake.com:3001 |
46
43
 
47
44
  Scenario: Don't include the Javascript notifier by default
48
- When I generate a new Rails application
49
- And I configure the Airbrake shim
50
- And I configure my application to require the "airbrake" gem
51
45
  When I configure the notifier to use the following configuration lines:
52
46
  """
53
47
  config.api_key = "myapikey!"
@@ -61,9 +55,6 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
61
55
  Then I should not see notifier JavaScript
62
56
 
63
57
  Scenario: Don't include the Javascript notifier when enabled in non-public environments
64
- When I generate a new Rails application
65
- And I configure the Airbrake shim
66
- And I configure my application to require the "airbrake" gem
67
58
  When I configure the notifier to use the following configuration lines:
68
59
  """
69
60
  config.api_key = "myapikey!"
@@ -76,11 +67,8 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
76
67
  And I route "/test/index" to "test#index"
77
68
  And I perform a request to "http://example.com:123/test/index" in the "test" environment
78
69
  Then I should not see notifier JavaScript
79
-
80
- Scenario: Include the Javascript notifier with a custom api key
81
- When I generate a new Rails application
82
- And I configure the Airbrake shim
83
- And I configure my application to require the "airbrake" gem
70
+
71
+ Scenario: Use the js_api_key if present
84
72
  When I configure the notifier to use the following configuration lines:
85
73
  """
86
74
  config.api_key = "myapikey!"
@@ -91,7 +79,7 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
91
79
  render :inline => '<html><head><%= airbrake_javascript_notifier %></head><body></body></html>'
92
80
  """
93
81
  And I route "/test/index" to "test#index"
94
- And I perform a request to "http://example.com:123/test/index"
82
+ And I perform a request to "http://example.com:123/test/index" in the "production" environment
95
83
  Then I should see the notifier JavaScript for the following:
96
84
  | api_key | environment | host |
97
85
  | myjsapikey! | production | api.airbrake.io |
@@ -1,6 +1,7 @@
1
1
  Feature: Use the Gem to catch errors in a Rake application
2
+
2
3
  Background:
3
- Given I have built and installed the "airbrake" gem
4
+ Given I've prepared the Rakefile
4
5
 
5
6
  Scenario: Catching exceptions in Rake
6
7
  When I run rake with airbrake
@@ -22,6 +23,7 @@ Feature: Use the Gem to catch errors in a Rake application
22
23
  When I run rake with airbrake autodetect not from terminal
23
24
  Then Airbrake should catch the exception
24
25
 
25
- Scenario: Sending the correct component name
26
- When I run rake with airbrake
27
- Then Airbrake should send the rake command line as the component name
26
+ @wip
27
+ Scenario: Airbrake should also send the command name
28
+ When I run `rake airbrake_autodetect_not_from_terminal`
29
+ Then command "airbrake_autodetect_not_from_terminal" should be reported
@@ -1,21 +1,20 @@
1
1
  Feature: Use the notifier in a Sinatra app
2
2
 
3
- Background:
4
- Given I have built and installed the "airbrake" gem
5
-
6
3
  Scenario: Rescue an exception in a Sinatra app
7
4
  Given the following Rack app:
8
5
  """
9
6
  require 'sinatra/base'
10
7
  require 'airbrake'
8
+ require 'logger'
11
9
 
12
10
  Airbrake.configure do |config|
13
- config.api_key = 'my_api_key'
11
+ config.api_key = 'my_api_key'
12
+ config.logger = Logger.new STDOUT
13
+ config.development_environments = []
14
14
  end
15
15
 
16
16
  class FontaneApp < Sinatra::Base
17
- use Airbrake::Rack
18
- enable :raise_errors
17
+ use Airbrake::Sinatra
19
18
 
20
19
  get "/test/index" do
21
20
  raise "Sinatra has left the building"
@@ -26,4 +25,31 @@ Feature: Use the notifier in a Sinatra app
26
25
  """
27
26
  When I perform a Rack request to "http://example.com:123/test/index?param=value"
28
27
  Then I should receive a Airbrake notification
28
+
29
+ Scenario: Catching environment name in modular Sinatra app
30
+ Given the following Rack app:
31
+ """
32
+ require 'sinatra/base'
33
+ require 'airbrake'
34
+ require 'logger'
35
+
36
+ Airbrake.configure do |config|
37
+ config.api_key = 'my_api_key'
38
+ config.logger = Logger.new STDOUT
39
+ end
40
+
41
+ class FontaneApp < Sinatra::Base
42
+ use Airbrake::Sinatra
29
43
 
44
+ set :environment, :production
45
+
46
+ get "/test/index" do
47
+ raise "Sinatra has left the building"
48
+ end
49
+ end
50
+
51
+ app = FontaneApp
52
+ """
53
+ When I perform a Rack request to "http://example.com:123/test/index?param=value"
54
+ Then I should receive a Airbrake notification
55
+ And the output should contain "Env: production"
@@ -8,3 +8,7 @@ Then /^"([^\"]*)" should not contain text of "([^\"]*)"$/ do |target_file, conte
8
8
 
9
9
  target_text.should_not include(contents_text)
10
10
  end
11
+
12
+ Then /^I append "([^\"]*)" to Gemfile$/ do |contents|
13
+ append_to_gemfile(contents)
14
+ end
@@ -2,6 +2,14 @@ Given /^the following Rack app:$/ do |definition|
2
2
  File.open(RACK_FILE, 'w') { |file| file.write(definition) }
3
3
  end
4
4
 
5
+ When /^I add "([^\"]*)" requirement(?: with "([^\"]*)" option)?$/ do |gem,option|
6
+ append_to_gemfile("gem '#{gem}'#{option ? ", #{option}":""}")
7
+ end
8
+
9
+ When /^I initialize Gemfile$/ do
10
+ step %{I run `bundle init`}
11
+ end
12
+
5
13
  When /^I perform a Rack request to "([^\"]*)"$/ do |url|
6
14
  shim_file = File.join(PROJECT_ROOT, 'features', 'support', 'airbrake_shim.rb.template')
7
15
  request_file = File.join(TEMP_DIR, 'rack_request.rb')
@@ -15,9 +23,5 @@ When /^I perform a Rack request to "([^\"]*)"$/ do |url|
15
23
  file.puts %{headers.each { |key, value| puts "\#{key}: \#{value}"}}
16
24
  file.puts "body.each { |part| print part }"
17
25
  end
18
- @terminal.run("ruby #{request_file}")
19
- end
20
-
21
- Then /^I should receive a Airbrake notification for rack$/ do
22
- Then %{I should see "You have accessed a deleted account."}
26
+ step %{I run `bundle exec ruby #{request_file}`}
23
27
  end
@@ -1,21 +1,11 @@
1
1
  require 'uri'
2
- require 'active_support/core_ext/string/inflections'
3
-
4
- Given /^I have built and installed the "([^\"]*)" gem$/ do |gem_name|
5
- @terminal.build_and_install_gem(File.join(PROJECT_ROOT, "#{gem_name}.gemspec"))
6
- end
7
2
 
8
- Given /^PENDING/ do
9
- pending
10
- end
3
+ require 'active_support/core_ext/string/inflections'
11
4
 
12
5
  Given /^Airbrake server is not responding$/ do
13
- bundle_gem("sham_rack")
14
6
  content = <<-CONTENT
15
7
  require 'sham_rack'
16
8
 
17
- Airbrake.configuration.logger = Logger.new STDOUT
18
-
19
9
  ShamRack.at("api.airbrake.io") {["500", { "Content-type" => "text/xml" }, ["Internal server error"]]}
20
10
 
21
11
  CONTENT
@@ -23,105 +13,20 @@ Given /^Airbrake server is not responding$/ do
23
13
  File.open(target,"w") { |f| f.write content }
24
14
  end
25
15
 
26
- When /^I generate a new Rails application$/ do
27
- @terminal.cd(TEMP_DIR)
28
-
29
- rails3 = version_string =~ /^3/
30
-
31
- if rails3
32
- rails_create_command = 'new'
33
- else
34
- rails_create_command = ''
35
- end
36
-
37
- load_rails = <<-RUBY
38
- gem 'rails', '#{version_string}'; \
39
- load Gem.bin_path('#{version_string >= "3.2.0" ? "railties" : "rails"}', 'rails', '#{version_string}')
40
- RUBY
41
-
42
- @terminal.run(%{ruby -rrubygems -rthread -e "#{load_rails.strip!}" #{rails_create_command} rails_root})
43
- if rails_root_exists?
44
- @terminal.echo("Generated a Rails #{version_string.strip} application")
45
- else
46
- raise "Unable to generate a Rails application:\n#{@terminal.output}"
47
- end
48
- require_thread
49
- if version_string >= "3.1.0"
50
- When %{I configure my application to require the "therubyracer" gem with version "0.10.1"}
51
- elsif version_string =~ /2.3.14/
52
- monkeypatch_old_version
53
- end
54
- config_gem_dependencies unless rails3
55
- end
56
-
57
- When /^I run the airbrake generator with "([^\"]*)"$/ do |generator_args|
58
- if rails3?
59
- When %{I run "./script/rails generate airbrake #{generator_args}"}
60
- else
61
- When %{I run "./script/generate airbrake #{generator_args}"}
62
- end
63
- end
64
-
65
- When /^I print the console output$/ do
66
- puts @terminal.output
67
- end
68
-
69
- Given /^I have installed the "([^\"]*)" gem$/ do |gem_name|
70
- @terminal.install_gem(gem_name)
71
- end
72
-
73
-
74
- When /^I configure my application to require the "capistrano" gem if necessary$/ do
75
- When %{I configure my application to require the "capistrano" gem} if version_string >= "3.0.0"
76
- end
77
-
78
- When /^I configure my application to require the "([^\"]*)" gem(?: with version "(.+)")?$/ do |gem_name, version|
79
- if rails_manages_gems?
80
- config_gem(gem_name, version)
81
- elsif bundler_manages_gems?
82
- bundle_gem(gem_name, version)
83
- else
84
- File.open(environment_path, 'a') do |file|
85
- file.puts
86
- file.puts("require 'airbrake'")
87
- file.puts("require 'airbrake/rails'")
88
- end
89
-
90
- unless rails_finds_generators_in_gems?
91
- FileUtils.cp_r(File.join(PROJECT_ROOT, 'generators'), File.join(rails_root, 'lib'))
92
- end
93
- end
94
- end
95
-
96
- When /^I run "([^\"]*)"$/ do |command|
97
- @terminal.cd(rails_root)
98
- @terminal.run(command)
99
- end
100
-
101
- Then /^I should( not)? receive a Airbrake notification$/ do |or_should_not|
102
- Then %{I should#{or_should_not} see "** [Airbrake] Response from Airbrake:"}
103
- And %{I should#{or_should_not} see "b6817316-9c45-ed26-45eb-780dbb86aadb"}
104
- And %{I should#{or_should_not} see "http://airbrake.io/locate/b6817316-9c45-ed26-45eb-780dbb86aadb"}
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
+ }
105
22
  end
106
23
 
107
24
  Then /^I should receive two Airbrake notifications$/ do
108
- @terminal.output.scan(/\[Airbrake\] Response from Airbrake:/).size.should == 2
25
+ step %{the output should match /\[Airbrake\] Response from Airbrake:/}
109
26
  end
110
27
 
111
28
  When /^I configure the Airbrake shim$/ do
112
- if bundler_manages_gems?
113
- bundle_gem("sham_rack")
114
- end
115
29
  shim_file = File.join(PROJECT_ROOT, 'features', 'support', 'airbrake_shim.rb.template')
116
- if rails_supports_initializers?
117
- target = File.join(rails_root, 'config', 'initializers', 'airbrake_shim.rb')
118
- FileUtils.cp(shim_file, target)
119
- else
120
- File.open(environment_path, 'a') do |file|
121
- file.puts
122
- file.write IO.read(shim_file)
123
- end
124
- end
125
30
  target = File.join(rails_root, 'config', 'initializers', 'airbrake_shim.rb')
126
31
  FileUtils.cp(shim_file, target)
127
32
  end
@@ -136,28 +41,13 @@ When /^I configure the notifier to use "([^\"]*)" as an API key$/ do |api_key|
136
41
  end
137
42
 
138
43
  When /^I configure the notifier to use the following configuration lines:$/ do |configuration_lines|
139
- if rails_manages_gems?
140
- requires = ''
141
- else
142
- requires = "require 'airbrake'"
143
- end
144
-
145
44
  initializer_code = <<-EOF
146
- #{requires}
147
45
  Airbrake.configure do |config|
148
46
  #{configuration_lines}
149
47
  end
150
48
  EOF
151
49
 
152
- if rails_supports_initializers?
153
- File.open(rails_initializer_file, 'w') { |file| file.write(initializer_code) }
154
- else
155
- File.open(environment_path, 'a') do |file|
156
- file.puts
157
- file.puts initializer_code
158
- end
159
- end
160
-
50
+ File.open(rails_initializer_file, 'w') { |file| file.write(initializer_code) }
161
51
  end
162
52
 
163
53
  def rails_initializer_file
@@ -168,47 +58,8 @@ def rails_non_initializer_airbrake_config_file
168
58
  File.join(rails_root, 'config', 'airbrake.rb')
169
59
  end
170
60
 
171
- Then /^I should see "([^\"]*)"$/ do |expected_text|
172
- unless @terminal.output.include?(expected_text)
173
- raise("Got terminal output:\n#{@terminal.output}\n\nExpected output:\n#{expected_text}")
174
- end
175
- end
176
-
177
- Then /^I should not see "([^\"]*)"$/ do |unexpected_text|
178
- if @terminal.output.include?(unexpected_text)
179
- raise("Got terminal output:\n#{@terminal.output}\n\nDid not expect the following output:\n#{unexpected_text}")
180
- end
181
- end
182
-
183
- When /^I uninstall the "([^\"]*)" gem$/ do |gem_name|
184
- @terminal.uninstall_gem(gem_name)
185
- end
186
-
187
- When /^I unpack the "([^\"]*)" gem$/ do |gem_name|
188
- if bundler_manages_gems?
189
- @terminal.cd(rails_root)
190
- @terminal.run("bundle pack")
191
- elsif rails_manages_gems?
192
- @terminal.cd(rails_root)
193
- @terminal.run("rake gems:unpack GEM=#{gem_name}")
194
- else
195
- vendor_dir = File.join(rails_root, 'vendor', 'gems')
196
- FileUtils.mkdir_p(vendor_dir)
197
- @terminal.cd(vendor_dir)
198
- @terminal.run("gem unpack #{gem_name}")
199
- gem_path =
200
- Dir.glob(File.join(rails_root, 'vendor', 'gems', "#{gem_name}-*", 'lib')).first
201
- File.open(environment_path, 'a') do |file|
202
- file.puts
203
- file.puts("$: << #{gem_path.inspect}")
204
- end
205
- end
206
- end
207
-
208
- When /^I install cached gems$/ do
209
- if bundler_manages_gems?
210
- Then %{I run "bundle install"}
211
- end
61
+ Then /^I should (?:(not ))?see "([^\"]*)"$/ do |negator,expected_text|
62
+ step %{the output should #{negator}contain "#{expected_text}"}
212
63
  end
213
64
 
214
65
  When /^I install the "([^\"]*)" plugin$/ do |plugin_name|
@@ -232,10 +83,12 @@ end
232
83
 
233
84
  When /^I perform a request to "([^\"]*)"$/ do |uri|
234
85
  perform_request(uri)
86
+ step %{I run `bundle exec ./script/rails runner request.rb`}
235
87
  end
236
88
 
237
89
  When /^I perform a request to "([^\"]*)" in the "([^\"]*)" environment$/ do |uri, environment|
238
- perform_request(uri, environment)
90
+ perform_request(uri,environment)
91
+ step %{I run `bundle exec rails runner -e #{environment} request.rb`}
239
92
  end
240
93
 
241
94
  Given /^the response page for a "([^\"]*)" error is$/ do |error, html|
@@ -244,55 +97,16 @@ Given /^the response page for a "([^\"]*)" error is$/ do |error, html|
244
97
  end
245
98
  end
246
99
 
247
- Then /^I should receive the following Airbrake notification:$/ do |table|
248
- exceptions = @terminal.output.scan(%r{Recieved the following exception:\n([^\n]*)\n}m)
249
- exceptions.should_not be_empty
250
-
251
- xml = exceptions.last[0]
252
- doc = Nokogiri::XML.parse(xml)
253
-
254
- hash = table.transpose.hashes.first
255
-
256
- doc.should have_content('//error/message', hash['error message'])
257
- doc.should have_content('//error/class', hash['error class'])
258
- doc.should have_content('//request/url', hash['url'])
259
-
260
- doc.should have_content('//component', hash['component']) if hash['component']
261
- doc.should have_content('//action', hash['action']) if hash['action']
262
- doc.should have_content('//server-environment/project-root', hash['project-root']) if hash['project-root']
263
-
264
- if hash['session']
265
- session_key, session_value = hash['session'].split(': ')
266
- doc.should have_content('//request/session/var/@key', session_key)
267
- doc.should have_content('//request/session/var', session_value)
268
- end
269
-
270
- if hash['parameters']
271
- param_key, param_value = hash['parameters'].split(': ')
272
- doc.should have_content('//request/params/var/@key', param_key)
273
- doc.should have_content('//request/params/var', param_value)
274
- end
275
- end
276
-
277
100
  Then /^I should see the Rails version$/ do
278
- Then %{I should see "[Rails: #{rails_version}]"}
101
+ step %{I should see "Rails: #{ENV["RAILS_VERSION"]}"}
279
102
  end
280
103
 
281
104
  Then /^I should see that "([^\"]*)" is not considered a framework gem$/ do |gem_name|
282
- Then %{I should not see "[R] #{gem_name}"}
283
- end
284
-
285
- Then /^the command should have run successfully$/ do
286
- @terminal.status.exitstatus.should == 0
105
+ step %{I should not see "[R] #{gem_name}"}
287
106
  end
288
107
 
289
108
  When /^I route "([^\"]*)" to "([^\"]*)"$/ do |path, controller_action_pair|
290
- route = if rails3?
291
- %(match "#{path}", :to => "#{controller_action_pair}")
292
- else
293
- controller, action = controller_action_pair.split('#')
294
- %(map.connect "#{path}", :controller => "#{controller}", :action => "#{action}")
295
- end
109
+ route = %(get "#{path}", :to => "#{controller_action_pair}")
296
110
  routes_file = File.join(rails_root, "config", "routes.rb")
297
111
  File.open(routes_file, "r+") do |file|
298
112
  content = file.read
@@ -310,12 +124,7 @@ Then /^"([^\"]*)" should not contain "([^\"]*)"$/ do |file_path, text|
310
124
  end
311
125
 
312
126
  Then /^my Airbrake configuration should contain the following line:$/ do |line|
313
- configuration_file = if rails_supports_initializers?
314
- rails_initializer_file
315
- else
316
- rails_non_initializer_airbrake_config_file
317
- # environment_path
318
- end
127
+ configuration_file = rails_initializer_file
319
128
 
320
129
  configuration = File.read(configuration_file)
321
130
  if ! configuration.include?(line.strip)
@@ -323,15 +132,7 @@ Then /^my Airbrake configuration should contain the following line:$/ do |line|
323
132
  end
324
133
  end
325
134
 
326
- When /^I set the environment variable "([^\"]*)" to "([^\"]*)"$/ do |environment_variable, value|
327
- @terminal.environment_variables[environment_variable] = value
328
- end
329
-
330
- When /^I configure the Heroku rake shim$/ do
331
- @terminal.invoke_heroku_rake_tasks_locally = true
332
- end
333
-
334
- When /^I configure the Heroku gem shim with "([^\"]*)"( and multiple app support)?$/ do |api_key, multi_app|
135
+ When /^I configure the Heroku shim with "([^\"]*)"( and multiple app support)?$/ do |api_key, multi_app|
335
136
  heroku_script_bin = File.join(TEMP_DIR, "bin")
336
137
  FileUtils.mkdir_p(heroku_script_bin)
337
138
  heroku_script = File.join(heroku_script_bin, "heroku")
@@ -372,36 +173,21 @@ fi
372
173
  end
373
174
  end
374
175
  FileUtils.chmod(0755, heroku_script)
375
- @terminal.prepend_path(heroku_script_bin)
176
+ prepend_path(heroku_script_bin)
376
177
  end
377
178
 
378
179
  When /^I configure the application to filter parameter "([^\"]*)"$/ do |parameter|
379
- if rails3?
380
- application_filename = File.join(rails_root, 'config', 'application.rb')
381
- application_lines = File.open(application_filename).readlines
180
+ application_filename = File.join(rails_root, 'config', 'application.rb')
181
+ application_lines = File.open(application_filename).readlines
382
182
 
383
- application_definition_line = application_lines.detect { |line| line =~ /Application/ }
384
- application_definition_line_index = application_lines.index(application_definition_line)
183
+ application_definition_line = application_lines.detect { |line| line =~ /Application/ }
184
+ application_definition_line_index = application_lines.index(application_definition_line)
385
185
 
386
- application_lines.insert(application_definition_line_index + 1,
387
- " config.filter_parameters += [#{parameter.inspect}]")
186
+ application_lines.insert(application_definition_line_index + 1,
187
+ " config.filter_parameters += [#{parameter.inspect}]")
388
188
 
389
- File.open(application_filename, "w") do |file|
390
- file.puts application_lines.join("\n")
391
- end
392
- else
393
- controller_filename = application_controller_filename
394
- controller_lines = File.open(controller_filename).readlines
395
-
396
- controller_definition_line = controller_lines.detect { |line| line =~ /ApplicationController/ }
397
- controller_definition_line_index = controller_lines.index(controller_definition_line)
398
-
399
- controller_lines.insert(controller_definition_line_index + 1,
400
- " filter_parameter_logging #{parameter.inspect}")
401
-
402
- File.open(controller_filename, "w") do |file|
403
- file.puts controller_lines.join("\n")
404
- end
189
+ File.open(application_filename, "w") do |file|
190
+ file.puts application_lines.join("\n")
405
191
  end
406
192
  end
407
193
 
@@ -412,46 +198,25 @@ Then /^I should see the notifier JavaScript for the following:$/ do |table|
412
198
  api_key = hash['api_key']
413
199
  environment = hash['environment'] || 'production'
414
200
 
415
- document_body = '<html>' + @terminal.output.split('<html>').last
416
- document_body.should include("#{host}/javascripts/notifier.js")
417
-
418
- response = Nokogiri::HTML.parse(document_body)
419
- response.css("script[type='text/javascript']:last-child").each do |element|
420
- content = element.content
421
- content.should include("Airbrake.setKey('#{api_key}');")
422
- content.should include("Airbrake.setHost('#{host}');")
423
- content.should include("Airbrake.setEnvironment('#{environment}');")
424
- end
201
+ steps %{
202
+ Then the output should contain "#{host}/javascripts/notifier.js"
203
+ And the output should contain "Airbrake.setKey('#{api_key}');"
204
+ And the output should contain "Airbrake.setHost('#{host}');"
205
+ And the output should contain "Airbrake.setEnvironment('#{environment}');"
206
+ }
425
207
  end
426
208
 
427
- Then "the notifier JavaScript should provide the following errorDefaults:" do |table|
209
+ Then /^the notifier JavaScript should provide the following errorDefaults:$/ do |table|
428
210
  hash = table.hashes.first
429
-
430
- document_body = '<html>' + @terminal.output.split('<html>').last
431
-
432
- response = Nokogiri::HTML.parse(document_body)
433
- response.css("script[type='text/javascript']:last-child").each do |element|
434
- content = element.content
435
-
436
- hash.each do |key, value|
437
- content.should =~ %r{Airbrake\.setErrorDefaults.*#{key}: "#{value}}m
438
- end
211
+ hash.each do |key, value|
212
+ assert_matching_output("Airbrake\.setErrorDefaults.*#{key}: \"#{value}\"",all_output)
439
213
  end
440
214
  end
441
215
 
442
216
  Then /^I should not see notifier JavaScript$/ do
443
- response = Nokogiri::HTML.parse('<html>' + @terminal.output.split('<html>').last)
444
- response.at_css("script[type='text/javascript'][src$='/javascripts/notifier.js']").should be_nil
217
+ step %{the output should not contain "script[type='text/javascript'][src$='/javascripts/notifier.js']"}
445
218
  end
446
219
 
447
-
448
- When /^I configure usage of Airbrake$/ do
449
- When %{I configure my application to require the "airbrake" gem}
450
- When %{I run the airbrake generator with "-k myapikey"}
451
- @terminal.flush! # flush the results of setting up Airbrake (generates notification)
452
- end
453
-
454
-
455
220
  When /^I have set up authentication system in my app that uses "([^\"]*)"$/ do |current_user|
456
221
  application_controller = File.join(rails_root, 'app', 'controllers', "application_controller.rb")
457
222
  definition =
@@ -462,7 +227,7 @@ When /^I have set up authentication system in my app that uses "([^\"]*)"$/ do |
462
227
 
463
228
  # this is the ultimate authentication system, devise is history
464
229
  def #{current_user}
465
- Struct.new(:attributes).new({:id => 1,:name => 'Bender',:email => 'bender@beer.com',:username => 'b3nd0r'})
230
+ Struct.new(:id, :name, :email, :username).new(1, 'Bender', 'bender@beer.com', 'b3nd0r')
466
231
  end
467
232
  end
468
233
  """
@@ -470,9 +235,12 @@ When /^I have set up authentication system in my app that uses "([^\"]*)"$/ do |
470
235
  end
471
236
 
472
237
  Then /^the Airbrake notification should contain user details$/ do
473
- Then %{I should see "Bender"}
474
- And %{I should see "bender@beer.com"}
475
- And %{I should see "<id>1</id>"}
476
- And %{I should see "b3nd0r"}
238
+ step %{I should see "Bender"}
239
+ step %{I should see "bender@beer.com"}
240
+ step %{I should see "<id>1</id>"}
241
+ step %{I should see "b3nd0r"}
477
242
  end
478
243
 
244
+ Then /^the Airbrake notification should contain the framework information$/ do
245
+ step %{the output should contain "Rails: #{ENV["RAILS_VERSION"]}"}
246
+ end