summaryrefslogtreecommitdiff
path: root/spec/ruby/core
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 /spec/ruby/core
parent31bb66a19df26409c9d47afcf37919c9a065516a (diff)
Update to ruby/spec@519df35
Diffstat (limited to 'spec/ruby/core')
-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
29 files changed, 317 insertions, 177 deletions
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