net-ping 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,12 @@
1
+ == 1.2.1 - 6-Apr-2007
2
+ * For the Ping::External class, if a ping attempt results in 100% packet loss
3
+ it is now considered a failed ping, regardless of whether or not an error
4
+ was sent to stdout.
5
+ * Fixed the Ping::External class for OS X.
6
+ * Added a Rakefile. Installation and testing should now be run via Rake tasks.
7
+ * Minor fix for the Ping::ICMP class where I had accidentally dup'd some
8
+ aliases. This was harmless, but did cause warnings with -w.
9
+
1
10
  == 1.2.0 - 5-Dec-2006
2
11
  * Internal reorganization - each class now lives in its own file.
3
12
  * Added the Ping::ICMP class. Thanks go to Jos Backus for contributing a
data/MANIFEST CHANGED
@@ -1,25 +1,23 @@
1
- MANIFEST
2
- CHANGES
3
- README
4
- test.rb
5
- install.rb
6
- net-ping.gemspec
7
-
8
- examples/test_pingexternal.rb
9
- examples/test_pinghttp.rb
10
- examples/test_pingtcp.rb
11
- examples/test_pingudp.rb
12
-
13
- lib/net/ping.rb
14
- lib/net/ping/icmp.rb
15
- lib/net/ping/tcp.rb
16
- lib/net/ping/udp.rb
17
- lib/net/ping/http.rb
18
- lib/net/ping/external.rb
19
-
20
- test/tc_pingexternal.rb
21
- test/tc_pinghttp.rb
22
- test/tc_pingicmp.rb
23
- test/tc_pingtcp.rb
24
- test/tc_pingudp.rb
25
- test/ts_ping.rb
1
+ * MANIFEST
2
+ * CHANGES
3
+ * Rakefile
4
+ * README
5
+ * test.rb
6
+ * install.rb
7
+ * net-ping.gemspec
8
+ * examples/test_pingexternal.rb
9
+ * examples/test_pinghttp.rb
10
+ * examples/test_pingtcp.rb
11
+ * examples/test_pingudp.rb
12
+ * lib/net/ping.rb
13
+ * lib/net/ping/icmp.rb
14
+ * lib/net/ping/tcp.rb
15
+ * lib/net/ping/udp.rb
16
+ * lib/net/ping/http.rb
17
+ * lib/net/ping/external.rb
18
+ * test/tc_pingexternal.rb
19
+ * test/tc_pinghttp.rb
20
+ * test/tc_pingicmp.rb
21
+ * test/tc_pingtcp.rb
22
+ * test/tc_pingudp.rb
23
+ * test/ts_ping.rb
data/README CHANGED
@@ -7,12 +7,8 @@
7
7
  Net::Ping::External class.
8
8
 
9
9
  == Installation
10
- === Manual Installation
11
- ruby test.rb (optional)
12
- ruby install.rb
13
- === Gem Installation
14
- ruby net-ping.gemspec
15
- gem install net-ping-<version>.gem
10
+ rake test (optional)
11
+ rake install (standard) OR rake gem_install (gems)
16
12
 
17
13
  == Notes
18
14
  Please read the documentation. Especially pay attention to the docs
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc "Install the net-ping package without gems"
5
+ task :install do
6
+ ruby 'install.rb'
7
+ end
8
+
9
+ desc "Create and install a net-ping gem"
10
+ task :gem_install do
11
+ ruby 'net-ping.gemspec'
12
+ gem_file = Dir["*.gem"].first
13
+ sh "gem install #{gem_file}"
14
+ end
15
+
16
+ Rake::TestTask.new("test") do |t|
17
+ t.warning = true
18
+ t.test_files = FileList['test/ts_ping.rb']
19
+ end
20
+
21
+ Rake::TestTask.new("test_external") do |t|
22
+ t.warning = true
23
+ t.test_files = FileList['test/tc_pingexternal.rb']
24
+ end
25
+
26
+ Rake::TestTask.new("test_http") do |t|
27
+ t.warning = true
28
+ t.test_files = FileList['test/tc_pinghttp.rb']
29
+ end
30
+
31
+ Rake::TestTask.new("test_icmp") do |t|
32
+ t.warning = true
33
+ t.test_files = FileList['test/tc_pingicmp.rb']
34
+ end
35
+
36
+ Rake::TestTask.new("test_tcp") do |t|
37
+ t.warning = true
38
+ t.test_files = FileList['test/tc_pingtcp.rb']
39
+ end
40
+
41
+ Rake::TestTask.new("test_udp") do |t|
42
+ t.warning = true
43
+ t.test_files = FileList['test/tc_pingudp.rb']
44
+ end
@@ -18,7 +18,7 @@ module Net
18
18
  bool = false
19
19
 
20
20
  case RUBY_PLATFORM
21
- when /linux|bsd/i
21
+ when /linux|bsd|osx|mach|darwin/i
22
22
  pstring += "-c 1 #{host}"
23
23
  when /solaris|sunos/i
24
24
  pstring += "#{host} 1"
@@ -65,7 +65,8 @@ module Net
65
65
  no\ answer|
66
66
  host\ unreachable|
67
67
  could\ not\ find\ host|
68
- request\ timed\ out
68
+ request\ timed\ out|
69
+ 100%\ packet\ loss
69
70
  /ix
70
71
  lines.each{ |e|
71
72
  if regexp.match(e)
data/lib/net/ping/icmp.rb CHANGED
@@ -158,9 +158,6 @@ module Net
158
158
  check = (check >> 16) + (check & 0xffff)
159
159
  return (~((check >> 16) + check) & 0xffff)
160
160
  end
161
-
162
- alias ping? ping
163
- alias pingecho ping
164
161
  end
165
162
 
166
163
  # Alias for consistency with other ping related classes
data/lib/net/ping/ping.rb CHANGED
@@ -3,7 +3,7 @@ require 'timeout'
3
3
 
4
4
  module Net
5
5
  class Ping
6
- VERSION = '1.2.0'
6
+ VERSION = '1.2.1'
7
7
 
8
8
  # The host to ping. In the case of Ping::HTTP, this is the URI.
9
9
  attr_accessor :host
@@ -1,15 +1,9 @@
1
- ############################################
1
+ #########################################################################
2
2
  # tc_pingexternal.rb
3
3
  #
4
- # Test case for the Net::PingExternal class
5
- ############################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" || base =~ /net-pingsimple.*/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
- end
12
-
4
+ # Test case for the Net::PingExternal class. Run this via the 'test' or
5
+ # 'test_external' rake task.
6
+ #########################################################################
13
7
  require "test/unit"
14
8
  require "net/ping/external"
15
9
  include Net
@@ -23,16 +17,24 @@ class TC_PingExternal < Test::Unit::TestCase
23
17
  end
24
18
 
25
19
  def test_version
26
- assert_equal("1.2.0", PingExternal::VERSION)
20
+ assert_equal("1.2.1", PingExternal::VERSION)
27
21
  end
28
22
 
29
23
  def test_ping
30
24
  assert_respond_to(@pe, :ping)
31
- assert_respond_to(@pe, :ping?)
32
25
  assert_nothing_raised{ @pe.ping }
33
26
  assert_nothing_raised{ @pe.ping(@host) }
34
27
  end
35
28
 
29
+ def test_ping_aliases
30
+ assert_respond_to(@pe, :ping?)
31
+ assert_respond_to(@pe, :pingecho)
32
+ assert_nothing_raised{ @pe.ping? }
33
+ assert_nothing_raised{ @pe.ping?(@host) }
34
+ assert_nothing_raised{ @pe.pingecho }
35
+ assert_nothing_raised{ @pe.pingecho(@host) }
36
+ end
37
+
36
38
  def test_good_ping
37
39
  assert_equal(true, @pe.ping?)
38
40
  end
data/test/tc_pinghttp.rb CHANGED
@@ -1,15 +1,9 @@
1
- #########################################
1
+ #################################################################################
2
2
  # tc_pinghttp.rb
3
3
  #
4
- # Test case for the Net::PingHTTP class.
5
- #########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" || base =~ /net-pingsimple.*/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
- end
12
-
4
+ # Test case for the Net::PingHTTP class. This should be run via the 'test' or
5
+ # 'test_http' test task.
6
+ #################################################################################
13
7
  require "test/unit"
14
8
  require "net/ping/http"
15
9
  include Net
@@ -17,19 +11,24 @@ include Net
17
11
  class TC_PingHTTP < Test::Unit::TestCase
18
12
  def setup
19
13
  @uri = "http://www.pragmaticprogrammer.com/index.html"
20
- @http = Ping::HTTP.new(@uri)
14
+ @http = Ping::HTTP.new(@uri, 80, 30)
21
15
  @bad = Ping::HTTP.new("http://www.blabfoobarurgh.com") # One hopes not
22
16
  end
23
17
 
24
18
  def test_version
25
- assert_equal("1.2.0", PingHTTP::VERSION)
19
+ assert_equal("1.2.1", Ping::HTTP::VERSION)
26
20
  end
27
21
 
28
22
  def test_ping
29
23
  assert_respond_to(@http, :ping)
30
- assert_respond_to(@http, :ping?)
31
24
  assert_nothing_raised{ @http.ping }
32
- assert_raises(ArgumentError){ @http.ping(@host) }
25
+ end
26
+
27
+ def test_ping_aliases
28
+ assert_respond_to(@http, :ping?)
29
+ assert_respond_to(@http, :pingecho)
30
+ assert_nothing_raised{ @http.ping? }
31
+ assert_nothing_raised{ @http.pingecho }
33
32
  end
34
33
 
35
34
  def test_ping_success
@@ -61,7 +60,8 @@ class TC_PingHTTP < Test::Unit::TestCase
61
60
  def test_timeout
62
61
  assert_respond_to(@http, :timeout)
63
62
  assert_respond_to(@http, :timeout=)
64
- assert_equal(5, @http.timeout)
63
+ assert_equal(30, @http.timeout)
64
+ assert_equal(5, @bad.timeout)
65
65
  end
66
66
 
67
67
  def test_exception
data/test/tc_pingicmp.rb CHANGED
@@ -2,19 +2,17 @@
2
2
  # tc_pingicmp.rb
3
3
  #
4
4
  # Test case for the Net::PingICMP class. You must run this test case
5
- # with root privileges on UNIX systems.
5
+ # with root privileges on UNIX systems. This should be run via the
6
+ # 'test' or 'test_icmp' Rake task.
6
7
  #######################################################################
7
- base = File.basename(Dir.pwd)
8
-
9
- if base == "test" || base =~ /net-pingsimple.*/
10
- Dir.chdir("..") if base == "test"
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- end
13
-
14
8
  require "test/unit"
15
9
  require "net/ping/icmp"
16
10
  include Net
17
11
 
12
+ unless Process.euid == 0
13
+ raise "The test_icmp task must be run with root privileges"
14
+ end
15
+
18
16
  class TC_PingICMP < Test::Unit::TestCase
19
17
  def setup
20
18
  @host = "www.ruby-lang.org"
@@ -22,16 +20,24 @@ class TC_PingICMP < Test::Unit::TestCase
22
20
  end
23
21
 
24
22
  def test_version
25
- assert_equal("1.2.0", PingICMP::VERSION)
23
+ assert_equal("1.2.1", PingICMP::VERSION)
26
24
  end
27
25
 
28
26
  def test_ping
29
27
  assert_respond_to(@icmp, :ping)
30
- assert_respond_to(@icmp, :ping?)
31
28
  assert_nothing_raised{ @icmp.ping }
32
29
  assert_nothing_raised{ @icmp.ping(@host) }
33
30
  end
34
31
 
32
+ def test_ping_aliases
33
+ assert_respond_to(@icmp, :ping?)
34
+ assert_respond_to(@icmp, :pingecho)
35
+ assert_nothing_raised{ @icmp.ping? }
36
+ assert_nothing_raised{ @icmp.ping?(@host) }
37
+ assert_nothing_raised{ @icmp.pingecho }
38
+ assert_nothing_raised{ @icmp.pingecho(@host) }
39
+ end
40
+
35
41
  def test_bind
36
42
  assert_respond_to(@icmp, :bind)
37
43
  assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
@@ -44,12 +50,6 @@ class TC_PingICMP < Test::Unit::TestCase
44
50
  assert_kind_of(Float, @icmp.duration)
45
51
  end
46
52
 
47
- def test_duration
48
- assert_nothing_raised{ @icmp.ping }
49
- assert_respond_to(@icmp, :duration)
50
- assert_kind_of(Float, @icmp.duration)
51
- end
52
-
53
53
  def test_host
54
54
  assert_respond_to(@icmp, :host)
55
55
  assert_respond_to(@icmp, :host=)
data/test/tc_pingtcp.rb CHANGED
@@ -1,36 +1,38 @@
1
- #######################################
1
+ #####################################################################
2
2
  # tc_pingtcp.rb
3
3
  #
4
- # Test case for the Net::PingTCP class
5
- #######################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" || base =~ /net-pingsimple.*/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
- end
12
-
4
+ # Test case for the Net::PingTCP class. This test should be run via
5
+ # the 'test' or 'test_tcp' Rake task.
6
+ #####################################################################
13
7
  require "test/unit"
14
8
  require "net/ping/tcp"
15
9
  include Net
16
10
 
17
11
  class TC_PingTCP < Test::Unit::TestCase
18
12
  def setup
19
- @host = "www.ruby-lang.org"
20
- @tcp = Ping::TCP.new(@host)
13
+ @host = "www.ruby-lang.org"
14
+ @tcp = Ping::TCP.new(@host)
21
15
  end
22
16
 
23
17
  def test_version
24
- assert_equal("1.2.0", PingTCP::VERSION, "Bad version constant")
18
+ assert_equal("1.2.1", PingTCP::VERSION)
25
19
  end
26
20
 
27
21
  def test_ping
28
22
  assert_respond_to(@tcp, :ping)
29
- assert_respond_to(@tcp, :ping?)
30
23
  assert_nothing_raised{ @tcp.ping }
31
24
  assert_nothing_raised{ @tcp.ping(@host) }
32
25
  end
33
26
 
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
35
+
34
36
  def test_ping_ecr_false
35
37
  msg = "+this test may fail depending on your network environment+"
36
38
  PingTCP.ecr = false
@@ -55,7 +57,7 @@ class TC_PingTCP < Test::Unit::TestCase
55
57
  def test_duration
56
58
  assert_nothing_raised{ @tcp.ping }
57
59
  assert_respond_to(@tcp, :duration)
58
- assert_kind_of(Float, @tcp.duration)
60
+ assert_kind_of(Float, @tcp.duration, '+nil if the ping failed+')
59
61
  end
60
62
 
61
63
  def test_host
data/test/tc_pingudp.rb CHANGED
@@ -1,18 +1,12 @@
1
1
  ################################################################
2
2
  # tc_pingudp.rb
3
3
  #
4
- # Test case for the Net::PingUDP class
4
+ # Test case for the Net::Ping::UDP class. This should be run
5
+ # via the 'test' or 'test_udp' Rake task.
5
6
  #
6
7
  # If someone could provide me a host where a udp ping actually
7
8
  # works, I would appreciate it. :)
8
9
  ################################################################
9
- base = File.basename(Dir.pwd)
10
-
11
- if base == "test" || base =~ /net-pingsimple.*/
12
- Dir.chdir("..") if base == "test"
13
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
14
- end
15
-
16
10
  require "test/unit"
17
11
  require "net/ping/udp"
18
12
  include Net
@@ -24,16 +18,24 @@ class TC_PingUDP < Test::Unit::TestCase
24
18
  end
25
19
 
26
20
  def test_version
27
- assert_equal("1.2.0", PingUDP::VERSION)
21
+ assert_equal("1.2.1", Ping::UDP::VERSION)
28
22
  end
29
23
 
30
24
  def test_ping
31
25
  assert_respond_to(@udp, :ping)
32
- assert_respond_to(@udp, :ping?)
33
26
  assert_nothing_raised{ @udp.ping }
34
27
  assert_nothing_raised{ @udp.ping(@host) }
35
28
  end
36
29
 
30
+ def test_ping_aliases
31
+ assert_respond_to(@udp, :ping?)
32
+ assert_respond_to(@udp, :pingecho)
33
+ assert_nothing_raised{ @udp.ping? }
34
+ assert_nothing_raised{ @udp.ping?(@host) }
35
+ assert_nothing_raised{ @udp.pingecho }
36
+ assert_nothing_raised{ @udp.pingecho(@host) }
37
+ end
38
+
37
39
  def test_ping_standard
38
40
  assert_equal(false, @udp.ping?)
39
41
  assert_equal(false, @udp.exception.nil?, "Bad exception data")
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: net-ping
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.0
7
- date: 2006-12-08 00:00:00 -07:00
6
+ version: 1.2.1
7
+ date: 2007-04-06 00:00:00 -06:00
8
8
  summary: A ping interface for Ruby.
9
9
  require_paths:
10
10
  - lib
@@ -34,6 +34,7 @@ files:
34
34
  - CHANGES
35
35
  - MANIFEST
36
36
  - README
37
+ - Rakefile
37
38
  - test/tc_pingexternal.rb
38
39
  - test/tc_pinghttp.rb
39
40
  - test/tc_pingicmp.rb