net-ping 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,84 +9,79 @@ gem 'test-unit'
9
9
 
10
10
  require 'test/unit'
11
11
  require 'net/ping/external'
12
- include Net
13
12
 
14
- class TC_PingExternal < Test::Unit::TestCase
15
- def setup
16
- @host = 'www.ruby-lang.org'
17
- @bogus = 'foo.bar.baz'
18
- @pe = Ping::External.new(@host)
19
- @bad = Ping::External.new(@bogus)
20
- end
13
+ class TC_Net_Ping_External < Test::Unit::TestCase
14
+ def setup
15
+ @host = 'www.ruby-lang.org'
16
+ @bogus = 'foo.bar.baz'
17
+ @pe = Net::Ping::External.new(@host)
18
+ @bad = Net::Ping::External.new(@bogus)
19
+ end
21
20
 
22
- def test_version
23
- assert_equal('1.3.2', Ping::External::VERSION)
24
- end
25
-
26
- def test_ping
27
- assert_respond_to(@pe, :ping)
28
- assert_nothing_raised{ @pe.ping }
29
- assert_nothing_raised{ @pe.ping(@host) }
30
- end
21
+ def test_ping
22
+ assert_respond_to(@pe, :ping)
23
+ assert_nothing_raised{ @pe.ping }
24
+ assert_nothing_raised{ @pe.ping(@host) }
25
+ end
31
26
 
32
- def test_ping_aliases
33
- assert_respond_to(@pe, :ping?)
34
- assert_respond_to(@pe, :pingecho)
35
- assert_nothing_raised{ @pe.ping? }
36
- assert_nothing_raised{ @pe.ping?(@host) }
37
- assert_nothing_raised{ @pe.pingecho }
38
- assert_nothing_raised{ @pe.pingecho(@host) }
39
- end
27
+ def test_ping_aliases
28
+ assert_respond_to(@pe, :ping?)
29
+ assert_respond_to(@pe, :pingecho)
30
+ assert_nothing_raised{ @pe.ping? }
31
+ assert_nothing_raised{ @pe.ping?(@host) }
32
+ assert_nothing_raised{ @pe.pingecho }
33
+ assert_nothing_raised{ @pe.pingecho(@host) }
34
+ end
40
35
 
41
- def test_good_ping
42
- assert_equal(true, @pe.ping?)
43
- end
36
+ def test_good_ping
37
+ assert_equal(true, @pe.ping?)
38
+ end
44
39
 
45
- def test_bad_ping
46
- assert_equal(false, @bad.ping?)
47
- assert_equal(false, @bad.exception.nil?, "Bad exception data")
48
- end
40
+ def test_bad_ping
41
+ assert_equal(false, @bad.ping?)
42
+ assert_equal(false, @bad.exception.nil?, "Bad exception data")
43
+ end
49
44
 
50
- def test_duration
51
- assert_nothing_raised{ @pe.ping }
52
- assert_respond_to(@pe, :duration)
53
- assert_kind_of(Float, @pe.duration)
54
- end
45
+ def test_duration
46
+ assert_nothing_raised{ @pe.ping }
47
+ assert_respond_to(@pe, :duration)
48
+ assert_kind_of(Float, @pe.duration)
49
+ end
55
50
 
56
- def test_host
57
- assert_respond_to(@pe, :host)
58
- assert_respond_to(@pe, :host=)
59
- assert_equal('www.ruby-lang.org', @pe.host)
60
- end
51
+ def test_host
52
+ assert_respond_to(@pe, :host)
53
+ assert_respond_to(@pe, :host=)
54
+ assert_equal('www.ruby-lang.org', @pe.host)
55
+ end
61
56
 
62
- def test_port
63
- assert_respond_to(@pe, :port)
64
- assert_respond_to(@pe, :port=)
65
- assert_equal(7, @pe.port)
66
- end
57
+ def test_port
58
+ assert_respond_to(@pe, :port)
59
+ assert_respond_to(@pe, :port=)
60
+ assert_equal(7, @pe.port)
61
+ end
67
62
 
68
- def test_timeout
69
- assert_respond_to(@pe, :timeout)
70
- assert_respond_to(@pe, :timeout=)
71
- assert_equal(5, @pe.timeout)
72
- end
63
+ def test_timeout
64
+ assert_respond_to(@pe, :timeout)
65
+ assert_respond_to(@pe, :timeout=)
66
+ assert_equal(5, @pe.timeout)
67
+ end
73
68
 
74
- def test_exception
75
- assert_respond_to(@pe, :exception)
76
- assert_nothing_raised{ @pe.ping }
77
- assert_nothing_raised{ @bad.ping }
78
- assert_nil(@pe.exception)
79
- assert_not_nil(@bad.exception)
80
- end
69
+ def test_exception
70
+ assert_respond_to(@pe, :exception)
71
+ assert_nothing_raised{ @pe.ping }
72
+ assert_nothing_raised{ @bad.ping }
73
+ assert_nil(@pe.exception)
74
+ assert_not_nil(@bad.exception)
75
+ end
81
76
 
82
- def test_warning
83
- assert_respond_to(@pe, :warning)
84
- end
77
+ def test_warning
78
+ assert_respond_to(@pe, :warning)
79
+ end
85
80
 
86
- def teardown
87
- @host = nil
88
- @bogus = nil
89
- @pe = nil
90
- @bad = nil
91
- end
81
+ def teardown
82
+ @host = nil
83
+ @bogus = nil
84
+ @pe = nil
85
+ @bad = nil
86
+ end
92
87
  end
@@ -9,78 +9,107 @@ gem 'test-unit'
9
9
 
10
10
  require 'test/unit'
11
11
  require 'net/ping/http'
12
- include Net
13
-
14
- class TC_PingHTTP < Test::Unit::TestCase
15
- def setup
16
- @uri = 'http://www.google.com/index.html'
17
- @http = Ping::HTTP.new(@uri, 80, 30)
18
- @bad = Ping::HTTP.new('http://www.blabfoobarurgh.com') # One hopes not
19
- end
20
-
21
- def test_version
22
- assert_equal('1.3.2', Ping::HTTP::VERSION)
23
- end
24
-
25
- def test_ping
26
- assert_respond_to(@http, :ping)
27
- assert_nothing_raised{ @http.ping }
28
- end
29
-
30
- def test_ping_aliases
31
- assert_respond_to(@http, :ping?)
32
- assert_respond_to(@http, :pingecho)
33
- assert_nothing_raised{ @http.ping? }
34
- assert_nothing_raised{ @http.pingecho }
35
- end
36
-
37
- def test_ping_success
38
- assert_equal(true, @http.ping?)
39
- assert_equal(false, @bad.ping?)
40
- assert_not_nil(@bad.exception)
41
- end
42
-
43
- def test_duration
44
- assert_nothing_raised{ @http.ping }
45
- assert_respond_to(@http, :duration)
46
- assert_kind_of(Float, @http.duration)
47
- end
48
-
49
- def test_host
50
- assert_respond_to(@http, :host)
51
- assert_respond_to(@http, :host=)
52
- assert_respond_to(@http, :uri) # Alias
53
- assert_respond_to(@http, :uri=) # Alias
54
- assert_equal('http://www.google.com/index.html', @http.host)
55
- end
56
-
57
- def test_port
58
- assert_respond_to(@http, :port)
59
- assert_respond_to(@http, :port=)
60
- assert_equal(80, @http.port)
61
- end
62
-
63
- def test_timeout
64
- assert_respond_to(@http, :timeout)
65
- assert_respond_to(@http, :timeout=)
66
- assert_equal(30, @http.timeout)
67
- assert_equal(5, @bad.timeout)
68
- end
69
-
70
- def test_exception
71
- assert_respond_to(@http, :exception)
72
- assert_nothing_raised{ @http.ping }
73
- assert_nothing_raised{ @bad.ping }
74
- assert_nil(@http.exception)
75
- assert_not_nil(@bad.exception)
76
- end
77
-
78
- def test_warning
79
- assert_respond_to(@http, :warning)
80
- end
81
-
82
- def teardown
83
- @uri = nil
84
- @http = nil
85
- end
12
+
13
+ class TC_Net_Ping_HTTP < Test::Unit::TestCase
14
+ def setup
15
+ @uri = 'http://www.google.com/index.html'
16
+ @http = Net::Ping::HTTP.new(@uri, 80, 30)
17
+ @bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
18
+ end
19
+
20
+ test 'ping basic functionality' do
21
+ assert_respond_to(@http, :ping)
22
+ assert_nothing_raised{ @http.ping }
23
+ end
24
+
25
+ test 'ping returns a boolean value' do
26
+ assert_boolean(@http.ping?)
27
+ assert_boolean(@bad.ping?)
28
+ end
29
+
30
+ test 'ping? is an alias for ping' do
31
+ assert_alias_method(@http, :ping?, :ping)
32
+ end
33
+
34
+ test 'pingecho is an alias for ping' do
35
+ assert_alias_method(@http, :pingecho, :ping)
36
+ end
37
+
38
+ test 'ping should succeed for a valid website' do
39
+ assert_true(@http.ping?)
40
+ end
41
+
42
+ test 'ping should fail for an invalid website' do
43
+ assert_false(@bad.ping?)
44
+ end
45
+
46
+ test 'duration basic functionality' do
47
+ assert_respond_to(@http, :duration)
48
+ assert_nothing_raised{ @http.ping }
49
+ end
50
+
51
+ test 'duration returns a float value on a successful ping' do
52
+ assert_true(@http.ping)
53
+ assert_kind_of(Float, @http.duration)
54
+ end
55
+
56
+ test 'duration is nil on an unsuccessful ping' do
57
+ assert_false(@bad.ping)
58
+ assert_nil(@http.duration)
59
+ end
60
+
61
+ test 'host attribute basic functionality' do
62
+ assert_respond_to(@http, :host)
63
+ assert_respond_to(@http, :host=)
64
+ assert_equal('http://www.google.com/index.html', @http.host)
65
+ end
66
+
67
+ test 'uri is an alias for host' do
68
+ assert_alias_method(@http, :uri, :host)
69
+ assert_alias_method(@http, :uri=, :host=)
70
+ end
71
+
72
+ test 'port attribute basic functionality' do
73
+ assert_respond_to(@http, :port)
74
+ assert_respond_to(@http, :port=)
75
+ end
76
+
77
+ test 'port attribute expected value' do
78
+ assert_equal(80, @http.port)
79
+ end
80
+
81
+ test 'timeout attribute basic functionality' do
82
+ assert_respond_to(@http, :timeout)
83
+ assert_respond_to(@http, :timeout=)
84
+ end
85
+
86
+ test 'timeout attribute expected values' do
87
+ assert_equal(30, @http.timeout)
88
+ assert_equal(5, @bad.timeout)
89
+ end
90
+
91
+ test 'exception attribute basic functionality' do
92
+ assert_respond_to(@http, :exception)
93
+ assert_nil(@http.exception)
94
+ end
95
+
96
+ test 'exception attribute is nil if the ping is successful' do
97
+ assert_true(@http.ping)
98
+ assert_nil(@http.exception)
99
+ end
100
+
101
+ test 'exception attribute is not nil if the ping is unsuccessful' do
102
+ assert_false(@bad.ping)
103
+ assert_not_nil(@bad.exception)
104
+ end
105
+
106
+ test 'warning attribute basic functionality' do
107
+ assert_respond_to(@http, :warning)
108
+ assert_nil(@http.warning)
109
+ end
110
+
111
+ def teardown
112
+ @uri = nil
113
+ @http = nil
114
+ end
86
115
  end
@@ -26,10 +26,6 @@ class TC_PingICMP < Test::Unit::TestCase
26
26
  @icmp = Ping::ICMP.new(@host)
27
27
  end
28
28
 
29
- def test_version
30
- assert_equal('1.3.2', Ping::ICMP::VERSION)
31
- end
32
-
33
29
  def test_ping
34
30
  assert_respond_to(@icmp, :ping)
35
31
 
@@ -12,101 +12,97 @@ require 'net/ping/tcp'
12
12
  include Net
13
13
 
14
14
  class TC_PingTCP < Test::Unit::TestCase
15
- def setup
16
- @host = 'www.ruby-lang.org'
17
- @port = 'ftp'
18
- @tcp = Ping::TCP.new(@host, @port)
19
- end
15
+ def setup
16
+ @host = 'www.ruby-lang.org'
17
+ @port = 'ftp'
18
+ @tcp = Ping::TCP.new(@host, @port)
19
+ end
20
20
 
21
- def test_version
22
- assert_equal('1.3.2', Ping::TCP::VERSION)
23
- end
24
-
25
- def test_ping
26
- assert_respond_to(@tcp, :ping)
27
- assert_nothing_raised{ @tcp.ping }
28
- assert_nothing_raised{ @tcp.ping(@host) }
29
- end
21
+ def test_ping
22
+ assert_respond_to(@tcp, :ping)
23
+ assert_nothing_raised{ @tcp.ping }
24
+ assert_nothing_raised{ @tcp.ping(@host) }
25
+ end
30
26
 
31
- def test_ping_aliases
32
- assert_respond_to(@tcp, :ping?)
33
- assert_respond_to(@tcp, :pingecho)
34
- assert_nothing_raised{ @tcp.ping? }
35
- assert_nothing_raised{ @tcp.ping?(@host) }
36
- assert_nothing_raised{ @tcp.pingecho }
37
- assert_nothing_raised{ @tcp.pingecho(@host) }
38
- end
27
+ def test_ping_aliases
28
+ assert_respond_to(@tcp, :ping?)
29
+ assert_respond_to(@tcp, :pingecho)
30
+ assert_nothing_raised{ @tcp.ping? }
31
+ assert_nothing_raised{ @tcp.ping?(@host) }
32
+ assert_nothing_raised{ @tcp.pingecho }
33
+ assert_nothing_raised{ @tcp.pingecho(@host) }
34
+ end
39
35
 
40
- def test_ping_service_check_false
41
- msg = "+this test may fail depending on your network environment+"
42
- Ping::TCP.service_check = false
43
- @tcp = Ping::TCP.new('localhost')
44
- assert_equal(false, @tcp.ping?, msg)
45
- assert_equal(false, @tcp.exception.nil?, "Bad exception data")
46
- end
36
+ def test_ping_service_check_false
37
+ msg = "+this test may fail depending on your network environment+"
38
+ Ping::TCP.service_check = false
39
+ @tcp = Ping::TCP.new('localhost')
40
+ assert_false(@tcp.ping?, msg)
41
+ assert_false(@tcp.exception.nil?, "Bad exception data")
42
+ end
47
43
 
48
- def test_ping_service_check_true
49
- msg = "+this test may fail depending on your network environment+"
50
- Ping::TCP.service_check = true
51
- assert_equal(true, @tcp.ping?, msg)
52
- end
44
+ def test_ping_service_check_true
45
+ msg = "+this test may fail depending on your network environment+"
46
+ Ping::TCP.service_check = true
47
+ assert_true(@tcp.ping?, msg)
48
+ end
53
49
 
54
- def test_service_check
55
- assert_respond_to(Ping::TCP, :service_check)
56
- assert_respond_to(Ping::TCP, :service_check=)
57
- end
50
+ def test_service_check
51
+ assert_respond_to(Ping::TCP, :service_check)
52
+ assert_respond_to(Ping::TCP, :service_check=)
53
+ end
58
54
 
59
- # These will be removed eventually
60
- def test_service_check_aliases
61
- assert_respond_to(Ping::TCP, :econnrefused)
62
- assert_respond_to(Ping::TCP, :econnrefused=)
63
- assert_respond_to(Ping::TCP, :ecr)
64
- assert_respond_to(Ping::TCP, :ecr=)
65
- end
55
+ # These will be removed eventually
56
+ def test_service_check_aliases
57
+ assert_respond_to(Ping::TCP, :econnrefused)
58
+ assert_respond_to(Ping::TCP, :econnrefused=)
59
+ assert_respond_to(Ping::TCP, :ecr)
60
+ assert_respond_to(Ping::TCP, :ecr=)
61
+ end
66
62
 
67
- def test_service_check_expected_errors
68
- assert_raises(ArgumentError){ Ping::TCP.service_check = "blah" }
69
- end
63
+ def test_service_check_expected_errors
64
+ assert_raises(ArgumentError){ Ping::TCP.service_check = "blah" }
65
+ end
70
66
 
71
- # If the ping failed, the duration will be nil
72
- def test_duration
73
- assert_nothing_raised{ @tcp.ping }
74
- assert_respond_to(@tcp, :duration)
75
- omit_if(@tcp.duration.nil?, 'ping failed, skipping')
76
- assert_kind_of(Float, @tcp.duration)
77
- end
67
+ # If the ping failed, the duration will be nil
68
+ def test_duration
69
+ assert_nothing_raised{ @tcp.ping }
70
+ assert_respond_to(@tcp, :duration)
71
+ omit_if(@tcp.duration.nil?, 'ping failed, skipping')
72
+ assert_kind_of(Float, @tcp.duration)
73
+ end
78
74
 
79
- def test_host
80
- assert_respond_to(@tcp, :host)
81
- assert_respond_to(@tcp, :host=)
82
- assert_equal(@host, @tcp.host)
83
- end
75
+ def test_host
76
+ assert_respond_to(@tcp, :host)
77
+ assert_respond_to(@tcp, :host=)
78
+ assert_equal(@host, @tcp.host)
79
+ end
84
80
 
85
- def test_port
86
- assert_respond_to(@tcp, :port)
87
- assert_respond_to(@tcp, :port=)
88
- assert_equal('ftp', @tcp.port)
89
- end
81
+ def test_port
82
+ assert_respond_to(@tcp, :port)
83
+ assert_respond_to(@tcp, :port=)
84
+ assert_equal('ftp', @tcp.port)
85
+ end
90
86
 
91
- def test_timeout
92
- assert_respond_to(@tcp, :timeout)
93
- assert_respond_to(@tcp, :timeout=)
94
- assert_equal(5, @tcp.timeout)
95
- end
87
+ def test_timeout
88
+ assert_respond_to(@tcp, :timeout)
89
+ assert_respond_to(@tcp, :timeout=)
90
+ assert_equal(5, @tcp.timeout)
91
+ end
96
92
 
97
- def test_exception
98
- msg = "+this test may fail depending on your network environment+"
99
- assert_respond_to(@tcp, :exception)
100
- assert_nothing_raised{ @tcp.ping }
101
- assert_nil(@tcp.exception, msg)
102
- end
93
+ def test_exception
94
+ msg = "+this test may fail depending on your network environment+"
95
+ assert_respond_to(@tcp, :exception)
96
+ assert_nothing_raised{ @tcp.ping }
97
+ assert_nil(@tcp.exception, msg)
98
+ end
103
99
 
104
- def test_warning
105
- assert_respond_to(@tcp, :warning)
106
- end
100
+ def test_warning
101
+ assert_respond_to(@tcp, :warning)
102
+ end
107
103
 
108
- def teardown
109
- @host = nil
110
- @tcp = nil
111
- end
104
+ def teardown
105
+ @host = nil
106
+ @tcp = nil
107
+ end
112
108
  end