Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 86 lines (72 sloc) 2.226 kb
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
1 require File.dirname(__FILE__) + '/helper'
2
00770fa @qrush Adding support for Rails 1.2.6
qrush authored
3 class LoggerTest < Test::Unit::TestCase
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
4 def stub_http(response, body = nil)
5 response.stubs(:body => body) if body
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
6 @http = stub(:post => response,
7 :read_timeout= => nil,
8 :open_timeout= => nil,
9 :use_ssl= => nil)
10 Net::HTTP.stubs(:new).returns(@http)
11 end
12
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
13 def send_notice
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
14 Airbrake.sender.send_to_airbrake('data')
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
15 end
16
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
17 def stub_verbose_log
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
18 Airbrake.stubs(:write_verbose_log)
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
19 end
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
20
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
21 def assert_logged(expected)
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
22 assert_received(Airbrake, :write_verbose_log) do |expect|
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
23 expect.with {|actual| actual =~ expected }
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
24 end
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
25 end
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
26
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
27 def assert_not_logged(expected)
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
28 assert_received(Airbrake, :write_verbose_log) do |expect|
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
29 expect.with {|actual| actual =~ expected }.never
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
30 end
31 end
32
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
33 def configure
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
34 Airbrake.configure { |config| }
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
35 end
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
36
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
37 should "report that notifier is ready when configured" do
38 stub_verbose_log
39 configure
40 assert_logged /Notifier (.*) ready/
41 end
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
42
bbcdc12 Fixed logger being reported ready twice
Joe Ferris authored
43 should "not report that notifier is ready when internally configured" do
44 stub_verbose_log
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
45 Airbrake.configure(true) { |config| }
bbcdc12 Fixed logger being reported ready twice
Joe Ferris authored
46 assert_not_logged /.*/
47 end
48
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
49 should "print environment info a successful notification without a body" do
50 reset_config
51 stub_verbose_log
52 stub_http(Net::HTTPSuccess)
53 send_notice
54 assert_logged /Environment Info:/
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
55 assert_not_logged /Response from Airbrake:/
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
56 end
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
57
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
58 should "print environment info on a failed notification without a body" do
59 reset_config
60 stub_verbose_log
61 stub_http(Net::HTTPError)
62 send_notice
63 assert_logged /Environment Info:/
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
64 assert_not_logged /Response from Airbrake:/
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
65 end
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
66
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
67 should "print environment info and response on a success with a body" do
68 reset_config
69 stub_verbose_log
70 stub_http(Net::HTTPSuccess, 'test')
71 send_notice
72 assert_logged /Environment Info:/
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
73 assert_logged /Response from Airbrake:/
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
74 end
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
75
76 should "print environment info and response on a failure with a body" do
77 reset_config
78 stub_verbose_log
79 stub_http(Net::HTTPError, 'test')
80 send_notice
81 assert_logged /Environment Info:/
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
82 assert_logged /Response from Airbrake:/
568a973 Moved code out of the HoptoadNotifier module and into the Notice, Config...
Joe Ferris authored
83 end
84
f8111b8 @qrush Printing out the environment info and response from hoptoad in the logs
qrush authored
85 end
Something went wrong with that request. Please try again.