test/sender_test.rb in hydraulic_brake-0.1.0 vs test/sender_test.rb in hydraulic_brake-0.2.0
- old
+ new
@@ -10,42 +10,41 @@
HydraulicBrake.configure do |conf|
opts.each {|opt, value| conf.send(:"#{opt}=", value) }
end
end
+ def build_logger
+ klass = Class.new do
+ attr_reader :errors, :infos, :debugs
+
+ def error(i); @errors ||= []; @errors << i; end
+ def info(i); @infos ||= []; @infos << i; end
+ def debug(i); @debugs ||= []; @debugs << i; end
+ end
+
+ klass.new
+ end
+
def send_exception(args = {})
- notice = args.delete(:notice) || build_notice_data
- notice.stubs(:to_xml)
+ notice = args.delete(:notice) || HydraulicBrake::Notice.new(args)
sender = args.delete(:sender) || build_sender(args)
sender.send_to_airbrake(notice)
end
- def stub_http(options = {})
- response = stub(:body => options[:body] || 'body')
+ def stub_http(response=nil)
+ response ||= stub(:body => 'body')
+
http = stub(:post => response,
:read_timeout= => nil,
:open_timeout= => nil,
:ca_file= => nil,
:verify_mode= => nil,
:use_ssl= => nil)
Net::HTTP.stubs(:new => http)
http
end
- should "post to Airbrake with XML passed" do
- xml_notice = HydraulicBrake::Notice.new(:error_class => "FooBar", :error_message => "Foo Bar").to_xml
-
- http = stub_http
-
- sender = build_sender
- sender.send_to_airbrake(xml_notice)
-
- assert_received(http, :post) do |expect|
- expect.with(anything, xml_notice, HydraulicBrake::HEADERS)
- end
- end
-
should "post to Airbrake with a Notice instance passed" do
notice = HydraulicBrake::Notice.new(:error_class => "FooBar", :error_message => "Foo Bar")
http = stub_http
@@ -85,11 +84,34 @@
expect.with(proxy_host, proxy_port, proxy_user, proxy_pass)
end
end
should "return the created group's id on successful posting" do
- http = stub_http(:body => '<id type="integer">3799307</id>')
+ response = Net::HTTPSuccess.new(1.0, 200, "OK")
+ def response.body
+ '<id type="integer">3799307</id>'
+ end
+
+ stub_http(response)
assert_equal "3799307", send_exception(:secure => false)
+ end
+
+ should "log the url to the error on successful posting" do
+ response = Net::HTTPSuccess.new(1.0, 200, "OK")
+ def response.body
+ '<id type="integer">3799307</id><url>http://some-url.com/foo</url>'
+ end
+
+ logger = build_logger
+
+ HydraulicBrake.configure do |c|
+ c.logger = logger
+ end
+
+ stub_http(response)
+ send_exception(:secure => false)
+ matcher = %r{Success: sent error to Airbrake: http://some-url.com/foo}
+ assert_match matcher, logger.infos.first
end
context "when encountering exceptions: " do
context "HTTP connection setup problems" do
should "not be rescued" do