Skip to content
This repository has been archived by the owner on Feb 18, 2018. It is now read-only.

Commit

Permalink
Refactored the http tests to use declarative syntax, and did some min…
Browse files Browse the repository at this point in the history
…or refactoring of the tests in general.
  • Loading branch information
djberg96 committed Jun 20, 2010
1 parent d3f050a commit 9876fbc
Showing 1 changed file with 103 additions and 70 deletions.
173 changes: 103 additions & 70 deletions test/test_net_ping_http.rb
Expand Up @@ -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

0 comments on commit 9876fbc

Please sign in to comment.