errornot_notifier 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/INSTALL +8 -8
- data/README.rdoc +63 -53
- data/Rakefile +92 -8
- data/TESTING.rdoc +1 -1
- data/generators/{hoptoad/hoptoad_generator.rb → errornot/errornot_generator.rb} +6 -6
- data/generators/{hoptoad → errornot}/lib/insert_commands.rb +0 -0
- data/generators/{hoptoad → errornot}/lib/rake_commands.rb +0 -0
- data/generators/errornot/templates/capistrano_hook.rb +6 -0
- data/generators/errornot/templates/errornot_notifier_tasks.rake +5 -0
- data/generators/{hoptoad → errornot}/templates/initializer.rb +2 -2
- data/lib/{hoptoad_notifier → errornot_notifier}/backtrace.rb +1 -1
- data/lib/errornot_notifier/capistrano.rb +20 -0
- data/lib/{hoptoad_notifier → errornot_notifier}/configuration.rb +14 -16
- data/lib/{hoptoad_notifier → errornot_notifier}/notice.rb +2 -2
- data/lib/{hoptoad_notifier → errornot_notifier}/rack.rb +8 -8
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/action_controller_catcher.rb +9 -9
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/controller_methods.rb +15 -15
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/error_lookup.rb +9 -9
- data/lib/{hoptoad_notifier → errornot_notifier}/rails.rb +11 -11
- data/lib/{hoptoad_notifier → errornot_notifier}/sender.rb +8 -8
- data/lib/{hoptoad_notifier → errornot_notifier}/tasks.rb +19 -19
- data/lib/errornot_notifier/version.rb +3 -0
- data/lib/{hoptoad_notifier.rb → errornot_notifier.rb} +20 -20
- data/lib/{hoptoad_tasks.rb → errornot_tasks.rb} +9 -7
- data/lib/templates/rescue.erb +5 -5
- data/rails/init.rb +1 -1
- data/script/integration_test.rb +6 -6
- data/test/backtrace_test.rb +16 -16
- data/test/catcher_test.rb +22 -22
- data/test/configuration_test.rb +21 -23
- data/test/erronot_tasks_test.rb +147 -0
- data/test/helper.rb +16 -15
- data/test/logger_test.rb +12 -10
- data/test/notice_test.rb +9 -9
- data/test/notifier_test.rb +30 -30
- data/test/rack_test.rb +7 -7
- data/test/rails_initializer_test.rb +8 -8
- data/test/sender_test.rb +13 -12
- metadata +73 -53
- data/generators/hoptoad/templates/capistrano_hook.rb +0 -6
- data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +0 -5
- data/lib/hoptoad_notifier/capistrano.rb +0 -20
- data/lib/hoptoad_notifier/version.rb +0 -3
- data/test/hoptoad_tasks_test.rb +0 -138
data/rails/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'errornot_notifier/rails'
|
data/script/integration_test.rb
CHANGED
@@ -8,31 +8,31 @@ RAILS_ROOT = FileUtils.pwd
|
|
8
8
|
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
|
9
9
|
|
10
10
|
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
|
-
require '
|
11
|
+
require 'errornot_notifier'
|
12
12
|
require 'rails/init'
|
13
13
|
|
14
14
|
fail "Please supply an API Key as the first argument" if ARGV.empty?
|
15
15
|
|
16
16
|
host = ARGV[1]
|
17
|
-
|
17
|
+
raise ArgumentError.new('You need define your Errornot URL like params') unless host
|
18
18
|
|
19
19
|
secure = (ARGV[2] == "secure")
|
20
20
|
|
21
21
|
exception = begin
|
22
|
-
raise "Testing
|
22
|
+
raise "Testing errornot notifier with secure = #{secure}. If you can see this, it works."
|
23
23
|
rescue => foo
|
24
24
|
foo
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
ErrornotNotifier.configure do |config|
|
28
28
|
config.secure = secure
|
29
29
|
config.host = host
|
30
30
|
config.api_key = ARGV.first
|
31
31
|
end
|
32
32
|
puts "Configuration:"
|
33
|
-
|
33
|
+
ErrornotNotifier.configuration.to_hash.each do |key, value|
|
34
34
|
puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
|
35
35
|
end
|
36
36
|
puts "Sending #{secure ? "" : "in"}secure notification to project with key #{ARGV.first}"
|
37
|
-
|
37
|
+
ErrornotNotifier.notify(exception)
|
38
38
|
|
data/test/backtrace_test.rb
CHANGED
@@ -8,7 +8,7 @@ class BacktraceTest < Test::Unit::TestCase
|
|
8
8
|
"app/controllers/users_controller.rb:8:in `index'"
|
9
9
|
]
|
10
10
|
|
11
|
-
backtrace =
|
11
|
+
backtrace = ErrornotNotifier::Backtrace.parse(array)
|
12
12
|
|
13
13
|
line = backtrace.lines.first
|
14
14
|
assert_equal '13', line.number
|
@@ -26,13 +26,13 @@ class BacktraceTest < Test::Unit::TestCase
|
|
26
26
|
two = one.dup
|
27
27
|
assert_equal one, two
|
28
28
|
|
29
|
-
assert_equal
|
29
|
+
assert_equal ErrornotNotifier::Backtrace.parse(one), ErrornotNotifier::Backtrace.parse(two)
|
30
30
|
end
|
31
31
|
|
32
32
|
should "parse massive one-line exceptions into multiple lines" do
|
33
|
-
original_backtrace =
|
33
|
+
original_backtrace = ErrornotNotifier::Backtrace.
|
34
34
|
parse(["one:1:in `one'\n two:2:in `two'\n three:3:in `three`"])
|
35
|
-
expected_backtrace =
|
35
|
+
expected_backtrace = ErrornotNotifier::Backtrace.
|
36
36
|
parse(["one:1:in `one'", "two:2:in `two'", "three:3:in `three`"])
|
37
37
|
|
38
38
|
assert_equal expected_backtrace, original_backtrace
|
@@ -41,7 +41,7 @@ class BacktraceTest < Test::Unit::TestCase
|
|
41
41
|
context "with a project root" do
|
42
42
|
setup do
|
43
43
|
@project_root = '/some/path'
|
44
|
-
|
44
|
+
ErrornotNotifier.configure {|config| config.project_root = @project_root }
|
45
45
|
end
|
46
46
|
|
47
47
|
teardown do
|
@@ -49,12 +49,12 @@ class BacktraceTest < Test::Unit::TestCase
|
|
49
49
|
end
|
50
50
|
|
51
51
|
should "filter out the project root" do
|
52
|
-
backtrace_with_root =
|
52
|
+
backtrace_with_root = ErrornotNotifier::Backtrace.parse(
|
53
53
|
["#{@project_root}/app/models/user.rb:7:in `latest'",
|
54
54
|
"#{@project_root}/app/controllers/users_controller.rb:13:in `index'",
|
55
55
|
"/lib/something.rb:41:in `open'"],
|
56
56
|
:filters => default_filters)
|
57
|
-
backtrace_without_root =
|
57
|
+
backtrace_without_root = ErrornotNotifier::Backtrace.parse(
|
58
58
|
["[PROJECT_ROOT]/app/models/user.rb:7:in `latest'",
|
59
59
|
"[PROJECT_ROOT]/app/controllers/users_controller.rb:13:in `index'",
|
60
60
|
"/lib/something.rb:41:in `open'"])
|
@@ -65,7 +65,7 @@ class BacktraceTest < Test::Unit::TestCase
|
|
65
65
|
|
66
66
|
context "with a blank project root" do
|
67
67
|
setup do
|
68
|
-
|
68
|
+
ErrornotNotifier.configure {|config| config.project_root = '' }
|
69
69
|
end
|
70
70
|
|
71
71
|
teardown do
|
@@ -78,21 +78,21 @@ class BacktraceTest < Test::Unit::TestCase
|
|
78
78
|
"/lib/something.rb:41:in `open'"]
|
79
79
|
|
80
80
|
backtrace_with_root =
|
81
|
-
|
81
|
+
ErrornotNotifier::Backtrace.parse(backtrace, :filters => default_filters)
|
82
82
|
|
83
83
|
backtrace_without_root =
|
84
|
-
|
84
|
+
ErrornotNotifier::Backtrace.parse(backtrace)
|
85
85
|
|
86
86
|
assert_equal backtrace_without_root, backtrace_with_root
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
should "remove notifier trace" do
|
91
|
-
inside_notifier = ['lib/
|
91
|
+
inside_notifier = ['lib/errornot_notifier.rb:13:in `voodoo`']
|
92
92
|
outside_notifier = ['users_controller:8:in `index`']
|
93
93
|
|
94
|
-
without_inside =
|
95
|
-
with_inside =
|
94
|
+
without_inside = ErrornotNotifier::Backtrace.parse(outside_notifier)
|
95
|
+
with_inside = ErrornotNotifier::Backtrace.parse(inside_notifier + outside_notifier,
|
96
96
|
:filters => default_filters)
|
97
97
|
|
98
98
|
assert_equal without_inside, with_inside
|
@@ -100,9 +100,9 @@ class BacktraceTest < Test::Unit::TestCase
|
|
100
100
|
|
101
101
|
should "run filters on the backtrace" do
|
102
102
|
filters = [lambda { |line| line.sub('foo', 'bar') }]
|
103
|
-
input =
|
103
|
+
input = ErrornotNotifier::Backtrace.parse(["foo:13:in `one'", "baz:14:in `two'"],
|
104
104
|
:filters => filters)
|
105
|
-
expected =
|
105
|
+
expected = ErrornotNotifier::Backtrace.parse(["bar:13:in `one'", "baz:14:in `two'"])
|
106
106
|
assert_equal expected, input
|
107
107
|
end
|
108
108
|
|
@@ -112,7 +112,7 @@ class BacktraceTest < Test::Unit::TestCase
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def default_filters
|
115
|
-
|
115
|
+
ErrornotNotifier::Configuration::DEFAULT_BACKTRACE_FILTERS
|
116
116
|
end
|
117
117
|
|
118
118
|
end
|
data/test/catcher_test.rb
CHANGED
@@ -7,19 +7,19 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
|
|
7
7
|
def setup
|
8
8
|
super
|
9
9
|
reset_config
|
10
|
-
|
10
|
+
ErrornotNotifier.sender = CollectingSender.new
|
11
11
|
define_constant('RAILS_ROOT', '/path/to/rails/root')
|
12
12
|
end
|
13
13
|
|
14
14
|
def ignore(exception_class)
|
15
|
-
|
15
|
+
ErrornotNotifier.configuration.ignore << exception_class
|
16
16
|
end
|
17
17
|
|
18
18
|
def build_controller_class(&definition)
|
19
19
|
returning Class.new(ActionController::Base) do |klass|
|
20
|
-
klass.__send__(:include,
|
20
|
+
klass.__send__(:include, ErrornotNotifier::Rails::ActionControllerCatcher)
|
21
21
|
klass.class_eval(&definition) if definition
|
22
|
-
define_constant('
|
22
|
+
define_constant('ErrornotTestController', klass)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -44,7 +44,7 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def sender
|
47
|
-
|
47
|
+
ErrornotNotifier.sender
|
48
48
|
end
|
49
49
|
|
50
50
|
def last_sent_notice_xml
|
@@ -82,7 +82,7 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
|
|
82
82
|
klass.consider_all_requests_local = opts[:all_local]
|
83
83
|
klass.local = opts[:local]
|
84
84
|
controller = klass.new
|
85
|
-
controller.stubs(:
|
85
|
+
controller.stubs(:rescue_action_in_public_without_errornot)
|
86
86
|
opts[:request].query_parameters = opts[:request].query_parameters.merge(opts[:params] || {})
|
87
87
|
opts[:request].session = ActionController::TestSession.new(opts[:session] || {})
|
88
88
|
controller.process(opts[:request], opts[:response])
|
@@ -91,7 +91,7 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
|
|
91
91
|
|
92
92
|
def process_action_with_manual_notification(args = {})
|
93
93
|
process_action(args) do
|
94
|
-
|
94
|
+
notify_errornot(:error_message => 'fail')
|
95
95
|
# Rails will raise a template error if we don't render something
|
96
96
|
render :nothing => true
|
97
97
|
end
|
@@ -152,28 +152,28 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
|
|
152
152
|
should "continue with default behavior after delivering an exception" do
|
153
153
|
controller = process_action_with_automatic_notification(:public => true)
|
154
154
|
# TODO: can we test this without stubbing?
|
155
|
-
assert_received(controller, :
|
155
|
+
assert_received(controller, :rescue_action_in_public_without_errornot)
|
156
156
|
end
|
157
157
|
|
158
|
-
should "not create actions from
|
158
|
+
should "not create actions from Errornot methods" do
|
159
159
|
controller = build_controller_class.new
|
160
|
-
assert_equal [],
|
160
|
+
assert_equal [], ErrornotNotifier::Rails::ActionControllerCatcher.instance_methods
|
161
161
|
end
|
162
162
|
|
163
163
|
should "ignore exceptions when user agent is being ignored by regular expression" do
|
164
|
-
|
164
|
+
ErrornotNotifier.configuration.ignore_user_agent_only = [/Ignored/]
|
165
165
|
process_action_with_automatic_notification(:user_agent => 'ShouldBeIgnored')
|
166
166
|
assert_caught_and_not_sent
|
167
167
|
end
|
168
168
|
|
169
169
|
should "ignore exceptions when user agent is being ignored by string" do
|
170
|
-
|
170
|
+
ErrornotNotifier.configuration.ignore_user_agent_only = ['IgnoredUserAgent']
|
171
171
|
process_action_with_automatic_notification(:user_agent => 'IgnoredUserAgent')
|
172
172
|
assert_caught_and_not_sent
|
173
173
|
end
|
174
174
|
|
175
175
|
should "not ignore exceptions when user agent is not being ignored" do
|
176
|
-
|
176
|
+
ErrornotNotifier.configuration.ignore_user_agent_only = ['IgnoredUserAgent']
|
177
177
|
process_action_with_automatic_notification(:user_agent => 'NonIgnoredAgent')
|
178
178
|
assert_caught_and_sent
|
179
179
|
end
|
@@ -191,25 +191,25 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
|
|
191
191
|
end
|
192
192
|
|
193
193
|
should "send request data for manual notification" do
|
194
|
-
params = { 'controller' => "
|
194
|
+
params = { 'controller' => "errornot_test", 'action' => "index" }
|
195
195
|
controller = process_action_with_manual_notification(:params => params)
|
196
196
|
assert_sent_request_info_for controller.request
|
197
197
|
end
|
198
198
|
|
199
199
|
should "send request data for manual notification with non-standard port" do
|
200
|
-
params = { 'controller' => "
|
200
|
+
params = { 'controller' => "errornot_test", 'action' => "index" }
|
201
201
|
controller = process_action_with_manual_notification(:params => params, :port => 81)
|
202
202
|
assert_sent_request_info_for controller.request
|
203
203
|
end
|
204
204
|
|
205
205
|
should "send request data for automatic notification" do
|
206
|
-
params = { 'controller' => "
|
206
|
+
params = { 'controller' => "errornot_test", 'action' => "index" }
|
207
207
|
controller = process_action_with_automatic_notification(:params => params)
|
208
208
|
assert_sent_request_info_for controller.request
|
209
209
|
end
|
210
210
|
|
211
211
|
should "send request data for automatic notification with non-standard port" do
|
212
|
-
params = { 'controller' => "
|
212
|
+
params = { 'controller' => "errornot_test", 'action' => "index" }
|
213
213
|
controller = process_action_with_automatic_notification(:params => params, :port => 81)
|
214
214
|
assert_sent_request_info_for controller.request
|
215
215
|
end
|
@@ -233,8 +233,8 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
|
|
233
233
|
|
234
234
|
context "for a local error with development lookup enabled" do
|
235
235
|
setup do
|
236
|
-
|
237
|
-
|
236
|
+
ErrornotNotifier.configuration.development_lookup = true
|
237
|
+
ErrornotNotifier.stubs(:build_lookup_hash_for).returns({ :awesome => 2 })
|
238
238
|
|
239
239
|
@controller = process_action_with_automatic_notification(:local => true)
|
240
240
|
@response = @controller.response
|
@@ -246,15 +246,15 @@ class ActionControllerCatcherTest < Test::Unit::TestCase
|
|
246
246
|
end
|
247
247
|
|
248
248
|
should "contain host, API key and notice JSON" do
|
249
|
-
assert_match
|
250
|
-
assert_match
|
249
|
+
assert_match ErrornotNotifier.configuration.host.to_json, @response.body
|
250
|
+
assert_match ErrornotNotifier.configuration.api_key.to_json, @response.body
|
251
251
|
assert_match ({ :awesome => 2 }).to_json, @response.body
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
255
|
context "for a local error with development lookup disabled" do
|
256
256
|
setup do
|
257
|
-
|
257
|
+
ErrornotNotifier.configuration.development_lookup = false
|
258
258
|
|
259
259
|
@controller = process_action_with_automatic_notification(:local => true)
|
260
260
|
@response = @controller.response
|
data/test/configuration_test.rb
CHANGED
@@ -12,41 +12,39 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
12
12
|
assert_config_default :project_root, nil
|
13
13
|
assert_config_default :environment_name, nil
|
14
14
|
assert_config_default :logger, nil
|
15
|
-
assert_config_default :notifier_version,
|
16
|
-
assert_config_default :notifier_name, '
|
17
|
-
assert_config_default :notifier_url, 'http://hoptoadapp.com'
|
15
|
+
assert_config_default :notifier_version, ErrornotNotifier::VERSION
|
16
|
+
assert_config_default :notifier_name, 'Errornot Notifier'
|
18
17
|
assert_config_default :secure, false
|
19
|
-
assert_config_default :host, 'hoptoadapp.com'
|
20
18
|
assert_config_default :http_open_timeout, 2
|
21
19
|
assert_config_default :http_read_timeout, 5
|
22
20
|
assert_config_default :ignore_by_filters, []
|
23
21
|
assert_config_default :ignore_user_agent, []
|
24
22
|
assert_config_default :params_filters,
|
25
|
-
|
23
|
+
ErrornotNotifier::Configuration::DEFAULT_PARAMS_FILTERS
|
26
24
|
assert_config_default :backtrace_filters,
|
27
|
-
|
25
|
+
ErrornotNotifier::Configuration::DEFAULT_BACKTRACE_FILTERS
|
28
26
|
assert_config_default :ignore,
|
29
|
-
|
27
|
+
ErrornotNotifier::Configuration::IGNORE_DEFAULT
|
30
28
|
assert_config_default :development_lookup, true
|
31
29
|
assert_config_default :framework, 'Standalone'
|
32
30
|
end
|
33
31
|
|
34
32
|
should "provide default values for secure connections" do
|
35
|
-
config =
|
33
|
+
config = ErrornotNotifier::Configuration.new
|
36
34
|
config.secure = true
|
37
35
|
assert_equal 443, config.port
|
38
36
|
assert_equal 'https', config.protocol
|
39
37
|
end
|
40
38
|
|
41
39
|
should "provide default values for insecure connections" do
|
42
|
-
config =
|
40
|
+
config = ErrornotNotifier::Configuration.new
|
43
41
|
config.secure = false
|
44
42
|
assert_equal 80, config.port
|
45
43
|
assert_equal 'http', config.protocol
|
46
44
|
end
|
47
45
|
|
48
46
|
should "not cache inferred ports" do
|
49
|
-
config =
|
47
|
+
config = ErrornotNotifier::Configuration.new
|
50
48
|
config.secure = false
|
51
49
|
config.port
|
52
50
|
config.secure = true
|
@@ -77,7 +75,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
77
75
|
end
|
78
76
|
|
79
77
|
should "act like a hash" do
|
80
|
-
config =
|
78
|
+
config = ErrornotNotifier::Configuration.new
|
81
79
|
hash = config.to_hash
|
82
80
|
[:api_key, :backtrace_filters, :development_environments,
|
83
81
|
:environment_name, :host, :http_open_timeout,
|
@@ -90,7 +88,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
90
88
|
end
|
91
89
|
|
92
90
|
should "be mergable" do
|
93
|
-
config =
|
91
|
+
config = ErrornotNotifier::Configuration.new
|
94
92
|
hash = config.to_hash
|
95
93
|
assert_equal hash.merge(:key => 'value'), config.merge(:key => 'value')
|
96
94
|
end
|
@@ -100,7 +98,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
100
98
|
end
|
101
99
|
|
102
100
|
should "warn when attempting to read environment filters" do
|
103
|
-
config =
|
101
|
+
config = ErrornotNotifier::Configuration.new
|
104
102
|
config.
|
105
103
|
expects(:warn).
|
106
104
|
with(regexp_matches(/deprecated/i))
|
@@ -128,7 +126,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
128
126
|
end
|
129
127
|
|
130
128
|
should "allow ignored exceptions to be appended" do
|
131
|
-
config =
|
129
|
+
config = ErrornotNotifier::Configuration.new
|
132
130
|
original_filters = config.ignore.dup
|
133
131
|
new_filter = 'hello'
|
134
132
|
config.ignore << new_filter
|
@@ -144,48 +142,48 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
144
142
|
end
|
145
143
|
|
146
144
|
should "use development and test as development environments by default" do
|
147
|
-
config =
|
145
|
+
config = ErrornotNotifier::Configuration.new
|
148
146
|
assert_same_elements %w(development test cucumber), config.development_environments
|
149
147
|
end
|
150
148
|
|
151
149
|
should "be public in a public environment" do
|
152
|
-
config =
|
150
|
+
config = ErrornotNotifier::Configuration.new
|
153
151
|
config.development_environments = %w(development)
|
154
152
|
config.environment_name = 'production'
|
155
153
|
assert config.public?
|
156
154
|
end
|
157
155
|
|
158
156
|
should "not be public in a development environment" do
|
159
|
-
config =
|
157
|
+
config = ErrornotNotifier::Configuration.new
|
160
158
|
config.development_environments = %w(staging)
|
161
159
|
config.environment_name = 'staging'
|
162
160
|
assert !config.public?
|
163
161
|
end
|
164
162
|
|
165
163
|
should "be public without an environment name" do
|
166
|
-
config =
|
164
|
+
config = ErrornotNotifier::Configuration.new
|
167
165
|
assert config.public?
|
168
166
|
end
|
169
167
|
|
170
168
|
should "use the assigned logger if set" do
|
171
|
-
config =
|
169
|
+
config = ErrornotNotifier::Configuration.new
|
172
170
|
config.logger = "CUSTOM LOGGER"
|
173
171
|
assert_equal "CUSTOM LOGGER", config.logger
|
174
172
|
end
|
175
173
|
|
176
174
|
def assert_config_default(option, default_value, config = nil)
|
177
|
-
config ||=
|
175
|
+
config ||= ErrornotNotifier::Configuration.new
|
178
176
|
assert_equal default_value, config.send(option)
|
179
177
|
end
|
180
178
|
|
181
179
|
def assert_config_overridable(option, value = 'a value')
|
182
|
-
config =
|
180
|
+
config = ErrornotNotifier::Configuration.new
|
183
181
|
config.send(:"#{option}=", value)
|
184
182
|
assert_equal value, config.send(option)
|
185
183
|
end
|
186
184
|
|
187
185
|
def assert_appends_value(option, &block)
|
188
|
-
config =
|
186
|
+
config = ErrornotNotifier::Configuration.new
|
189
187
|
original_values = config.send(option).dup
|
190
188
|
block ||= lambda do |config|
|
191
189
|
new_value = 'hello'
|
@@ -197,7 +195,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
197
195
|
end
|
198
196
|
|
199
197
|
def assert_replaces(option, setter)
|
200
|
-
config =
|
198
|
+
config = ErrornotNotifier::Configuration.new
|
201
199
|
new_value = 'hello'
|
202
200
|
config.send(setter, [new_value])
|
203
201
|
assert_equal [new_value], config.send(option)
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../lib/errornot_tasks'
|
5
|
+
require 'fakeweb'
|
6
|
+
|
7
|
+
FakeWeb.allow_net_connect = false
|
8
|
+
|
9
|
+
class ErrornotTasksTest < Test::Unit::TestCase
|
10
|
+
def test_assert
|
11
|
+
assert true
|
12
|
+
end
|
13
|
+
# TODO: reactivate spec when it's implement
|
14
|
+
#def successful_response(body = "")
|
15
|
+
#response = Net::HTTPSuccess.new('1.2', '200', 'OK')
|
16
|
+
#response.stubs(:body).returns(body)
|
17
|
+
#return response
|
18
|
+
#end
|
19
|
+
|
20
|
+
#def unsuccessful_response(body = "")
|
21
|
+
#response = Net::HTTPClientError.new('1.2', '200', 'OK')
|
22
|
+
#response.stubs(:body).returns(body)
|
23
|
+
#return response
|
24
|
+
#end
|
25
|
+
|
26
|
+
#context "being quiet" do
|
27
|
+
#setup { ErrornotTasks.stubs(:puts) }
|
28
|
+
|
29
|
+
#context "in a configured project" do
|
30
|
+
#setup {
|
31
|
+
#ErrornotNotifier.configure { |config|
|
32
|
+
#config.host = 'localhost'
|
33
|
+
#config.api_key = "1234123412341234"
|
34
|
+
#}
|
35
|
+
#}
|
36
|
+
|
37
|
+
#context "on deploy({})" do
|
38
|
+
#setup { @output = ErrornotTasks.deploy({}) }
|
39
|
+
|
40
|
+
#before_should "complain about missing rails env" do
|
41
|
+
#ErrornotTasks.expects(:puts).with(regexp_matches(/rails environment/i))
|
42
|
+
#end
|
43
|
+
|
44
|
+
#should "return false" do
|
45
|
+
#assert !@output
|
46
|
+
#end
|
47
|
+
#end
|
48
|
+
|
49
|
+
#context "given valid options" do
|
50
|
+
#setup { @options = {:rails_env => "staging"} }
|
51
|
+
|
52
|
+
#context "on deploy(options)" do
|
53
|
+
#setup { @output = ErrornotTasks.deploy(@options) }
|
54
|
+
|
55
|
+
#before_should "post to http://errornotapp.com/deploys.txt" do
|
56
|
+
#URI.stubs(:parse).with('http://errornotapp.com/deploys.txt').returns(:uri)
|
57
|
+
#Net::HTTP.expects(:post_form).with(:uri, kind_of(Hash)).returns(successful_response)
|
58
|
+
#end
|
59
|
+
|
60
|
+
#before_should "use the project api key" do
|
61
|
+
#Net::HTTP.expects(:post_form).
|
62
|
+
#with(kind_of(URI), has_entries('api_key' => "1234123412341234")).
|
63
|
+
#returns(successful_response)
|
64
|
+
#end
|
65
|
+
|
66
|
+
#before_should "use send the rails_env param" do
|
67
|
+
#Net::HTTP.expects(:post_form).
|
68
|
+
#with(kind_of(URI), has_entries("deploy[rails_env]" => "staging")).
|
69
|
+
#returns(successful_response)
|
70
|
+
#end
|
71
|
+
|
72
|
+
#[:local_username, :scm_repository, :scm_revision].each do |key|
|
73
|
+
#before_should "use send the #{key} param if it's passed in." do
|
74
|
+
#@options[key] = "value"
|
75
|
+
#Net::HTTP.expects(:post_form).
|
76
|
+
#with(kind_of(URI), has_entries("deploy[#{key}]" => "value")).
|
77
|
+
#returns(successful_response)
|
78
|
+
#end
|
79
|
+
#end
|
80
|
+
|
81
|
+
#before_should "use the :api_key param if it's passed in." do
|
82
|
+
#@options[:api_key] = "value"
|
83
|
+
#Net::HTTP.expects(:post_form).
|
84
|
+
#with(kind_of(URI), has_entries("api_key" => "value")).
|
85
|
+
#returns(successful_response)
|
86
|
+
#end
|
87
|
+
|
88
|
+
#before_should "puts the response body on success" do
|
89
|
+
#ErrornotTasks.expects(:puts).with("body")
|
90
|
+
#Net::HTTP.expects(:post_form).with(any_parameters).returns(successful_response('body'))
|
91
|
+
#end
|
92
|
+
|
93
|
+
#before_should "puts the response body on failure" do
|
94
|
+
#ErrornotTasks.expects(:puts).with("body")
|
95
|
+
#Net::HTTP.expects(:post_form).with(any_parameters).returns(unsuccessful_response('body'))
|
96
|
+
#end
|
97
|
+
|
98
|
+
#should "return false on failure", :before => lambda {
|
99
|
+
#Net::HTTP.expects(:post_form).with(any_parameters).returns(unsuccessful_response('body'))
|
100
|
+
#} do
|
101
|
+
#assert !@output
|
102
|
+
#end
|
103
|
+
|
104
|
+
#should "return true on success", :before => lambda {
|
105
|
+
#Net::HTTP.expects(:post_form).with(any_parameters).returns(successful_response('body'))
|
106
|
+
#} do
|
107
|
+
#assert @output
|
108
|
+
#end
|
109
|
+
#end
|
110
|
+
#end
|
111
|
+
#end
|
112
|
+
|
113
|
+
#context "in a configured project with custom host" do
|
114
|
+
#setup do
|
115
|
+
#ErrornotNotifier.configure do |config|
|
116
|
+
#config.api_key = "1234123412341234"
|
117
|
+
#config.host = "custom.host"
|
118
|
+
#end
|
119
|
+
#end
|
120
|
+
|
121
|
+
#context "on deploy(:rails_env => 'staging')" do
|
122
|
+
#setup { @output = ErrornotTasks.deploy(:rails_env => "staging") }
|
123
|
+
|
124
|
+
#before_should "post to the custom host" do
|
125
|
+
#URI.stubs(:parse).with('http://custom.host/deploys.txt').returns(:uri)
|
126
|
+
#Net::HTTP.expects(:post_form).with(:uri, kind_of(Hash)).returns(successful_response)
|
127
|
+
#end
|
128
|
+
#end
|
129
|
+
#end
|
130
|
+
|
131
|
+
#context "when not configured" do
|
132
|
+
#setup { ErrornotNotifier.configure { |config| config.api_key = "" } }
|
133
|
+
|
134
|
+
#context "on deploy(:rails_env => 'staging')" do
|
135
|
+
#setup { @output = ErrornotTasks.deploy(:rails_env => "staging") }
|
136
|
+
|
137
|
+
#before_should "complain about missing api key" do
|
138
|
+
#ErrornotTasks.expects(:puts).with(regexp_matches(/api key/i))
|
139
|
+
#end
|
140
|
+
|
141
|
+
#should "return false" do
|
142
|
+
#assert !@output
|
143
|
+
#end
|
144
|
+
#end
|
145
|
+
#end
|
146
|
+
#end
|
147
|
+
end
|