summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-09-29 16:03:58 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-09-29 16:03:58 +0200
commit1c938a72aa9378f982dbc55327e86150c47b8707 (patch)
tree34a0bb0a45396c26eed111877a810c3aa793bff5
parent31bb66a19df26409c9d47afcf37919c9a065516a (diff)
downloadruby-1c938a72aa9378f982dbc55327e86150c47b8707.tar.gz
Update to ruby/spec@519df35
-rw-r--r--spec/ruby/.travis.yml28
-rw-r--r--spec/ruby/appveyor.yml34
-rw-r--r--spec/ruby/core/dir/shared/open.rb2
-rw-r--r--spec/ruby/core/encoding/converter/convpath_spec.rb4
-rw-r--r--spec/ruby/core/encoding/converter/new_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/primitive_convert_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/search_convpath_spec.rb6
-rw-r--r--spec/ruby/core/file/open_spec.rb2
-rw-r--r--spec/ruby/core/hash/fetch_values_spec.rb4
-rw-r--r--spec/ruby/core/io/initialize_spec.rb2
-rw-r--r--spec/ruby/core/io/pipe_spec.rb2
-rw-r--r--spec/ruby/core/io/read_spec.rb16
-rw-r--r--spec/ruby/core/io/reopen_spec.rb2
-rw-r--r--spec/ruby/core/io/shared/binwrite.rb4
-rw-r--r--spec/ruby/core/io/shared/new.rb44
-rw-r--r--spec/ruby/core/io/shared/readlines.rb8
-rw-r--r--spec/ruby/core/method/fixtures/classes.rb1
-rw-r--r--spec/ruby/core/method/original_name_spec.rb22
-rw-r--r--spec/ruby/core/numeric/shared/step.rb213
-rw-r--r--spec/ruby/core/numeric/step_spec.rb19
-rw-r--r--spec/ruby/core/random/rand_spec.rb17
-rw-r--r--spec/ruby/core/random/shared/bytes.rb8
-rw-r--r--spec/ruby/core/random/shared/rand.rb9
-rw-r--r--spec/ruby/core/string/shared/encode.rb6
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/classes.rb18
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/locations_in_main.rb5
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/locations_in_required.rb3
-rw-r--r--spec/ruby/core/thread/backtrace/location/label_spec.rb17
-rw-r--r--spec/ruby/core/thread/backtrace_locations_spec.rb33
-rw-r--r--spec/ruby/core/unboundmethod/fixtures/classes.rb1
-rw-r--r--spec/ruby/core/unboundmethod/original_name_spec.rb22
-rw-r--r--spec/ruby/language/block_spec.rb24
-rw-r--r--spec/ruby/language/hash_spec.rb2
-rw-r--r--spec/ruby/language/lambda_spec.rb16
-rw-r--r--spec/ruby/language/method_spec.rb43
-rw-r--r--spec/ruby/language/return_spec.rb9
-rw-r--r--spec/ruby/language/send_spec.rb5
-rw-r--r--spec/ruby/library/cmath/math/acos_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/acosh_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/asin_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/asinh_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/atan2_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/atan_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/atanh_spec.rb20
-rw-r--r--spec/ruby/library/cmath/math/cos_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/cosh_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/exp_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/fixtures/classes.rb4
-rw-r--r--spec/ruby/library/cmath/math/log10_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/log_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/shared/acos.rb41
-rw-r--r--spec/ruby/library/cmath/math/shared/acosh.rb37
-rw-r--r--spec/ruby/library/cmath/math/shared/asin.rb47
-rw-r--r--spec/ruby/library/cmath/math/shared/asinh.rb32
-rw-r--r--spec/ruby/library/cmath/math/shared/atan.rb32
-rw-r--r--spec/ruby/library/cmath/math/shared/atan2.rb34
-rw-r--r--spec/ruby/library/cmath/math/shared/atanh.rb30
-rw-r--r--spec/ruby/library/cmath/math/shared/cos.rb30
-rw-r--r--spec/ruby/library/cmath/math/shared/cosh.rb28
-rw-r--r--spec/ruby/library/cmath/math/shared/exp.rb28
-rw-r--r--spec/ruby/library/cmath/math/shared/log.rb39
-rw-r--r--spec/ruby/library/cmath/math/shared/log10.rb41
-rw-r--r--spec/ruby/library/cmath/math/shared/sin.rb30
-rw-r--r--spec/ruby/library/cmath/math/shared/sinh.rb28
-rw-r--r--spec/ruby/library/cmath/math/shared/sqrt.rb34
-rw-r--r--spec/ruby/library/cmath/math/shared/tan.rb28
-rw-r--r--spec/ruby/library/cmath/math/shared/tanh.rb32
-rw-r--r--spec/ruby/library/cmath/math/sin_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/sinh_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/sqrt_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/tan_spec.rb18
-rw-r--r--spec/ruby/library/cmath/math/tanh_spec.rb18
-rw-r--r--spec/ruby/library/logger/device/new_spec.rb6
-rw-r--r--spec/ruby/library/scanf/io/block_scanf_spec.rb10
-rw-r--r--spec/ruby/library/scanf/io/fixtures/date.txt4
-rw-r--r--spec/ruby/library/scanf/io/fixtures/helloworld.txt1
-rw-r--r--spec/ruby/library/scanf/io/scanf_spec.rb38
-rw-r--r--spec/ruby/library/scanf/io/shared/block_scanf.rb28
-rw-r--r--spec/ruby/library/scanf/string/block_scanf_spec.rb10
-rw-r--r--spec/ruby/library/scanf/string/scanf_spec.rb56
-rw-r--r--spec/ruby/library/scanf/string/shared/block_scanf.rb25
-rw-r--r--spec/ruby/library/securerandom/random_bytes_spec.rb4
-rw-r--r--spec/ruby/library/securerandom/random_number_spec.rb4
83 files changed, 1416 insertions, 308 deletions
diff --git a/spec/ruby/.travis.yml b/spec/ruby/.travis.yml
deleted file mode 100644
index 467a5e9f68..0000000000
--- a/spec/ruby/.travis.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-sudo: false
-language: ruby
-install:
- - git clone https://github.com/ruby/mspec.git ../mspec
-script:
- - CHECK_LEAKS=true ../mspec/bin/mspec
-matrix:
- include:
- - name: Running each spec twice
- rvm: 2.5.5
- script:
- - CHECK_LEAKS=true ../mspec/bin/mspec -R2 -ff
- - rvm: 2.4.6
- - rvm: 2.5.5
- - rvm: 2.6.3
- - name: RuboCop Lint Checks
- rvm: 2.4.6
- script:
- - gem install rubocop:0.61.0
- - rubocop
-branches:
- only:
- - master
- - /^try/
-notifications:
- email:
- on_success: change
- on_failure: change
diff --git a/spec/ruby/appveyor.yml b/spec/ruby/appveyor.yml
deleted file mode 100644
index 588172ee3d..0000000000
--- a/spec/ruby/appveyor.yml
+++ /dev/null
@@ -1,34 +0,0 @@
----
-version: "{build}"
-clone_depth: 100
-init:
- # To avoid duplicated executables in PATH, see https://github.com/ruby/spec/pull/468
- - set PATH=C:\Ruby%ruby_version%\bin;C:\Program Files\7-Zip;C:\Program Files\AppVeyor\BuildAgent;C:\Program Files\Git\cmd;C:\Windows\system32;C:\Program Files;C:\Windows
- # Loads trunk build and updates MSYS2 / MinGW to most recent gcc compiler
- - ps: |
- if ($env:ruby_version -eq '_trunk') {
- $trunk_uri = 'https://ci.appveyor.com/api/projects/MSP-Greg/ruby-loco/artifacts/ruby_trunk.7z'
- (New-Object Net.WebClient).DownloadFile($trunk_uri, 'C:\ruby_trunk.7z')
- 7z.exe x C:\ruby_trunk.7z -oC:\Ruby_trunk
- }
-
-environment:
- matrix:
- - ruby_version: 24-x64
- - ruby_version: 25-x64
- - ruby_version: _trunk # So the folder name is ruby_trunk
-install:
- - git clone https://github.com/ruby/mspec.git ../mspec
-build: off
-test_script:
- - SET CHECK_LEAKS=true
- - ../mspec/bin/mspec -rdevkit -ff
-on_finish:
- - ruby -v
-matrix:
- allow_failures:
- - ruby_version: _trunk
-branches:
- only:
- - master
- - /^try/
diff --git a/spec/ruby/core/dir/shared/open.rb b/spec/ruby/core/dir/shared/open.rb
index fb2af71e05..76b08dc288 100644
--- a/spec/ruby/core/dir/shared/open.rb
+++ b/spec/ruby/core/dir/shared/open.rb
@@ -52,7 +52,7 @@ describe :dir_open, shared: true do
options = mock("dir_open")
options.should_receive(:to_hash).and_return({ encoding: Encoding::UTF_8 })
- dir = Dir.send(@method, DirSpecs.mock_dir, options) {|d| d }
+ dir = Dir.send(@method, DirSpecs.mock_dir, **options) {|d| d }
dir.should be_kind_of(Dir)
end
diff --git a/spec/ruby/core/encoding/converter/convpath_spec.rb b/spec/ruby/core/encoding/converter/convpath_spec.rb
index 473f2db91e..23f1e5dc33 100644
--- a/spec/ruby/core/encoding/converter/convpath_spec.rb
+++ b/spec/ruby/core/encoding/converter/convpath_spec.rb
@@ -15,10 +15,10 @@ describe "Encoding::Converter#convpath" do
end
it "indicates if crlf_newline conversion would occur" do
- ec = Encoding::Converter.new("ISo-8859-1", "EUC-JP", {crlf_newline: true})
+ ec = Encoding::Converter.new("ISo-8859-1", "EUC-JP", crlf_newline: true)
ec.convpath.last.should == "crlf_newline"
- ec = Encoding::Converter.new("ASCII", "UTF-8", {crlf_newline: false})
+ ec = Encoding::Converter.new("ASCII", "UTF-8", crlf_newline: false)
ec.convpath.last.should_not == "crlf_newline"
end
end
diff --git a/spec/ruby/core/encoding/converter/new_spec.rb b/spec/ruby/core/encoding/converter/new_spec.rb
index 6a6343012c..9fc97263fe 100644
--- a/spec/ruby/core/encoding/converter/new_spec.rb
+++ b/spec/ruby/core/encoding/converter/new_spec.rb
@@ -50,7 +50,7 @@ describe "Encoding::Converter.new" do
it "calls #to_hash to convert the options argument to a Hash if not a Fixnum" do
opts = mock("encoding converter options")
opts.should_receive(:to_hash).and_return({ replace: "fubar" })
- conv = Encoding::Converter.new("us-ascii", "utf-8", opts)
+ conv = Encoding::Converter.new("us-ascii", "utf-8", **opts)
conv.replacement.should == "fubar"
end
diff --git a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
index 4a22606375..802d8e7cb1 100644
--- a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
+++ b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
@@ -85,7 +85,7 @@ describe "Encoding::Converter#primitive_convert" do
end
it "accepts an options hash" do
- @ec.primitive_convert("","",nil,nil, {after_output: true}).should == :finished
+ @ec.primitive_convert("","",nil,nil, after_output: true).should == :finished
end
it "sets the destination buffer's encoding to the destination encoding if the conversion succeeded" do
diff --git a/spec/ruby/core/encoding/converter/search_convpath_spec.rb b/spec/ruby/core/encoding/converter/search_convpath_spec.rb
index 0535e7bdc3..0882af5539 100644
--- a/spec/ruby/core/encoding/converter/search_convpath_spec.rb
+++ b/spec/ruby/core/encoding/converter/search_convpath_spec.rb
@@ -15,12 +15,10 @@ describe "Encoding::Converter.search_convpath" do
end
it "indicates if crlf_newline conversion would occur" do
- cp = Encoding::Converter.search_convpath(
- "ISO-8859-1", "EUC-JP", {crlf_newline: true})
+ cp = Encoding::Converter.search_convpath("ISO-8859-1", "EUC-JP", crlf_newline: true)
cp.last.should == "crlf_newline"
- cp = Encoding::Converter.search_convpath(
- "ASCII", "UTF-8", {crlf_newline: false})
+ cp = Encoding::Converter.search_convpath("ASCII", "UTF-8", crlf_newline: false)
cp.last.should_not == "crlf_newline"
end
diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb
index d946fc5ecf..b6af2686e4 100644
--- a/spec/ruby/core/file/open_spec.rb
+++ b/spec/ruby/core/file/open_spec.rb
@@ -566,7 +566,7 @@ describe "File.open" do
options = mock("file open options")
options.should_receive(:to_hash).and_return({ mode: "r" })
- @fh = File.open(@file, options)
+ @fh = File.open(@file, **options)
end
it "accepts extra flags as a keyword argument and combine with a string mode" do
diff --git a/spec/ruby/core/hash/fetch_values_spec.rb b/spec/ruby/core/hash/fetch_values_spec.rb
index 041a3f07e9..af3673f6ef 100644
--- a/spec/ruby/core/hash/fetch_values_spec.rb
+++ b/spec/ruby/core/hash/fetch_values_spec.rb
@@ -12,6 +12,10 @@ describe "Hash#fetch_values" do
@hash.fetch_values(:a).should == [1]
@hash.fetch_values(:a, :c).should == [1, 3]
end
+
+ it "returns the values for keys ordered in the order of the requested keys" do
+ @hash.fetch_values(:c, :a).should == [3, 1]
+ end
end
describe "with unmatched keys" do
diff --git a/spec/ruby/core/io/initialize_spec.rb b/spec/ruby/core/io/initialize_spec.rb
index c8f3faf110..c0d84765a8 100644
--- a/spec/ruby/core/io/initialize_spec.rb
+++ b/spec/ruby/core/io/initialize_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
describe "IO#initialize" do
before :each do
@name = tmp("io_initialize.txt")
- @io = new_io @name
+ @io = IO.new(new_fd(@name))
@fd = @io.fileno
end
diff --git a/spec/ruby/core/io/pipe_spec.rb b/spec/ruby/core/io/pipe_spec.rb
index 5b2f18d836..a7dcb7fab8 100644
--- a/spec/ruby/core/io/pipe_spec.rb
+++ b/spec/ruby/core/io/pipe_spec.rb
@@ -179,7 +179,7 @@ describe "IO.pipe" do
it "calls #to_hash to convert an options argument" do
options = mock("io pipe encoding options")
options.should_receive(:to_hash).and_return({ invalid: :replace })
- IO.pipe("UTF-8", "ISO-8859-1", options) { |r, w| }
+ IO.pipe("UTF-8", "ISO-8859-1", **options) { |r, w| }
end
it "calls #to_str to convert the first argument to a String" do
diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb
index 267d840cd3..1e9a8d2a4f 100644
--- a/spec/ruby/core/io/read_spec.rb
+++ b/spec/ruby/core/io/read_spec.rb
@@ -24,35 +24,35 @@ describe "IO.read" do
end
it "accepts an empty options Hash" do
- IO.read(@fname, {}).should == @contents
+ IO.read(@fname, **{}).should == @contents
end
it "accepts a length, and empty options Hash" do
- IO.read(@fname, 3, {}).should == @contents[0, 3]
+ IO.read(@fname, 3, **{}).should == @contents[0, 3]
end
it "accepts a length, offset, and empty options Hash" do
- IO.read(@fname, 3, 0, {}).should == @contents[0, 3]
+ IO.read(@fname, 3, 0, **{}).should == @contents[0, 3]
end
it "raises an IOError if the options Hash specifies write mode" do
- -> { IO.read(@fname, 3, 0, {mode: "w"}) }.should raise_error(IOError)
+ -> { IO.read(@fname, 3, 0, mode: "w") }.should raise_error(IOError)
end
it "raises an IOError if the options Hash specifies append only mode" do
- -> { IO.read(@fname, {mode: "a"}) }.should raise_error(IOError)
+ -> { IO.read(@fname, mode: "a") }.should raise_error(IOError)
end
it "reads the file if the options Hash includes read mode" do
- IO.read(@fname, {mode: "r"}).should == @contents
+ IO.read(@fname, mode: "r").should == @contents
end
it "reads the file if the options Hash includes read/write mode" do
- IO.read(@fname, {mode: "r+"}).should == @contents
+ IO.read(@fname, mode: "r+").should == @contents
end
it "reads the file if the options Hash includes read/write append mode" do
- IO.read(@fname, {mode: "a+"}).should == @contents
+ IO.read(@fname, mode: "a+").should == @contents
end
it "treats second nil argument as no length limit" do
diff --git a/spec/ruby/core/io/reopen_spec.rb b/spec/ruby/core/io/reopen_spec.rb
index 133ff03ea5..975f654b66 100644
--- a/spec/ruby/core/io/reopen_spec.rb
+++ b/spec/ruby/core/io/reopen_spec.rb
@@ -230,7 +230,7 @@ describe "IO#reopen with an IO" do
end
@io = new_io @name
- @other_io = new_io @other_name, "r"
+ @other_io = IO.new(new_fd(@other_name, "r"), "r")
end
after :each do
diff --git a/spec/ruby/core/io/shared/binwrite.rb b/spec/ruby/core/io/shared/binwrite.rb
index 17682a1a93..29310e1eaf 100644
--- a/spec/ruby/core/io/shared/binwrite.rb
+++ b/spec/ruby/core/io/shared/binwrite.rb
@@ -56,7 +56,7 @@ describe :io_binwrite, shared: true do
end
it "doesn't truncate and writes at the given offset after passing empty opts" do
- IO.send(@method, @filename, "hello world!", 1, {})
+ IO.send(@method, @filename, "hello world!", 1, **{})
File.read(@filename).should == "0hello world!34567890123456789"
end
@@ -72,7 +72,7 @@ describe :io_binwrite, shared: true do
end
it "truncates if empty :opts provided and offset skipped" do
- IO.send(@method, @filename, "hello, world!", {})
+ IO.send(@method, @filename, "hello, world!", **{})
File.read(@filename).should == "hello, world!"
end
end
diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb
index 2101958170..cc76955784 100644
--- a/spec/ruby/core/io/shared/new.rb
+++ b/spec/ruby/core/io/shared/new.rb
@@ -89,59 +89,59 @@ describe :io_new, shared: true do
end
it "uses the external encoding specified via the :external_encoding option" do
- @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8'})
+ @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8')
@io.external_encoding.to_s.should == 'UTF-8'
end
it "uses the internal encoding specified via the :internal_encoding option" do
- @io = IO.send(@method, @fd, 'w', {internal_encoding: 'ibm866'})
+ @io = IO.send(@method, @fd, 'w', internal_encoding: 'ibm866')
@io.internal_encoding.to_s.should == 'IBM866'
end
it "uses the colon-separated encodings specified via the :encoding option" do
- @io = IO.send(@method, @fd, 'w', {encoding: 'utf-8:ISO-8859-1'})
+ @io = IO.send(@method, @fd, 'w', encoding: 'utf-8:ISO-8859-1')
@io.external_encoding.to_s.should == 'UTF-8'
@io.internal_encoding.to_s.should == 'ISO-8859-1'
end
it "uses the :encoding option as the external encoding when only one is given" do
- @io = IO.send(@method, @fd, 'w', {encoding: 'ISO-8859-1'})
+ @io = IO.send(@method, @fd, 'w', encoding: 'ISO-8859-1')
@io.external_encoding.to_s.should == 'ISO-8859-1'
end
it "uses the :encoding options as the external encoding when it's an Encoding object" do
- @io = IO.send(@method, @fd, 'w', {encoding: Encoding::ISO_8859_1})
+ @io = IO.send(@method, @fd, 'w', encoding: Encoding::ISO_8859_1)
@io.external_encoding.should == Encoding::ISO_8859_1
end
it "ignores the :encoding option when the :external_encoding option is present" do
-> {
- @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', encoding: 'iso-8859-1:iso-8859-1'})
+ @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', encoding: 'iso-8859-1:iso-8859-1')
}.should complain(/Ignoring encoding parameter/)
@io.external_encoding.to_s.should == 'UTF-8'
end
it "ignores the :encoding option when the :internal_encoding option is present" do
-> {
- @io = IO.send(@method, @fd, 'w', {internal_encoding: 'ibm866', encoding: 'iso-8859-1:iso-8859-1'})
+ @io = IO.send(@method, @fd, 'w', internal_encoding: 'ibm866', encoding: 'iso-8859-1:iso-8859-1')
}.should complain(/Ignoring encoding parameter/)
@io.internal_encoding.to_s.should == 'IBM866'
end
it "uses the encoding specified via the :mode option hash" do
- @io = IO.send(@method, @fd, {mode: 'w:utf-8:ISO-8859-1'})
+ @io = IO.send(@method, @fd, mode: 'w:utf-8:ISO-8859-1')
@io.external_encoding.to_s.should == 'UTF-8'
@io.internal_encoding.to_s.should == 'ISO-8859-1'
end
it "ignores the :internal_encoding option when the same as the external encoding" do
- @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', internal_encoding: 'utf-8'})
+ @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', internal_encoding: 'utf-8')
@io.external_encoding.to_s.should == 'UTF-8'
@io.internal_encoding.to_s.should == ''
end
it "sets internal encoding to nil when passed '-'" do
- @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', internal_encoding: '-'})
+ @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', internal_encoding: '-')
@io.external_encoding.to_s.should == 'UTF-8'
@io.internal_encoding.to_s.should == ''
end
@@ -157,12 +157,12 @@ describe :io_new, shared: true do
end
it "sets binmode from :binmode option" do
- @io = IO.send(@method, @fd, 'w', {binmode: true})
+ @io = IO.send(@method, @fd, 'w', binmode: true)
@io.binmode?.should == true
end
it "does not set binmode from false :binmode" do
- @io = IO.send(@method, @fd, 'w', {binmode: false})
+ @io = IO.send(@method, @fd, 'w', binmode: false)
@io.binmode?.should == false
end
@@ -173,7 +173,7 @@ describe :io_new, shared: true do
# #5917
it "sets external encoding to binary with :binmode option" do
- @io = IO.send(@method, @fd, 'w', {binmode: true})
+ @io = IO.send(@method, @fd, 'w', binmode: true)
@io.external_encoding.should == Encoding::BINARY
end
@@ -198,7 +198,9 @@ describe :io_new, shared: true do
end
it "accepts nil options" do
- @io = IO.send(@method, @fd, 'w', nil)
+ @io = suppress_keyword_warning do
+ IO.send(@method, @fd, 'w', nil)
+ end
@io.write("foo").should == 3
end
@@ -247,13 +249,13 @@ describe :io_new, shared: true do
it "coerces options as third argument with #to_hash" do
options = mock("options")
options.should_receive(:to_hash).and_return({})
- @io = IO.send(@method, @fd, 'w', options)
+ @io = IO.send(@method, @fd, 'w', **options)
end
it "coerces options as second argument with #to_hash" do
options = mock("options")
options.should_receive(:to_hash).and_return({})
- @io = IO.send(@method, @fd, options)
+ @io = IO.send(@method, @fd, **options)
end
it "accepts an :autoclose option" do
@@ -307,13 +309,13 @@ describe :io_new_errors, shared: true do
it "raises an error if passed encodings two ways" do
-> {
- @io = IO.send(@method, @fd, 'w:ISO-8859-1', {encoding: 'ISO-8859-1'})
+ @io = IO.send(@method, @fd, 'w:ISO-8859-1', encoding: 'ISO-8859-1')
}.should raise_error(ArgumentError)
-> {
- @io = IO.send(@method, @fd, 'w:ISO-8859-1', {external_encoding: 'ISO-8859-1'})
+ @io = IO.send(@method, @fd, 'w:ISO-8859-1', external_encoding: 'ISO-8859-1')
}.should raise_error(ArgumentError)
-> {
- @io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', {internal_encoding: 'ISO-8859-1'})
+ @io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1')
}.should raise_error(ArgumentError)
end
@@ -372,7 +374,9 @@ describe :io_new_errors, shared: true do
it "raises TypeError if passed a hash for mode and nil for options" do
-> {
- @io = IO.send(@method, @fd, {mode: 'w'}, nil)
+ suppress_keyword_warning do
+ @io = IO.send(@method, @fd, {mode: 'w'}, nil)
+ end
}.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/core/io/shared/readlines.rb b/spec/ruby/core/io/shared/readlines.rb
index 9bc02da0bd..de803f42e5 100644
--- a/spec/ruby/core/io/shared/readlines.rb
+++ b/spec/ruby/core/io/shared/readlines.rb
@@ -107,7 +107,7 @@ describe :io_readlines_options_19, shared: true do
options = mock("io readlines options Hash")
options.should_receive(:to_hash).and_return({ mode: "w" })
-> do
- IO.send(@method, @filename, 10, options, &@object)
+ IO.send(@method, @filename, 10, **options, &@object)
end.should raise_error(IOError)
end
end
@@ -135,7 +135,7 @@ describe :io_readlines_options_19, shared: true do
options = mock("io readlines options Hash")
options.should_receive(:to_hash).and_return({ mode: "w" })
-> do
- IO.send(@method, @filename, " ", options, &@object)
+ IO.send(@method, @filename, " ", **options, &@object)
end.should raise_error(IOError)
end
end
@@ -170,7 +170,7 @@ describe :io_readlines_options_19, shared: true do
options = mock("io readlines options Hash")
options.should_receive(:to_hash).and_return({ mode: "w" })
-> do
- IO.send(@method, @filename, " ", options, &@object)
+ IO.send(@method, @filename, " ", **options, &@object)
end.should raise_error(IOError)
end
end
@@ -202,7 +202,7 @@ describe :io_readlines_options_19, shared: true do
options = mock("io readlines options Hash")
options.should_receive(:to_hash).and_return({ mode: "w" })
-> do
- IO.send(@method, @filename, " ", 10, options, &@object)
+ IO.send(@method, @filename, " ", 10, **options, &@object)
end.should raise_error(IOError)
end
end
diff --git a/spec/ruby/core/method/fixtures/classes.rb b/spec/ruby/core/method/fixtures/classes.rb
index 315672c6e0..f3b7ff921c 100644
--- a/spec/ruby/core/method/fixtures/classes.rb
+++ b/spec/ruby/core/method/fixtures/classes.rb
@@ -26,6 +26,7 @@ module MethodSpecs
end
alias bar foo
+ alias baz bar
def same_as_foo
true
diff --git a/spec/ruby/core/method/original_name_spec.rb b/spec/ruby/core/method/original_name_spec.rb
new file mode 100644
index 0000000000..676fdaedb4
--- /dev/null
+++ b/spec/ruby/core/method/original_name_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Method#original_name" do
+ it "returns the name of the method" do
+ "abc".method(:upcase).original_name.should == :upcase
+ end
+
+ it "returns the original name when aliased" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:foo).original_name.should == :foo
+ obj.method(:bar).original_name.should == :foo
+ obj.method(:bar).unbind.bind(obj).original_name.should == :foo
+ end
+
+ it "returns the original name even when aliased twice" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:foo).original_name.should == :foo
+ obj.method(:baz).original_name.should == :foo
+ obj.method(:baz).unbind.bind(obj).original_name.should == :foo
+ end
+end
diff --git a/spec/ruby/core/numeric/shared/step.rb b/spec/ruby/core/numeric/shared/step.rb
index b0cbbd0585..364d4769ad 100644
--- a/spec/ruby/core/numeric/shared/step.rb
+++ b/spec/ruby/core/numeric/shared/step.rb
@@ -2,7 +2,7 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
# Describes Numeric#step shared specs between different argument styles.
-# To be able to do it, the @step_args var must contain a Proc that transforms
+# To be able to do it, the @step ivar must contain a Proc that transforms
# the step call arguments passed as positional arguments to the style of
# arguments pretended to test.
describe :numeric_step, :shared => true do
@@ -12,7 +12,7 @@ describe :numeric_step, :shared => true do
end
it "defaults to step = 1" do
- 1.send(@method, *@step_args.call(5), &@prc)
+ @step.call(1, 5, &@prc)
ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
end
@@ -26,39 +26,39 @@ describe :numeric_step, :shared => true do
describe "when self, stop and step are Fixnums" do
it "yields only Fixnums" do
- 1.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Fixnum) }
+ @step.call(1, 5, 1) { |x| x.should be_an_instance_of(Fixnum) }
end
describe "with a positive step" do
it "yields while increasing self by step until stop is reached" do
- 1.send(@method, *@step_args.call(5, 1), &@prc)
+ @step.call(1, 5, 1, &@prc)
ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
end
it "yields once when self equals stop" do
- 1.send(@method, *@step_args.call(1, 1), &@prc)
+ @step.call(1, 1, 1, &@prc)
ScratchPad.recorded.should eql [1]
end
it "does not yield when self is greater than stop" do
- 2.send(@method, *@step_args.call(1, 1), &@prc)
+ @step.call(2, 1, 1, &@prc)
ScratchPad.recorded.should eql []
end
end
describe "with a negative step" do
it "yields while decreasing self by step until stop is reached" do
- 5.send(@method, *@step_args.call(1, -1), &@prc)
+ @step.call(5, 1, -1, &@prc)
ScratchPad.recorded.should eql [5, 4, 3, 2, 1]
end
it "yields once when self equals stop" do
- 5.send(@method, *@step_args.call(5, -1), &@prc)
+ @step.call(5, 5, -1, &@prc)
ScratchPad.recorded.should eql [5]
end
it "does not yield when self is less than stop" do
- 1.send(@method, *@step_args.call(5, -1), &@prc)
+ @step.call(1, 5, -1, &@prc)
ScratchPad.recorded.should == []
end
end
@@ -66,156 +66,157 @@ describe :numeric_step, :shared => true do
describe "when at least one of self, stop or step is a Float" do
it "yields Floats even if only self is a Float" do
- 1.5.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1.5, 5, 1) { |x| x.should be_an_instance_of(Float) }
end
it "yields Floats even if only stop is a Float" do
- 1.send(@method, *@step_args.call(5.0, 1)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1, 5.0, 1) { |x| x.should be_an_instance_of(Float) }
end
it "yields Floats even if only step is a Float" do
- 1.send(@method, *@step_args.call(5, 1.0)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1, 5, 1.0) { |x| x.should be_an_instance_of(Float) }
end
describe "with a positive step" do
it "yields while increasing self by step while < stop" do
- 1.5.send(@method, *@step_args.call(5, 1), &@prc)
+ @step.call(1.5, 5, 1, &@prc)
ScratchPad.recorded.should eql [1.5, 2.5, 3.5, 4.5]
end
it "yields once when self equals stop" do
- 1.5.send(@method, *@step_args.call(1.5, 1), &@prc)
+ @step.call(1.5, 1.5, 1, &@prc)
ScratchPad.recorded.should eql [1.5]
end
it "does not yield when self is greater than stop" do
- 2.5.send(@method, *@step_args.call(1.5, 1), &@prc)
+ @step.call(2.5, 1.5, 1, &@prc)
ScratchPad.recorded.should == []
end
it "is careful about not yielding a value greater than limit" do
# As 9*1.3+1.0 == 12.700000000000001 > 12.7, we test:
- 1.0.send(@method, *@step_args.call(12.7, 1.3), &@prc)
+ @step.call(1.0, 12.7, 1.3, &@prc)
ScratchPad.recorded.should eql [1.0, 2.3, 3.6, 4.9, 6.2, 7.5, 8.8, 10.1, 11.4, 12.7]
end
end
describe "with a negative step" do
it "yields while decreasing self by step while self > stop" do
- 5.send(@method, *@step_args.call(1.5, -1), &@prc)
+ @step.call(5, 1.5, -1, &@prc)
ScratchPad.recorded.should eql [5.0, 4.0, 3.0, 2.0]
end
it "yields once when self equals stop" do
- 1.5.send(@method, *@step_args.call(1.5, -1), &@prc)
+ @step.call(1.5, 1.5, -1, &@prc)
ScratchPad.recorded.should eql [1.5]
end
it "does not yield when self is less than stop" do
- 1.send(@method, *@step_args.call(5, -1.5), &@prc)
+ @step.call(1, 5, -1.5, &@prc)
ScratchPad.recorded.should == []
end
it "is careful about not yielding a value smaller than limit" do
# As -9*1.3-1.0 == -12.700000000000001 < -12.7, we test:
- -1.0.send(@method, *@step_args.call(-12.7, -1.3), &@prc)
+ @step.call(-1.0, -12.7, -1.3, &@prc)
ScratchPad.recorded.should eql [-1.0, -2.3, -3.6, -4.9, -6.2, -7.5, -8.8, -10.1, -11.4, -12.7]
end
end
describe "with a positive Infinity step" do
it "yields once if self < stop" do
- 42.send(@method, *@step_args.call(100, infinity_value), &@prc)
+ @step.call(42, 100, infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when stop is Infinity" do
- 42.send(@method, *@step_args.call(infinity_value, infinity_value), &@prc)
+ @step.call(42, infinity_value, infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when self equals stop" do
- 42.send(@method, *@step_args.call(42, infinity_value), &@prc)
+ @step.call(42, 42, infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when self and stop are Infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, infinity_value), &@prc)
+ # @step.call(infinity_value, infinity_value, infinity_value, &@prc)
+ @step.call(infinity_value, infinity_value, infinity_value, &@prc)
ScratchPad.recorded.should == [infinity_value]
end
it "does not yield when self > stop" do
- 100.send(@method, *@step_args.call(42, infinity_value), &@prc)
+ @step.call(100, 42, infinity_value, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when stop is -Infinity" do
- 42.send(@method, *@step_args.call(-infinity_value, infinity_value), &@prc)
+ @step.call(42, -infinity_value, infinity_value, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity step" do
it "yields once if self > stop" do
- 42.send(@method, *@step_args.call(6, -infinity_value), &@prc)
+ @step.call(42, 6, -infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once if stop is -Infinity" do
- 42.send(@method, *@step_args.call(-infinity_value, -infinity_value), &@prc)
+ @step.call(42, -infinity_value, -infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when self equals stop" do
- 42.send(@method, *@step_args.call(42, -infinity_value), &@prc)
+ @step.call(42, 42, -infinity_value, &@prc)
ScratchPad.recorded.should eql [42.0]
end
it "yields once when self and stop are Infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, -infinity_value), &@prc)
+ @step.call(infinity_value, infinity_value, -infinity_value, &@prc)
ScratchPad.recorded.should == [infinity_value]
end
it "does not yield when self > stop" do
- 42.send(@method, *@step_args.call(100, -infinity_value), &@prc)
+ @step.call(42, 100, -infinity_value, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when stop is Infinity" do
- 42.send(@method, *@step_args.call(infinity_value, -infinity_value), &@prc)
+ @step.call(42, infinity_value, -infinity_value, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a Infinity stop and a positive step" do
it "does not yield when self is infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, 1), &@prc)
+ @step.call(infinity_value, infinity_value, 1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a Infinity stop and a negative step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(infinity_value, -1), &@prc)
+ @step.call(-infinity_value, infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when self is positive infinity" do
- infinity_value.send(@method, *@step_args.call(infinity_value, -1), &@prc)
+ @step.call(infinity_value, infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity stop and a positive step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(-infinity_value, 1), &@prc)
+ @step.call(-infinity_value, -infinity_value, 1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity stop and a negative step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(-infinity_value, -1), &@prc)
+ @step.call(-infinity_value, -infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
end
@@ -233,33 +234,33 @@ describe :numeric_step, :shared => true do
describe "with self and stop as Fixnums" do
it "raises an #{error} when step is a numeric representation" do
- -> { 1.send(@method, *@step_args.call(5, "1")) {} }.should raise_error(error)
- -> { 1.send(@method, *@step_args.call(5, "0.1")) {} }.should raise_error(error)
- -> { 1.send(@method, *@step_args.call(5, "1/3")) {} }.should raise_error(error)
+ -> { @step.call(1, 5, "1") {} }.should raise_error(error)
+ -> { @step.call(1, 5, "0.1") {} }.should raise_error(error)
+ -> { @step.call(1, 5, "1/3") {} }.should raise_error(error)
end
it "raises an #{error} with step as an alphanumeric string" do
- -> { 1.send(@method, *@step_args.call(5, "foo")) {} }.should raise_error(error)
+ -> { @step.call(1, 5, "foo") {} }.should raise_error(error)
end
end
describe "with self and stop as Floats" do
it "raises an #{error} when step is a numeric representation" do
- -> { 1.1.send(@method, *@step_args.call(5.1, "1")) {} }.should raise_error(error)
- -> { 1.1.send(@method, *@step_args.call(5.1, "0.1")) {} }.should raise_error(error)
- -> { 1.1.send(@method, *@step_args.call(5.1, "1/3")) {} }.should raise_error(error)
+ -> { @step.call(1.1, 5.1, "1") {} }.should raise_error(error)
+ -> { @step.call(1.1, 5.1, "0.1") {} }.should raise_error(error)
+ -> { @step.call(1.1, 5.1, "1/3") {} }.should raise_error(error)
end
it "raises an #{error} with step as an alphanumeric string" do
- -> { 1.1.send(@method, *@step_args.call(5.1, "foo")) {} }.should raise_error(error)
+ -> { @step.call(1.1, 5.1, "foo") {} }.should raise_error(error)
end
end
end
it "does not rescue ArgumentError exceptions" do
- -> { 1.send(@method, *@step_args.call(2)) { raise ArgumentError, "" }}.should raise_error(ArgumentError)
+ -> { @step.call(1, 2) { raise ArgumentError, "" }}.should raise_error(ArgumentError)
end
it "does not rescue TypeError exceptions" do
- -> { 1.send(@method, *@step_args.call(2)) { raise TypeError, "" } }.should raise_error(TypeError)
+ -> { @step.call(1, 2) { raise TypeError, "" } }.should raise_error(TypeError)
end
describe "when no block is given" do
@@ -269,31 +270,31 @@ describe :numeric_step, :shared => true do
end
it "returns an #{step_enum_class} when step is 0" do
- 1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(step_enum_class)
+ @step.call(1, 2, 0).should be_an_instance_of(step_enum_class)
end
it "returns an #{step_enum_class} when not passed a block and self > stop" do
- 1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(step_enum_class)
+ @step.call(1, 0, 2).should be_an_instance_of(step_enum_class)
end
it "returns an #{step_enum_class} when not passed a block and self < stop" do
- 1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(step_enum_class)
+ @step.call(1, 2, 3).should be_an_instance_of(step_enum_class)
end
it "returns an #{step_enum_class} that uses the given step" do
- 0.send(@method, *@step_args.call(5, 2)).to_a.should eql [0, 2, 4]
+ @step.call(0, 5, 2).to_a.should eql [0, 2, 4]
end
describe "when step is a String" do
describe "with self and stop as Fixnums" do
it "returns an Enumerator" do
- 1.send(@method, *@step_args.call(5, "foo")).should be_an_instance_of(Enumerator)
+ @step.call(1, 5, "foo").should be_an_instance_of(Enumerator)
end
end
describe "with self and stop as Floats" do
it "returns an Enumerator" do
- 1.1.send(@method, *@step_args.call(5.1, "foo")).should be_an_instance_of(Enumerator)
+ @step.call(1.1, 5.1, "foo").should be_an_instance_of(Enumerator)
end
end
end
@@ -311,119 +312,119 @@ describe :numeric_step, :shared => true do
describe "with self and stop as Fixnums" do
it "raises an #{error} when step is a numeric representation" do
- -> { 1.send(@method, *@step_args.call(5, "1")).size }.should raise_error(error)
- -> { 1.send(@method, *@step_args.call(5, "0.1")).size }.should raise_error(error)
- -> { 1.send(@method, *@step_args.call(5, "1/3")).size }.should raise_error(error)
+ -> { @step.call(1, 5, "1").size }.should raise_error(error)
+ -> { @step.call(1, 5, "0.1").size }.should raise_error(error)
+ -> { @step.call(1, 5, "1/3").size }.should raise_error(error)
end
it "raises an #{error} with step as an alphanumeric string" do
- -> { 1.send(@method, *@step_args.call(5, "foo")).size }.should raise_error(error)
+ -> { @step.call(1, 5, "foo").size }.should raise_error(error)
end
end
describe "with self and stop as Floats" do
it "raises an #{error} when step is a numeric representation" do
- -> { 1.1.send(@method, *@step_args.call(5.1, "1")).size }.should raise_error(error)
- -> { 1.1.send(@method, *@step_args.call(5.1, "0.1")).size }.should raise_error(error)
- -> { 1.1.send(@method, *@step_args.call(5.1, "1/3")).size }.should raise_error(error)
+ -> { @step.call(1.1, 5.1, "1").size }.should raise_error(error)
+ -> { @step.call(1.1, 5.1, "0.1").size }.should raise_error(error)
+ -> { @step.call(1.1, 5.1, "1/3").size }.should raise_error(error)
end
it "raises an #{error} with step as an alphanumeric string" do
- -> { 1.1.send(@method, *@step_args.call(5.1, "foo")).size }.should raise_error(error)
+ -> { @step.call(1.1, 5.1, "foo").size }.should raise_error(error)
end
end
end
describe "when self, stop and step are Fixnums and step is positive" do
it "returns the difference between self and stop divided by the number of steps" do
- 5.send(@method, *@step_args.call(10, 11)).size.should == 1
- 5.send(@method, *@step_args.call(10, 6)).size.should == 1
- 5.send(@method, *@step_args.call(10, 5)).size.should == 2
- 5.send(@method, *@step_args.call(10, 4)).size.should == 2
- 5.send(@method, *@step_args.call(10, 2)).size.should == 3
- 5.send(@method, *@step_args.call(10, 1)).size.should == 6
- 5.send(@method, *@step_args.call(10)).size.should == 6
- 10.send(@method, *@step_args.call(10, 1)).size.should == 1
+ @step.call(5, 10, 11).size.should == 1
+ @step.call(5, 10, 6).size.should == 1
+ @step.call(5, 10, 5).size.should == 2
+ @step.call(5, 10, 4).size.should == 2
+ @step.call(5, 10, 2).size.should == 3
+ @step.call(5, 10, 1).size.should == 6
+ @step.call(5, 10).size.should == 6
+ @step.call(10, 10, 1).size.should == 1
end
it "returns 0 if value > limit" do
- 11.send(@method, *@step_args.call(10, 1)).size.should == 0
+ @step.call(11, 10, 1).size.should == 0
end
end
describe "when self, stop and step are Fixnums and step is negative" do
it "returns the difference between self and stop divided by the number of steps" do
- 10.send(@method, *@step_args.call(5, -11)).size.should == 1
- 10.send(@method, *@step_args.call(5, -6)).size.should == 1
- 10.send(@method, *@step_args.call(5, -5)).size.should == 2
- 10.send(@method, *@step_args.call(5, -4)).size.should == 2
- 10.send(@method, *@step_args.call(5, -2)).size.should == 3
- 10.send(@method, *@step_args.call(5, -1)).size.should == 6
- 10.send(@method, *@step_args.call(10, -1)).size.should == 1
+ @step.call(10, 5, -11).size.should == 1
+ @step.call(10, 5, -6).size.should == 1
+ @step.call(10, 5, -5).size.should == 2
+ @step.call(10, 5, -4).size.should == 2
+ @step.call(10, 5, -2).size.should == 3
+ @step.call(10, 5, -1).size.should == 6
+ @step.call(10, 10, -1).size.should == 1
end
it "returns 0 if value < limit" do
- 10.send(@method, *@step_args.call(11, -1)).size.should == 0
+ @step.call(10, 11, -1).size.should == 0
end
end
describe "when self, stop or step is a Float" do
describe "and step is positive" do
it "returns the difference between self and stop divided by the number of steps" do
- 5.send(@method, *@step_args.call(10, 11.0)).size.should == 1
- 5.send(@method, *@step_args.call(10, 6.0)).size.should == 1
- 5.send(@method, *@step_args.call(10, 5.0)).size.should == 2
- 5.send(@method, *@step_args.call(10, 4.0)).size.should == 2
- 5.send(@method, *@step_args.call(10, 2.0)).size.should == 3
- 5.send(@method, *@step_args.call(10, 0.5)).size.should == 11
- 5.send(@method, *@step_args.call(10, 1.0)).size.should == 6
- 5.send(@method, *@step_args.call(10.5)).size.should == 6
- 10.send(@method, *@step_args.call(10, 1.0)).size.should == 1
+ @step.call(5, 10, 11.0).size.should == 1
+ @step.call(5, 10, 6.0).size.should == 1
+ @step.call(5, 10, 5.0).size.should == 2
+ @step.call(5, 10, 4.0).size.should == 2
+ @step.call(5, 10, 2.0).size.should == 3
+ @step.call(5, 10, 0.5).size.should == 11
+ @step.call(5, 10, 1.0).size.should == 6
+ @step.call(5, 10.5).size.should == 6
+ @step.call(10, 10, 1.0).size.should == 1
end
it "returns 0 if value > limit" do
- 10.send(@method, *@step_args.call(5.5)).size.should == 0
- 11.send(@method, *@step_args.call(10, 1.0)).size.should == 0
- 11.send(@method, *@step_args.call(10, 1.5)).size.should == 0
- 10.send(@method, *@step_args.call(5, infinity_value)).size.should == 0
+ @step.call(10, 5.5).size.should == 0
+ @step.call(11, 10, 1.0).size.should == 0
+ @step.call(11, 10, 1.5).size.should == 0
+ @step.call(10, 5, infinity_value).size.should == 0
end
it "returns 1 if step is infinity_value" do
- 5.send(@method, *@step_args.call(10, infinity_value)).size.should == 1
+ @step.call(5, 10, infinity_value).size.should == 1
end
end
describe "and step is negative" do
it "returns the difference between self and stop divided by the number of steps" do
- 10.send(@method, *@step_args.call(5, -11.0)).size.should == 1
- 10.send(@method, *@step_args.call(5, -6.0)).size.should == 1
- 10.send(@method, *@step_args.call(5, -5.0)).size.should == 2
- 10.send(@method, *@step_args.call(5, -4.0)).size.should == 2
- 10.send(@method, *@step_args.call(5, -2.0)).size.should == 3
- 10.send(@method, *@step_args.call(5, -0.5)).size.should == 11
- 10.send(@method, *@step_args.call(5, -1.0)).size.should == 6
- 10.send(@method, *@step_args.call(10, -1.0)).size.should == 1
+ @step.call(10, 5, -11.0).size.should == 1
+ @step.call(10, 5, -6.0).size.should == 1
+ @step.call(10, 5, -5.0).size.should == 2
+ @step.call(10, 5, -4.0).size.should == 2
+ @step.call(10, 5, -2.0).size.should == 3
+ @step.call(10, 5, -0.5).size.should == 11
+ @step.call(10, 5, -1.0).size.should == 6
+ @step.call(10, 10, -1.0).size.should == 1
end
it "returns 0 if value < limit" do
- 10.send(@method, *@step_args.call(11, -1.0)).size.should == 0
- 10.send(@method, *@step_args.call(11, -1.5)).size.should == 0
- 5.send(@method, *@step_args.call(10, -infinity_value)).size.should == 0
+ @step.call(10, 11, -1.0).size.should == 0
+ @step.call(10, 11, -1.5).size.should == 0
+ @step.call(5, 10, -infinity_value).size.should == 0
end
it "returns 1 if step is infinity_value" do
- 10.send(@method, *@step_args.call(5, -infinity_value)).size.should == 1
+ @step.call(10, 5, -infinity_value).size.should == 1
end
end
end
describe "when stop is not passed" do
it "returns infinity_value" do
- 1.send(@method, *@step_args.call()).size.should == infinity_value
+ @step.call(1).size.should == infinity_value
end
end
describe "when stop is nil" do
it "returns infinity_value" do
- 1.send(@method, *@step_args.call(nil, 5)).size.should == infinity_value
+ @step.call(1, nil, 5).size.should == infinity_value
end
end
end
diff --git a/spec/ruby/core/numeric/step_spec.rb b/spec/ruby/core/numeric/step_spec.rb
index fc80cc4ab0..e9067864c8 100644
--- a/spec/ruby/core/numeric/step_spec.rb
+++ b/spec/ruby/core/numeric/step_spec.rb
@@ -16,9 +16,8 @@ describe "Numeric#step" do
before :all do
# This lambda definition limits to return the arguments it receives.
# It's needed to test numeric_step behaviour with positional arguments.
- @step_args = -> *args { args }
+ @step = -> receiver, *args, &block { receiver.step(*args, &block) }
end
-
it_behaves_like :numeric_step, :step
describe "when no block is given" do
@@ -135,13 +134,12 @@ describe "Numeric#step" do
end
before :all do
- # This lambda transforms a positional step method args into
- # keyword arguments.
+ # This lambda transforms a positional step method args into keyword arguments.
# It's needed to test numeric_step behaviour with keyword arguments.
- @step_args = -> *args do
- kw_args = {to: args[0]}
+ @step = -> receiver, *args, &block do
+ kw_args = { to: args[0] }
kw_args[:by] = args[1] if args.size == 2
- [kw_args]
+ receiver.step(**kw_args, &block)
end
end
it_behaves_like :numeric_step, :step
@@ -183,16 +181,17 @@ describe "Numeric#step" do
end
end
end
+
before :all do
# This lambda definition transforms a positional step method args into
# a mix of positional and keyword arguments.
# It's needed to test numeric_step behaviour with positional mixed with
# keyword arguments.
- @step_args = -> *args do
+ @step = -> receiver, *args, &block do
if args.size == 2
- [args[0], {by: args[1]}]
+ receiver.step(args[0], by: args[1], &block)
else
- args
+ receiver.step(*args, &block)
end
end
end
diff --git a/spec/ruby/core/random/rand_spec.rb b/spec/ruby/core/random/rand_spec.rb
index b585aa9737..d1a76e5dac 100644
--- a/spec/ruby/core/random/rand_spec.rb
+++ b/spec/ruby/core/random/rand_spec.rb
@@ -1,10 +1,11 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
+require_relative 'shared/rand'
describe "Random.rand" do
- it "returns a Float if no max argument is passed" do
- Random.rand.should be_kind_of(Float)
- end
+ it_behaves_like :random_number, :rand, Random.new
+ it_behaves_like :random_number, :random_number, Random.new
+ it_behaves_like :random_number, :rand, Random
it "returns a Float >= 0 if no max argument is passed" do
floats = 200.times.map { Random.rand }
@@ -24,10 +25,6 @@ describe "Random.rand" do
floats_a.should == floats_b
end
- it "returns an Integer if an Integer argument is passed" do
- Random.rand(20).should be_kind_of(Integer)
- end
-
it "returns an Integer >= 0 if an Integer argument is passed" do
ints = 200.times.map { Random.rand(34) }
ints.min.should >= 0
@@ -221,3 +218,9 @@ describe "Random#rand with Range" do
end.should raise_error(ArgumentError)
end
end
+
+ruby_version_is "2.6" do
+ describe "Random.random_number" do
+ it_behaves_like :random_number, :random_number, Random
+ end
+end
diff --git a/spec/ruby/core/random/shared/bytes.rb b/spec/ruby/core/random/shared/bytes.rb
index fe8cd8d683..9afad3b7f8 100644
--- a/spec/ruby/core/random/shared/bytes.rb
+++ b/spec/ruby/core/random/shared/bytes.rb
@@ -1,17 +1,17 @@
describe :random_bytes, shared: true do
it "returns a String" do
- @object.bytes(1).should be_an_instance_of(String)
+ @object.send(@method, 1).should be_an_instance_of(String)
end
it "returns a String of the length given as argument" do
- @object.bytes(15).length.should == 15
+ @object.send(@method, 15).length.should == 15
end
it "returns a binary String" do
- @object.bytes(15).encoding.should == Encoding::BINARY
+ @object.send(@method, 15).encoding.should == Encoding::BINARY
end
it "returns a random binary String" do
- @object.bytes(12).should_not == @object.bytes(12)
+ @object.send(@method, 12).should_not == @object.send(@method, 12)
end
end
diff --git a/spec/ruby/core/random/shared/rand.rb b/spec/ruby/core/random/shared/rand.rb
new file mode 100644
index 0000000000..d3b24b8851
--- /dev/null
+++ b/spec/ruby/core/random/shared/rand.rb
@@ -0,0 +1,9 @@
+describe :random_number, shared: true do
+ it "returns a Float if no max argument is passed" do
+ @object.send(@method).should be_kind_of(Float)
+ end
+
+ it "returns an Integer if an Integer argument is passed" do
+ @object.send(@method, 20).should be_kind_of(Integer)
+ end
+end
diff --git a/spec/ruby/core/string/shared/encode.rb b/spec/ruby/core/string/shared/encode.rb
index b5a8bf9b72..a73de5b943 100644
--- a/spec/ruby/core/string/shared/encode.rb
+++ b/spec/ruby/core/string/shared/encode.rb
@@ -83,7 +83,7 @@ describe :string_encode, shared: true do
options = mock("string encode options")
options.should_receive(:to_hash).and_return({ undef: :replace })
- result = "あ\ufffdあ".send(@method, options)
+ result = "あ\ufffdあ".send(@method, **options)
result.should == "あ\ufffdあ"
end
@@ -145,7 +145,7 @@ describe :string_encode, shared: true do
options = mock("string encode options")
options.should_receive(:to_hash).and_return({ undef: :replace })
- result = "あ?あ".send(@method, Encoding::EUC_JP, options)
+ result = "あ?あ".send(@method, Encoding::EUC_JP, **options)
xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding('utf-8')
result.should == "#{xA4xA2}?#{xA4xA2}".force_encoding("euc-jp")
end
@@ -189,7 +189,7 @@ describe :string_encode, shared: true do
xFF = [0xFF].pack('C').force_encoding('utf-8')
str = "ab#{xFF}c".force_encoding Encoding::BINARY
- str.send(@method, "iso-8859-1", "utf-8", options).should == "ab?c"
+ str.send(@method, "iso-8859-1", "utf-8", **options).should == "ab?c"
end
end
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/classes.rb b/spec/ruby/core/thread/backtrace/location/fixtures/classes.rb
index 3e42d8cf81..e903c3e450 100644
--- a/spec/ruby/core/thread/backtrace/location/fixtures/classes.rb
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/classes.rb
@@ -14,4 +14,22 @@ module ThreadBacktraceLocationSpecs
return caller_locations(0)
end
end
+
+ def self.locations_inside_nested_blocks
+ first_level_location = nil
+ second_level_location = nil
+ third_level_location = nil
+
+ 1.times do
+ first_level_location = locations[0]
+ 1.times do
+ second_level_location = locations[0]
+ 1.times do
+ third_level_location = locations[0]
+ end
+ end
+ end
+
+ [first_level_location, second_level_location, third_level_location]
+ end
end
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_main.rb b/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_main.rb
new file mode 100644
index 0000000000..b124c8161c
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_main.rb
@@ -0,0 +1,5 @@
+1.times do
+ puts Thread.current.backtrace_locations(1..1)[0].label
+end
+
+require_relative 'locations_in_required'
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_required.rb b/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_required.rb
new file mode 100644
index 0000000000..5f5ed89e98
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_required.rb
@@ -0,0 +1,3 @@
+1.times do
+ puts Thread.current.backtrace_locations(1..1)[0].label
+end
diff --git a/spec/ruby/core/thread/backtrace/location/label_spec.rb b/spec/ruby/core/thread/backtrace/location/label_spec.rb
index be8da5646f..7312d017e5 100644
--- a/spec/ruby/core/thread/backtrace/location/label_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/label_spec.rb
@@ -17,4 +17,21 @@ describe 'Thread::Backtrace::Location#label' do
it 'returns the module name for a module location' do
ThreadBacktraceLocationSpecs::MODULE_LOCATION[0].label.should include "ThreadBacktraceLocationSpecs"
end
+
+ it 'includes the nesting level of a block as part of the location label' do
+ first_level_location, second_level_location, third_level_location =
+ ThreadBacktraceLocationSpecs.locations_inside_nested_blocks
+
+ first_level_location.label.should == 'block in locations_inside_nested_blocks'
+ second_level_location.label.should == 'block (2 levels) in locations_inside_nested_blocks'
+ third_level_location.label.should == 'block (3 levels) in locations_inside_nested_blocks'
+ end
+
+ it 'sets the location label for a top-level block differently depending on it being in the main file or a required file' do
+ path = fixture(__FILE__, "locations_in_main.rb")
+ main_label, required_label = ruby_exe(path).lines
+
+ main_label.should == "block in <main>\n"
+ required_label.should == "block in <top (required)>\n"
+ end
end
diff --git a/spec/ruby/core/thread/backtrace_locations_spec.rb b/spec/ruby/core/thread/backtrace_locations_spec.rb
new file mode 100644
index 0000000000..66947f8ea6
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace_locations_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+describe "Thread#backtrace_locations" do
+ it "returns an Array" do
+ locations = Thread.current.backtrace_locations
+ locations.should be_an_instance_of(Array)
+ locations.should_not be_empty
+ end
+
+ it "sets each element to a Thread::Backtrace::Location" do
+ locations = Thread.current.backtrace_locations
+ locations.each { |loc| loc.should be_an_instance_of(Thread::Backtrace::Location) }
+ end
+
+ it "can be called on any Thread" do
+ locations = Thread.new { Thread.current.backtrace_locations }.value
+ locations.should be_an_instance_of(Array)
+ locations.should_not be_empty
+ locations.each { |loc| loc.should be_an_instance_of(Thread::Backtrace::Location) }
+ end
+
+ it "without argument is the same as showing all locations with 0..-1" do
+ Thread.current.backtrace_locations.map(&:to_s).should == Thread.current.backtrace_locations(0..-1).map(&:to_s)
+ end
+
+ it "the first location reports the call to #backtrace_locations" do
+ Thread.current.backtrace_locations(0..0)[0].to_s.should == "#{__FILE__ }:#{__LINE__ }:in `backtrace_locations'"
+ end
+
+ it "[1..-1] is the same as #caller_locations(0..-1) for Thread.current" do
+ Thread.current.backtrace_locations(1..-1).map(&:to_s).should == caller_locations(0..-1).map(&:to_s)
+ end
+end
diff --git a/spec/ruby/core/unboundmethod/fixtures/classes.rb b/spec/ruby/core/unboundmethod/fixtures/classes.rb
index 43e21916bf..46b1c51669 100644
--- a/spec/ruby/core/unboundmethod/fixtures/classes.rb
+++ b/spec/ruby/core/unboundmethod/fixtures/classes.rb
@@ -34,6 +34,7 @@ module UnboundMethodSpecs
def with_block(&block); end
alias bar foo
+ alias baz bar
alias alias_1 foo
alias alias_2 foo
diff --git a/spec/ruby/core/unboundmethod/original_name_spec.rb b/spec/ruby/core/unboundmethod/original_name_spec.rb
new file mode 100644
index 0000000000..7280dcb2b4
--- /dev/null
+++ b/spec/ruby/core/unboundmethod/original_name_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "UnboundMethod#original_name" do
+ it "returns the name of the method" do
+ String.instance_method(:upcase).original_name.should == :upcase
+ end
+
+ it "returns the original name" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:foo).unbind.original_name.should == :foo
+ obj.method(:bar).unbind.original_name.should == :foo
+ UnboundMethodSpecs::Methods.instance_method(:bar).original_name.should == :foo
+ end
+
+ it "returns the original name even when aliased twice" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:foo).unbind.original_name.should == :foo
+ obj.method(:baz).unbind.original_name.should == :foo
+ UnboundMethodSpecs::Methods.instance_method(:baz).original_name.should == :foo
+ end
+end
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb
index f8bfc8d9ed..e5c9fcb762 100644
--- a/spec/ruby/language/block_spec.rb
+++ b/spec/ruby/language/block_spec.rb
@@ -6,14 +6,6 @@ describe "A block yielded a single" do
def m(a) yield a end
end
- def supress_keyword_warning(&block)
- if RUBY_VERSION > '2.7'
- suppress_warning(&block)
- else
- yield
- end
- end
-
context "Array" do
it "assigns the Array to a single argument" do
m([1, 2]) { |a| a }.should == [1, 2]
@@ -53,21 +45,21 @@ describe "A block yielded a single" do
end
it "assigns elements to mixed argument types" do
- supress_keyword_warning do
+ suppress_keyword_warning do
result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] }
result.should == [1, 2, [], 3, 2, {x: 9}]
end
end
it "assigns symbol keys from a Hash to keyword arguments" do
- supress_keyword_warning do
+ suppress_keyword_warning do
result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] }
result.should == [{"a" => 1}, a: 10]
end
end
it "assigns symbol keys from a Hash returned by #to_hash to keyword arguments" do
- supress_keyword_warning do
+ suppress_keyword_warning do
obj = mock("coerce block keyword arguments")
obj.should_receive(:to_hash).and_return({"a" => 1, b: 2})
@@ -76,7 +68,7 @@ describe "A block yielded a single" do
end
end
- ruby_version_is "0"..."2.7" do
+ ruby_version_is ""..."2.7" do
it "calls #to_hash on the argument and uses resulting hash as first argument when optional argument and keyword argument accepted" do
obj = mock("coerce block keyword arguments")
obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2})
@@ -98,7 +90,7 @@ describe "A block yielded a single" do
describe "when non-symbol keys are in a keyword arguments Hash" do
it "separates non-symbol keys and symbol keys" do
- supress_keyword_warning do
+ suppress_keyword_warning do
result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] }
result.should == [{"a" => 10}, {b: 2}]
end
@@ -111,7 +103,7 @@ describe "A block yielded a single" do
end
it "calls #to_hash on the last element if keyword arguments are present" do
- supress_keyword_warning do
+ suppress_keyword_warning do
obj = mock("destructure block keyword arguments")
obj.should_receive(:to_hash).and_return({x: 9})
@@ -121,7 +113,7 @@ describe "A block yielded a single" do
end
it "assigns the last element to a non-keyword argument if #to_hash returns nil" do
- supress_keyword_warning do
+ suppress_keyword_warning do
obj = mock("destructure block keyword arguments")
obj.should_receive(:to_hash).and_return(nil)
@@ -131,7 +123,7 @@ describe "A block yielded a single" do
end
it "calls #to_hash on the last element when there are more arguments than parameters" do
- supress_keyword_warning do
+ suppress_keyword_warning do
x = mock("destructure matching block keyword argument")
x.should_receive(:to_hash).and_return({x: 9})
diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb
index 79131e9da6..6f2e8e5cf0 100644
--- a/spec/ruby/language/hash_spec.rb
+++ b/spec/ruby/language/hash_spec.rb
@@ -128,7 +128,7 @@ describe "Hash literal" do
{a: 1, **obj, c: 3}.should == {a:1, b: 2, c: 3, d: 4}
end
- ruby_version_is "0"..."2.7" do
+ ruby_version_is ""..."2.7" do
it "raises a TypeError if any splatted elements keys are not symbols" do
h = {1 => 2, b: 3}
-> { {a: 1, **h} }.should raise_error(TypeError)
diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb
index 3b06a0d595..5fa7fa6bfa 100644
--- a/spec/ruby/language/lambda_spec.rb
+++ b/spec/ruby/language/lambda_spec.rb
@@ -186,14 +186,6 @@ describe "A lambda literal -> () { }" do
@a.().should == {}
@a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- def self.suppress_keyword_warning(&block)
- if RUBY_VERSION > '2.7'
- suppress_warning(&block)
- else
- yield
- end
- end
-
suppress_keyword_warning do
h = mock("keyword splat")
h.should_receive(:to_hash).and_return({a: 1})
@@ -530,14 +522,6 @@ describe "A lambda expression 'lambda { ... }'" do
@a.().should == {}
@a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- def self.suppress_keyword_warning(&block)
- if RUBY_VERSION > '2.7'
- suppress_warning(&block)
- else
- yield
- end
- end
-
suppress_keyword_warning do
h = mock("keyword splat")
h.should_receive(:to_hash).and_return({a: 1})
diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb
index 410dba99e2..0486025792 100644
--- a/spec/ruby/language/method_spec.rb
+++ b/spec/ruby/language/method_spec.rb
@@ -480,15 +480,6 @@ describe "A method" do
end
context "assigns local variables from method parameters" do
-
- suppress_keyword_warning = ->(&block) do
- if RUBY_VERSION >= '2.7'
- suppress_warning(&block)
- else
- block.call
- end
- end
-
evaluate <<-ruby do
def m(a) a end
ruby
@@ -555,7 +546,7 @@ describe "A method" do
-> { m() }.should raise_error(ArgumentError)
m(a: 1).should == 1
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
-> { m("a" => 1, a: 1) }.should raise_error(ArgumentError)
end
end
@@ -717,7 +708,7 @@ describe "A method" do
ruby
m(1, b: 2).should == [1, 2]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
-> { m("a" => 1, b: 2) }.should raise_error(ArgumentError)
end
end
@@ -728,7 +719,7 @@ describe "A method" do
m(2).should == [2, 1]
m(1, b: 2).should == [1, 2]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, 1]
end
end
@@ -739,7 +730,7 @@ describe "A method" do
m(1).should == 1
m(1, a: 2, b: 3).should == 1
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, b: 2).should == {"a" => 1, b: 2}
end
end
@@ -750,7 +741,7 @@ describe "A method" do
m(1).should == [1, {}]
m(1, a: 2, b: 3).should == [1, {a: 2, b: 3}]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, {}]
end
end
@@ -869,7 +860,7 @@ describe "A method" do
m(b: 2).should == [1, 2]
m(2, b: 1).should == [2, 1]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, b: 2).should == [{"a" => 1}, 2]
end
end
@@ -881,12 +872,12 @@ describe "A method" do
m().should == [1, 2]
m(2).should == [2, 2]
m(b: 3).should == [1, 3]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, b: 2).should == [{"a" => 1}, 2]
end
end
- ruby_version_is "0"..."2.7" do
+ ruby_version_is ""..."2.7" do
evaluate <<-ruby do
def m(a=1, **) a end
ruby
@@ -951,7 +942,7 @@ describe "A method" do
m(a: 1).should == 1
m(1, 2, a: 3).should == 3
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, a: 2).should == 2
end
end
@@ -962,7 +953,7 @@ describe "A method" do
m(b: 1).should == [[], 1]
m(1, 2, b: 3).should == [[1, 2], 3]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
end
end
@@ -975,7 +966,7 @@ describe "A method" do
m(1, 2).should == 1
m(a: 2).should == 2
m(1, a: 2).should == 2
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, a: 2).should == 2
end
end
@@ -986,7 +977,7 @@ describe "A method" do
m().should == [[], 1]
m(1, 2, 3, b: 4).should == [[1, 2, 3], 4]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
end
@@ -1005,7 +996,7 @@ describe "A method" do
h = mock("keyword splat")
h.should_receive(:to_hash).and_return({a: 1})
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
m(h).should be_nil
end
@@ -1015,7 +1006,7 @@ describe "A method" do
-> { m(h) }.should raise_error(error)
end
- ruby_version_is "0"..."2.7" do
+ ruby_version_is ""..."2.7" do
evaluate <<-ruby do
def m(*a, **) a end
ruby
@@ -1218,7 +1209,7 @@ describe "A method" do
ruby
m(a: 1, b: 2).should == [1, 2]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
-> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
end
end
@@ -1229,12 +1220,12 @@ describe "A method" do
m(a: 1).should == [1, 1]
m(a: 1, b: 2).should == [1, 2]
- suppress_keyword_warning.call do
+ suppress_keyword_warning do
-> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
end
end
- ruby_version_is '0'...'2.7' do
+ ruby_version_is ''...'2.7' do
evaluate <<-ruby do
def m(a:, **) a end
ruby
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb
index 27729750f1..7f740be25b 100644
--- a/spec/ruby/language/return_spec.rb
+++ b/spec/ruby/language/return_spec.rb
@@ -496,13 +496,12 @@ describe "The return keyword" do
ruby_version_is "2.7" do
it "warns but does not affect exit status" do
- ruby_exe(<<-END_OF_CODE).should == "-e: warning: argument of top-level return is ignored\n"
- $stderr.reopen($stdout)
- system(ENV['RUBY_EXE'], '-e', 'return 10')
- exit($?.exitstatus)
+ err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
+ return 10
END_OF_CODE
-
$?.exitstatus.should == 0
+
+ err.should =~ /warning: argument of top-level return is ignored/
end
end
end
diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb
index 5e6571893c..c56d5e8c26 100644
--- a/spec/ruby/language/send_spec.rb
+++ b/spec/ruby/language/send_spec.rb
@@ -265,11 +265,12 @@ describe "Invoking a private getter method" do
-> { receiver.call_self_foo_or_equals(6) }.should raise_error(NoMethodError)
end
end
+
ruby_version_is "2.7" do
it "permits self as a receiver" do
receiver = LangSendSpecs::PrivateGetter.new
- -> { receiver.call_self_foo }.should_not raise_error(NoMethodError)
- -> { receiver.call_self_foo_or_equals(6) }.should_not raise_error(NoMethodError)
+ receiver.call_self_foo_or_equals(6)
+ receiver.call_self_foo.should == 6
end
end
end
diff --git a/spec/ruby/library/cmath/math/acos_spec.rb b/spec/ruby/library/cmath/math/acos_spec.rb
new file mode 100644
index 0000000000..2e9104f835
--- /dev/null
+++ b/spec/ruby/library/cmath/math/acos_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/acos'
+
+ describe "Math#acos" do
+ it_behaves_like :complex_math_acos, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:acos)
+ end
+ end
+
+ describe "Math.acos" do
+ it_behaves_like :complex_math_acos, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/acosh_spec.rb b/spec/ruby/library/cmath/math/acosh_spec.rb
new file mode 100644
index 0000000000..809112f6c0
--- /dev/null
+++ b/spec/ruby/library/cmath/math/acosh_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/acosh'
+
+ describe "Math#acosh" do
+ it_behaves_like :complex_math_acosh, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:acosh)
+ end
+ end
+
+ describe "Math.acosh" do
+ it_behaves_like :complex_math_acosh, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/asin_spec.rb b/spec/ruby/library/cmath/math/asin_spec.rb
new file mode 100644
index 0000000000..4ac588ebd2
--- /dev/null
+++ b/spec/ruby/library/cmath/math/asin_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/asin'
+
+ describe "Math#asin" do
+ it_behaves_like :complex_math_asin, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:asin)
+ end
+ end
+
+ describe "Math.asin" do
+ it_behaves_like :complex_math_asin, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/asinh_spec.rb b/spec/ruby/library/cmath/math/asinh_spec.rb
new file mode 100644
index 0000000000..7d8b397a04
--- /dev/null
+++ b/spec/ruby/library/cmath/math/asinh_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/asinh'
+
+ describe "Math#asinh" do
+ it_behaves_like :complex_math_asinh, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:asinh)
+ end
+ end
+
+ describe "Math.asinh" do
+ it_behaves_like :complex_math_asinh, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/atan2_spec.rb b/spec/ruby/library/cmath/math/atan2_spec.rb
new file mode 100644
index 0000000000..1a9b7d7607
--- /dev/null
+++ b/spec/ruby/library/cmath/math/atan2_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/atan2'
+
+ describe "Math#atan2" do
+ it_behaves_like :complex_math_atan2, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:atan2)
+ end
+ end
+
+ describe "Math.atan2" do
+ it_behaves_like :complex_math_atan2, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/atan_spec.rb b/spec/ruby/library/cmath/math/atan_spec.rb
new file mode 100644
index 0000000000..b0171081a6
--- /dev/null
+++ b/spec/ruby/library/cmath/math/atan_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/atan'
+
+ describe "Math#atan" do
+ it_behaves_like :complex_math_atan, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:atan)
+ end
+ end
+
+ describe "Math.atan" do
+ it_behaves_like :complex_math_atan, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/atanh_spec.rb b/spec/ruby/library/cmath/math/atanh_spec.rb
new file mode 100644
index 0000000000..6b22c6c9e4
--- /dev/null
+++ b/spec/ruby/library/cmath/math/atanh_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative '../../../fixtures/math/common'
+ require_relative '../../../shared/math/atanh'
+ require_relative 'shared/atanh'
+
+ describe "Math#atanh" do
+ it_behaves_like :math_atanh_base, :atanh, IncludesMath.new
+ it_behaves_like :complex_math_atanh_complex, :atanh, IncludesMath.new
+
+ it_behaves_like :math_atanh_private, :atanh, IncludesMath.new
+ end
+
+ describe "Math.atanh" do
+ it_behaves_like :math_atanh_base, :atanh, CMath
+ it_behaves_like :complex_math_atanh_complex, :atanh, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/cos_spec.rb b/spec/ruby/library/cmath/math/cos_spec.rb
new file mode 100644
index 0000000000..3f097bcb3b
--- /dev/null
+++ b/spec/ruby/library/cmath/math/cos_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/cos'
+
+ describe "Math#cos" do
+ it_behaves_like :complex_math_cos, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:cos)
+ end
+ end
+
+ describe "Math.cos" do
+ it_behaves_like :complex_math_cos, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/cosh_spec.rb b/spec/ruby/library/cmath/math/cosh_spec.rb
new file mode 100644
index 0000000000..197f899981
--- /dev/null
+++ b/spec/ruby/library/cmath/math/cosh_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/cosh'
+
+ describe "Math#cosh" do
+ it_behaves_like :complex_math_cosh, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:cosh)
+ end
+ end
+
+ describe "Math.cosh" do
+ it_behaves_like :complex_math_cosh, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/exp_spec.rb b/spec/ruby/library/cmath/math/exp_spec.rb
new file mode 100644
index 0000000000..eef2ec3129
--- /dev/null
+++ b/spec/ruby/library/cmath/math/exp_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/exp'
+
+ describe "Math#exp" do
+ it_behaves_like :complex_math_exp, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:exp)
+ end
+ end
+
+ describe "Math.exp" do
+ it_behaves_like :complex_math_exp, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/fixtures/classes.rb b/spec/ruby/library/cmath/math/fixtures/classes.rb
new file mode 100644
index 0000000000..443c1a9ace
--- /dev/null
+++ b/spec/ruby/library/cmath/math/fixtures/classes.rb
@@ -0,0 +1,4 @@
+require 'cmath'
+class IncludesMath
+ include CMath
+end
diff --git a/spec/ruby/library/cmath/math/log10_spec.rb b/spec/ruby/library/cmath/math/log10_spec.rb
new file mode 100644
index 0000000000..603bbb1457
--- /dev/null
+++ b/spec/ruby/library/cmath/math/log10_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/log10'
+
+ describe "Math#log10" do
+ it_behaves_like :complex_math_log10, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:log10)
+ end
+ end
+
+ describe "Math.log10" do
+ it_behaves_like :complex_math_log10, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/log_spec.rb b/spec/ruby/library/cmath/math/log_spec.rb
new file mode 100644
index 0000000000..b4da781323
--- /dev/null
+++ b/spec/ruby/library/cmath/math/log_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/log'
+
+ describe "Math#log" do
+ it_behaves_like :complex_math_log, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:log)
+ end
+ end
+
+ describe "Math.log" do
+ it_behaves_like :complex_math_log, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/acos.rb b/spec/ruby/library/cmath/math/shared/acos.rb
new file mode 100644
index 0000000000..65637fa838
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/acos.rb
@@ -0,0 +1,41 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_acos, shared: true do
+ it "returns the arccosine of the passed argument" do
+ @object.send(:acos, 1).should be_close(0.0, TOLERANCE)
+ @object.send(:acos, 0).should be_close(1.5707963267949, TOLERANCE)
+ @object.send(:acos, -1).should be_close(Math::PI,TOLERANCE)
+ end
+
+ it "returns the arccosine for Complex numbers" do
+ @object.send(:acos, Complex(3, 4)).should be_close(Complex(0.93681246115572, -2.30550903124348), TOLERANCE)
+ end
+
+ it "returns the arccosine for numbers greater than 1.0 as a Complex number" do
+ @object.send(:acos, 1.0001).should be_close(Complex(0.0, 0.0141420177752494), TOLERANCE)
+ end
+
+ it "returns the arccosine for numbers less than -1.0 as a Complex number" do
+ @object.send(:acos, -1.0001).should be_close(Complex(3.14159265358979, -0.0141420177752495), TOLERANCE)
+ end
+end
+
+describe :complex_math_acos_bang, shared: true do
+ it "returns the arccosine of the argument" do
+ @object.send(:acos!, 1).should be_close(0.0, TOLERANCE)
+ @object.send(:acos!, 0).should be_close(1.5707963267949, TOLERANCE)
+ @object.send(:acos!, -1).should be_close(Math::PI,TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:acos!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+
+ it "raises an Errno::EDOM for numbers greater than 1.0" do
+ -> { @object.send(:acos!, 1.0001) }.should raise_error(Errno::EDOM)
+ end
+
+ it "raises an Errno::EDOM for numbers less than -1.0" do
+ -> { @object.send(:acos!, -1.0001) }.should raise_error(Errno::EDOM)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/acosh.rb b/spec/ruby/library/cmath/math/shared/acosh.rb
new file mode 100644
index 0000000000..285b0b823f
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/acosh.rb
@@ -0,0 +1,37 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_acosh, shared: true do
+ it "returns the principle value of the inverse hyperbolic cosine of the argument" do
+ @object.send(:acosh, 14.2).should be_close(3.345146999647, TOLERANCE)
+ @object.send(:acosh, 1.0).should be_close(0.0, TOLERANCE)
+ end
+
+ it "returns the principle value of the inverse hyperbolic cosine for numbers less than 1.0 as a Complex number" do
+ @object.send(:acosh, 1.0 - TOLERANCE).should be_close(Complex(0.0, 0.00774598605746135), TOLERANCE)
+ @object.send(:acosh, 0).should be_close(Complex(0.0, 1.5707963267949), TOLERANCE)
+ @object.send(:acosh, -1.0).should be_close(Complex(0.0, 3.14159265358979), TOLERANCE)
+ end
+
+ it "returns the principle value of the inverse hyperbolic cosine for Complex numbers" do
+ @object.send(:acosh, Complex(3, 4))
+ @object.send(:acosh, Complex(3, 4)).imaginary.should be_close(0.93681246115572, TOLERANCE)
+ @object.send(:acosh, Complex(3, 4)).real.should be_close(2.305509031243477, TOLERANCE)
+ end
+end
+
+describe :complex_math_acosh_bang, shared: true do
+ it "returns the principle value of the inverse hyperbolic cosine of the argument" do
+ @object.send(:acosh!, 14.2).should be_close(3.345146999647, TOLERANCE)
+ @object.send(:acosh!, 1.0).should be_close(0.0, TOLERANCE)
+ end
+
+ it "raises Errno::EDOM for numbers less than 1.0" do
+ -> { @object.send(:acosh!, 1.0 - TOLERANCE) }.should raise_error(Errno::EDOM)
+ -> { @object.send(:acosh!, 0) }.should raise_error(Errno::EDOM)
+ -> { @object.send(:acosh!, -1.0) }.should raise_error(Errno::EDOM)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:acosh!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/asin.rb b/spec/ruby/library/cmath/math/shared/asin.rb
new file mode 100644
index 0000000000..91fed7aa06
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/asin.rb
@@ -0,0 +1,47 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_asin, shared: true do
+ it "returns the arcsine of the argument" do
+ @object.send(:asin, 1).should be_close(Math::PI/2, TOLERANCE)
+ @object.send(:asin, 0).should be_close(0.0, TOLERANCE)
+ @object.send(:asin, -1).should be_close(-Math::PI/2, TOLERANCE)
+ @object.send(:asin, 0.25).should be_close(0.252680255142079, TOLERANCE)
+ @object.send(:asin, 0.50).should be_close(0.523598775598299, TOLERANCE)
+ @object.send(:asin, 0.75).should be_close(0.8480620789814816,TOLERANCE)
+ end
+
+ it "returns the arcsine for Complex numbers" do
+ @object.send(:asin, Complex(3, 4)).should be_close(Complex(0.633983865639174, 2.30550903124347), TOLERANCE)
+ end
+
+ it "returns a Complex number when the argument is greater than 1.0" do
+ @object.send(:asin, 1.0001).should be_close(Complex(1.5707963267949, -0.0141420177752494), TOLERANCE)
+ end
+
+ it "returns a Complex number when the argument is less than -1.0" do
+ @object.send(:asin, -1.0001).should be_close(Complex(-1.5707963267949, 0.0141420177752494), TOLERANCE)
+ end
+end
+
+describe :complex_math_asin_bang, shared: true do
+ it "returns the arcsine of the argument" do
+ @object.send(:asin!, 1).should be_close(Math::PI/2, TOLERANCE)
+ @object.send(:asin!, 0).should be_close(0.0, TOLERANCE)
+ @object.send(:asin!, -1).should be_close(-Math::PI/2, TOLERANCE)
+ @object.send(:asin!, 0.25).should be_close(0.252680255142079, TOLERANCE)
+ @object.send(:asin!, 0.50).should be_close(0.523598775598299, TOLERANCE)
+ @object.send(:asin!, 0.75).should be_close(0.8480620789814816,TOLERANCE)
+ end
+
+ it "raises an Errno::EDOM if the argument is greater than 1.0" do
+ -> { @object.send(:asin!, 1.0001) }.should raise_error( Errno::EDOM)
+ end
+
+ it "raises an Errno::EDOM if the argument is less than -1.0" do
+ -> { @object.send(:asin!, -1.0001) }.should raise_error( Errno::EDOM)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:asin!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/asinh.rb b/spec/ruby/library/cmath/math/shared/asinh.rb
new file mode 100644
index 0000000000..b4ddd3a22e
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/asinh.rb
@@ -0,0 +1,32 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_asinh, shared: true do
+ it "returns the inverse hyperbolic sin of the argument" do
+ @object.send(:asinh, 1.5).should be_close(1.19476321728711, TOLERANCE)
+ @object.send(:asinh, -2.97).should be_close(-1.8089166921397, TOLERANCE)
+ @object.send(:asinh, 0.0).should == 0.0
+ @object.send(:asinh, -0.0).should == -0.0
+ @object.send(:asinh, 1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
+ @object.send(:asinh, -1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
+ end
+
+ it "returns the inverse hyperbolic sin for Complex numbers" do
+ @object.send(:asinh, Complex(3, 4)).should be_close(Complex(2.29991404087927, 0.917616853351479), TOLERANCE)
+ @object.send(:asinh, Complex(3.5, -4)).should be_close(Complex(2.36263337274419, -0.843166327537659), TOLERANCE)
+ end
+end
+
+describe :complex_math_asinh_bang, shared: true do
+ it "returns the inverse hyperbolic sin of the argument" do
+ @object.send(:asinh!, 1.5).should be_close(1.19476321728711, TOLERANCE)
+ @object.send(:asinh!, -2.97).should be_close(-1.8089166921397, TOLERANCE)
+ @object.send(:asinh!, 0.0).should == 0.0
+ @object.send(:asinh!, -0.0).should == -0.0
+ @object.send(:asinh!, 1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
+ @object.send(:asinh!, -1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:asinh!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/atan.rb b/spec/ruby/library/cmath/math/shared/atan.rb
new file mode 100644
index 0000000000..63a496e841
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/atan.rb
@@ -0,0 +1,32 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_atan, shared: true do
+ it "returns the arctangent of the argument" do
+ @object.send(:atan, 1).should be_close(Math::PI/4, TOLERANCE)
+ @object.send(:atan, 0).should be_close(0.0, TOLERANCE)
+ @object.send(:atan, -1).should be_close(-Math::PI/4, TOLERANCE)
+ @object.send(:atan, 0.25).should be_close(0.244978663126864, TOLERANCE)
+ @object.send(:atan, 0.50).should be_close(0.463647609000806, TOLERANCE)
+ @object.send(:atan, 0.75).should be_close(0.643501108793284, TOLERANCE)
+ end
+
+ it "returns the arctangent for Complex numbers" do
+ @object.send(:atan, Complex(3, 4)).should be_close(Complex(1.44830699523146, 0.158997191679999), TOLERANCE)
+ @object.send(:atan, Complex(3.5, -4)).should be_close(Complex(1.44507428165589, -0.140323762363786), TOLERANCE)
+ end
+end
+
+describe :complex_math_atan_bang, shared: true do
+ it "returns the arctangent of the argument" do
+ @object.send(:atan!, 1).should be_close(Math::PI/4, TOLERANCE)
+ @object.send(:atan!, 0).should be_close(0.0, TOLERANCE)
+ @object.send(:atan!, -1).should be_close(-Math::PI/4, TOLERANCE)
+ @object.send(:atan!, 0.25).should be_close(0.244978663126864, TOLERANCE)
+ @object.send(:atan!, 0.50).should be_close(0.463647609000806, TOLERANCE)
+ @object.send(:atan!, 0.75).should be_close(0.643501108793284, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:atan!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/atan2.rb b/spec/ruby/library/cmath/math/shared/atan2.rb
new file mode 100644
index 0000000000..6d89423924
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/atan2.rb
@@ -0,0 +1,34 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_atan2, shared: true do
+ it "returns the arc tangent of the passed arguments" do
+ @object.send(:atan2, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
+ @object.send(:atan2, 0.0, 1.0).should be_close(0.0, TOLERANCE)
+ @object.send(:atan2, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
+ @object.send(:atan2, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
+ end
+
+ it "returns the arc tangent for two Complex numbers" do
+ CMath.atan2(Complex(3, 4), Complex(3.5, -4)).should be_close(Complex(-0.641757436698881, 1.10829873031207), TOLERANCE)
+ end
+
+ it "returns the arc tangent for Complex and real numbers" do
+ CMath.atan2(Complex(3, 4), -7).should be_close(Complex(2.61576754731561, -0.494290673139855), TOLERANCE)
+ CMath.atan2(5, Complex(3.5, -4)).should be_close(Complex(0.739102348493673, 0.487821626522923), TOLERANCE)
+ end
+end
+
+describe :complex_math_atan2_bang, shared: true do
+ it "returns the arc tangent of the passed arguments" do
+ @object.send(:atan2!, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
+ @object.send(:atan2!, 0.0, 1.0).should be_close(0.0, TOLERANCE)
+ @object.send(:atan2!, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
+ @object.send(:atan2!, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:atan2!, Complex(4, 5), Complex(4, 5)) }.should raise_error(TypeError)
+ -> { @object.send(:atan2!, 4, Complex(4, 5)) }.should raise_error(TypeError)
+ -> { @object.send(:atan2!, Complex(4, 5), 5) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/atanh.rb b/spec/ruby/library/cmath/math/shared/atanh.rb
new file mode 100644
index 0000000000..ae80e61bec
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/atanh.rb
@@ -0,0 +1,30 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_atanh_complex, shared: true do
+ it "returns the inverse hyperbolic tangent as a Complex number for arguments greater than 1.0" do
+ value = Complex(18.36840028483855, 1.5707963267948966)
+ @object.send(@method, 1.0 + Float::EPSILON).should be_close(value, TOLERANCE)
+
+ value = Complex(0.100335347731076, 1.5707963267949)
+ @object.send(@method, 10).should be_close(value, TOLERANCE)
+ end
+
+ it "returns the inverse hyperbolic tangent as a Complex number for arguments greater than 1.0" do
+ value = Complex(-18.36840028483855, 1.5707963267948966)
+ @object.send(@method, -1.0 - Float::EPSILON).should be_close(value, TOLERANCE)
+
+ value = Complex(0.100335347731076, 1.5707963267949)
+ @object.send(@method, 10).should be_close(value, TOLERANCE)
+ end
+
+ it "returns the inverse hyperbolic tangent for Complex numbers" do
+ value = Complex(0.117500907311434, 1.40992104959658)
+ @object.send(@method, Complex(3, 4)).should be_close(value, TOLERANCE)
+ end
+end
+
+describe :complex_math_atanh_no_complex, shared: true do
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:atanh!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/cos.rb b/spec/ruby/library/cmath/math/shared/cos.rb
new file mode 100644
index 0000000000..31cb5ab1e5
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/cos.rb
@@ -0,0 +1,30 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_cos, shared: true do
+ it "returns the cosine of the argument expressed in radians" do
+ @object.send(:cos, CMath::PI).should be_close(-1.0, TOLERANCE)
+ @object.send(:cos, 0).should be_close(1.0, TOLERANCE)
+ @object.send(:cos, CMath::PI/2).should be_close(0.0, TOLERANCE)
+ @object.send(:cos, 3*Math::PI/2).should be_close(0.0, TOLERANCE)
+ @object.send(:cos, 2*Math::PI).should be_close(1.0, TOLERANCE)
+ end
+
+ it "returns the cosine for Complex numbers" do
+ @object.send(:cos, Complex(0, CMath::PI)).should be_close(Complex(11.5919532755215, 0.0), TOLERANCE)
+ @object.send(:cos, Complex(3, 4)).should be_close(Complex(-27.0349456030742, -3.85115333481178), TOLERANCE)
+ end
+end
+
+describe :complex_math_cos_bang, shared: true do
+ it "returns the cosine of the argument expressed in radians" do
+ @object.send(:cos!, CMath::PI).should be_close(-1.0, TOLERANCE)
+ @object.send(:cos!, 0).should be_close(1.0, TOLERANCE)
+ @object.send(:cos!, CMath::PI/2).should be_close(0.0, TOLERANCE)
+ @object.send(:cos!, 3*Math::PI/2).should be_close(0.0, TOLERANCE)
+ @object.send(:cos!, 2*Math::PI).should be_close(1.0, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:cos!, Complex(3, 4)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/cosh.rb b/spec/ruby/library/cmath/math/shared/cosh.rb
new file mode 100644
index 0000000000..7cf561c985
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/cosh.rb
@@ -0,0 +1,28 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_cosh, shared: true do
+ it "returns the hyperbolic cosine of the passed argument" do
+ @object.send(:cosh, 0.0).should == 1.0
+ @object.send(:cosh, -0.0).should == 1.0
+ @object.send(:cosh, 1.5).should be_close(2.35240961524325, TOLERANCE)
+ @object.send(:cosh, -2.99).should be_close(9.96798496414416, TOLERANCE)
+ end
+
+ it "returns the hyperbolic cosine for Complex numbers" do
+ @object.send(:cosh, Complex(0, CMath::PI)).should be_close(Complex(-1.0, 0.0), TOLERANCE)
+ @object.send(:cosh, Complex(3, 4)).should be_close(Complex(-6.58066304055116, -7.58155274274654), TOLERANCE)
+ end
+end
+
+describe :complex_math_cosh_bang, shared: true do
+ it "returns the hyperbolic cosine of the passed argument" do
+ @object.send(:cosh!, 0.0).should == 1.0
+ @object.send(:cosh!, -0.0).should == 1.0
+ @object.send(:cosh!, 1.5).should be_close(2.35240961524325, TOLERANCE)
+ @object.send(:cosh!, -2.99).should be_close(9.96798496414416, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:cosh!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/exp.rb b/spec/ruby/library/cmath/math/shared/exp.rb
new file mode 100644
index 0000000000..6715ac63d3
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/exp.rb
@@ -0,0 +1,28 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_exp, shared: true do
+ it "returns the base-e exponential of the passed argument" do
+ @object.send(:exp, 0.0).should == 1.0
+ @object.send(:exp, -0.0).should == 1.0
+ @object.send(:exp, -1.8).should be_close(0.165298888221587, TOLERANCE)
+ @object.send(:exp, 1.25).should be_close(3.49034295746184, TOLERANCE)
+ end
+
+ it "returns the base-e exponential for Complex numbers" do
+ @object.send(:exp, Complex(0, 0)).should == Complex(1.0, 0.0)
+ @object.send(:exp, Complex(1, 3)).should be_close(Complex(-2.69107861381979, 0.383603953541131), TOLERANCE)
+ end
+end
+
+describe :complex_math_exp_bang, shared: true do
+ it "returns the base-e exponential of the passed argument" do
+ @object.send(:exp!, 0.0).should == 1.0
+ @object.send(:exp!, -0.0).should == 1.0
+ @object.send(:exp!, -1.8).should be_close(0.165298888221587, TOLERANCE)
+ @object.send(:exp!, 1.25).should be_close(3.49034295746184, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:exp!, Complex(1, 3)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/log.rb b/spec/ruby/library/cmath/math/shared/log.rb
new file mode 100644
index 0000000000..4b23e8c5f2
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/log.rb
@@ -0,0 +1,39 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_log, shared: true do
+ it "returns the natural logarithm of the passed argument" do
+ @object.send(:log, 0.0001).should be_close(-9.21034037197618, TOLERANCE)
+ @object.send(:log, 0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
+ @object.send(:log, 1).should be_close(0.0, TOLERANCE)
+ @object.send(:log, 10).should be_close( 2.30258509299405, TOLERANCE)
+ @object.send(:log, 10e15).should be_close(36.8413614879047, TOLERANCE)
+ end
+
+ it "returns the natural logarithm for Complex numbers" do
+ @object.send(:log, Complex(3, 4)).should be_close(Complex(1.6094379124341, 0.927295218001612), TOLERANCE)
+ @object.send(:log, Complex(-3, 4)).should be_close(Complex(1.6094379124341, 2.21429743558818), TOLERANCE)
+ end
+
+ it "returns the natural logarithm for negative numbers as a Complex number" do
+ @object.send(:log, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
+ @object.send(:log, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
+ end
+end
+
+describe :complex_math_log_bang, shared: true do
+ it "returns the natural logarithm of the argument" do
+ @object.send(:log!, 0.0001).should be_close(-9.21034037197618, TOLERANCE)
+ @object.send(:log!, 0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
+ @object.send(:log!, 1).should be_close(0.0, TOLERANCE)
+ @object.send(:log!, 10).should be_close( 2.30258509299405, TOLERANCE)
+ @object.send(:log!, 10e15).should be_close(36.8413614879047, TOLERANCE)
+ end
+
+ it "raises an Errno::EDOM if the argument is less than 0" do
+ -> { @object.send(:log!, -10) }.should raise_error(Errno::EDOM)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:log!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/log10.rb b/spec/ruby/library/cmath/math/shared/log10.rb
new file mode 100644
index 0000000000..f49934d958
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/log10.rb
@@ -0,0 +1,41 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_log10, shared: true do
+ it "returns the base-10 logarithm of the passed argument" do
+ @object.send(:log10, 0.0001).should be_close(-4.0, TOLERANCE)
+ @object.send(:log10, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
+ @object.send(:log10, 1).should be_close(0.0, TOLERANCE)
+ @object.send(:log10, 10).should be_close(1.0, TOLERANCE)
+ @object.send(:log10, 10e15).should be_close(16.0, TOLERANCE)
+ end
+
+ it "returns the base-10 logarithm for Complex numbers" do
+ @object.send(:log10, Complex(3, 4)).should be_close(Complex(0.698970004336019, 0.402719196273373), TOLERANCE)
+ @object.send(:log10, Complex(-3, 4)).should be_close(Complex(0.698970004336019, 0.961657157568468), TOLERANCE)
+ end
+
+ # BUG: does not work correctly, because Math#log10
+ # does not check for negative values
+ #it "returns the base-10 logarithm for negative numbers as a Complex number" do
+ # @object.send(:log10, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
+ # @object.send(:log10, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
+ #end
+end
+
+describe :complex_math_log10_bang, shared: true do
+ it "returns the base-10 logarithm of the argument" do
+ @object.send(:log10!, 0.0001).should be_close(-4.0, TOLERANCE)
+ @object.send(:log10!, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
+ @object.send(:log10!, 1).should be_close(0.0, TOLERANCE)
+ @object.send(:log10!, 10).should be_close(1.0, TOLERANCE)
+ @object.send(:log10!, 10e15).should be_close(16.0, TOLERANCE)
+ end
+
+ it "raises an Errno::EDOM when the passed argument is negative" do
+ -> { @object.send(:log10!, -10) }.should raise_error(Errno::EDOM)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:log10!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/sin.rb b/spec/ruby/library/cmath/math/shared/sin.rb
new file mode 100644
index 0000000000..1cb1b29cda
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/sin.rb
@@ -0,0 +1,30 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_sin, shared: true do
+ it "returns the sine of the passed argument expressed in radians" do
+ @object.send(:sin, CMath::PI).should be_close(0.0, TOLERANCE)
+ @object.send(:sin, 0).should be_close(0.0, TOLERANCE)
+ @object.send(:sin, CMath::PI/2).should be_close(1.0, TOLERANCE)
+ @object.send(:sin, 3*Math::PI/2).should be_close(-1.0, TOLERANCE)
+ @object.send(:sin, 2*Math::PI).should be_close(0.0, TOLERANCE)
+ end
+
+ it "returns the sine for Complex numbers" do
+ @object.send(:sin, Complex(0, CMath::PI)).should be_close(Complex(0.0, 11.5487393572577), TOLERANCE)
+ @object.send(:sin, Complex(3, 4)).should be_close(Complex(3.85373803791938, -27.0168132580039), TOLERANCE)
+ end
+end
+
+describe :complex_math_sin_bang, shared: true do
+ it "returns the sine of the passed argument expressed in radians" do
+ @object.send(:sin!, CMath::PI).should be_close(0.0, TOLERANCE)
+ @object.send(:sin!, 0).should be_close(0.0, TOLERANCE)
+ @object.send(:sin!, CMath::PI/2).should be_close(1.0, TOLERANCE)
+ @object.send(:sin!, 3*Math::PI/2).should be_close(-1.0, TOLERANCE)
+ @object.send(:sin!, 2*Math::PI).should be_close(0.0, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:sin!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/sinh.rb b/spec/ruby/library/cmath/math/shared/sinh.rb
new file mode 100644
index 0000000000..de80a376da
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/sinh.rb
@@ -0,0 +1,28 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_sinh, shared: true do
+ it "returns the hyperbolic sin of the argument" do
+ @object.send(:sinh, 0.0).should == 0.0
+ @object.send(:sinh, -0.0).should == 0.0
+ @object.send(:sinh, 1.5).should be_close(2.12927945509482, TOLERANCE)
+ @object.send(:sinh, -2.8).should be_close(-8.19191835423591, TOLERANCE)
+ end
+
+ it "returns the hyperbolic sin for Complex numbers" do
+ @object.send(:sinh, Complex(0, CMath::PI)).should be_close(Complex(-0.0, 1.22464679914735e-16), TOLERANCE)
+ @object.send(:sinh, Complex(3, 4)).should be_close(Complex(-6.548120040911, -7.61923172032141), TOLERANCE)
+ end
+end
+
+describe :complex_math_sinh_bang, shared: true do
+ it "returns the hyperbolic sin of the argument" do
+ @object.send(:sinh!, 0.0).should == 0.0
+ @object.send(:sinh!, -0.0).should == 0.0
+ @object.send(:sinh!, 1.5).should be_close(2.12927945509482, TOLERANCE)
+ @object.send(:sinh!, -2.8).should be_close(-8.19191835423591, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:sinh!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/sqrt.rb b/spec/ruby/library/cmath/math/shared/sqrt.rb
new file mode 100644
index 0000000000..23b1ba48ff
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/sqrt.rb
@@ -0,0 +1,34 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_sqrt, shared: true do
+ it "returns the square root for positive numbers" do
+ @object.send(:sqrt, 4).should == 2
+ @object.send(:sqrt, 19.36).should == 4.4
+ end
+
+ it "returns the square root for negative numbers" do
+ @object.send(:sqrt, -4).should == Complex(0, 2.0)
+ @object.send(:sqrt, -19.36).should == Complex(0, 4.4)
+ end
+
+ it "returns the square root for Complex numbers" do
+ @object.send(:sqrt, Complex(4, 5)).should be_close(Complex(2.2806933416653, 1.09615788950152), TOLERANCE)
+ @object.send(:sqrt, Complex(4, -5)).should be_close(Complex(2.2806933416653, -1.09615788950152), TOLERANCE)
+ end
+end
+
+describe :complex_math_sqrt_bang, shared: true do
+ it "returns the square root for positive numbers" do
+ @object.send(:sqrt!, 4).should == 2
+ @object.send(:sqrt!, 19.36).should == 4.4
+ end
+
+ it "raises Errno::EDOM when the passed argument is negative" do
+ -> { @object.send(:sqrt!, -4) }.should raise_error(Errno::EDOM)
+ -> { @object.send(:sqrt!, -19.36) }.should raise_error(Errno::EDOM)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:sqrt!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/tan.rb b/spec/ruby/library/cmath/math/shared/tan.rb
new file mode 100644
index 0000000000..9022c84fc9
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/tan.rb
@@ -0,0 +1,28 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_tan, shared: true do
+ it "returns the tangent of the argument" do
+ @object.send(:tan, 0.0).should == 0.0
+ @object.send(:tan, -0.0).should == -0.0
+ @object.send(:tan, 4.22).should be_close(1.86406937682395, TOLERANCE)
+ @object.send(:tan, -9.65).should be_close(-0.229109052606441, TOLERANCE)
+ end
+
+ it "returns the tangent for Complex numbers" do
+ @object.send(:tan, Complex(0, CMath::PI)).should be_close(Complex(0.0, 0.99627207622075), TOLERANCE)
+ @object.send(:tan, Complex(3, 4)).should be_close(Complex(-0.000187346204629452, 0.999355987381473), TOLERANCE)
+ end
+end
+
+describe :complex_math_tan_bang, shared: true do
+ it "returns the tangent of the argument" do
+ @object.send(:tan!, 0.0).should == 0.0
+ @object.send(:tan!, -0.0).should == -0.0
+ @object.send(:tan!, 4.22).should be_close(1.86406937682395, TOLERANCE)
+ @object.send(:tan!, -9.65).should be_close(-0.229109052606441, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:tan!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/shared/tanh.rb b/spec/ruby/library/cmath/math/shared/tanh.rb
new file mode 100644
index 0000000000..f2c9a5abb1
--- /dev/null
+++ b/spec/ruby/library/cmath/math/shared/tanh.rb
@@ -0,0 +1,32 @@
+require_relative '../fixtures/classes'
+
+describe :complex_math_tanh, shared: true do
+ it "returns the hyperbolic tangent of the argument" do
+ @object.send(:tanh, 0.0).should == 0.0
+ @object.send(:tanh, -0.0).should == -0.0
+ @object.send(:tanh, infinity_value).should == 1.0
+ @object.send(:tanh, -infinity_value).should == -1.0
+ @object.send(:tanh, 2.5).should be_close(0.98661429815143, TOLERANCE)
+ @object.send(:tanh, -4.892).should be_close(-0.999887314427707, TOLERANCE)
+ end
+
+ it "returns the hyperbolic tangent for Complex numbers" do
+ @object.send(:tanh, Complex(0, CMath::PI)).should be_close(Complex(0.0, -1.22464679914735e-16), TOLERANCE)
+ @object.send(:tanh, Complex(3, 4)).should be_close(Complex(1.00070953606723, 0.00490825806749599), TOLERANCE)
+ end
+end
+
+describe :complex_math_tanh_bang, shared: true do
+ it "returns the hyperbolic tangent of the argument" do
+ @object.send(:tanh!, 0.0).should == 0.0
+ @object.send(:tanh!, -0.0).should == -0.0
+ @object.send(:tanh!, infinity_value).should == 1.0
+ @object.send(:tanh!, -infinity_value).should == -1.0
+ @object.send(:tanh!, 2.5).should be_close(0.98661429815143, TOLERANCE)
+ @object.send(:tanh!, -4.892).should be_close(-0.999887314427707, TOLERANCE)
+ end
+
+ it "raises a TypeError when passed a Complex number" do
+ -> { @object.send(:tanh!, Complex(4, 5)) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/library/cmath/math/sin_spec.rb b/spec/ruby/library/cmath/math/sin_spec.rb
new file mode 100644
index 0000000000..b7a219fbbd
--- /dev/null
+++ b/spec/ruby/library/cmath/math/sin_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/sin'
+
+ describe "Math#sin" do
+ it_behaves_like :complex_math_sin, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:sin)
+ end
+ end
+
+ describe "Math.sin" do
+ it_behaves_like :complex_math_sin, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/sinh_spec.rb b/spec/ruby/library/cmath/math/sinh_spec.rb
new file mode 100644
index 0000000000..c6e6a3baf4
--- /dev/null
+++ b/spec/ruby/library/cmath/math/sinh_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/sinh'
+
+ describe "Math#sinh" do
+ it_behaves_like :complex_math_sinh, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:sinh)
+ end
+ end
+
+ describe "Math.sinh" do
+ it_behaves_like :complex_math_sinh, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/sqrt_spec.rb b/spec/ruby/library/cmath/math/sqrt_spec.rb
new file mode 100644
index 0000000000..421824f99c
--- /dev/null
+++ b/spec/ruby/library/cmath/math/sqrt_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/sqrt'
+
+ describe "Math#sqrt" do
+ it_behaves_like :complex_math_sqrt, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:sqrt)
+ end
+ end
+
+ describe "Math.sqrt" do
+ it_behaves_like :complex_math_sqrt, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/tan_spec.rb b/spec/ruby/library/cmath/math/tan_spec.rb
new file mode 100644
index 0000000000..e2acdd8091
--- /dev/null
+++ b/spec/ruby/library/cmath/math/tan_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/tan'
+
+ describe "Math#tan" do
+ it_behaves_like :complex_math_tan, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:tan)
+ end
+ end
+
+ describe "Math.tan" do
+ it_behaves_like :complex_math_tan, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/cmath/math/tanh_spec.rb b/spec/ruby/library/cmath/math/tanh_spec.rb
new file mode 100644
index 0000000000..94da20cd51
--- /dev/null
+++ b/spec/ruby/library/cmath/math/tanh_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require 'complex'
+ require_relative 'shared/tanh'
+
+ describe "Math#tanh" do
+ it_behaves_like :complex_math_tanh, :_, IncludesMath.new
+
+ it "is a private instance method" do
+ IncludesMath.should have_private_instance_method(:tanh)
+ end
+ end
+
+ describe "Math.tanh" do
+ it_behaves_like :complex_math_tanh, :_, CMath
+ end
+end
diff --git a/spec/ruby/library/logger/device/new_spec.rb b/spec/ruby/library/logger/device/new_spec.rb
index c77376d078..2002e6f68e 100644
--- a/spec/ruby/library/logger/device/new_spec.rb
+++ b/spec/ruby/library/logger/device/new_spec.rb
@@ -40,8 +40,8 @@ describe "Logger::LogDevice#new" do
end
it "receives options via a hash as second argument" do
- -> { Logger::LogDevice.new(STDERR,
- shift_age: 8, shift_size: 10
- )}.should_not raise_error
+ -> {
+ Logger::LogDevice.new(STDERR, shift_age: 8, shift_size: 10)
+ }.should_not raise_error
end
end
diff --git a/spec/ruby/library/scanf/io/block_scanf_spec.rb b/spec/ruby/library/scanf/io/block_scanf_spec.rb
new file mode 100644
index 0000000000..b9cc1b507e
--- /dev/null
+++ b/spec/ruby/library/scanf/io/block_scanf_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require_relative 'shared/block_scanf'
+ require 'scanf'
+
+ describe "IO#block_scanf" do
+ it_behaves_like :scanf_io_block_scanf, :block_scanf
+ end
+end
diff --git a/spec/ruby/library/scanf/io/fixtures/date.txt b/spec/ruby/library/scanf/io/fixtures/date.txt
new file mode 100644
index 0000000000..a1bd635c0c
--- /dev/null
+++ b/spec/ruby/library/scanf/io/fixtures/date.txt
@@ -0,0 +1,4 @@
+Beethoven 1770
+Bach 1685
+Handel 1685
+
diff --git a/spec/ruby/library/scanf/io/fixtures/helloworld.txt b/spec/ruby/library/scanf/io/fixtures/helloworld.txt
new file mode 100644
index 0000000000..3b18e512db
--- /dev/null
+++ b/spec/ruby/library/scanf/io/fixtures/helloworld.txt
@@ -0,0 +1 @@
+hello world
diff --git a/spec/ruby/library/scanf/io/scanf_spec.rb b/spec/ruby/library/scanf/io/scanf_spec.rb
new file mode 100644
index 0000000000..6a1fd66780
--- /dev/null
+++ b/spec/ruby/library/scanf/io/scanf_spec.rb
@@ -0,0 +1,38 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require_relative 'shared/block_scanf'
+ require 'scanf'
+
+ describe "IO#scanf" do
+ before :each do
+ @hw = File.open(fixture(__FILE__, 'helloworld.txt'), 'r')
+ @data = File.open(fixture(__FILE__, 'date.txt'), 'r')
+ end
+
+ after :each do
+ @hw.close unless @hw.closed?
+ @data.close unless @data.closed?
+ end
+
+ it "returns an array containing the input converted in the specified type" do
+ @hw.scanf("%s%s").should == ["hello", "world"]
+ @data.scanf("%s%d").should == ["Beethoven", 1770]
+ end
+
+ it "returns an array containing the input converted in the specified type with given maximum field width" do
+ @hw.scanf("%2s").should == ["he"]
+ @data.scanf("%2c").should == ["Be"]
+ end
+
+ it "returns an empty array when a wrong specifier is passed" do
+ @hw.scanf("%a").should == []
+ @hw.scanf("%1").should == []
+ @data.scanf("abc").should == []
+ end
+ end
+
+ describe "IO#scanf with block" do
+ it_behaves_like :scanf_io_block_scanf, :scanf
+ end
+end
diff --git a/spec/ruby/library/scanf/io/shared/block_scanf.rb b/spec/ruby/library/scanf/io/shared/block_scanf.rb
new file mode 100644
index 0000000000..2031f4c2b7
--- /dev/null
+++ b/spec/ruby/library/scanf/io/shared/block_scanf.rb
@@ -0,0 +1,28 @@
+require 'scanf'
+
+describe :scanf_io_block_scanf, shared: true do
+ before :each do
+ @data = File.open(fixture(__FILE__, 'date.txt'), 'r')
+ end
+
+ after :each do
+ @data.close unless @data.closed?
+ end
+
+ it "passes each match to the block as an array" do
+ res = @data.send(@method, "%s%d") { |name, year| "#{name} was born in #{year}." }
+ res.should == ["Beethoven was born in 1770.", "Bach was born in 1685.", "Handel was born in 1685."]
+ end
+
+ it "keeps scanning the input and cycling back to the beginning of the input string" do
+ a = []
+ @data.send(@method, "%s"){|w| a << w}
+ a.should == [["Beethoven"], ["1770"], ["Bach"], ["1685"], ["Handel"], ["1685"]]
+ end
+
+ it "returns an empty array when a wrong specifier is passed" do
+ a = []
+ @data.send(@method, "%z"){|w| a << w}
+ a.empty?.should be_true
+ end
+end
diff --git a/spec/ruby/library/scanf/string/block_scanf_spec.rb b/spec/ruby/library/scanf/string/block_scanf_spec.rb
new file mode 100644
index 0000000000..277e1fa1d7
--- /dev/null
+++ b/spec/ruby/library/scanf/string/block_scanf_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require_relative 'shared/block_scanf'
+ require 'scanf'
+
+ describe "String#block_scanf" do
+ it_behaves_like :scanf_string_block_scanf, :block_scanf
+ end
+end
diff --git a/spec/ruby/library/scanf/string/scanf_spec.rb b/spec/ruby/library/scanf/string/scanf_spec.rb
new file mode 100644
index 0000000000..c8897db675
--- /dev/null
+++ b/spec/ruby/library/scanf/string/scanf_spec.rb
@@ -0,0 +1,56 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is ''...'2.7' do
+ require_relative 'shared/block_scanf'
+ require 'scanf'
+
+ describe "String#scanf" do
+ it "returns an array containing the input converted in the specified type" do
+ "hello world".scanf("%s").should == ["hello"]
+ "hello world".scanf("%s%d").should == ["hello"]
+ "hello world".scanf("%s%c").should == ["hello", " "]
+ "hello world".scanf("%c%s").should == ["h", "ello"]
+ "hello world".scanf("%s%s").should == ["hello", "world"]
+ "hello world".scanf("%c").should == ["h"]
+ "123".scanf("%s").should == ["123"]
+ "123".scanf("%c").should == ["1"]
+ "123".scanf("%d").should == [123]
+ "123".scanf("%u").should == [123]
+ "123".scanf("%o").should == [83]
+ "123".scanf("%x").should == [291]
+ "123".scanf("%i").should == [123]
+ "0123".scanf("%i").should == [83]
+ "123".scanf("%f").should == [123.0]
+ "0X123".scanf("%i").should == [291]
+ "0x123".scanf("%i").should == [291]
+ end
+
+ it "returns an array containing the input converted in the specified type with given maximum field width" do
+ "hello world".scanf("%2s").should == ["he"]
+ "hello world".scanf("%2c").should == ["he"]
+ "123".scanf("%2s").should == ["12"]
+ "123".scanf("%2c").should == ["12"]
+ "123".scanf("%2d").should == [12]
+ "123".scanf("%2u").should == [12]
+ "123".scanf("%2o").should == [10]
+ "123".scanf("%2x").should == [18]
+ "123".scanf("%2i").should == [12]
+ "0123".scanf("%2i").should == [1]
+ "123".scanf("%2f").should == [12.0]
+ "0X123".scanf("%2i").should == [0]
+ "0X123".scanf("%3i").should == [1]
+ "0X123".scanf("%4i").should == [18]
+ end
+
+ it "returns an empty array when a wrong specifier is passed" do
+ "hello world".scanf("%a").should == []
+ "123".scanf("%1").should == []
+ "123".scanf("abc").should == []
+ "123".scanf(:d).should == []
+ end
+ end
+
+ describe "String#scanf with block" do
+ it_behaves_like :scanf_string_block_scanf, :scanf
+ end
+end
diff --git a/spec/ruby/library/scanf/string/shared/block_scanf.rb b/spec/ruby/library/scanf/string/shared/block_scanf.rb
new file mode 100644
index 0000000000..25ab3f442a
--- /dev/null
+++ b/spec/ruby/library/scanf/string/shared/block_scanf.rb
@@ -0,0 +1,25 @@
+require 'scanf'
+
+describe :scanf_string_block_scanf, shared: true do
+ it "passes each match to the block as an array" do
+ a = []
+ "hello world".send(@method, "%s%s"){|w| a << w}
+ a.should == [["hello", "world"]]
+ end
+
+ it "keeps scanning the input and cycling back to the beginning of the input string" do
+ a = []
+ "hello world".send(@method, "%s"){|w| a << w}
+ a.should == [["hello"], ["world"]]
+
+ string = "123 abc 456 def 789 ghi"
+ s = string.send(@method, "%d%s"){|num,str| [num * 2, str.upcase]}
+ s.should == [[246, "ABC"], [912, "DEF"], [1578, "GHI"]]
+ end
+
+ it "returns an empty array when a wrong specifier is passed" do
+ a = []
+ "hello world".send(@method, "%z"){|w| a << w}
+ a.empty?.should be_true
+ end
+end
diff --git a/spec/ruby/library/securerandom/random_bytes_spec.rb b/spec/ruby/library/securerandom/random_bytes_spec.rb
index 275a897315..2794174f40 100644
--- a/spec/ruby/library/securerandom/random_bytes_spec.rb
+++ b/spec/ruby/library/securerandom/random_bytes_spec.rb
@@ -1,8 +1,12 @@
require_relative '../../spec_helper'
+require_relative '../../core/random/shared/bytes'
require 'securerandom'
describe "SecureRandom.random_bytes" do
+ it_behaves_like :random_bytes, :random_bytes, SecureRandom
+ it_behaves_like :random_bytes, :bytes, SecureRandom
+
it "generates a random binary string of length 16 if no argument is provided" do
bytes = SecureRandom.random_bytes
bytes.should be_kind_of(String)
diff --git a/spec/ruby/library/securerandom/random_number_spec.rb b/spec/ruby/library/securerandom/random_number_spec.rb
index 3c86f55bf5..3e1812c6e8 100644
--- a/spec/ruby/library/securerandom/random_number_spec.rb
+++ b/spec/ruby/library/securerandom/random_number_spec.rb
@@ -1,8 +1,12 @@
require_relative '../../spec_helper'
+require_relative '../../core/random/shared/rand'
require 'securerandom'
describe "SecureRandom.random_number" do
+ it_behaves_like :random_number, :rand, SecureRandom
+ it_behaves_like :random_number, :random_number, SecureRandom
+
it "generates a random positive number smaller then the positive integer argument" do
(1..64).each do |idx|
num = SecureRandom.random_number(idx)