summaryrefslogtreecommitdiff
path: root/spec/ruby/library
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library')
-rw-r--r--spec/ruby/library/bigdecimal/divmod_spec.rb6
-rw-r--r--spec/ruby/library/bigdecimal/to_s_spec.rb22
-rw-r--r--spec/ruby/library/datetime/add_spec.rb9
-rw-r--r--spec/ruby/library/datetime/subtract_spec.rb9
-rw-r--r--spec/ruby/library/socket/unixsocket/open_spec.rb2
-rw-r--r--spec/ruby/library/stringio/getbyte_spec.rb6
-rw-r--r--spec/ruby/library/stringio/getc_spec.rb6
-rw-r--r--spec/ruby/library/stringio/getch_spec.rb22
-rw-r--r--spec/ruby/library/stringio/readbyte_spec.rb4
-rw-r--r--spec/ruby/library/stringio/readchar_spec.rb4
-rw-r--r--spec/ruby/library/zlib/crc32_spec.rb2
11 files changed, 61 insertions, 31 deletions
diff --git a/spec/ruby/library/bigdecimal/divmod_spec.rb b/spec/ruby/library/bigdecimal/divmod_spec.rb
index 22b66c2d48..3a18b150dd 100644
--- a/spec/ruby/library/bigdecimal/divmod_spec.rb
+++ b/spec/ruby/library/bigdecimal/divmod_spec.rb
@@ -38,9 +38,9 @@ describe "BigDecimal#mod_part_of_divmod" do
it "raises ZeroDivisionError if other is zero" do
bd5667 = BigDecimal("5667.19")
- lambda { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError)
- lambda { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError)
- lambda { @zero.send(@method, @zero) }.should raise_error(ZeroDivisionError)
+ lambda { bd5667.mod_part_of_divmod(0) }.should raise_error(ZeroDivisionError)
+ lambda { bd5667.mod_part_of_divmod(BigDecimal("0")) }.should raise_error(ZeroDivisionError)
+ lambda { @zero.mod_part_of_divmod(@zero) }.should raise_error(ZeroDivisionError)
end
end
diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb
index acc2e943f0..75741c5050 100644
--- a/spec/ruby/library/bigdecimal/to_s_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_s_spec.rb
@@ -15,8 +15,16 @@ describe "BigDecimal#to_s" do
@bigneg.to_s.kind_of?(String).should == true
end
- it "the default format looks like 0.xxxxEnn" do
- @bigdec.to_s.should =~ /^0\.[0-9]*E[0-9]*$/i
+ ruby_version_is ''...'2.4' do
+ it "the default format looks like 0.xxxxEnn" do
+ @bigdec.to_s.should =~ /^0\.[0-9]*E[0-9]*$/
+ end
+ end
+
+ ruby_version_is '2.4' do
+ it "the default format looks like 0.xxxxenn" do
+ @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/
+ end
end
it "takes an optional argument" do
@@ -63,10 +71,12 @@ describe "BigDecimal#to_s" do
end
it "can use conventional floating point notation" do
- @bigdec.to_s("F").should == @bigdec_str
- @bigneg.to_s("F").should == @bigneg_str
- str2 = "+123.45678901 23456789"
- BigDecimal('123.45678901234567890').to_s('+8F').should == str2
+ %w[f F].each do |format_char|
+ @bigdec.to_s(format_char).should == @bigdec_str
+ @bigneg.to_s(format_char).should == @bigneg_str
+ str2 = "+123.45678901 23456789"
+ BigDecimal('123.45678901234567890').to_s("+8#{format_char}").should == str2
+ end
end
end
diff --git a/spec/ruby/library/datetime/add_spec.rb b/spec/ruby/library/datetime/add_spec.rb
new file mode 100644
index 0000000000..a6d98914bd
--- /dev/null
+++ b/spec/ruby/library/datetime/add_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require 'date'
+
+describe "DateTime#+" do
+ it "is able to add sub-millisecond precision values" do
+ datetime = DateTime.new(2017)
+ (datetime + 0.00001).to_time.usec.should == 864000
+ end
+end
diff --git a/spec/ruby/library/datetime/subtract_spec.rb b/spec/ruby/library/datetime/subtract_spec.rb
new file mode 100644
index 0000000000..ed88533246
--- /dev/null
+++ b/spec/ruby/library/datetime/subtract_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require 'date'
+
+describe "DateTime#-" do
+ it "is able to subtract sub-millisecond precision values" do
+ date = DateTime.new(2017)
+ ((date + 0.00001) - date).should == Rational(1, 100000)
+ end
+end
diff --git a/spec/ruby/library/socket/unixsocket/open_spec.rb b/spec/ruby/library/socket/unixsocket/open_spec.rb
index 6c4b7c5676..ad5048fedd 100644
--- a/spec/ruby/library/socket/unixsocket/open_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/open_spec.rb
@@ -19,7 +19,7 @@ describe "UNIXSocket.open" do
end
it "opens a unix socket on the specified file and yields it to the block" do
- UNIXSocket.send(@method, @path) do |client|
+ UNIXSocket.open(@path) do |client|
client.addr[0].should == "AF_UNIX"
client.closed?.should == false
end
diff --git a/spec/ruby/library/stringio/getbyte_spec.rb b/spec/ruby/library/stringio/getbyte_spec.rb
index 99737614b9..3daa3d8e02 100644
--- a/spec/ruby/library/stringio/getbyte_spec.rb
+++ b/spec/ruby/library/stringio/getbyte_spec.rb
@@ -8,9 +8,9 @@ describe "StringIO#getbyte" do
it "returns the 8-bit byte at the current position" do
io = StringIO.new("example")
- io.send(@method).should == 101
- io.send(@method).should == 120
- io.send(@method).should == 97
+ io.getbyte.should == 101
+ io.getbyte.should == 120
+ io.getbyte.should == 97
end
end
diff --git a/spec/ruby/library/stringio/getc_spec.rb b/spec/ruby/library/stringio/getc_spec.rb
index 9c0a28a1f0..263d418316 100644
--- a/spec/ruby/library/stringio/getc_spec.rb
+++ b/spec/ruby/library/stringio/getc_spec.rb
@@ -8,9 +8,9 @@ describe "StringIO#getc" do
it "returns the character at the current position" do
io = StringIO.new("example")
- io.send(@method).should == ?e
- io.send(@method).should == ?x
- io.send(@method).should == ?a
+ io.getc.should == ?e
+ io.getc.should == ?x
+ io.getc.should == ?a
end
end
diff --git a/spec/ruby/library/stringio/getch_spec.rb b/spec/ruby/library/stringio/getch_spec.rb
index cd846705de..06670a178c 100644
--- a/spec/ruby/library/stringio/getch_spec.rb
+++ b/spec/ruby/library/stringio/getch_spec.rb
@@ -12,32 +12,32 @@ describe "StringIO#getch" do
it "returns the character at the current position" do
io = StringIO.new("example")
- io.send(@method).should == ?e
- io.send(@method).should == ?x
- io.send(@method).should == ?a
+ io.getch.should == ?e
+ io.getch.should == ?x
+ io.getch.should == ?a
end
with_feature :encoding do
it "increments #pos by the byte size of the character in multibyte strings" do
io = StringIO.new("föóbar")
- io.send(@method); io.pos.should == 1 # "f" has byte size 1
- io.send(@method); io.pos.should == 3 # "ö" has byte size 2
- io.send(@method); io.pos.should == 5 # "ó" has byte size 2
- io.send(@method); io.pos.should == 6 # "b" has byte size 1
+ io.getch; io.pos.should == 1 # "f" has byte size 1
+ io.getch; io.pos.should == 3 # "ö" has byte size 2
+ io.getch; io.pos.should == 5 # "ó" has byte size 2
+ io.getch; io.pos.should == 6 # "b" has byte size 1
end
end
it "returns nil at the end of the string" do
# empty string case
io = StringIO.new("")
- io.send(@method).should == nil
- io.send(@method).should == nil
+ io.getch.should == nil
+ io.getch.should == nil
# non-empty string case
io = StringIO.new("a")
- io.send(@method) # skip one
- io.send(@method).should == nil
+ io.getch # skip one
+ io.getch.should == nil
end
describe "StringIO#getch when self is not readable" do
diff --git a/spec/ruby/library/stringio/readbyte_spec.rb b/spec/ruby/library/stringio/readbyte_spec.rb
index b87b88b9c2..41a0911293 100644
--- a/spec/ruby/library/stringio/readbyte_spec.rb
+++ b/spec/ruby/library/stringio/readbyte_spec.rb
@@ -8,10 +8,10 @@ describe "StringIO#readbyte" do
it "reads the next 8-bit byte from self's current position" do
io = StringIO.new("example")
- io.send(@method).should == 101
+ io.readbyte.should == 101
io.pos = 4
- io.send(@method).should == 112
+ io.readbyte.should == 112
end
end
diff --git a/spec/ruby/library/stringio/readchar_spec.rb b/spec/ruby/library/stringio/readchar_spec.rb
index 1d2ad45b9a..38944819a2 100644
--- a/spec/ruby/library/stringio/readchar_spec.rb
+++ b/spec/ruby/library/stringio/readchar_spec.rb
@@ -8,10 +8,10 @@ describe "StringIO#readchar" do
it "reads the next 8-bit byte from self's current position" do
io = StringIO.new("example")
- io.send(@method).should == ?e
+ io.readchar.should == ?e
io.pos = 4
- io.send(@method).should == ?p
+ io.readchar.should == ?p
end
end
diff --git a/spec/ruby/library/zlib/crc32_spec.rb b/spec/ruby/library/zlib/crc32_spec.rb
index 5c39586ed9..02f95fd92c 100644
--- a/spec/ruby/library/zlib/crc32_spec.rb
+++ b/spec/ruby/library/zlib/crc32_spec.rb
@@ -24,6 +24,8 @@ describe "Zlib.crc32" do
Zlib.crc32(test_string, 1).should == 1809313411
Zlib.crc32(test_string, 2**8).should == 1722745982
Zlib.crc32(test_string, 2**16).should == 1932511220
+ Zlib.crc32("p", ~305419896).should == 4046865307
+ Zlib.crc32("p", -305419897).should == 4046865307
lambda { Zlib.crc32(test_string, 2**128) }.should raise_error(RangeError)
end