errornot_notifier 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL +25 -0
- data/MIT-LICENSE +22 -0
- data/README.rdoc +289 -0
- data/Rakefile +124 -0
- data/SUPPORTED_RAILS_VERSIONS +8 -0
- data/TESTING.rdoc +8 -0
- data/generators/hoptoad/hoptoad_generator.rb +55 -0
- data/generators/hoptoad/lib/insert_commands.rb +34 -0
- data/generators/hoptoad/lib/rake_commands.rb +24 -0
- data/generators/hoptoad/templates/capistrano_hook.rb +6 -0
- data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +5 -0
- data/generators/hoptoad/templates/initializer.rb +7 -0
- data/lib/hoptoad_notifier/backtrace.rb +99 -0
- data/lib/hoptoad_notifier/capistrano.rb +20 -0
- data/lib/hoptoad_notifier/configuration.rb +232 -0
- data/lib/hoptoad_notifier/notice.rb +287 -0
- data/lib/hoptoad_notifier/rack.rb +40 -0
- data/lib/hoptoad_notifier/rails/action_controller_catcher.rb +29 -0
- data/lib/hoptoad_notifier/rails/controller_methods.rb +59 -0
- data/lib/hoptoad_notifier/rails/error_lookup.rb +33 -0
- data/lib/hoptoad_notifier/rails.rb +37 -0
- data/lib/hoptoad_notifier/sender.rb +85 -0
- data/lib/hoptoad_notifier/tasks.rb +97 -0
- data/lib/hoptoad_notifier/version.rb +3 -0
- data/lib/hoptoad_notifier.rb +146 -0
- data/lib/hoptoad_tasks.rb +37 -0
- data/lib/templates/rescue.erb +91 -0
- data/rails/init.rb +1 -0
- data/script/integration_test.rb +38 -0
- data/test/backtrace_test.rb +118 -0
- data/test/catcher_test.rb +300 -0
- data/test/configuration_test.rb +208 -0
- data/test/helper.rb +232 -0
- data/test/hoptoad_tasks_test.rb +138 -0
- data/test/logger_test.rb +85 -0
- data/test/notice_test.rb +395 -0
- data/test/notifier_test.rb +222 -0
- data/test/rack_test.rb +58 -0
- data/test/rails_initializer_test.rb +36 -0
- data/test/sender_test.rb +123 -0
- metadata +164 -0
data/INSTALL
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
=== Configuration
|
2
|
+
|
3
|
+
You should have something like this in config/initializers/hoptoad.rb.
|
4
|
+
|
5
|
+
HoptoadNotifier.configure do |config|
|
6
|
+
config.api_key = '1234567890abcdef'
|
7
|
+
end
|
8
|
+
|
9
|
+
(Please note that this configuration should be in a global configuration, and
|
10
|
+
is *not* environment-specific. Hoptoad is smart enough to know what errors are
|
11
|
+
caused by what environments, so your staging errors don't get mixed in with
|
12
|
+
your production errors.)
|
13
|
+
|
14
|
+
You can test that Hoptoad is working in your production environment by using
|
15
|
+
this rake task (from RAILS_ROOT):
|
16
|
+
|
17
|
+
rake hoptoad:test
|
18
|
+
|
19
|
+
If everything is configured properly, that task will send a notice to Hoptoad
|
20
|
+
which will be visible immediately.
|
21
|
+
|
22
|
+
NOTE FOR RAILS 1.2.* USERS:
|
23
|
+
|
24
|
+
You will need to copy the hoptoad_notifier_tasks.rake file into your
|
25
|
+
RAILS_ROOT/lib/tasks directory in order for the rake hoptoad:test task to work.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2007, Tammer Saleh, Thoughtbot, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
= ErrorNotNotifier
|
2
|
+
|
3
|
+
This is the notifier gem for integrating apps with your ErrorNot application
|
4
|
+
|
5
|
+
When an uncaught exception occurs, ErrorNotNotifier will POST the relevant data
|
6
|
+
to your errorNot application server specified in your environment.
|
7
|
+
|
8
|
+
== Rails Installation
|
9
|
+
|
10
|
+
=== Remove exception_notifier
|
11
|
+
|
12
|
+
in your ApplicationController, REMOVE this line:
|
13
|
+
|
14
|
+
include ExceptionNotifiable
|
15
|
+
|
16
|
+
In your config/environment* files, remove all references to ExceptionNotifier
|
17
|
+
|
18
|
+
Remove the vendor/plugins/exception_notifier directory.
|
19
|
+
|
20
|
+
=== Rails 2.x
|
21
|
+
|
22
|
+
Add the errornot_notifier gem to your app. In config/environment.rb:
|
23
|
+
|
24
|
+
config.gem 'errornot_notifier', :lib => 'hoptoad_notifier'
|
25
|
+
|
26
|
+
Then from your project's RAILS_ROOT, run:
|
27
|
+
|
28
|
+
rake gems:install
|
29
|
+
script/generate hoptoad --api-key your_key_here --server your_host
|
30
|
+
|
31
|
+
Once installed, you should vendor the hoptoad_notifier gem.
|
32
|
+
|
33
|
+
rake gems:unpack GEM=errornot_notifier
|
34
|
+
|
35
|
+
As always, if you choose not to vendor the errornot_notifier gem, make sure
|
36
|
+
every server you deploy to has the gem installed or your application won't start.
|
37
|
+
|
38
|
+
=== Rails 1.2.6
|
39
|
+
|
40
|
+
Install the errornot_notifier gem:
|
41
|
+
|
42
|
+
gem install errornot_notifier
|
43
|
+
|
44
|
+
Once installed, you should vendor the hoptoad_notifier gem:
|
45
|
+
|
46
|
+
mkdir vendor/gems
|
47
|
+
cd vendor/gems
|
48
|
+
gem unpack errornot_notifier
|
49
|
+
|
50
|
+
And then add the following to the Rails::Initializer.run do |config|
|
51
|
+
block in environment.rb so that the vendored gem is loaded.
|
52
|
+
|
53
|
+
# Add the vendor/gems/*/lib directories to the LOAD_PATH
|
54
|
+
config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
|
55
|
+
|
56
|
+
Next add something like this at the bottom of your config/environment.rb:
|
57
|
+
|
58
|
+
require 'hoptoad_notifier'
|
59
|
+
require 'hoptoad_notifier/rails'
|
60
|
+
HoptoadNotifier.configure do |config|
|
61
|
+
config.api_key = 'your_key_here'
|
62
|
+
config.host = 'host_of_your_errornot_instance'
|
63
|
+
end
|
64
|
+
|
65
|
+
You will also need to copy the hoptoad_notifier_tasks.rake file into your
|
66
|
+
RAILS_ROOT/lib/tasks directory in order for the rake hoptoad:test task to work:
|
67
|
+
|
68
|
+
cp vendor/gems/errornot_notifier-0.1.0/generators/hoptoad/templates/hoptoad_notifier_tasks.rake lib/tasks
|
69
|
+
|
70
|
+
As always, if you choose not to vendor the errornot_notifier gem, make sure
|
71
|
+
every server you deploy to has the gem installed or your application won't start.
|
72
|
+
|
73
|
+
=== Testing it out
|
74
|
+
|
75
|
+
You can test that ErrorNot is working in your production environment by using
|
76
|
+
this rake task (from RAILS_ROOT):
|
77
|
+
|
78
|
+
rake hoptoad:test
|
79
|
+
|
80
|
+
If everything is configured properly, that task will send a notice to Hoptoad
|
81
|
+
which will be visible immediately.
|
82
|
+
|
83
|
+
== Rack
|
84
|
+
|
85
|
+
In order to use hoptoad_notifier in a non-Rails rack app, just load the
|
86
|
+
hoptoad_notifier, configure your API key, and use the HoptoadNotifier::Rack
|
87
|
+
middleware:
|
88
|
+
|
89
|
+
require 'rack'
|
90
|
+
require 'hoptoad_notifier'
|
91
|
+
|
92
|
+
HoptoadNotifier.configure do |config|
|
93
|
+
config.api_key = 'my_api_key'
|
94
|
+
config.host = 'host_of_your_errornot_instance'
|
95
|
+
end
|
96
|
+
|
97
|
+
app = Rack::Builder.app do
|
98
|
+
use HoptoadNotifier::Rack
|
99
|
+
run lambda { |env| raise "Rack down" }
|
100
|
+
end
|
101
|
+
|
102
|
+
== Sinatra
|
103
|
+
|
104
|
+
Using errornot_notifier in a Sinatra app is just like a Rack app, but you have
|
105
|
+
to disable Sinatra's error rescuing functionality:
|
106
|
+
|
107
|
+
require 'sinatra/base'
|
108
|
+
require 'hoptoad_notifier'
|
109
|
+
|
110
|
+
HoptoadNotifier.configure do |config|
|
111
|
+
config.api_key = 'my_api_key'
|
112
|
+
config.host =' host_of_your_errornot_instance'
|
113
|
+
end
|
114
|
+
|
115
|
+
class MyApp < Sinatra::Default
|
116
|
+
use HoptoadNotifier::Rack
|
117
|
+
enable :raise_errors
|
118
|
+
|
119
|
+
get "/" do
|
120
|
+
raise "Sinatra has left the building"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
== Usage
|
125
|
+
|
126
|
+
For the most part, ErrorNot works for itself. Once you've included the notifier
|
127
|
+
in your ApplicationController (which is now done automatically by the gem),
|
128
|
+
all errors will be rescued by the #rescue_action_in_public provided by the gem.
|
129
|
+
|
130
|
+
If you want to log arbitrary things which you've rescued yourself from a
|
131
|
+
controller, you can do something like this:
|
132
|
+
|
133
|
+
...
|
134
|
+
rescue => ex
|
135
|
+
notify_hoptoad(ex)
|
136
|
+
flash[:failure] = 'Encryptions could not be rerouted, try again.'
|
137
|
+
end
|
138
|
+
...
|
139
|
+
|
140
|
+
The #notify_hoptoad call will send the notice over to Hoptoad for later
|
141
|
+
analysis. While in your controllers you use the notify_hoptoad method, anywhere
|
142
|
+
else in your code, use HoptoadNotifier.notify.
|
143
|
+
|
144
|
+
To perform custom error processing after Hoptoad has been notified, define the
|
145
|
+
instance method #rescue_action_in_public_without_hoptoad(exception) in your
|
146
|
+
controller.
|
147
|
+
|
148
|
+
== Tracking deployments in Hoptoad ( It's not implement in ErrorNot )
|
149
|
+
|
150
|
+
Paying Hoptoad plans support the ability to track deployments of your application in Hoptoad.
|
151
|
+
By notifying Hoptoad of your application deployments, all errors are resolved when a deploy occurs,
|
152
|
+
so that you'll be notified again about any errors that reoccur after a deployment.
|
153
|
+
|
154
|
+
Additionally, it's possible to review the errors in Hoptoad that occurred before and after a deploy.
|
155
|
+
|
156
|
+
When Hoptoad is installed as a gem, you need to add
|
157
|
+
|
158
|
+
require 'hoptoad_notifier/capistrano'
|
159
|
+
|
160
|
+
to your deploy.rb
|
161
|
+
|
162
|
+
== Going beyond exceptions
|
163
|
+
|
164
|
+
You can also pass a hash to notify_hoptoad method and store whatever you want,
|
165
|
+
not just an exception. And you can also use it anywhere, not just in
|
166
|
+
controllers:
|
167
|
+
|
168
|
+
begin
|
169
|
+
params = {
|
170
|
+
# params that you pass to a method that can throw an exception
|
171
|
+
}
|
172
|
+
my_unpredicable_method(params)
|
173
|
+
rescue => e
|
174
|
+
HoptoadNotifier.notify(
|
175
|
+
:error_class => "Special Error",
|
176
|
+
:error_message => "Special Error: #{e.message}",
|
177
|
+
:parameters => params
|
178
|
+
)
|
179
|
+
end
|
180
|
+
|
181
|
+
While in your controllers you use the notify_hoptoad method, anywhere else in
|
182
|
+
your code, use HoptoadNotifier.notify. Hoptoad will get all the information
|
183
|
+
about the error itself. As for a hash, these are the keys you should pass:
|
184
|
+
|
185
|
+
* :error_class - Use this to group similar errors together. When Hoptoad catches an exception it sends the class name of that exception object.
|
186
|
+
* :error_message - This is the title of the error you see in the errors list. For exceptions it is "#{exception.class.name}: #{exception.message}"
|
187
|
+
* :parameters - While there are several ways to send additional data to Hoptoad, passing a Hash as :parameters as in the example above is the most common use case. When Hoptoad catches an exception in a controller, the actual HTTP client request parameters are sent using this key.
|
188
|
+
|
189
|
+
Hoptoad merges the hash you pass with these default options:
|
190
|
+
|
191
|
+
{
|
192
|
+
:api_key => HoptoadNotifier.api_key,
|
193
|
+
:error_message => 'Notification',
|
194
|
+
:backtrace => caller,
|
195
|
+
:parameters => {},
|
196
|
+
:session => {}
|
197
|
+
}
|
198
|
+
|
199
|
+
You can override any of those parameters.
|
200
|
+
|
201
|
+
== Filtering
|
202
|
+
|
203
|
+
You can specify a whitelist of errors, that Hoptoad will not report on. Use
|
204
|
+
this feature when you are so apathetic to certain errors that you don't want
|
205
|
+
them even logged.
|
206
|
+
|
207
|
+
This filter will only be applied to automatic notifications, not manual
|
208
|
+
notifications (when #notify is called directly).
|
209
|
+
|
210
|
+
Hoptoad ignores the following exceptions by default:
|
211
|
+
|
212
|
+
ActiveRecord::RecordNotFound
|
213
|
+
ActionController::RoutingError
|
214
|
+
ActionController::InvalidAuthenticityToken
|
215
|
+
ActionController::UnknownAction
|
216
|
+
CGI::Session::CookieStore::TamperedWithCookie
|
217
|
+
|
218
|
+
To ignore errors in addition to those, specify their names in your Hoptoad
|
219
|
+
configuration block.
|
220
|
+
|
221
|
+
HoptoadNotifier.configure do |config|
|
222
|
+
config.api_key = '1234567890abcdef'
|
223
|
+
config.ignore << ActiveRecord::IgnoreThisError
|
224
|
+
end
|
225
|
+
|
226
|
+
To ignore *only* certain errors (and override the defaults), use the
|
227
|
+
#ignore_only attribute.
|
228
|
+
|
229
|
+
HoptoadNotifier.configure do |config|
|
230
|
+
config.api_key = '1234567890abcdef'
|
231
|
+
config.ignore_only = [ActiveRecord::IgnoreThisError]
|
232
|
+
end
|
233
|
+
|
234
|
+
To ignore certain user agents, add in the #ignore_user_agent attribute as a
|
235
|
+
string or regexp:
|
236
|
+
|
237
|
+
HoptoadNotifier.configure do |config|
|
238
|
+
config.api_key = '1234567890abcdef'
|
239
|
+
config.ignore_user_agent << /Ignored/
|
240
|
+
config.ignore_user_agent << 'IgnoredUserAgent'
|
241
|
+
end
|
242
|
+
|
243
|
+
To ignore exceptions based on other conditions, use #ignore_by_filter:
|
244
|
+
|
245
|
+
HoptoadNotifier.configure do |config|
|
246
|
+
config.api_key = '1234567890abcdef'
|
247
|
+
config.ignore_by_filter do |exception_data|
|
248
|
+
true if exception_data[:error_class] == "RuntimeError"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
To replace sensitive information sent to the Hoptoad service with [FILTERED] use #params_filters:
|
253
|
+
|
254
|
+
HoptoadNotifier.configure do |config|
|
255
|
+
config.api_key = '1234567890abcdef'
|
256
|
+
config.params_filters << "credit_card_number"
|
257
|
+
end
|
258
|
+
|
259
|
+
Note that, when rescuing exceptions within an ActionController method,
|
260
|
+
hoptoad_notifier will reuse filters specified by #filter_params_logging.
|
261
|
+
|
262
|
+
== Testing
|
263
|
+
|
264
|
+
When you run your tests, you might notice that the Hoptoad service is recording
|
265
|
+
notices generated using #notify when you don't expect it to. You can
|
266
|
+
use code like this in your test_helper.rb to redefine that method so those
|
267
|
+
errors are not reported while running tests.
|
268
|
+
|
269
|
+
module HoptoadNotifier
|
270
|
+
def self.notify(thing)
|
271
|
+
# do nothing.
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
== Supported Rails versions
|
276
|
+
|
277
|
+
See SUPPORTED_RAILS_VERSIONS for a list of official supported versions of
|
278
|
+
Rails.
|
279
|
+
|
280
|
+
Please open up a support ticket on Tender ( http://help.hoptoadapp.com ) if
|
281
|
+
you're using a version of Rails that is not listed above and the notifier is
|
282
|
+
not working properly.
|
283
|
+
|
284
|
+
== Thanks
|
285
|
+
|
286
|
+
Thanks to Eugene Bolshakov for the excellent write-up on GOING BEYOND
|
287
|
+
EXCEPTIONS, which we have included above.
|
288
|
+
|
289
|
+
Thanks to thoughtbot, to create this gem before we updated it to use with errornot
|
data/Rakefile
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'cucumber/rake/task'
|
6
|
+
|
7
|
+
desc 'Default: run unit tests.'
|
8
|
+
task :default => [:test, :cucumber]
|
9
|
+
|
10
|
+
desc 'Test the hoptoad_notifier gem.'
|
11
|
+
Rake::TestTask.new(:test) do |t|
|
12
|
+
t.libs << 'lib'
|
13
|
+
t.pattern = 'test/**/*_test.rb'
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Run ginger tests'
|
18
|
+
task :ginger do
|
19
|
+
$LOAD_PATH << File.join(*%w[vendor ginger lib])
|
20
|
+
ARGV.clear
|
21
|
+
ARGV << 'test'
|
22
|
+
load File.join(*%w[vendor ginger bin ginger])
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'yard'
|
27
|
+
YARD::Rake::YardocTask.new do |t|
|
28
|
+
t.files = ['lib/**/*.rb', 'TESTING.rdoc']
|
29
|
+
end
|
30
|
+
rescue LoadError
|
31
|
+
end
|
32
|
+
|
33
|
+
GEM_ROOT = File.dirname(__FILE__).freeze
|
34
|
+
VERSION_FILE = File.join(GEM_ROOT, 'lib', 'hoptoad_notifier', 'version')
|
35
|
+
|
36
|
+
require VERSION_FILE
|
37
|
+
|
38
|
+
gemspec = Gem::Specification.new do |s|
|
39
|
+
s.name = %q{errornot_notifier}
|
40
|
+
s.version = HoptoadNotifier::VERSION
|
41
|
+
s.summary = %q{Send your application errors to a hosted service and reclaim your inbox.}
|
42
|
+
|
43
|
+
s.files = FileList['[A-Z]*', 'generators/**/*.*', 'lib/**/*.rb',
|
44
|
+
'test/**/*.rb', 'rails/**/*.rb', 'script/*',
|
45
|
+
'lib/templates/*.erb']
|
46
|
+
s.require_path = 'lib'
|
47
|
+
s.test_files = Dir[*['test/**/*_test.rb']]
|
48
|
+
|
49
|
+
s.has_rdoc = true
|
50
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
51
|
+
s.rdoc_options = ['--line-numbers', "--main", "README.rdoc"]
|
52
|
+
|
53
|
+
s.add_runtime_dependency("activesupport")
|
54
|
+
s.add_development_dependency("activerecord")
|
55
|
+
s.add_development_dependency("actionpack")
|
56
|
+
s.add_development_dependency("jferris-mocha")
|
57
|
+
s.add_development_dependency("nokogiri")
|
58
|
+
s.add_development_dependency("shoulda")
|
59
|
+
|
60
|
+
s.authors = ["thoughtbot, inc, Cyril Mougel"]
|
61
|
+
s.email = %q{support@hoptoadapp.com}
|
62
|
+
s.homepage = "http://www.hoptoadapp.com"
|
63
|
+
|
64
|
+
s.platform = Gem::Platform::RUBY
|
65
|
+
end
|
66
|
+
|
67
|
+
Rake::GemPackageTask.new gemspec do |pkg|
|
68
|
+
pkg.need_tar = true
|
69
|
+
pkg.need_zip = true
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "Clean files generated by rake tasks"
|
73
|
+
task :clobber => [:clobber_rdoc, :clobber_package]
|
74
|
+
|
75
|
+
desc "Generate a gemspec file"
|
76
|
+
task :gemspec do
|
77
|
+
File.open("#{gemspec.name}.gemspec", 'w') do |f|
|
78
|
+
f.write gemspec.to_ruby
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
|
83
|
+
RAILS_VERSIONS = IO.read('SUPPORTED_RAILS_VERSIONS').strip.split("\n")
|
84
|
+
LOCAL_GEMS = [['sham_rack', nil], ['capistrano', nil], ['sqlite3-ruby', nil], ['sinatra', nil]] +
|
85
|
+
RAILS_VERSIONS.collect { |version| ['rails', version] }
|
86
|
+
|
87
|
+
task :vendor_test_gems do
|
88
|
+
LOCAL_GEMS.each do |gem_name, version|
|
89
|
+
gem_file_pattern = [gem_name, version || '*'].compact.join('-')
|
90
|
+
version_option = version ? "-v #{version}" : ''
|
91
|
+
pattern = File.join(LOCAL_GEM_ROOT, 'gems', "#{gem_file_pattern}")
|
92
|
+
existing = Dir.glob(pattern).first
|
93
|
+
unless existing
|
94
|
+
command = "gem install -i #{LOCAL_GEM_ROOT} --no-ri --no-rdoc #{version_option} #{gem_name}"
|
95
|
+
puts "Vendoring #{gem_file_pattern}..."
|
96
|
+
unless system(command)
|
97
|
+
$stderr.puts "Command failed: #{command}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
104
|
+
t.fork = true
|
105
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
|
106
|
+
end
|
107
|
+
|
108
|
+
task :cucumber => [:gemspec, :vendor_test_gems]
|
109
|
+
|
110
|
+
namespace :cucumber do
|
111
|
+
namespace :rails do
|
112
|
+
RAILS_VERSIONS.each do |version|
|
113
|
+
desc "Test integration of the gem with Rails #{version}"
|
114
|
+
task version do
|
115
|
+
puts "Testing Rails #{version}"
|
116
|
+
ENV['RAILS_VERSION'] = version
|
117
|
+
system("cucumber --format progress features/rails.feature")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
desc "Test integration of the gem with all Rails versions"
|
122
|
+
task :all => RAILS_VERSIONS
|
123
|
+
end
|
124
|
+
end
|
data/TESTING.rdoc
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
= For Maintainers:
|
2
|
+
|
3
|
+
When developing the Hoptoad Notifier, be sure to use the integration test
|
4
|
+
against an existing project on staging before pushing to master.
|
5
|
+
|
6
|
+
+./script/integration_test.rb <test project's api key> <staging server hostname>+
|
7
|
+
|
8
|
+
+./script/integration_test.rb <test project's api key> <staging server hostname> secure+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/rake_commands.rb")
|
3
|
+
|
4
|
+
class HoptoadGenerator < Rails::Generator::Base
|
5
|
+
def add_options!(opt)
|
6
|
+
opt.on('-k', '--api-key=key', String, "Your ErrorNot API key") {|v| options[:api_key] = v}
|
7
|
+
opt.on('-s', '--server=host', String, "Your host with errorNot is installed") {|v| options[:host] = v}
|
8
|
+
end
|
9
|
+
|
10
|
+
def manifest
|
11
|
+
if !api_key_configured? && !options[:api_key]
|
12
|
+
puts "Must pass --api-key or create config/initializers/errornot.rb"
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
if !api_key_configured? && !options[:host]
|
17
|
+
puts "Must pass --server or create config/initializers/errornot.rb"
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
record do |m|
|
21
|
+
m.directory 'lib/tasks'
|
22
|
+
m.file 'hoptoad_notifier_tasks.rake', 'lib/tasks/hoptoad_notifier_tasks.rake'
|
23
|
+
if File.exists?('config/deploy.rb')
|
24
|
+
m.append_to 'config/deploy.rb', capistrano_hook
|
25
|
+
end
|
26
|
+
if options[:api_key]
|
27
|
+
if use_initializer?
|
28
|
+
m.template 'initializer.rb', 'config/initializers/errornot.rb',
|
29
|
+
:assigns => {:api_key => options[:api_key],
|
30
|
+
:host => options[:host]}
|
31
|
+
else
|
32
|
+
m.template 'initializer.rb', 'config/errornot.rb',
|
33
|
+
:assigns => {:api_key => options[:api_key],
|
34
|
+
:host => options[:host]}
|
35
|
+
m.append_to 'config/environment.rb', "require 'config/hoptoad'"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
m.rake "hoptoad:test", :generate_only => true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def use_initializer?
|
43
|
+
Rails::VERSION::MAJOR > 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def api_key_configured?
|
47
|
+
File.exists?('config/initializers/hoptoad.rb') ||
|
48
|
+
system("grep HoptoadNotifier config/environment.rb")
|
49
|
+
end
|
50
|
+
|
51
|
+
def capistrano_hook
|
52
|
+
IO.read(source_path('capistrano_hook.rb'))
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
|
2
|
+
|
3
|
+
Rails::Generator::Commands::Base.class_eval do
|
4
|
+
def file_contains?(relative_destination, line)
|
5
|
+
File.read(destination_path(relative_destination)).include?(line)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Rails::Generator::Commands::Create.class_eval do
|
10
|
+
def append_to(file, line)
|
11
|
+
logger.insert "#{line} appended to #{file}"
|
12
|
+
unless options[:pretend] || file_contains?(file, line)
|
13
|
+
File.open(file, "a") do |file|
|
14
|
+
file.puts
|
15
|
+
file.puts line
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
22
|
+
def append_to(file, line)
|
23
|
+
logger.remove "#{line} removed from #{file}"
|
24
|
+
unless options[:pretend]
|
25
|
+
gsub_file file, "\n#{line}", ''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Rails::Generator::Commands::List.class_eval do
|
31
|
+
def append_to(file, line)
|
32
|
+
logger.insert "#{line} appended to #{file}"
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Rails::Generator::Commands::Create.class_eval do
|
2
|
+
def rake(cmd, opts = {})
|
3
|
+
logger.rake "rake #{cmd}"
|
4
|
+
unless system("rake #{cmd}")
|
5
|
+
logger.rake "#{cmd} failed. Rolling back"
|
6
|
+
command(:destroy).invoke!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
12
|
+
def rake(cmd, opts = {})
|
13
|
+
unless opts[:generate_only]
|
14
|
+
logger.rake "rake #{cmd}"
|
15
|
+
system "rake #{cmd}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Rails::Generator::Commands::List.class_eval do
|
21
|
+
def rake(cmd, opts = {})
|
22
|
+
logger.rake "rake #{cmd}"
|
23
|
+
end
|
24
|
+
end
|