hatless-hoptoad_notifier 2.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGELOG +149 -0
  2. data/INSTALL +25 -0
  3. data/MIT-LICENSE +22 -0
  4. data/README.rdoc +382 -0
  5. data/Rakefile +217 -0
  6. data/SUPPORTED_RAILS_VERSIONS +9 -0
  7. data/TESTING.rdoc +8 -0
  8. data/generators/hoptoad/hoptoad_generator.rb +54 -0
  9. data/generators/hoptoad/lib/insert_commands.rb +34 -0
  10. data/generators/hoptoad/lib/rake_commands.rb +24 -0
  11. data/generators/hoptoad/templates/capistrano_hook.rb +6 -0
  12. data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +25 -0
  13. data/generators/hoptoad/templates/initializer.rb +6 -0
  14. data/lib/hoptoad_notifier/backtrace.rb +99 -0
  15. data/lib/hoptoad_notifier/capistrano.rb +20 -0
  16. data/lib/hoptoad_notifier/configuration.rb +232 -0
  17. data/lib/hoptoad_notifier/notice.rb +318 -0
  18. data/lib/hoptoad_notifier/rack.rb +40 -0
  19. data/lib/hoptoad_notifier/rails/action_controller_catcher.rb +29 -0
  20. data/lib/hoptoad_notifier/rails/controller_methods.rb +58 -0
  21. data/lib/hoptoad_notifier/rails/error_lookup.rb +33 -0
  22. data/lib/hoptoad_notifier/rails.rb +37 -0
  23. data/lib/hoptoad_notifier/rails3_tasks.rb +90 -0
  24. data/lib/hoptoad_notifier/railtie.rb +23 -0
  25. data/lib/hoptoad_notifier/sender.rb +63 -0
  26. data/lib/hoptoad_notifier/tasks.rb +97 -0
  27. data/lib/hoptoad_notifier/version.rb +3 -0
  28. data/lib/hoptoad_notifier.rb +148 -0
  29. data/lib/hoptoad_tasks.rb +40 -0
  30. data/lib/rails/generators/hoptoad/hoptoad_generator.rb +64 -0
  31. data/lib/templates/rescue.erb +91 -0
  32. data/rails/init.rb +1 -0
  33. data/script/integration_test.rb +38 -0
  34. data/test/backtrace_test.rb +118 -0
  35. data/test/catcher_test.rb +324 -0
  36. data/test/configuration_test.rb +208 -0
  37. data/test/helper.rb +239 -0
  38. data/test/hoptoad_tasks_test.rb +138 -0
  39. data/test/logger_test.rb +85 -0
  40. data/test/notice_test.rb +443 -0
  41. data/test/notifier_test.rb +222 -0
  42. data/test/rack_test.rb +58 -0
  43. data/test/rails_initializer_test.rb +36 -0
  44. data/test/sender_test.rb +123 -0
  45. metadata +204 -0
data/test/rack_test.rb ADDED
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class RackTest < Test::Unit::TestCase
4
+
5
+ should "call the upstream app with the environment" do
6
+ environment = { 'key' => 'value' }
7
+ app = lambda { |env| ['response', {}, env] }
8
+ stack = HoptoadNotifier::Rack.new(app)
9
+
10
+ response = stack.call(environment)
11
+
12
+ assert_equal ['response', {}, environment], response
13
+ end
14
+
15
+ should "deliver an exception raised while calling an upstream app" do
16
+ HoptoadNotifier.stubs(:notify_or_ignore)
17
+
18
+ exception = build_exception
19
+ environment = { 'key' => 'value' }
20
+ app = lambda do |env|
21
+ raise exception
22
+ end
23
+
24
+ begin
25
+ stack = HoptoadNotifier::Rack.new(app)
26
+ stack.call(environment)
27
+ rescue Exception => raised
28
+ assert_equal exception, raised
29
+ else
30
+ flunk "Didn't raise an exception"
31
+ end
32
+
33
+ assert_received(HoptoadNotifier, :notify_or_ignore) do |expect|
34
+ expect.with(exception, :rack_env => environment)
35
+ end
36
+ end
37
+
38
+ should "deliver an exception in rack.exception" do
39
+ HoptoadNotifier.stubs(:notify_or_ignore)
40
+ exception = build_exception
41
+ environment = { 'key' => 'value' }
42
+
43
+ response = [200, {}, ['okay']]
44
+ app = lambda do |env|
45
+ env['rack.exception'] = exception
46
+ response
47
+ end
48
+ stack = HoptoadNotifier::Rack.new(app)
49
+
50
+ actual_response = stack.call(environment)
51
+
52
+ assert_equal response, actual_response
53
+ assert_received(HoptoadNotifier, :notify_or_ignore) do |expect|
54
+ expect.with(exception, :rack_env => environment)
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ require 'hoptoad_notifier/rails'
4
+
5
+ class RailsInitializerTest < Test::Unit::TestCase
6
+ include DefinesConstants
7
+
8
+ should "trigger use of Rails' logger if logger isn't set and Rails' logger exists" do
9
+ rails = Module.new do
10
+ def self.logger
11
+ "RAILS LOGGER"
12
+ end
13
+ end
14
+ define_constant("Rails", rails)
15
+ HoptoadNotifier::Rails.initialize
16
+ assert_equal "RAILS LOGGER", HoptoadNotifier.logger
17
+ end
18
+
19
+ should "trigger use of Rails' default logger if logger isn't set and Rails.logger doesn't exist" do
20
+ define_constant("RAILS_DEFAULT_LOGGER", "RAILS DEFAULT LOGGER")
21
+
22
+ HoptoadNotifier::Rails.initialize
23
+ assert_equal "RAILS DEFAULT LOGGER", HoptoadNotifier.logger
24
+ end
25
+
26
+ should "allow overriding of the logger if already assigned" do
27
+ define_constant("RAILS_DEFAULT_LOGGER", "RAILS DEFAULT LOGGER")
28
+ HoptoadNotifier::Rails.initialize
29
+
30
+ HoptoadNotifier.configure(true) do |config|
31
+ config.logger = "OVERRIDDEN LOGGER"
32
+ end
33
+
34
+ assert_equal "OVERRIDDEN LOGGER", HoptoadNotifier.logger
35
+ end
36
+ end
@@ -0,0 +1,123 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class SenderTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ reset_config
7
+ end
8
+
9
+ def build_sender(opts = {})
10
+ config = HoptoadNotifier::Configuration.new
11
+ opts.each {|opt, value| config.send(:"#{opt}=", value) }
12
+ HoptoadNotifier::Sender.new(config)
13
+ end
14
+
15
+ def send_exception(args = {})
16
+ notice = args.delete(:notice) || build_notice_data
17
+ sender = args.delete(:sender) || build_sender(args)
18
+ sender.send_to_hoptoad(notice)
19
+ sender
20
+ end
21
+
22
+ def stub_http
23
+ response = stub(:body => 'body')
24
+ http = stub(:post => response,
25
+ :read_timeout= => nil,
26
+ :open_timeout= => nil,
27
+ :use_ssl= => nil)
28
+ Net::HTTP.stubs(:new => http)
29
+ http
30
+ end
31
+
32
+ should "post to Hoptoad when using an HTTP proxy" do
33
+ response = stub(:body => 'body')
34
+ http = stub(:post => response,
35
+ :read_timeout= => nil,
36
+ :open_timeout= => nil,
37
+ :use_ssl= => nil)
38
+ proxy = stub(:new => http)
39
+ Net::HTTP.stubs(:Proxy => proxy)
40
+
41
+ url = "http://hoptoadapp.com:80#{HoptoadNotifier::Sender::NOTICES_URI}"
42
+ uri = URI.parse(url)
43
+
44
+ proxy_host = 'some.host'
45
+ proxy_port = 88
46
+ proxy_user = 'login'
47
+ proxy_pass = 'passwd'
48
+
49
+ send_exception(:proxy_host => proxy_host,
50
+ :proxy_port => proxy_port,
51
+ :proxy_user => proxy_user,
52
+ :proxy_pass => proxy_pass)
53
+ assert_received(http, :post) do |expect|
54
+ expect.with(uri.path, anything, HoptoadNotifier::HEADERS)
55
+ end
56
+ assert_received(Net::HTTP, :Proxy) do |expect|
57
+ expect.with(proxy_host, proxy_port, proxy_user, proxy_pass)
58
+ end
59
+ end
60
+
61
+ should "post to the right url for non-ssl" do
62
+ http = stub_http
63
+ url = "http://hoptoadapp.com:80#{HoptoadNotifier::Sender::NOTICES_URI}"
64
+ uri = URI.parse(url)
65
+ send_exception(:secure => false)
66
+ assert_received(http, :post) {|expect| expect.with(uri.path, anything, HoptoadNotifier::HEADERS) }
67
+ end
68
+
69
+ should "post to the right path for ssl" do
70
+ http = stub_http
71
+ send_exception(:secure => true)
72
+ assert_received(http, :post) {|expect| expect.with(HoptoadNotifier::Sender::NOTICES_URI, anything, HoptoadNotifier::HEADERS) }
73
+ end
74
+
75
+ should "default the open timeout to 2 seconds" do
76
+ http = stub_http
77
+ send_exception
78
+ assert_received(http, :open_timeout=) {|expect| expect.with(2) }
79
+ end
80
+
81
+ should "default the read timeout to 5 seconds" do
82
+ http = stub_http
83
+ send_exception
84
+ assert_received(http, :read_timeout=) {|expect| expect.with(5) }
85
+ end
86
+
87
+ should "allow override of the open timeout" do
88
+ http = stub_http
89
+ send_exception(:http_open_timeout => 4)
90
+ assert_received(http, :open_timeout=) {|expect| expect.with(4) }
91
+ end
92
+
93
+ should "allow override of the read timeout" do
94
+ http = stub_http
95
+ send_exception(:http_read_timeout => 10)
96
+ assert_received(http, :read_timeout=) {|expect| expect.with(10) }
97
+ end
98
+
99
+ should "connect to the right port for ssl" do
100
+ stub_http
101
+ send_exception(:secure => true)
102
+ assert_received(Net::HTTP, :new) {|expect| expect.with("hoptoadapp.com", 443) }
103
+ end
104
+
105
+ should "connect to the right port for non-ssl" do
106
+ stub_http
107
+ send_exception(:secure => false)
108
+ assert_received(Net::HTTP, :new) {|expect| expect.with("hoptoadapp.com", 80) }
109
+ end
110
+
111
+ should "use ssl if secure" do
112
+ stub_http
113
+ send_exception(:secure => true, :host => 'example.org')
114
+ assert_received(Net::HTTP, :new) {|expect| expect.with('example.org', 443) }
115
+ end
116
+
117
+ should "not use ssl if not secure" do
118
+ stub_http
119
+ send_exception(:secure => false, :host => 'example.org')
120
+ assert_received(Net::HTTP, :new) {|expect| expect.with('example.org', 80) }
121
+ end
122
+
123
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hatless-hoptoad_notifier
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease: false
6
+ segments:
7
+ - 2
8
+ - 2
9
+ - 6
10
+ version: 2.2.6
11
+ platform: ruby
12
+ authors:
13
+ - thoughtbot, inc
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-22 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: activerecord
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: actionpack
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: jferris-mocha
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: nokogiri
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :development
90
+ version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: shoulda
93
+ prerelease: false
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :development
104
+ version_requirements: *id006
105
+ description:
106
+ email: support@hoptoadapp.com
107
+ executables: []
108
+
109
+ extensions: []
110
+
111
+ extra_rdoc_files:
112
+ - README.rdoc
113
+ files:
114
+ - CHANGELOG
115
+ - INSTALL
116
+ - MIT-LICENSE
117
+ - Rakefile
118
+ - README.rdoc
119
+ - SUPPORTED_RAILS_VERSIONS
120
+ - TESTING.rdoc
121
+ - generators/hoptoad/hoptoad_generator.rb
122
+ - generators/hoptoad/lib/insert_commands.rb
123
+ - generators/hoptoad/lib/rake_commands.rb
124
+ - generators/hoptoad/templates/capistrano_hook.rb
125
+ - generators/hoptoad/templates/hoptoad_notifier_tasks.rake
126
+ - generators/hoptoad/templates/initializer.rb
127
+ - lib/hoptoad_notifier/backtrace.rb
128
+ - lib/hoptoad_notifier/capistrano.rb
129
+ - lib/hoptoad_notifier/configuration.rb
130
+ - lib/hoptoad_notifier/notice.rb
131
+ - lib/hoptoad_notifier/rack.rb
132
+ - lib/hoptoad_notifier/rails/action_controller_catcher.rb
133
+ - lib/hoptoad_notifier/rails/controller_methods.rb
134
+ - lib/hoptoad_notifier/rails/error_lookup.rb
135
+ - lib/hoptoad_notifier/rails.rb
136
+ - lib/hoptoad_notifier/rails3_tasks.rb
137
+ - lib/hoptoad_notifier/railtie.rb
138
+ - lib/hoptoad_notifier/sender.rb
139
+ - lib/hoptoad_notifier/tasks.rb
140
+ - lib/hoptoad_notifier/version.rb
141
+ - lib/hoptoad_notifier.rb
142
+ - lib/hoptoad_tasks.rb
143
+ - lib/rails/generators/hoptoad/hoptoad_generator.rb
144
+ - test/backtrace_test.rb
145
+ - test/catcher_test.rb
146
+ - test/configuration_test.rb
147
+ - test/helper.rb
148
+ - test/hoptoad_tasks_test.rb
149
+ - test/logger_test.rb
150
+ - test/notice_test.rb
151
+ - test/notifier_test.rb
152
+ - test/rack_test.rb
153
+ - test/rails_initializer_test.rb
154
+ - test/sender_test.rb
155
+ - rails/init.rb
156
+ - script/integration_test.rb
157
+ - lib/templates/rescue.erb
158
+ has_rdoc: true
159
+ homepage: http://www.hoptoadapp.com
160
+ licenses: []
161
+
162
+ post_install_message:
163
+ rdoc_options:
164
+ - --line-numbers
165
+ - --main
166
+ - README.rdoc
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ hash: 3
175
+ segments:
176
+ - 0
177
+ version: "0"
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ hash: 3
184
+ segments:
185
+ - 0
186
+ version: "0"
187
+ requirements: []
188
+
189
+ rubyforge_project:
190
+ rubygems_version: 1.3.7
191
+ signing_key:
192
+ specification_version: 3
193
+ summary: Send your application errors to our hosted service and reclaim your inbox.
194
+ test_files:
195
+ - test/backtrace_test.rb
196
+ - test/catcher_test.rb
197
+ - test/configuration_test.rb
198
+ - test/hoptoad_tasks_test.rb
199
+ - test/logger_test.rb
200
+ - test/notice_test.rb
201
+ - test/notifier_test.rb
202
+ - test/rack_test.rb
203
+ - test/rails_initializer_test.rb
204
+ - test/sender_test.rb