hoptoad_notifier 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoptoad_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ platform: ruby
6
+ authors:
7
+ - thoughtbot, inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-19 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: support@hoptoadapp.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - INSTALL
26
+ - MIT-LICENSE
27
+ - Rakefile
28
+ - README.rdoc
29
+ - SUPPORTED_RAILS_VERSIONS
30
+ - TESTING.rdoc
31
+ - generators/hoptoad/hoptoad_generator.rb
32
+ - generators/hoptoad/lib/insert_commands.rb
33
+ - generators/hoptoad/lib/rake_commands.rb
34
+ - generators/hoptoad/templates/hoptoad_notifier_tasks.rake
35
+ - generators/hoptoad/templates/initializer.rb
36
+ - lib/hoptoad_notifier/backtrace.rb
37
+ - lib/hoptoad_notifier/capistrano.rb
38
+ - lib/hoptoad_notifier/catcher.rb
39
+ - lib/hoptoad_notifier/configuration.rb
40
+ - lib/hoptoad_notifier/notice.rb
41
+ - lib/hoptoad_notifier/rails.rb
42
+ - lib/hoptoad_notifier/rails_initializer.rb
43
+ - lib/hoptoad_notifier/sender.rb
44
+ - lib/hoptoad_notifier/tasks.rb
45
+ - lib/hoptoad_notifier/version.rb
46
+ - lib/hoptoad_notifier.rb
47
+ - lib/hoptoad_tasks.rb
48
+ - test/backtrace_test.rb
49
+ - test/catcher_test.rb
50
+ - test/configuration_test.rb
51
+ - test/helper.rb
52
+ - test/hoptoad_tasks_test.rb
53
+ - test/logger_test.rb
54
+ - test/notice_test.rb
55
+ - test/notifier_test.rb
56
+ - test/rails_initializer_test.rb
57
+ - test/sender_test.rb
58
+ - rails/init.rb
59
+ - tasks/hoptoad_notifier_tasks.rake
60
+ has_rdoc: true
61
+ homepage: http://www.hoptoadapp.com
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --line-numbers
67
+ - --main
68
+ - README.rdoc
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Send your application errors to our hosted service and reclaim your inbox.
90
+ test_files:
91
+ - test/backtrace_test.rb
92
+ - test/catcher_test.rb
93
+ - test/configuration_test.rb
94
+ - test/hoptoad_tasks_test.rb
95
+ - test/logger_test.rb
96
+ - test/notice_test.rb
97
+ - test/notifier_test.rb
98
+ - test/rails_initializer_test.rb
99
+ - test/sender_test.rb