honeybadger 1.3.1 → 1.4.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 (53) hide show
  1. data/Appraisals +20 -0
  2. data/Gemfile +1 -13
  3. data/Gemfile.lock +39 -64
  4. data/MIT-LICENSE +5 -0
  5. data/README.md +102 -3
  6. data/Rakefile +9 -134
  7. data/features/metal.feature +6 -4
  8. data/features/rack.feature +3 -4
  9. data/features/rails.feature +106 -99
  10. data/features/rake.feature +0 -2
  11. data/features/sinatra.feature +1 -3
  12. data/features/step_definitions/metal_steps.rb +2 -1
  13. data/features/step_definitions/rack_steps.rb +2 -2
  14. data/features/step_definitions/rails_steps.rb +238 -0
  15. data/features/step_definitions/rake_steps.rb +1 -1
  16. data/features/support/env.rb +7 -7
  17. data/features/support/rails.rb +41 -58
  18. data/gemfiles/rails2.3.gemfile +9 -0
  19. data/gemfiles/rails2.3.gemfile.lock +102 -0
  20. data/gemfiles/rails3.0.gemfile +8 -0
  21. data/gemfiles/rails3.0.gemfile.lock +146 -0
  22. data/gemfiles/rails3.1.gemfile +8 -0
  23. data/gemfiles/rails3.1.gemfile.lock +161 -0
  24. data/gemfiles/rails3.2.gemfile +8 -0
  25. data/gemfiles/rails3.2.gemfile.lock +160 -0
  26. data/honeybadger.gemspec +30 -24
  27. data/lib/honeybadger.rb +117 -113
  28. data/lib/honeybadger/backtrace.rb +9 -3
  29. data/lib/honeybadger/configuration.rb +22 -0
  30. data/lib/honeybadger/notice.rb +9 -0
  31. data/lib/honeybadger/rack.rb +5 -4
  32. data/lib/honeybadger/rails3_tasks.rb +20 -23
  33. data/lib/honeybadger/sender.rb +10 -4
  34. data/lib/honeybadger/shared_tasks.rb +12 -1
  35. data/lib/honeybadger/tasks.rb +6 -1
  36. data/test/test_helper.rb +71 -71
  37. data/test/unit/backtrace_test.rb +26 -23
  38. data/test/unit/capistrano_test.rb +1 -1
  39. data/test/unit/configuration_test.rb +19 -3
  40. data/test/unit/honeybadger_tasks_test.rb +1 -1
  41. data/test/unit/logger_test.rb +1 -1
  42. data/test/unit/notice_test.rb +71 -16
  43. data/test/unit/notifier_test.rb +25 -5
  44. data/test/unit/rack_test.rb +21 -1
  45. data/test/unit/rails/action_controller_catcher_test.rb +1 -1
  46. data/test/unit/rails_test.rb +1 -1
  47. data/test/unit/sender_test.rb +1 -1
  48. metadata +69 -45
  49. data/SUPPORTED_RAILS_VERSIONS +0 -37
  50. data/TESTING.md +0 -33
  51. data/features/step_definitions/file_steps.rb +0 -10
  52. data/features/step_definitions/rails_application_steps.rb +0 -394
  53. data/features/support/terminal.rb +0 -107
@@ -1,11 +1,13 @@
1
1
  Feature: Rescue errors in Rails middleware
2
2
 
3
3
  Background:
4
- Given I have built and installed the "honeybadger" gem
5
- And I generate a new Rails application
4
+ Given I generate a new Rails application
6
5
  And I configure the Honeybadger shim
7
- And I configure my application to require the "honeybadger" gem
8
- And I run the honeybadger generator with "-k myapikey"
6
+ And I configure Honeybadger with:
7
+ """
8
+ config.api_key = 'myapikey'
9
+ config.logger = Logger.new(STDOUT)
10
+ """
9
11
 
10
12
  Scenario: Rescue an exception in the dispatcher
11
13
  When I define a Metal endpoint called "Exploder":
@@ -1,8 +1,5 @@
1
1
  Feature: Use the notifier in a plain Rack app
2
2
 
3
- Background:
4
- Given I have built and installed the "honeybadger" gem
5
-
6
3
  Scenario: Rescue and exception in a Rack app
7
4
  Given the following Rack app:
8
5
  """
@@ -11,6 +8,7 @@ Feature: Use the notifier in a plain Rack app
11
8
 
12
9
  Honeybadger.configure do |config|
13
10
  config.api_key = 'my_api_key'
11
+ config.logger = Logger.new(STDOUT)
14
12
  end
15
13
 
16
14
  app = Rack::Builder.app do
@@ -29,6 +27,7 @@ Feature: Use the notifier in a plain Rack app
29
27
 
30
28
  Honeybadger.configure do |config|
31
29
  config.api_key = 'my_api_key'
30
+ config.logger = Logger.new(STDOUT)
32
31
  config.ignore_user_agent << /ignore/
33
32
  end
34
33
 
@@ -52,5 +51,5 @@ Feature: Use the notifier in a plain Rack app
52
51
  end
53
52
  """
54
53
  When I perform a Rack request to "http://example.com:123/test/index?param=value"
55
- Then I should not see "** [Honeybadger] Response from Honeybadger:"
54
+ Then the output should not contain "** [Honeybadger] Response from Honeybadger:"
56
55
 
@@ -1,91 +1,57 @@
1
1
  Feature: Install the Gem in a Rails application
2
2
 
3
3
  Background:
4
- Given I have built and installed the "honeybadger" gem
5
- And I generate a new Rails application
4
+ Given I generate a new Rails application
5
+ And I configure the Honeybadger shim
6
6
 
7
7
  Scenario: Use the gem without vendoring the gem in a Rails application
8
- When I configure the Honeybadger shim
9
- And I configure my application to require the "honeybadger" gem
10
- And I run the honeybadger generator with "-k myapikey"
11
- Then the command should have run successfully
12
- And I should receive a Honeybadger notification
8
+ When I run the honeybadger generator with "-k myapikey"
9
+ Then I should receive a Honeybadger notification
13
10
  And I should see the Rails version
14
11
 
15
- Scenario: vendor the gem and uninstall
16
- When I configure the Honeybadger shim
17
- And I configure my application to require the "honeybadger" gem
18
- And I unpack the "honeybadger" gem
19
- And I run the honeybadger generator with "-k myapikey"
20
- Then the command should have run successfully
21
- When I uninstall the "honeybadger" gem
22
- And I install cached gems
23
- And I run "rake honeybadger:test"
24
- Then I should see "** [Honeybadger] Response from Honeybadger:"
25
- And I should receive two Honeybadger notifications
26
-
27
12
  Scenario: Configure the notifier by hand
28
- When I configure the Honeybadger shim
13
+ When I configure my application to require Honeybadger
29
14
  And I configure the notifier to use "myapikey" as an API key
30
- And I configure my application to require the "honeybadger" gem
31
15
  And I run the honeybadger generator with ""
32
16
  Then I should receive a Honeybadger notification
33
17
 
34
18
  Scenario: Configuration within initializer isn't overridden by Railtie
35
- When I configure the Honeybadger shim
36
- And I configure usage of Honeybadger
37
- Then the command should have run successfully
38
- When I configure the notifier to use the following configuration lines:
19
+ When I configure my application to require Honeybadger
20
+ And I run the honeybadger generator with "-k myapikey"
21
+ And I configure Honeybadger with:
39
22
  """
40
23
  config.api_key = "myapikey"
41
24
  config.project_root = "argle/bargle"
42
25
  """
43
- And I define a response for "TestController#index":
44
- """
45
- session[:value] = "test"
46
- raise RuntimeError, "some message"
47
- """
48
- And I route "/test/index" to "test#index"
49
- And I perform a request to "http://example.com:123/test/index?param=value"
50
- Then I should receive a Honeybadger notification
26
+ And I run `rake honeybadger:test`
27
+ Then the output should contain "argle/bargle"
51
28
 
52
29
  Scenario: Try to install without an api key
53
- When I configure my application to require the "honeybadger" gem
30
+ When I configure my application to require Honeybadger
54
31
  And I run the honeybadger generator with ""
55
- Then I should see "Must pass --api-key or --heroku or create config/initializers/honeybadger.rb"
56
-
57
- Scenario: Configure and deploy using only installed gem
58
- When I run "capify ."
59
- And I configure the Honeybadger shim
60
- And I configure my application to require the "honeybadger" gem
61
- And I run the honeybadger generator with "-k myapikey"
62
- And I configure my application to require the "capistrano" gem if necessary
63
- And I run "cap -T"
64
- Then I should see "honeybadger:deploy"
32
+ Then the output should contain "Must pass --api-key or --heroku or create config/initializers/honeybadger.rb"
65
33
 
66
- Scenario: Configure and deploy using only vendored gem
67
- When I run "capify ."
68
- And I configure the Honeybadger shim
69
- And I configure my application to require the "honeybadger" gem
70
- And I unpack the "honeybadger" gem
34
+ Scenario: Configure and deploy with Capistrano
35
+ When I successfully run `capify .`
36
+ And I configure my application to require Honeybadger
71
37
  And I run the honeybadger generator with "-k myapikey"
72
- And I uninstall the "honeybadger" gem
73
- And I install cached gems
74
- And I configure my application to require the "capistrano" gem if necessary
75
- And I run "cap -T"
76
- Then I should see "honeybadger:deploy"
38
+ And I run `cap -T`
39
+ Then the output should contain "honeybadger:deploy"
77
40
 
78
41
  Scenario: Try to install when the honeybadger plugin still exists
79
42
  When I install the "honeybadger" plugin
80
- And I configure the Honeybadger shim
81
43
  And I configure the notifier to use "myapikey" as an API key
82
- And I configure my application to require the "honeybadger" gem
44
+ And I configure my application to require Honeybadger
83
45
  And I run the honeybadger generator with ""
84
- Then I should see "You must first remove the honeybadger plugin. Please run: script/plugin remove honeybadger"
46
+ Then the output should contain "You must first remove the honeybadger plugin. Please run: script/plugin remove honeybadger"
85
47
 
86
48
  Scenario: Rescue an exception in a controller
87
- When I configure the Honeybadger shim
88
- And I configure usage of Honeybadger
49
+ When I configure my application to require Honeybadger
50
+ And I configure Honeybadger with:
51
+ """
52
+ config.api_key = 'myapikey'
53
+ config.logger = Logger.new(STDOUT)
54
+ """
89
55
  And I define a response for "TestController#index":
90
56
  """
91
57
  session[:value] = "test"
@@ -95,29 +61,18 @@ Feature: Install the Gem in a Rails application
95
61
  And I perform a request to "http://example.com:123/test/index?param=value"
96
62
  Then I should receive a Honeybadger notification
97
63
 
98
- Scenario: The gem should not be considered a framework gem
99
- When I configure the Honeybadger shim
100
- And I configure my application to require the "honeybadger" gem
101
- And I run the honeybadger generator with "-k myapikey"
102
- And I run "rake gems"
103
- Then I should see that "honeybadger" is not considered a framework gem
104
-
105
64
  Scenario: The app uses Vlad instead of Capistrano
106
- When I configure the Honeybadger shim
107
- And I configure my application to require the "honeybadger" gem
108
- And I run "touch config/deploy.rb"
109
- And I run "rm Capfile"
65
+ When I configure my application to require Honeybadger
66
+ And I run `touch config/deploy.rb`
67
+ And I run `rm Capfile`
110
68
  And I run the honeybadger generator with "-k myapikey"
111
- Then "config/deploy.rb" should not contain "capistrano"
69
+ Then the file "config/deploy.rb" should not contain "capistrano"
112
70
 
113
71
  Scenario: Support the Heroku addon in the generator
114
- When I configure the Honeybadger shim
115
- And I configure the Heroku rake shim
116
- And I configure the Heroku gem shim with "myapikey"
117
- And I configure my application to require the "honeybadger" gem
72
+ When I configure the Heroku gem shim with "myapikey"
73
+ And I configure my application to require Honeybadger
118
74
  And I run the honeybadger generator with "--heroku"
119
- Then the command should have run successfully
120
- And I should receive a Honeybadger notification
75
+ Then I should receive a Honeybadger notification
121
76
  And I should see the Rails version
122
77
  And my Honeybadger configuration should contain the following line:
123
78
  """
@@ -125,13 +80,10 @@ Feature: Install the Gem in a Rails application
125
80
  """
126
81
 
127
82
  Scenario: Support the --app option for the Heroku addon in the generator
128
- When I configure the Honeybadger shim
129
- And I configure the Heroku rake shim
130
- And I configure the Heroku gem shim with "myapikey" and multiple app support
131
- And I configure my application to require the "honeybadger" gem
83
+ When I configure the Heroku gem shim with "myapikey" and multiple app support
84
+ And I configure my application to require Honeybadger
132
85
  And I run the honeybadger generator with "--heroku -a myapp"
133
- Then the command should have run successfully
134
- And I should receive a Honeybadger notification
86
+ Then I should receive a Honeybadger notification
135
87
  And I should see the Rails version
136
88
  And my Honeybadger configuration should contain the following line:
137
89
  """
@@ -139,11 +91,11 @@ Feature: Install the Gem in a Rails application
139
91
  """
140
92
 
141
93
  Scenario: Filtering parameters in a controller
142
- When I configure the Honeybadger shim
143
- And I configure usage of Honeybadger
144
- When I configure the notifier to use the following configuration lines:
94
+ When I configure my application to require Honeybadger
95
+ And I configure Honeybadger with:
145
96
  """
146
97
  config.api_key = "myapikey"
98
+ config.logger = Logger.new(STDOUT)
147
99
  config.params_filters << "credit_card_number"
148
100
  """
149
101
  And I define a response for "TestController#index":
@@ -154,13 +106,15 @@ Feature: Install the Gem in a Rails application
154
106
  And I route "/test/index" to "test#index"
155
107
  And I perform a request to "http://example.com:123/test/index?param=value"
156
108
  Then I should receive a Honeybadger notification
109
+ And the request should not contain "blue42"
110
+ And the request params should contain "FILTERED"
157
111
 
158
112
  Scenario: Filtering session in a controller
159
- When I configure the Honeybadger shim
160
- And I configure usage of Honeybadger
161
- When I configure the notifier to use the following configuration lines:
113
+ When I configure my application to require Honeybadger
114
+ And I configure Honeybadger with:
162
115
  """
163
116
  config.api_key = "myapikey"
117
+ config.logger = Logger.new(STDOUT)
164
118
  config.params_filters << "secret"
165
119
  """
166
120
  And I define a response for "TestController#index":
@@ -171,10 +125,16 @@ Feature: Install the Gem in a Rails application
171
125
  And I route "/test/index" to "test#index"
172
126
  And I perform a request to "http://example.com:123/test/index?param=value"
173
127
  Then I should receive a Honeybadger notification
128
+ And the request should not contain "blue42"
129
+ And the request session should contain "FILTERED"
174
130
 
175
131
  Scenario: Filtering session and params based on Rails parameter filters
176
- When I configure the Honeybadger shim
177
- And I configure usage of Honeybadger
132
+ When I configure my application to require Honeybadger
133
+ And I configure Honeybadger with:
134
+ """
135
+ config.api_key = 'myapikey'
136
+ config.logger = Logger.new(STDOUT)
137
+ """
178
138
  And I configure the application to filter parameter "secret"
179
139
  And I define a response for "TestController#index":
180
140
  """
@@ -185,10 +145,18 @@ Feature: Install the Gem in a Rails application
185
145
  And I route "/test/index" to "test#index"
186
146
  And I perform a request to "http://example.com:123/test/index?param=value"
187
147
  Then I should receive a Honeybadger notification
148
+ And the request should not contain "red23"
149
+ And the request should not contain "blue42"
150
+ And the request session should contain "FILTERED"
151
+ And the request params should contain "FILTERED"
188
152
 
189
153
  Scenario: Notify honeybadger within the controller
190
- When I configure the Honeybadger shim
191
- And I configure usage of Honeybadger
154
+ When I configure my application to require Honeybadger
155
+ And I configure Honeybadger with:
156
+ """
157
+ config.api_key = 'myapikey'
158
+ config.logger = Logger.new(STDOUT)
159
+ """
192
160
  And I define a response for "TestController#index":
193
161
  """
194
162
  session[:value] = "test"
@@ -200,8 +168,12 @@ Feature: Install the Gem in a Rails application
200
168
  Then I should receive a Honeybadger notification
201
169
 
202
170
  Scenario: Notify honeybadger within a metal controller
203
- When I configure the Honeybadger shim
204
- And I configure usage of Honeybadger
171
+ When I configure my application to require Honeybadger
172
+ And I configure Honeybadger with:
173
+ """
174
+ config.api_key = 'myapikey'
175
+ config.logger = Logger.new(STDOUT)
176
+ """
205
177
  And I define a metal response for "TestController#index":
206
178
  """
207
179
  raise RuntimeError, "some message"
@@ -211,12 +183,47 @@ Feature: Install the Gem in a Rails application
211
183
  Then I should receive a Honeybadger notification
212
184
 
213
185
  Scenario: Reporting 404s
214
- When I configure the Honeybadger shim
215
- And I configure usage of Honeybadger
216
- And I configure the notifier to use the following configuration lines:
186
+ When I configure my application to require Honeybadger
187
+ And I configure Honeybadger with:
217
188
  """
189
+ config.api_key = 'myapikey'
190
+ config.logger = Logger.new(STDOUT)
218
191
  config.ignore_only = []
219
192
  """
220
193
  And I perform a request to "http://example.com:123/this/route/does/not/exist"
221
- Then I should see "The page you were looking for doesn't exist."
194
+ Then the output should contain "The page you were looking for doesn't exist."
195
+ And I should receive a Honeybadger notification
196
+
197
+ Scenario: Asynchronous delivery
198
+ When I configure my application to require Honeybadger
199
+ And I configure Honeybadger with:
200
+ """
201
+ config.api_key = 'myapikey'
202
+ config.logger = Logger.new(STDOUT)
203
+ config.async do |notice|
204
+ handler = Thread.new do
205
+ notice.deliver
206
+ end
207
+ handler.join
208
+ end
209
+ """
210
+ And I define a response for "TestController#index":
211
+ """
212
+ raise RuntimeError, "some message"
213
+ """
214
+ And I route "/test/index" to "test#index"
215
+ And I perform a request to "http://example.com:123/test/index?param=value"
216
+ Then I should receive a Honeybadger notification
217
+
218
+ Scenario: Asynchronous delivery in generator
219
+ When I configure my application to require Honeybadger
220
+ And I configure Honeybadger with:
221
+ """
222
+ config.api_key = 'myapikey'
223
+ config.async do |notice|
224
+ Thread.new { notice.deliver }
225
+ end
226
+ """
227
+ And I run the honeybadger generator with ""
228
+ Then the output should contain "Temporarily disabling asynchronous delivery"
222
229
  And I should receive a Honeybadger notification
@@ -1,6 +1,4 @@
1
1
  Feature: Use the Gem to catch errors in a Rake application
2
- Background:
3
- Given I have built and installed the "honeybadger" gem
4
2
 
5
3
  Scenario: Catching exceptions in Rake
6
4
  When I run rake with honeybadger
@@ -1,8 +1,5 @@
1
1
  Feature: Use the notifier in a Sinatra app
2
2
 
3
- Background:
4
- Given I have built and installed the "honeybadger" gem
5
-
6
3
  Scenario: Rescue an exception in a Sinatra app
7
4
  Given the following Rack app:
8
5
  """
@@ -11,6 +8,7 @@ Feature: Use the notifier in a Sinatra app
11
8
 
12
9
  Honeybadger.configure do |config|
13
10
  config.api_key = 'my_api_key'
11
+ config.logger = Logger.new(STDOUT)
14
12
  end
15
13
 
16
14
  class FontaneApp < Sinatra::Base
@@ -6,7 +6,7 @@ When /^I define a Metal endpoint called "([^\"]*)":$/ do |class_name, definition
6
6
  file.puts definition
7
7
  file.puts "end"
8
8
  end
9
- When %{the metal endpoint "#{class_name}" is mounted in the Rails 3 routes.rb} if rails3?
9
+ step %(the metal endpoint "#{class_name}" is mounted in the Rails 3 routes.rb) if rails3?
10
10
  end
11
11
 
12
12
  When /^the metal endpoint "([^\"]*)" is mounted in the Rails 3 routes.rb$/ do |class_name|
@@ -15,6 +15,7 @@ When /^the metal endpoint "([^\"]*)" is mounted in the Rails 3 routes.rb$/ do |c
15
15
  rack_route = "match '/metal(/*other)' => #{class_name}"
16
16
  routes = routes[0..-2] + [rack_route, routes[-1]]
17
17
  File.open(routesrb, "w") do |f|
18
+ f.puts "$:<< '#{LOCAL_RAILS_ROOT}'"
18
19
  f.puts "require 'app/metal/#{class_name.underscore}'"
19
20
  routes.each do |route_line|
20
21
  f.puts route_line
@@ -15,9 +15,9 @@ When /^I perform a Rack request to "([^\"]*)"$/ do |url|
15
15
  file.puts %{headers.each { |key, value| puts "\#{key}: \#{value}"}}
16
16
  file.puts "body.each { |part| print part }"
17
17
  end
18
- @terminal.run("ruby #{request_file}")
18
+ step %(I run `ruby #{request_file}`)
19
19
  end
20
20
 
21
21
  Then /^I should receive a Honeybadger notification for rack$/ do
22
- Then %{I should see "You have accessed a deleted account."}
22
+ step %(The output should contain "You have accessed a deleted account.")
23
23
  end
@@ -0,0 +1,238 @@
1
+ require 'uri'
2
+ require 'active_support/core_ext'
3
+
4
+ When /^I generate a new Rails application$/ do
5
+ rails_create_command = !rails3? ? 'rails rails_root' :
6
+ 'rails new rails_root -O -S -G -J -T --skip-gemfile --skip-bundle'
7
+
8
+ step %(I successfully run `bundle exec #{rails_create_command}`)
9
+ step %(I cd to "rails_root")
10
+
11
+ require_thread
12
+
13
+ monkeypatch_old_version if rails_version == "2.3.14"
14
+
15
+ unless rails3?
16
+ config_gem_dependencies
17
+ disable_activerecord
18
+ end
19
+ end
20
+
21
+ When /^I configure the Honeybadger shim$/ do
22
+ shim_file = File.join(PROJECT_ROOT, 'features', 'support', 'honeybadger_shim.rb.template')
23
+ if rails_supports_initializers?
24
+ target = File.join(rails_root, 'config', 'initializers', 'honeybadger_shim.rb')
25
+ FileUtils.cp(shim_file, target)
26
+ else
27
+ File.open(environment_path, 'a') do |file|
28
+ file.puts
29
+ file.write IO.read(shim_file)
30
+ end
31
+ end
32
+ end
33
+
34
+ When /^I configure my application to require Honeybadger$/ do
35
+ if rails3?
36
+ # Do nothing - bundler's on it
37
+ elsif rails_manages_gems?
38
+ config_gem('honeybadger')
39
+ else
40
+ File.open(environment_path, 'a') do |file|
41
+ file.puts
42
+ file.puts("require 'honeybadger'")
43
+ file.puts("require 'honeybadger/rails'")
44
+ end
45
+
46
+ unless rails_finds_generators_in_gems?
47
+ FileUtils.cp_r(File.join(PROJECT_ROOT, 'generators'), File.join(rails_root, 'lib'))
48
+ end
49
+ end
50
+ end
51
+
52
+ When /^I configure Honeybadger with:$/ do |config|
53
+ if rails_manages_gems?
54
+ requires = ''
55
+ else
56
+ requires = "require 'honeybadger'"
57
+ end
58
+
59
+ initializer_code = <<-EOF
60
+ #{requires}
61
+ Honeybadger.configure do |config|
62
+ #{config}
63
+ end
64
+ EOF
65
+
66
+ if rails_supports_initializers?
67
+ File.open(rails_initializer_file, 'w') { |file| file.write(initializer_code) }
68
+ else
69
+ File.open(environment_path, 'a') do |file|
70
+ file.puts
71
+ file.puts initializer_code
72
+ end
73
+ end
74
+ end
75
+
76
+ When /^I run the honeybadger generator with "([^\"]*)"$/ do |generator_args|
77
+ if rails3?
78
+ step %(I successfully run `./script/rails generate honeybadger #{generator_args}`)
79
+ else
80
+ step %(I successfully run `./script/generate honeybadger #{generator_args}`)
81
+ end
82
+ end
83
+
84
+ Then /^I should receive (.+) Honeybadger notifications?$/ do |number|
85
+ number = case number
86
+ when /^(one|a)$/ then 1
87
+ when 'two' then 2
88
+ else number end
89
+
90
+ all_output.scan(/\[Honeybadger\] Response from Honeybadger:/).size.should == number
91
+ step %(the output should contain "123456789")
92
+ end
93
+
94
+ Then /^the request\s?(url|component|action|params|session|cgi_data|context)? should( not)? contain "([^\"]*)"$/ do |key, negate, expected|
95
+ notice = all_output.match(/Notice: ({.+})/) ? JSON.parse(Regexp.last_match(1)) : {}
96
+ hash = key ? notice['request'][key.strip] : notice['request']
97
+ hash.to_s.send(negate ? :should_not : :should, match(/#{Regexp.escape(expected)}/))
98
+ end
99
+
100
+ Then /^I should see the Rails version$/ do
101
+ step %(the output should contain "[Rails: #{rails_version}]")
102
+ end
103
+
104
+ When /^I define a( metal)? response for "([^\"]*)":$/ do |metal, controller_and_action, definition|
105
+ controller_class_name, action = controller_and_action.split('#')
106
+ controller_name = controller_class_name.underscore
107
+ controller_file_name = File.join(rails_root, 'app', 'controllers', "#{controller_name}.rb")
108
+ File.open(controller_file_name, "w") do |file|
109
+ file.puts "class #{controller_class_name} < #{ (metal && rails3?) ? 'ActionController::Metal' : 'ApplicationController'}"
110
+ file.puts "def consider_all_requests_local; false; end"
111
+ file.puts "def local_request?; false; end"
112
+ file.puts "def #{action}"
113
+ file.puts definition
114
+ file.puts "end"
115
+ file.puts "end"
116
+ end
117
+ end
118
+
119
+ When /^I perform a request to "([^\"]*)"$/ do |uri|
120
+ perform_request(uri)
121
+ end
122
+
123
+ When /^I route "([^\"]*)" to "([^\"]*)"$/ do |path, controller_action_pair|
124
+ route = if rails3?
125
+ %(match "#{path}", :to => "#{controller_action_pair}")
126
+ else
127
+ controller, action = controller_action_pair.split('#')
128
+ %(map.connect "#{path}", :controller => "#{controller}", :action => "#{action}")
129
+ end
130
+ routes_file = File.join(rails_root, "config", "routes.rb")
131
+ File.open(routes_file, "r+") do |file|
132
+ content = file.read
133
+ content.gsub!(/^end$/, " #{route}\nend")
134
+ file.rewind
135
+ file.write(content)
136
+ end
137
+ end
138
+
139
+ When /^I configure the Heroku gem shim with "([^\"]*)"( and multiple app support)?$/ do |api_key, multi_app|
140
+ heroku_script_bin = File.join(TEMP_DIR, "bin")
141
+ FileUtils.mkdir_p(heroku_script_bin)
142
+ heroku_script = File.join(heroku_script_bin, "heroku")
143
+ heroku_env_vars = <<-VARS
144
+ HONEYBADGER_API_KEY => myapikey
145
+ APP_NAME => cold-moon-2929
146
+ BUNDLE_WITHOUT => development:test
147
+ COMMIT_HASH => lj32j42ss9332jfa2
148
+ DATABASE_URL => postgres://fchovwjcyb:QLPVWmBBbf4hCG_YMrtV@ec3-107-28-193-23.compute-1.amazonaws.com/fhcvojwwcyb
149
+ LANG => en_US.UTF-8
150
+ LAST_GIT_BY => kensa
151
+ RACK_ENV => production
152
+ SHARED_DATABASE_URL => postgres://fchovwjcyb:QLPVwMbbbF8Hcg_yMrtV@ec2-94-29-181-224.compute-1.amazonaws.com/fhcvojcwwyb
153
+ STACK => bamboo-mri-1.9.2
154
+ URL => cold-moon-2929.heroku.com
155
+ VARS
156
+ single_app_script = <<-SINGLE
157
+ #!/bin/bash
158
+ if [ $1 == 'config' ]
159
+ then
160
+ echo "#{heroku_env_vars}"
161
+ fi
162
+ SINGLE
163
+
164
+ multi_app_script = <<-MULTI
165
+ #!/bin/bash
166
+ if [[ $1 == 'config' && $2 == '--app' ]]
167
+ then
168
+ echo "#{heroku_env_vars}"
169
+ fi
170
+ MULTI
171
+
172
+ File.open(heroku_script, "w") do |f|
173
+ if multi_app
174
+ f.puts multi_app_script
175
+ else
176
+ f.puts single_app_script
177
+ end
178
+ end
179
+ FileUtils.chmod(0755, heroku_script)
180
+
181
+ ENV['PATH'] = "#{heroku_script_bin}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
182
+ end
183
+
184
+ Then /^my Honeybadger configuration should contain the following line:$/ do |line|
185
+ configuration_file = if rails_supports_initializers?
186
+ rails_initializer_file
187
+ else
188
+ rails_non_initializer_honeybadger_config_file
189
+ end
190
+
191
+ configuration = File.read(configuration_file)
192
+ if ! configuration.include?(line.strip)
193
+ raise "Expected text:\n#{configuration}\nTo include:\n#{line}\nBut it didn't."
194
+ end
195
+ end
196
+
197
+ When /^I configure the application to filter parameter "([^\"]*)"$/ do |parameter|
198
+ if rails3?
199
+ application_filename = File.join(rails_root, 'config', 'application.rb')
200
+ application_lines = File.open(application_filename).readlines
201
+
202
+ application_definition_line = application_lines.detect { |line| line =~ /Application/ }
203
+ application_definition_line_index = application_lines.index(application_definition_line)
204
+
205
+ application_lines.insert(application_definition_line_index + 1,
206
+ " config.filter_parameters += [#{parameter.inspect}]")
207
+
208
+ File.open(application_filename, "w") do |file|
209
+ file.puts application_lines.join("\n")
210
+ end
211
+ else
212
+ controller_filename = application_controller_filename
213
+ controller_lines = File.open(controller_filename).readlines
214
+
215
+ controller_definition_line = controller_lines.detect { |line| line =~ /ApplicationController/ }
216
+ controller_definition_line_index = controller_lines.index(controller_definition_line)
217
+
218
+ controller_lines.insert(controller_definition_line_index + 1,
219
+ " filter_parameter_logging #{parameter.inspect}")
220
+
221
+ File.open(controller_filename, "w") do |file|
222
+ file.puts controller_lines.join("\n")
223
+ end
224
+ end
225
+ end
226
+
227
+ When /^I install the "([^\"]*)" plugin$/ do |plugin_name|
228
+ FileUtils.mkdir_p("#{rails_root}/vendor/plugins/#{plugin_name}")
229
+ end
230
+
231
+ When /^I configure the notifier to use "([^\"]*)" as an API key$/ do |api_key|
232
+ steps %{
233
+ When I configure Honeybadger with:
234
+ """
235
+ config.api_key = #{api_key.inspect}
236
+ """
237
+ }
238
+ end