From 9876fbcfe68ec7f7f6cf57eb6a16132f9b27006c Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Sun, 20 Jun 2010 09:25:56 -0600 Subject: [PATCH] Refactored the http tests to use declarative syntax, and did some minor refactoring of the tests in general. --- test/test_net_ping_http.rb | 173 ++++++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 70 deletions(-) diff --git a/test/test_net_ping_http.rb b/test/test_net_ping_http.rb index 9567fc4..ef48f68 100644 --- a/test/test_net_ping_http.rb +++ b/test/test_net_ping_http.rb @@ -9,74 +9,107 @@ require 'test/unit' require 'net/ping/http' -include Net - -class TC_PingHTTP < Test::Unit::TestCase - def setup - @uri = 'http://www.google.com/index.html' - @http = Ping::HTTP.new(@uri, 80, 30) - @bad = Ping::HTTP.new('http://www.blabfoobarurgh.com') # One hopes not - end - - def test_ping - assert_respond_to(@http, :ping) - assert_nothing_raised{ @http.ping } - end - - def test_ping_aliases - assert_respond_to(@http, :ping?) - assert_respond_to(@http, :pingecho) - assert_nothing_raised{ @http.ping? } - assert_nothing_raised{ @http.pingecho } - end - - def test_ping_success - assert_equal(true, @http.ping?) - assert_equal(false, @bad.ping?) - assert_not_nil(@bad.exception) - end - - def test_duration - assert_nothing_raised{ @http.ping } - assert_respond_to(@http, :duration) - assert_kind_of(Float, @http.duration) - end - - def test_host - assert_respond_to(@http, :host) - assert_respond_to(@http, :host=) - assert_respond_to(@http, :uri) # Alias - assert_respond_to(@http, :uri=) # Alias - assert_equal('http://www.google.com/index.html', @http.host) - end - - def test_port - assert_respond_to(@http, :port) - assert_respond_to(@http, :port=) - assert_equal(80, @http.port) - end - - def test_timeout - assert_respond_to(@http, :timeout) - assert_respond_to(@http, :timeout=) - assert_equal(30, @http.timeout) - assert_equal(5, @bad.timeout) - end - - def test_exception - assert_respond_to(@http, :exception) - assert_nothing_raised{ @http.ping } - assert_nothing_raised{ @bad.ping } - assert_nil(@http.exception) - assert_not_nil(@bad.exception) - end - - def test_warning - assert_respond_to(@http, :warning) - end - - def teardown - @uri = nil - @http = nil - end + +class TC_Net_Ping_HTTP < Test::Unit::TestCase + def setup + @uri = 'http://www.google.com/index.html' + @http = Net::Ping::HTTP.new(@uri, 80, 30) + @bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not + end + + test 'ping basic functionality' do + assert_respond_to(@http, :ping) + assert_nothing_raised{ @http.ping } + end + + test 'ping returns a boolean value' do + assert_boolean(@http.ping?) + assert_boolean(@bad.ping?) + end + + test 'ping? is an alias for ping' do + assert_alias_method(@http, :ping?, :ping) + end + + test 'pingecho is an alias for ping' do + assert_alias_method(@http, :pingecho, :ping) + end + + test 'ping should succeed for a valid website' do + assert_true(@http.ping?) + end + + test 'ping should fail for an invalid website' do + assert_false(@bad.ping?) + end + + test 'duration basic functionality' do + assert_respond_to(@http, :duration) + assert_nothing_raised{ @http.ping } + end + + test 'duration returns a float value on a successful ping' do + assert_true(@http.ping) + assert_kind_of(Float, @http.duration) + end + + test 'duration returns no value on an unsuccessful ping' do + assert_false(@bad.ping) + assert_kind_of(Float, @http.duration) + end + + test 'host attribute basic functionality' do + assert_respond_to(@http, :host) + assert_respond_to(@http, :host=) + assert_equal('http://www.google.com/index.html', @http.host) + end + + test 'uri is an alias for host' do + assert_alias_method(@http, :uri, :host) + assert_alias_method(@http, :uri=, :host=) + end + + test 'port attribute basic functionality' do + assert_respond_to(@http, :port) + assert_respond_to(@http, :port=) + end + + test 'port attribute expected value' do + assert_equal(80, @http.port) + end + + test 'timeout attribute basic functionality' do + assert_respond_to(@http, :timeout) + assert_respond_to(@http, :timeout=) + end + + test 'timeout attribute expected values' do + assert_equal(30, @http.timeout) + assert_equal(5, @bad.timeout) + end + + test 'exception attribute basic functionality' do + assert_respond_to(@http, :exception) + assert_nil(@http.exception) + end + + test 'exception attribute is nil if the ping is successful' do + assert_true(@http.ping) + assert_nil(@http.exception) + end + + test 'exception attribute is not nil if the ping is unsuccessful' do + assert_false(@bad.ping) + assert_not_nil(@bad.exception) + end + + test 'warning attribute basic functionality' do + assert_respond_to(@http, :warning) + assert_nil(@http.warning) + end + + def teardown + @uri = nil + @http = nil + end end