summaryrefslogtreecommitdiff
path: root/spec/ruby/library/ipaddr
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/ipaddr')
-rw-r--r--spec/ruby/library/ipaddr/hton_spec.rb2
-rw-r--r--spec/ruby/library/ipaddr/ipv4_conversion_spec.rb12
-rw-r--r--spec/ruby/library/ipaddr/new_spec.rb21
-rw-r--r--spec/ruby/library/ipaddr/operator_spec.rb33
-rw-r--r--spec/ruby/library/ipaddr/reverse_spec.rb10
-rw-r--r--spec/ruby/library/ipaddr/to_s_spec.rb2
6 files changed, 36 insertions, 44 deletions
diff --git a/spec/ruby/library/ipaddr/hton_spec.rb b/spec/ruby/library/ipaddr/hton_spec.rb
index 037bb3d328..9c0b821abf 100644
--- a/spec/ruby/library/ipaddr/hton_spec.rb
+++ b/spec/ruby/library/ipaddr/hton_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#hton" do
diff --git a/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb b/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb
index b69be82c13..1128c16dd2 100644
--- a/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb
+++ b/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#ipv4_compat" do
@@ -8,11 +8,11 @@ describe "IPAddr#ipv4_compat" do
a.to_s.should == "::192.168.1.2"
a.to_string.should == "0000:0000:0000:0000:0000:0000:c0a8:0102"
a.family.should == Socket::AF_INET6
- a.ipv4_compat?.should == true
+ a.should.ipv4_compat?
b = a.native
b.to_s.should == "192.168.1.2"
b.family.should == Socket::AF_INET
- b.ipv4_compat?.should == false
+ b.should_not.ipv4_compat?
a = IPAddr.new("192.168.1.2")
b = a.ipv4_compat
@@ -29,11 +29,11 @@ describe "IPAddr#ipv4_mapped" do
a.to_s.should == "::ffff:192.168.1.2"
a.to_string.should == "0000:0000:0000:0000:0000:ffff:c0a8:0102"
a.family.should == Socket::AF_INET6
- a.ipv4_mapped?.should == true
+ a.should.ipv4_mapped?
b = a.native
b.to_s.should == "192.168.1.2"
b.family.should == Socket::AF_INET
- b.ipv4_mapped?.should == false
+ b.should_not.ipv4_mapped?
a = IPAddr.new("192.168.1.2")
b = a.ipv4_mapped
@@ -42,5 +42,3 @@ describe "IPAddr#ipv4_mapped" do
end
end
-
-
diff --git a/spec/ruby/library/ipaddr/new_spec.rb b/spec/ruby/library/ipaddr/new_spec.rb
index d0b91af87d..7fba2b372e 100644
--- a/spec/ruby/library/ipaddr/new_spec.rb
+++ b/spec/ruby/library/ipaddr/new_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#new" do
it "initializes IPAddr" do
- lambda{ IPAddr.new("3FFE:505:ffff::/48") }.should_not raise_error
- lambda{ IPAddr.new("0:0:0:1::") }.should_not raise_error
- lambda{ IPAddr.new("2001:200:300::/48") }.should_not raise_error
+ ->{ IPAddr.new("3FFE:505:ffff::/48") }.should_not.raise
+ ->{ IPAddr.new("0:0:0:1::") }.should_not.raise
+ ->{ IPAddr.new("2001:200:300::/48") }.should_not.raise
end
it "initializes IPAddr ipv6 address with short notation" do
@@ -27,8 +27,8 @@ describe "IPAddr#new" do
a.to_s.should == "3ffe:505:2::"
a.to_string.should == "3ffe:0505:0002:0000:0000:0000:0000:0000"
a.family.should == Socket::AF_INET6
- a.ipv4?.should == false
- a.ipv6?.should == true
+ a.should_not.ipv4?
+ a.should.ipv6?
a.inspect.should == "#<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>"
end
@@ -51,8 +51,8 @@ describe "IPAddr#new" do
a.to_s.should == "192.168.1.2"
a.to_string.should == "192.168.1.2"
a.family.should == Socket::AF_INET
- a.ipv4?.should == true
- a.ipv6?.should == false
+ a.should.ipv4?
+ a.should_not.ipv6?
end
it "initializes IPAddr ipv4 address with / subnet notation" do
@@ -79,15 +79,14 @@ describe "IPAddr#new" do
it "raises on incorrect IPAddr strings" do
[
- ["fe80::1%fxp0"],
["::1/255.255.255.0"],
[IPAddr.new("::1").to_i],
["::ffff:192.168.1.2/120", Socket::AF_INET],
["[192.168.1.2]/120"],
].each { |args|
- lambda{
+ ->{
IPAddr.new(*args)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
}
end
end
diff --git a/spec/ruby/library/ipaddr/operator_spec.rb b/spec/ruby/library/ipaddr/operator_spec.rb
index 6d884780e3..3337d22300 100644
--- a/spec/ruby/library/ipaddr/operator_spec.rb
+++ b/spec/ruby/library/ipaddr/operator_spec.rb
@@ -1,15 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr Operator" do
- IN6MASK32 = "ffff:ffff::"
- IN6MASK128 = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
-
before do
@in6_addr_any = IPAddr.new()
@a = IPAddr.new("3ffe:505:2::/48")
@b = IPAddr.new("0:0:0:1::")
- @c = IPAddr.new(IN6MASK32)
+ @c = IPAddr.new("ffff:ffff::")
end
it "bitwises or" do
@@ -48,7 +45,7 @@ describe "IPAddr Operator" do
it "inverts" do
a = ~@in6_addr_any
- a.to_s.should == IN6MASK128
+ a.to_s.should == "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
@in6_addr_any.to_s.should == "::"
end
@@ -57,11 +54,9 @@ describe "IPAddr Operator" do
@a.should_not == IPAddr.new("3ffe:505:3::")
end
- ruby_version_is '2.4' do
- # https://bugs.ruby-lang.org/issues/12799
- it "tests for equality correctly if object cannot be converted to IPAddr" do
- IPAddr.new("1.1.1.1").should_not == "sometext"
- end
+ # https://bugs.ruby-lang.org/issues/12799
+ it "tests for equality correctly if object cannot be converted to IPAddr" do
+ IPAddr.new("1.1.1.1").should_not == "sometext"
end
it "sets a mask" do
@@ -71,17 +66,17 @@ describe "IPAddr Operator" do
end
it "checks whether an address is included in a range" do
- @a.should include(IPAddr.new("3ffe:505:2::"))
- @a.should include(IPAddr.new("3ffe:505:2::1"))
- @a.should_not include(IPAddr.new("3ffe:505:3::"))
+ @a.should.include?(IPAddr.new("3ffe:505:2::"))
+ @a.should.include?(IPAddr.new("3ffe:505:2::1"))
+ @a.should_not.include?(IPAddr.new("3ffe:505:3::"))
net1 = IPAddr.new("192.168.2.0/24")
- net1.should include(IPAddr.new("192.168.2.0"))
- net1.should include(IPAddr.new("192.168.2.255"))
- net1.should_not include(IPAddr.new("192.168.3.0"))
+ net1.should.include?(IPAddr.new("192.168.2.0"))
+ net1.should.include?(IPAddr.new("192.168.2.255"))
+ net1.should_not.include?(IPAddr.new("192.168.3.0"))
# test with integer parameter
int = (192 << 24) + (168 << 16) + (2 << 8) + 13
- net1.should include(int)
- net1.should_not include(int+255)
+ net1.should.include?(int)
+ net1.should_not.include?(int+255)
end
end
diff --git a/spec/ruby/library/ipaddr/reverse_spec.rb b/spec/ruby/library/ipaddr/reverse_spec.rb
index dec5c65178..9bda60ca70 100644
--- a/spec/ruby/library/ipaddr/reverse_spec.rb
+++ b/spec/ruby/library/ipaddr/reverse_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#reverse" do
@@ -11,17 +11,17 @@ end
describe "IPAddr#ip6_arpa" do
it "converts an IPv6 address into the reverse DNS lookup representation according to RFC3172" do
IPAddr.new("3ffe:505:2::f").ip6_arpa.should == "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.arpa"
- lambda{
+ ->{
IPAddr.new("192.168.2.1").ip6_arpa
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
describe "IPAddr#ip6_int" do
it "converts an IPv6 address into the reverse DNS lookup representation according to RFC1886" do
IPAddr.new("3ffe:505:2::f").ip6_int.should == "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.int"
- lambda{
+ ->{
IPAddr.new("192.168.2.1").ip6_int
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/ipaddr/to_s_spec.rb b/spec/ruby/library/ipaddr/to_s_spec.rb
index 30e5237436..2a9a027909 100644
--- a/spec/ruby/library/ipaddr/to_s_spec.rb
+++ b/spec/ruby/library/ipaddr/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#to_s" do