This repository has been archived by the owner on Nov 11, 2017. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
logger_test.rb
85 lines (72 loc) · 2.21 KB
/
logger_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require File.dirname(__FILE__) + '/helper'
class LoggerTest < Test::Unit::TestCase
def stub_http(response, body = nil)
response.stubs(:body => body) if body
@http = stub(:post => response,
:read_timeout= => nil,
:open_timeout= => nil,
:use_ssl= => nil)
Net::HTTP.stubs(:new).returns(@http)
end
def send_notice
HoptoadNotifier.sender.send_to_hoptoad('data')
end
def stub_verbose_log
HoptoadNotifier.stubs(:write_verbose_log)
end
def assert_logged(expected)
assert_received(HoptoadNotifier, :write_verbose_log) do |expect|
expect.with {|actual| actual =~ expected }
end
end
def assert_not_logged(expected)
assert_received(HoptoadNotifier, :write_verbose_log) do |expect|
expect.with {|actual| actual =~ expected }.never
end
end
def configure
HoptoadNotifier.configure { |config| }
end
should "report that notifier is ready when configured" do
stub_verbose_log
configure
assert_logged /Notifier (.*) ready/
end
should "not report that notifier is ready when internally configured" do
stub_verbose_log
HoptoadNotifier.configure(true) { |config| }
assert_not_logged /.*/
end
should "print environment info a successful notification without a body" do
reset_config
stub_verbose_log
stub_http(Net::HTTPSuccess)
send_notice
assert_logged /Environment Info:/
assert_not_logged /Response from Hoptoad:/
end
should "print environment info on a failed notification without a body" do
reset_config
stub_verbose_log
stub_http(Net::HTTPError)
send_notice
assert_logged /Environment Info:/
assert_not_logged /Response from Hoptoad:/
end
should "print environment info and response on a success with a body" do
reset_config
stub_verbose_log
stub_http(Net::HTTPSuccess, 'test')
send_notice
assert_logged /Environment Info:/
assert_logged /Response from Hoptoad:/
end
should "print environment info and response on a failure with a body" do
reset_config
stub_verbose_log
stub_http(Net::HTTPError, 'test')
send_notice
assert_logged /Environment Info:/
assert_logged /Response from Hoptoad:/
end
end