This commit is contained in:
Benoit Daloze 2023-06-26 15:55:11 +02:00
parent f73fa29927
commit 515bd42144
428 changed files with 3666 additions and 9321 deletions

View File

@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml inherit_from: .rubocop_todo.yml
AllCops: AllCops:
TargetRubyVersion: 2.7 TargetRubyVersion: 3.0
DisplayCopNames: true DisplayCopNames: true
Exclude: Exclude:
- command_line/fixtures/bad_syntax.rb - command_line/fixtures/bad_syntax.rb

View File

@ -138,12 +138,12 @@ Here is a list of the most commonly-used guards:
#### Version guards #### Version guards
```ruby ```ruby
ruby_version_is ""..."2.6" do ruby_version_is ""..."3.2" do
# Specs for RUBY_VERSION < 2.6 # Specs for RUBY_VERSION < 3.2
end end
ruby_version_is "2.6" do ruby_version_is "3.2" do
# Specs for RUBY_VERSION >= 2.6 # Specs for RUBY_VERSION >= 3.2
end end
``` ```
@ -191,11 +191,11 @@ end
#### Combining guards #### Combining guards
```ruby ```ruby
guard -> { platform_is :windows and ruby_version_is ""..."2.6" } do guard -> { platform_is :windows and ruby_version_is ""..."3.2" } do
# Windows and RUBY_VERSION < 2.6 # Windows and RUBY_VERSION < 3.2
end end
guard_not -> { platform_is :windows and ruby_version_is ""..."2.6" } do guard_not -> { platform_is :windows and ruby_version_is ""..."3.2" } do
# The opposite # The opposite
end end
``` ```

View File

@ -30,8 +30,8 @@ ruby/spec is known to be tested in these implementations for every commit:
* [Opal](https://github.com/opal/opal/tree/master/spec) * [Opal](https://github.com/opal/opal/tree/master/spec)
* [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor) * [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor)
ruby/spec describes the behavior of Ruby 2.7 and more recent Ruby versions. ruby/spec describes the behavior of Ruby 3.0 and more recent Ruby versions.
More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (2.7.x, 3.0.x, 3.1.x, etc), and those are tested in CI. More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (3.0.x, 3.1.x, 3.2.x, etc), and those are tested in CI.
### Synchronization with Ruby Implementations ### Synchronization with Ruby Implementations
@ -61,6 +61,7 @@ For older specs try these commits:
* Ruby 2.4.10 - [Suite](https://github.com/ruby/spec/commit/bce4f2b81d6c31db67cf4d023a0625ceadde59bd) using [MSpec](https://github.com/ruby/mspec/commit/e7eb8aa4c26495b7b461e687d950b96eb08b3ff2) * Ruby 2.4.10 - [Suite](https://github.com/ruby/spec/commit/bce4f2b81d6c31db67cf4d023a0625ceadde59bd) using [MSpec](https://github.com/ruby/mspec/commit/e7eb8aa4c26495b7b461e687d950b96eb08b3ff2)
* Ruby 2.5.9 - [Suite](https://github.com/ruby/spec/commit/c503335d3d9f6ec6ef24de60a0716c34af69b64f) using [MSpec](https://github.com/ruby/mspec/commit/0091e8a62e954717cd54641f935eaf1403692041) * Ruby 2.5.9 - [Suite](https://github.com/ruby/spec/commit/c503335d3d9f6ec6ef24de60a0716c34af69b64f) using [MSpec](https://github.com/ruby/mspec/commit/0091e8a62e954717cd54641f935eaf1403692041)
* Ruby 2.6.10 - [Suite](https://github.com/ruby/spec/commit/aaf998fb8c92c4e63ad423a2e7ca6e6921818c6e) using [MSpec](https://github.com/ruby/mspec/commit/5e36c684e9e2b92b1187589bba1df22c640a8661) * Ruby 2.6.10 - [Suite](https://github.com/ruby/spec/commit/aaf998fb8c92c4e63ad423a2e7ca6e6921818c6e) using [MSpec](https://github.com/ruby/mspec/commit/5e36c684e9e2b92b1187589bba1df22c640a8661)
* Ruby 2.7.8 - [Suite](https://github.com/ruby/spec/commit/93787e6035c925b593a9c0c6fb0e7e07a6f1df1f) using [MSpec](https://github.com/ruby/mspec/commit/1d8cf64722d8a7529f7cd205be5f16a89b7a67fd)
### Running the specs ### Running the specs

View File

@ -1,48 +1,46 @@
require_relative '../spec_helper' require_relative '../spec_helper'
ruby_version_is "3.0" do describe "The --backtrace-limit command line option" do
describe "The --backtrace-limit command line option" do it "limits top-level backtraces to a given number of entries" do
it "limits top-level backtraces to a given number of entries" do file = fixture(__FILE__ , "backtrace.rb")
file = fixture(__FILE__ , "backtrace.rb") out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1) out = out.gsub(__dir__, '')
out = out.gsub(__dir__, '')
out.should == <<-MSG out.should == <<-MSG
top top
/fixtures/backtrace.rb:2:in `a': oops (RuntimeError) /fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
\tfrom /fixtures/backtrace.rb:6:in `b' \tfrom /fixtures/backtrace.rb:6:in `b'
\tfrom /fixtures/backtrace.rb:10:in `c' \tfrom /fixtures/backtrace.rb:10:in `c'
\t ... 2 levels... \t ... 2 levels...
MSG MSG
end end
it "affects Exception#full_message" do it "affects Exception#full_message" do
file = fixture(__FILE__ , "backtrace.rb") file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1") out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
out = out.gsub(__dir__, '') out = out.gsub(__dir__, '')
out.should == <<-MSG out.should == <<-MSG
full_message full_message
/fixtures/backtrace.rb:2:in `a': oops (RuntimeError) /fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
\tfrom /fixtures/backtrace.rb:6:in `b' \tfrom /fixtures/backtrace.rb:6:in `b'
\tfrom /fixtures/backtrace.rb:10:in `c' \tfrom /fixtures/backtrace.rb:10:in `c'
\t ... 2 levels... \t ... 2 levels...
MSG MSG
end end
it "does not affect Exception#backtrace" do it "does not affect Exception#backtrace" do
file = fixture(__FILE__ , "backtrace.rb") file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1") out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
out = out.gsub(__dir__, '') out = out.gsub(__dir__, '')
out.should == <<-MSG out.should == <<-MSG
backtrace backtrace
/fixtures/backtrace.rb:2:in `a' /fixtures/backtrace.rb:2:in `a'
/fixtures/backtrace.rb:6:in `b' /fixtures/backtrace.rb:6:in `b'
/fixtures/backtrace.rb:10:in `c' /fixtures/backtrace.rb:10:in `c'
/fixtures/backtrace.rb:14:in `d' /fixtures/backtrace.rb:14:in `d'
/fixtures/backtrace.rb:29:in `<main>' /fixtures/backtrace.rb:29:in `<main>'
MSG MSG
end
end end
end end

View File

@ -1,16 +0,0 @@
require_relative '../../spec_helper'
require_relative 'shared/each_byte'
ruby_version_is ''...'3.0' do
describe "ARGF.bytes" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
end
it_behaves_like :argf_each_byte, :bytes
end
end

View File

@ -1,16 +0,0 @@
require_relative '../../spec_helper'
require_relative 'shared/each_char'
ruby_version_is ''...'3.0' do
describe "ARGF.chars" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
end
it_behaves_like :argf_each_char, :chars
end
end

View File

@ -1,16 +0,0 @@
require_relative '../../spec_helper'
require_relative 'shared/each_codepoint'
ruby_version_is ''...'3.0' do
describe "ARGF.codepoints" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
end
it_behaves_like :argf_each_codepoint, :codepoints
end
end

View File

@ -1,16 +0,0 @@
require_relative '../../spec_helper'
require_relative 'shared/each_line'
ruby_version_is ''...'3.0' do
describe "ARGF.lines" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
end
it_behaves_like :argf_each_line, :lines
end
end

View File

@ -50,15 +50,7 @@ describe "Array#drop" do
-> { [1, 2].drop(obj) }.should raise_error(TypeError) -> { [1, 2].drop(obj) }.should raise_error(TypeError)
end end
ruby_version_is ''...'3.0' do it 'returns a Array instance for Array subclasses' do
it 'returns a subclass instance for Array subclasses' do ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should be_an_instance_of(Array)
ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should be_an_instance_of(ArraySpecs::MyArray)
end
end
ruby_version_is '3.0' do
it 'returns a Array instance for Array subclasses' do
ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should be_an_instance_of(Array)
end
end end
end end

View File

@ -18,15 +18,7 @@ describe "Array#drop_while" do
[1, 2, 3, false, 5].drop_while { |n| n }.should == [false, 5] [1, 2, 3, false, 5].drop_while { |n| n }.should == [false, 5]
end end
ruby_version_is ''...'3.0' do it 'returns a Array instance for Array subclasses' do
it 'returns a subclass instance for Array subclasses' do ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should be_an_instance_of(Array)
ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should be_an_instance_of(ArraySpecs::MyArray)
end
end
ruby_version_is '3.0' do
it 'returns a Array instance for Array subclasses' do
ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should be_an_instance_of(Array)
end
end end
end end

View File

@ -75,24 +75,12 @@ describe "Array#flatten" do
[[obj]].flatten(1) [[obj]].flatten(1)
end end
ruby_version_is ''...'3.0' do it "returns Array instance for Array subclasses" do
it "returns subclass instance for Array subclasses" do ArraySpecs::MyArray[].flatten.should be_an_instance_of(Array)
ArraySpecs::MyArray[].flatten.should be_an_instance_of(ArraySpecs::MyArray) ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(Array)
ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(ArraySpecs::MyArray) ArraySpecs::MyArray[1, [2], 3].flatten.should be_an_instance_of(Array)
ArraySpecs::MyArray[1, [2], 3].flatten.should be_an_instance_of(ArraySpecs::MyArray) ArraySpecs::MyArray[1, [2, 3], 4].flatten.should == [1, 2, 3, 4]
ArraySpecs::MyArray[1, [2, 3], 4].flatten.should == ArraySpecs::MyArray[1, 2, 3, 4] [ArraySpecs::MyArray[1, 2, 3]].flatten.should be_an_instance_of(Array)
[ArraySpecs::MyArray[1, 2, 3]].flatten.should be_an_instance_of(Array)
end
end
ruby_version_is '3.0' do
it "returns Array instance for Array subclasses" do
ArraySpecs::MyArray[].flatten.should be_an_instance_of(Array)
ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(Array)
ArraySpecs::MyArray[1, [2], 3].flatten.should be_an_instance_of(Array)
ArraySpecs::MyArray[1, [2, 3], 4].flatten.should == [1, 2, 3, 4]
[ArraySpecs::MyArray[1, 2, 3]].flatten.should be_an_instance_of(Array)
end
end end
it "is not destructive" do it "is not destructive" do

View File

@ -76,20 +76,10 @@ describe "Array#* with an integer" do
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5] @array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
end end
ruby_version_is ''...'3.0' do it "returns an Array instance" do
it "returns a subclass instance" do (@array * 0).should be_an_instance_of(Array)
(@array * 0).should be_an_instance_of(ArraySpecs::MyArray) (@array * 1).should be_an_instance_of(Array)
(@array * 1).should be_an_instance_of(ArraySpecs::MyArray) (@array * 2).should be_an_instance_of(Array)
(@array * 2).should be_an_instance_of(ArraySpecs::MyArray)
end
end
ruby_version_is '3.0' do
it "returns an Array instance" do
(@array * 0).should be_an_instance_of(Array)
(@array * 1).should be_an_instance_of(Array)
(@array * 2).should be_an_instance_of(Array)
end
end end
it "does not call #initialize on the subclass instance" do it "does not call #initialize on the subclass instance" do

View File

@ -397,56 +397,28 @@ describe :array_slice, shared: true do
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5] @array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
end end
ruby_version_is ''...'3.0' do it "returns a Array instance with [n, m]" do
it "returns a subclass instance with [n, m]" do @array.send(@method, 0, 2).should be_an_instance_of(Array)
@array.send(@method, 0, 2).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [-n, m]" do
@array.send(@method, -3, 2).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [n..m]" do
@array.send(@method, 1..3).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [n...m]" do
@array.send(@method, 1...3).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [-n..-m]" do
@array.send(@method, -3..-1).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [-n...-m]" do
@array.send(@method, -3...-1).should be_an_instance_of(ArraySpecs::MyArray)
end
end end
ruby_version_is '3.0' do it "returns a Array instance with [-n, m]" do
it "returns a Array instance with [n, m]" do @array.send(@method, -3, 2).should be_an_instance_of(Array)
@array.send(@method, 0, 2).should be_an_instance_of(Array) end
end
it "returns a Array instance with [-n, m]" do it "returns a Array instance with [n..m]" do
@array.send(@method, -3, 2).should be_an_instance_of(Array) @array.send(@method, 1..3).should be_an_instance_of(Array)
end end
it "returns a Array instance with [n..m]" do it "returns a Array instance with [n...m]" do
@array.send(@method, 1..3).should be_an_instance_of(Array) @array.send(@method, 1...3).should be_an_instance_of(Array)
end end
it "returns a Array instance with [n...m]" do it "returns a Array instance with [-n..-m]" do
@array.send(@method, 1...3).should be_an_instance_of(Array) @array.send(@method, -3..-1).should be_an_instance_of(Array)
end end
it "returns a Array instance with [-n..-m]" do it "returns a Array instance with [-n...-m]" do
@array.send(@method, -3..-1).should be_an_instance_of(Array) @array.send(@method, -3...-1).should be_an_instance_of(Array)
end
it "returns a Array instance with [-n...-m]" do
@array.send(@method, -3...-1).should be_an_instance_of(Array)
end
end end
it "returns an empty array when m == n with [m...n]" do it "returns an empty array when m == n with [m...n]" do
@ -534,239 +506,237 @@ describe :array_slice, shared: true do
a.send(@method, eval("(-9...)")).should == nil a.send(@method, eval("(-9...)")).should == nil
end end
ruby_version_is "3.0" do describe "can be sliced with Enumerator::ArithmeticSequence" do
describe "can be sliced with Enumerator::ArithmeticSequence" do before :each do
before :each do @array = [0, 1, 2, 3, 4, 5]
@array = [0, 1, 2, 3, 4, 5] end
end
it "has endless range and positive steps" do it "has endless range and positive steps" do
@array.send(@method, eval("(0..).step(1)")).should == [0, 1, 2, 3, 4, 5] @array.send(@method, eval("(0..).step(1)")).should == [0, 1, 2, 3, 4, 5]
@array.send(@method, eval("(0..).step(2)")).should == [0, 2, 4] @array.send(@method, eval("(0..).step(2)")).should == [0, 2, 4]
@array.send(@method, eval("(0..).step(10)")).should == [0] @array.send(@method, eval("(0..).step(10)")).should == [0]
@array.send(@method, eval("(2..).step(1)")).should == [2, 3, 4, 5] @array.send(@method, eval("(2..).step(1)")).should == [2, 3, 4, 5]
@array.send(@method, eval("(2..).step(2)")).should == [2, 4] @array.send(@method, eval("(2..).step(2)")).should == [2, 4]
@array.send(@method, eval("(2..).step(10)")).should == [2] @array.send(@method, eval("(2..).step(10)")).should == [2]
@array.send(@method, eval("(-3..).step(1)")).should == [3, 4, 5] @array.send(@method, eval("(-3..).step(1)")).should == [3, 4, 5]
@array.send(@method, eval("(-3..).step(2)")).should == [3, 5] @array.send(@method, eval("(-3..).step(2)")).should == [3, 5]
@array.send(@method, eval("(-3..).step(10)")).should == [3] @array.send(@method, eval("(-3..).step(10)")).should == [3]
end end
it "has beginless range and positive steps" do it "has beginless range and positive steps" do
# end with zero index # end with zero index
@array.send(@method, (..0).step(1)).should == [0] @array.send(@method, (..0).step(1)).should == [0]
@array.send(@method, (...0).step(1)).should == [] @array.send(@method, (...0).step(1)).should == []
@array.send(@method, (..0).step(2)).should == [0] @array.send(@method, (..0).step(2)).should == [0]
@array.send(@method, (...0).step(2)).should == [] @array.send(@method, (...0).step(2)).should == []
@array.send(@method, (..0).step(10)).should == [0] @array.send(@method, (..0).step(10)).should == [0]
@array.send(@method, (...0).step(10)).should == [] @array.send(@method, (...0).step(10)).should == []
# end with positive index # end with positive index
@array.send(@method, (..3).step(1)).should == [0, 1, 2, 3] @array.send(@method, (..3).step(1)).should == [0, 1, 2, 3]
@array.send(@method, (...3).step(1)).should == [0, 1, 2] @array.send(@method, (...3).step(1)).should == [0, 1, 2]
@array.send(@method, (..3).step(2)).should == [0, 2] @array.send(@method, (..3).step(2)).should == [0, 2]
@array.send(@method, (...3).step(2)).should == [0, 2] @array.send(@method, (...3).step(2)).should == [0, 2]
@array.send(@method, (..3).step(10)).should == [0] @array.send(@method, (..3).step(10)).should == [0]
@array.send(@method, (...3).step(10)).should == [0] @array.send(@method, (...3).step(10)).should == [0]
# end with negative index # end with negative index
@array.send(@method, (..-2).step(1)).should == [0, 1, 2, 3, 4,] @array.send(@method, (..-2).step(1)).should == [0, 1, 2, 3, 4,]
@array.send(@method, (...-2).step(1)).should == [0, 1, 2, 3] @array.send(@method, (...-2).step(1)).should == [0, 1, 2, 3]
@array.send(@method, (..-2).step(2)).should == [0, 2, 4] @array.send(@method, (..-2).step(2)).should == [0, 2, 4]
@array.send(@method, (...-2).step(2)).should == [0, 2] @array.send(@method, (...-2).step(2)).should == [0, 2]
@array.send(@method, (..-2).step(10)).should == [0] @array.send(@method, (..-2).step(10)).should == [0]
@array.send(@method, (...-2).step(10)).should == [0] @array.send(@method, (...-2).step(10)).should == [0]
end end
it "has endless range and negative steps" do it "has endless range and negative steps" do
@array.send(@method, eval("(0..).step(-1)")).should == [0] @array.send(@method, eval("(0..).step(-1)")).should == [0]
@array.send(@method, eval("(0..).step(-2)")).should == [0] @array.send(@method, eval("(0..).step(-2)")).should == [0]
@array.send(@method, eval("(0..).step(-10)")).should == [0] @array.send(@method, eval("(0..).step(-10)")).should == [0]
@array.send(@method, eval("(2..).step(-1)")).should == [2, 1, 0] @array.send(@method, eval("(2..).step(-1)")).should == [2, 1, 0]
@array.send(@method, eval("(2..).step(-2)")).should == [2, 0] @array.send(@method, eval("(2..).step(-2)")).should == [2, 0]
@array.send(@method, eval("(-3..).step(-1)")).should == [3, 2, 1, 0] @array.send(@method, eval("(-3..).step(-1)")).should == [3, 2, 1, 0]
@array.send(@method, eval("(-3..).step(-2)")).should == [3, 1] @array.send(@method, eval("(-3..).step(-2)")).should == [3, 1]
end end
it "has closed range and positive steps" do it "has closed range and positive steps" do
# start and end with 0 # start and end with 0
@array.send(@method, eval("(0..0).step(1)")).should == [0] @array.send(@method, eval("(0..0).step(1)")).should == [0]
@array.send(@method, eval("(0...0).step(1)")).should == [] @array.send(@method, eval("(0...0).step(1)")).should == []
@array.send(@method, eval("(0..0).step(2)")).should == [0] @array.send(@method, eval("(0..0).step(2)")).should == [0]
@array.send(@method, eval("(0...0).step(2)")).should == [] @array.send(@method, eval("(0...0).step(2)")).should == []
@array.send(@method, eval("(0..0).step(10)")).should == [0] @array.send(@method, eval("(0..0).step(10)")).should == [0]
@array.send(@method, eval("(0...0).step(10)")).should == [] @array.send(@method, eval("(0...0).step(10)")).should == []
# start and end with positive index # start and end with positive index
@array.send(@method, eval("(1..3).step(1)")).should == [1, 2, 3] @array.send(@method, eval("(1..3).step(1)")).should == [1, 2, 3]
@array.send(@method, eval("(1...3).step(1)")).should == [1, 2] @array.send(@method, eval("(1...3).step(1)")).should == [1, 2]
@array.send(@method, eval("(1..3).step(2)")).should == [1, 3] @array.send(@method, eval("(1..3).step(2)")).should == [1, 3]
@array.send(@method, eval("(1...3).step(2)")).should == [1] @array.send(@method, eval("(1...3).step(2)")).should == [1]
@array.send(@method, eval("(1..3).step(10)")).should == [1] @array.send(@method, eval("(1..3).step(10)")).should == [1]
@array.send(@method, eval("(1...3).step(10)")).should == [1] @array.send(@method, eval("(1...3).step(10)")).should == [1]
# start with positive index, end with negative index # start with positive index, end with negative index
@array.send(@method, eval("(1..-2).step(1)")).should == [1, 2, 3, 4] @array.send(@method, eval("(1..-2).step(1)")).should == [1, 2, 3, 4]
@array.send(@method, eval("(1...-2).step(1)")).should == [1, 2, 3] @array.send(@method, eval("(1...-2).step(1)")).should == [1, 2, 3]
@array.send(@method, eval("(1..-2).step(2)")).should == [1, 3] @array.send(@method, eval("(1..-2).step(2)")).should == [1, 3]
@array.send(@method, eval("(1...-2).step(2)")).should == [1, 3] @array.send(@method, eval("(1...-2).step(2)")).should == [1, 3]
@array.send(@method, eval("(1..-2).step(10)")).should == [1] @array.send(@method, eval("(1..-2).step(10)")).should == [1]
@array.send(@method, eval("(1...-2).step(10)")).should == [1] @array.send(@method, eval("(1...-2).step(10)")).should == [1]
# start with negative index, end with positive index # start with negative index, end with positive index
@array.send(@method, eval("(-4..4).step(1)")).should == [2, 3, 4] @array.send(@method, eval("(-4..4).step(1)")).should == [2, 3, 4]
@array.send(@method, eval("(-4...4).step(1)")).should == [2, 3] @array.send(@method, eval("(-4...4).step(1)")).should == [2, 3]
@array.send(@method, eval("(-4..4).step(2)")).should == [2, 4] @array.send(@method, eval("(-4..4).step(2)")).should == [2, 4]
@array.send(@method, eval("(-4...4).step(2)")).should == [2] @array.send(@method, eval("(-4...4).step(2)")).should == [2]
@array.send(@method, eval("(-4..4).step(10)")).should == [2] @array.send(@method, eval("(-4..4).step(10)")).should == [2]
@array.send(@method, eval("(-4...4).step(10)")).should == [2] @array.send(@method, eval("(-4...4).step(10)")).should == [2]
# start with negative index, end with negative index # start with negative index, end with negative index
@array.send(@method, eval("(-4..-2).step(1)")).should == [2, 3, 4] @array.send(@method, eval("(-4..-2).step(1)")).should == [2, 3, 4]
@array.send(@method, eval("(-4...-2).step(1)")).should == [2, 3] @array.send(@method, eval("(-4...-2).step(1)")).should == [2, 3]
@array.send(@method, eval("(-4..-2).step(2)")).should == [2, 4] @array.send(@method, eval("(-4..-2).step(2)")).should == [2, 4]
@array.send(@method, eval("(-4...-2).step(2)")).should == [2] @array.send(@method, eval("(-4...-2).step(2)")).should == [2]
@array.send(@method, eval("(-4..-2).step(10)")).should == [2] @array.send(@method, eval("(-4..-2).step(10)")).should == [2]
@array.send(@method, eval("(-4...-2).step(10)")).should == [2] @array.send(@method, eval("(-4...-2).step(10)")).should == [2]
end end
it "has closed range and negative steps" do it "has closed range and negative steps" do
# start and end with 0 # start and end with 0
@array.send(@method, eval("(0..0).step(-1)")).should == [0] @array.send(@method, eval("(0..0).step(-1)")).should == [0]
@array.send(@method, eval("(0...0).step(-1)")).should == [] @array.send(@method, eval("(0...0).step(-1)")).should == []
@array.send(@method, eval("(0..0).step(-2)")).should == [0] @array.send(@method, eval("(0..0).step(-2)")).should == [0]
@array.send(@method, eval("(0...0).step(-2)")).should == [] @array.send(@method, eval("(0...0).step(-2)")).should == []
@array.send(@method, eval("(0..0).step(-10)")).should == [0] @array.send(@method, eval("(0..0).step(-10)")).should == [0]
@array.send(@method, eval("(0...0).step(-10)")).should == [] @array.send(@method, eval("(0...0).step(-10)")).should == []
# start and end with positive index # start and end with positive index
@array.send(@method, eval("(1..3).step(-1)")).should == [] @array.send(@method, eval("(1..3).step(-1)")).should == []
@array.send(@method, eval("(1...3).step(-1)")).should == [] @array.send(@method, eval("(1...3).step(-1)")).should == []
@array.send(@method, eval("(1..3).step(-2)")).should == [] @array.send(@method, eval("(1..3).step(-2)")).should == []
@array.send(@method, eval("(1...3).step(-2)")).should == [] @array.send(@method, eval("(1...3).step(-2)")).should == []
@array.send(@method, eval("(1..3).step(-10)")).should == [] @array.send(@method, eval("(1..3).step(-10)")).should == []
@array.send(@method, eval("(1...3).step(-10)")).should == [] @array.send(@method, eval("(1...3).step(-10)")).should == []
# start with positive index, end with negative index # start with positive index, end with negative index
@array.send(@method, eval("(1..-2).step(-1)")).should == [] @array.send(@method, eval("(1..-2).step(-1)")).should == []
@array.send(@method, eval("(1...-2).step(-1)")).should == [] @array.send(@method, eval("(1...-2).step(-1)")).should == []
@array.send(@method, eval("(1..-2).step(-2)")).should == [] @array.send(@method, eval("(1..-2).step(-2)")).should == []
@array.send(@method, eval("(1...-2).step(-2)")).should == [] @array.send(@method, eval("(1...-2).step(-2)")).should == []
@array.send(@method, eval("(1..-2).step(-10)")).should == [] @array.send(@method, eval("(1..-2).step(-10)")).should == []
@array.send(@method, eval("(1...-2).step(-10)")).should == [] @array.send(@method, eval("(1...-2).step(-10)")).should == []
# start with negative index, end with positive index # start with negative index, end with positive index
@array.send(@method, eval("(-4..4).step(-1)")).should == [] @array.send(@method, eval("(-4..4).step(-1)")).should == []
@array.send(@method, eval("(-4...4).step(-1)")).should == [] @array.send(@method, eval("(-4...4).step(-1)")).should == []
@array.send(@method, eval("(-4..4).step(-2)")).should == [] @array.send(@method, eval("(-4..4).step(-2)")).should == []
@array.send(@method, eval("(-4...4).step(-2)")).should == [] @array.send(@method, eval("(-4...4).step(-2)")).should == []
@array.send(@method, eval("(-4..4).step(-10)")).should == [] @array.send(@method, eval("(-4..4).step(-10)")).should == []
@array.send(@method, eval("(-4...4).step(-10)")).should == [] @array.send(@method, eval("(-4...4).step(-10)")).should == []
# start with negative index, end with negative index # start with negative index, end with negative index
@array.send(@method, eval("(-4..-2).step(-1)")).should == [] @array.send(@method, eval("(-4..-2).step(-1)")).should == []
@array.send(@method, eval("(-4...-2).step(-1)")).should == [] @array.send(@method, eval("(-4...-2).step(-1)")).should == []
@array.send(@method, eval("(-4..-2).step(-2)")).should == [] @array.send(@method, eval("(-4..-2).step(-2)")).should == []
@array.send(@method, eval("(-4...-2).step(-2)")).should == [] @array.send(@method, eval("(-4...-2).step(-2)")).should == []
@array.send(@method, eval("(-4..-2).step(-10)")).should == [] @array.send(@method, eval("(-4..-2).step(-10)")).should == []
@array.send(@method, eval("(-4...-2).step(-10)")).should == [] @array.send(@method, eval("(-4...-2).step(-10)")).should == []
end end
it "has inverted closed range and positive steps" do it "has inverted closed range and positive steps" do
# start and end with positive index # start and end with positive index
@array.send(@method, eval("(3..1).step(1)")).should == [] @array.send(@method, eval("(3..1).step(1)")).should == []
@array.send(@method, eval("(3...1).step(1)")).should == [] @array.send(@method, eval("(3...1).step(1)")).should == []
@array.send(@method, eval("(3..1).step(2)")).should == [] @array.send(@method, eval("(3..1).step(2)")).should == []
@array.send(@method, eval("(3...1).step(2)")).should == [] @array.send(@method, eval("(3...1).step(2)")).should == []
@array.send(@method, eval("(3..1).step(10)")).should == [] @array.send(@method, eval("(3..1).step(10)")).should == []
@array.send(@method, eval("(3...1).step(10)")).should == [] @array.send(@method, eval("(3...1).step(10)")).should == []
# start with negative index, end with positive index # start with negative index, end with positive index
@array.send(@method, eval("(-2..1).step(1)")).should == [] @array.send(@method, eval("(-2..1).step(1)")).should == []
@array.send(@method, eval("(-2...1).step(1)")).should == [] @array.send(@method, eval("(-2...1).step(1)")).should == []
@array.send(@method, eval("(-2..1).step(2)")).should == [] @array.send(@method, eval("(-2..1).step(2)")).should == []
@array.send(@method, eval("(-2...1).step(2)")).should == [] @array.send(@method, eval("(-2...1).step(2)")).should == []
@array.send(@method, eval("(-2..1).step(10)")).should == [] @array.send(@method, eval("(-2..1).step(10)")).should == []
@array.send(@method, eval("(-2...1).step(10)")).should == [] @array.send(@method, eval("(-2...1).step(10)")).should == []
# start with positive index, end with negative index # start with positive index, end with negative index
@array.send(@method, eval("(4..-4).step(1)")).should == [] @array.send(@method, eval("(4..-4).step(1)")).should == []
@array.send(@method, eval("(4...-4).step(1)")).should == [] @array.send(@method, eval("(4...-4).step(1)")).should == []
@array.send(@method, eval("(4..-4).step(2)")).should == [] @array.send(@method, eval("(4..-4).step(2)")).should == []
@array.send(@method, eval("(4...-4).step(2)")).should == [] @array.send(@method, eval("(4...-4).step(2)")).should == []
@array.send(@method, eval("(4..-4).step(10)")).should == [] @array.send(@method, eval("(4..-4).step(10)")).should == []
@array.send(@method, eval("(4...-4).step(10)")).should == [] @array.send(@method, eval("(4...-4).step(10)")).should == []
# start with negative index, end with negative index # start with negative index, end with negative index
@array.send(@method, eval("(-2..-4).step(1)")).should == [] @array.send(@method, eval("(-2..-4).step(1)")).should == []
@array.send(@method, eval("(-2...-4).step(1)")).should == [] @array.send(@method, eval("(-2...-4).step(1)")).should == []
@array.send(@method, eval("(-2..-4).step(2)")).should == [] @array.send(@method, eval("(-2..-4).step(2)")).should == []
@array.send(@method, eval("(-2...-4).step(2)")).should == [] @array.send(@method, eval("(-2...-4).step(2)")).should == []
@array.send(@method, eval("(-2..-4).step(10)")).should == [] @array.send(@method, eval("(-2..-4).step(10)")).should == []
@array.send(@method, eval("(-2...-4).step(10)")).should == [] @array.send(@method, eval("(-2...-4).step(10)")).should == []
end end
it "has range with bounds outside of array" do it "has range with bounds outside of array" do
# end is equal to array's length # end is equal to array's length
@array.send(@method, (0..6).step(1)).should == [0, 1, 2, 3, 4, 5] @array.send(@method, (0..6).step(1)).should == [0, 1, 2, 3, 4, 5]
-> { @array.send(@method, (0..6).step(2)) }.should raise_error(RangeError) -> { @array.send(@method, (0..6).step(2)) }.should raise_error(RangeError)
# end is greater than length with positive steps # end is greater than length with positive steps
@array.send(@method, (1..6).step(2)).should == [1, 3, 5] @array.send(@method, (1..6).step(2)).should == [1, 3, 5]
@array.send(@method, (2..7).step(2)).should == [2, 4] @array.send(@method, (2..7).step(2)).should == [2, 4]
-> { @array.send(@method, (2..8).step(2)) }.should raise_error(RangeError) -> { @array.send(@method, (2..8).step(2)) }.should raise_error(RangeError)
# begin is greater than length with negative steps # begin is greater than length with negative steps
@array.send(@method, (6..1).step(-2)).should == [5, 3, 1] @array.send(@method, (6..1).step(-2)).should == [5, 3, 1]
@array.send(@method, (7..2).step(-2)).should == [5, 3] @array.send(@method, (7..2).step(-2)).should == [5, 3]
-> { @array.send(@method, (8..2).step(-2)) }.should raise_error(RangeError) -> { @array.send(@method, (8..2).step(-2)) }.should raise_error(RangeError)
end end
it "has endless range with start outside of array's bounds" do it "has endless range with start outside of array's bounds" do
@array.send(@method, eval("(6..).step(1)")).should == [] @array.send(@method, eval("(6..).step(1)")).should == []
@array.send(@method, eval("(7..).step(1)")).should == nil @array.send(@method, eval("(7..).step(1)")).should == nil
@array.send(@method, eval("(6..).step(2)")).should == [] @array.send(@method, eval("(6..).step(2)")).should == []
-> { @array.send(@method, eval("(7..).step(2)")) }.should raise_error(RangeError) -> { @array.send(@method, eval("(7..).step(2)")) }.should raise_error(RangeError)
end
end end
end end

View File

@ -187,56 +187,28 @@ describe "Array#slice!" do
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5] @array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
end end
ruby_version_is ''...'3.0' do it "returns a Array instance with [n, m]" do
it "returns a subclass instance with [n, m]" do @array.slice!(0, 2).should be_an_instance_of(Array)
@array.slice!(0, 2).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [-n, m]" do
@array.slice!(-3, 2).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [n..m]" do
@array.slice!(1..3).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [n...m]" do
@array.slice!(1...3).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [-n..-m]" do
@array.slice!(-3..-1).should be_an_instance_of(ArraySpecs::MyArray)
end
it "returns a subclass instance with [-n...-m]" do
@array.slice!(-3...-1).should be_an_instance_of(ArraySpecs::MyArray)
end
end end
ruby_version_is '3.0' do it "returns a Array instance with [-n, m]" do
it "returns a Array instance with [n, m]" do @array.slice!(-3, 2).should be_an_instance_of(Array)
@array.slice!(0, 2).should be_an_instance_of(Array) end
end
it "returns a Array instance with [-n, m]" do it "returns a Array instance with [n..m]" do
@array.slice!(-3, 2).should be_an_instance_of(Array) @array.slice!(1..3).should be_an_instance_of(Array)
end end
it "returns a Array instance with [n..m]" do it "returns a Array instance with [n...m]" do
@array.slice!(1..3).should be_an_instance_of(Array) @array.slice!(1...3).should be_an_instance_of(Array)
end end
it "returns a Array instance with [n...m]" do it "returns a Array instance with [-n..-m]" do
@array.slice!(1...3).should be_an_instance_of(Array) @array.slice!(-3..-1).should be_an_instance_of(Array)
end end
it "returns a Array instance with [-n..-m]" do it "returns a Array instance with [-n...-m]" do
@array.slice!(-3..-1).should be_an_instance_of(Array) @array.slice!(-3...-1).should be_an_instance_of(Array)
end
it "returns a Array instance with [-n...-m]" do
@array.slice!(-3...-1).should be_an_instance_of(Array)
end
end end
end end
end end

View File

@ -26,15 +26,7 @@ describe "Array#take" do
->{ [1].take(-3) }.should raise_error(ArgumentError) ->{ [1].take(-3) }.should raise_error(ArgumentError)
end end
ruby_version_is ''...'3.0' do it 'returns a Array instance for Array subclasses' do
it 'returns a subclass instance for Array subclasses' do ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should be_an_instance_of(Array)
ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should be_an_instance_of(ArraySpecs::MyArray)
end
end
ruby_version_is '3.0' do
it 'returns a Array instance for Array subclasses' do
ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should be_an_instance_of(Array)
end
end end
end end

View File

@ -15,16 +15,8 @@ describe "Array#take_while" do
[1, 2, false, 4].take_while{ |element| element }.should == [1, 2] [1, 2, false, 4].take_while{ |element| element }.should == [1, 2]
end end
ruby_version_is ''...'3.0' do it 'returns a Array instance for Array subclasses' do
it 'returns a subclass instance for Array subclasses' do ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should be_an_instance_of(Array)
ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should be_an_instance_of(ArraySpecs::MyArray)
end
end
ruby_version_is '3.0' do
it 'returns a Array instance for Array subclasses' do
ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should be_an_instance_of(Array)
end
end end
end end

View File

@ -85,16 +85,8 @@ describe "Array#uniq" do
[false, nil, 42].uniq { :bar }.should == [false] [false, nil, 42].uniq { :bar }.should == [false]
end end
ruby_version_is ''...'3.0' do it "returns Array instance on Array subclasses" do
it "returns subclass instance on Array subclasses" do ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(Array)
ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(ArraySpecs::MyArray)
end
end
ruby_version_is '3.0' do
it "returns Array instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(Array)
end
end end
it "properly handles an identical item even when its #eql? isn't reflexive" do it "properly handles an identical item even when its #eql? isn't reflexive" do

View File

@ -23,58 +23,29 @@ describe "Binding#eval" do
bind2.local_variables.should == [] bind2.local_variables.should == []
end end
ruby_version_is ""..."3.0" do it "starts with line 1 if single argument is given" do
it "inherits __LINE__ from the enclosing scope" do obj = BindingSpecs::Demo.new(1)
obj = BindingSpecs::Demo.new(1) bind = obj.get_binding
bind = obj.get_binding bind.eval("__LINE__").should == 1
suppress_warning {bind.eval("__LINE__")}.should == obj.get_line_of_binding
end
it "preserves __LINE__ across multiple calls to eval" do
obj = BindingSpecs::Demo.new(1)
bind = obj.get_binding
suppress_warning {bind.eval("__LINE__")}.should == obj.get_line_of_binding
suppress_warning {bind.eval("__LINE__")}.should == obj.get_line_of_binding
end
it "increments __LINE__ on each line of a multiline eval" do
obj = BindingSpecs::Demo.new(1)
bind = obj.get_binding
suppress_warning {bind.eval("#foo\n__LINE__")}.should == obj.get_line_of_binding + 1
end
it "inherits __LINE__ from the enclosing scope even if the Binding is created with #send" do
obj = BindingSpecs::Demo.new(1)
bind, line = obj.get_binding_with_send_and_line
suppress_warning {bind.eval("__LINE__")}.should == line
end
end end
ruby_version_is "3.0" do it "preserves __LINE__ across multiple calls to eval" do
it "starts with line 1 if single argument is given" do obj = BindingSpecs::Demo.new(1)
obj = BindingSpecs::Demo.new(1) bind = obj.get_binding
bind = obj.get_binding bind.eval("__LINE__").should == 1
bind.eval("__LINE__").should == 1 bind.eval("__LINE__").should == 1
end end
it "preserves __LINE__ across multiple calls to eval" do it "increments __LINE__ on each line of a multiline eval" do
obj = BindingSpecs::Demo.new(1) obj = BindingSpecs::Demo.new(1)
bind = obj.get_binding bind = obj.get_binding
bind.eval("__LINE__").should == 1 bind.eval("#foo\n__LINE__").should == 2
bind.eval("__LINE__").should == 1 end
end
it "increments __LINE__ on each line of a multiline eval" do it "starts with line 1 if the Binding is created with #send" do
obj = BindingSpecs::Demo.new(1) obj = BindingSpecs::Demo.new(1)
bind = obj.get_binding bind, line = obj.get_binding_with_send_and_line
bind.eval("#foo\n__LINE__").should == 2 bind.eval("__LINE__").should == 1
end
it "starts with line 1 if the Binding is created with #send" do
obj = BindingSpecs::Demo.new(1)
bind, line = obj.get_binding_with_send_and_line
bind.eval("__LINE__").should == 1
end
end end
it "starts with a __LINE__ of 1 if a filename is passed" do it "starts with a __LINE__ of 1 if a filename is passed" do
@ -89,32 +60,16 @@ describe "Binding#eval" do
bind.eval("#foo\n__LINE__", "(test)", 88).should == 89 bind.eval("#foo\n__LINE__", "(test)", 88).should == 89
end end
ruby_version_is ""..."3.0" do it "uses (eval) as __FILE__ if single argument given" do
it "inherits __FILE__ from the enclosing scope" do obj = BindingSpecs::Demo.new(1)
obj = BindingSpecs::Demo.new(1) bind = obj.get_binding
bind = obj.get_binding bind.eval("__FILE__").should == '(eval)'
suppress_warning { bind.eval("__FILE__") }.should == obj.get_file_of_binding
end
it "inherits __LINE__ from the enclosing scope" do
obj = BindingSpecs::Demo.new(1)
bind, line = obj.get_binding_and_line
suppress_warning { bind.eval("__LINE__") }.should == line
end
end end
ruby_version_is "3.0" do it "uses 1 as __LINE__" do
it "uses (eval) as __FILE__ if single argument given" do obj = BindingSpecs::Demo.new(1)
obj = BindingSpecs::Demo.new(1) bind = obj.get_binding
bind = obj.get_binding suppress_warning { bind.eval("__LINE__") }.should == 1
bind.eval("__FILE__").should == '(eval)'
end
it "uses 1 as __LINE__" do
obj = BindingSpecs::Demo.new(1)
bind = obj.get_binding
suppress_warning { bind.eval("__LINE__") }.should == 1
end
end end
it "uses the __FILE__ that is passed in" do it "uses the __FILE__ that is passed in" do

View File

@ -1,20 +1,6 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
ruby_version_is ''...'3.0' do ruby_version_is ''...'3.2' do
describe "Data" do
it "is a subclass of Object" do
suppress_warning do
Data.superclass.should == Object
end
end
it "is deprecated" do
-> { Data }.should complain(/constant ::Data is deprecated/)
end
end
end
ruby_version_is '3.0'...'3.2' do
describe "Data" do describe "Data" do
it "does not exist anymore" do it "does not exist anymore" do
Object.should_not have_constant(:Data) Object.should_not have_constant(:Data)

View File

@ -260,7 +260,7 @@ describe "Dir.glob" do
Dir.glob('**/.*', base: "deeply/nested").sort.should == expected Dir.glob('**/.*', base: "deeply/nested").sort.should == expected
end end
# 2.7 and 3.0 include a "." entry for every dir: ["directory/.", "directory/structure/.", ...] # < 3.1 include a "." entry for every dir: ["directory/.", "directory/structure/.", ...]
ruby_version_is '3.1' do ruby_version_is '3.1' do
it "handles **/.* with base keyword argument and FNM_DOTMATCH" do it "handles **/.* with base keyword argument and FNM_DOTMATCH" do
expected = %w[ expected = %w[

View File

@ -27,24 +27,22 @@ describe :dir_glob, shared: true do
-> {Dir.send(@method, "file_o*\0file_t*")}.should raise_error ArgumentError, /nul-separated/ -> {Dir.send(@method, "file_o*\0file_t*")}.should raise_error ArgumentError, /nul-separated/
end end
ruby_version_is "3.0" do it "result is sorted by default" do
it "result is sorted by default" do result = Dir.send(@method, '*')
result = Dir.send(@method, '*') result.should == result.sort
result.should == result.sort
end
it "result is sorted with sort: true" do
result = Dir.send(@method, '*', sort: true)
result.should == result.sort
end
it "sort: false returns same files" do
result = Dir.send(@method,'*', sort: false)
result.sort.should == Dir.send(@method, '*').sort
end
end end
ruby_version_is "3.0"..."3.1" do it "result is sorted with sort: true" do
result = Dir.send(@method, '*', sort: true)
result.should == result.sort
end
it "sort: false returns same files" do
result = Dir.send(@method,'*', sort: false)
result.sort.should == Dir.send(@method, '*').sort
end
ruby_version_is ""..."3.1" do
it "result is sorted with any non false value of sort:" do it "result is sorted with any non false value of sort:" do
result = Dir.send(@method, '*', sort: 0) result = Dir.send(@method, '*', sort: 0)
result.should == result.sort result.should == result.sort

View File

@ -18,11 +18,9 @@ describe "Encoding.default_external" do
Encoding.default_external.should == Encoding::SHIFT_JIS Encoding.default_external.should == Encoding::SHIFT_JIS
end end
ruby_version_is "3.0" do platform_is :windows do
platform_is :windows do it 'is UTF-8 by default on Windows' do
it 'is UTF-8 by default on Windows' do Encoding.default_external.should == Encoding::UTF_8
Encoding.default_external.should == Encoding::UTF_8
end
end end
end end
end end

View File

@ -40,43 +40,28 @@ describe "Enumerable#grep" do
$~.should == nil $~.should == nil
end end
ruby_version_is ""..."3.0.0" do it "does not set $~ when given no block" do
it "sets $~ to the last match when given no block" do "z" =~ /z/ # Reset $~
"z" =~ /z/ # Reset $~ ["abc", "def"].grep(/b/).should == ["abc"]
["abc", "def"].grep(/b/).should == ["abc"] $&.should == "z"
# Set by the failed match of "def"
$~.should == nil
["abc", "def"].grep(/e/)
$&.should == "e"
end
end end
ruby_version_is "3.0.0" do it "does not modify Regexp.last_match without block" do
it "does not set $~ when given no block" do "z" =~ /z/ # Reset last match
"z" =~ /z/ # Reset $~ ["abc", "def"].grep(/b/).should == ["abc"]
["abc", "def"].grep(/b/).should == ["abc"] Regexp.last_match[0].should == "z"
$&.should == "z" end
end
it "does not modify Regexp.last_match without block" do it "correctly handles non-string elements" do
"z" =~ /z/ # Reset last match 'set last match' =~ /set last (.*)/
["abc", "def"].grep(/b/).should == ["abc"] [:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c]
Regexp.last_match[0].should == "z" $1.should == 'match'
end
it "correctly handles non-string elements" do o = Object.new
'set last match' =~ /set last (.*)/ def o.to_str
[:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c] 'hello'
$1.should == 'match'
o = Object.new
def o.to_str
'hello'
end
[o].grep(/ll/).first.should.equal?(o)
end end
[o].grep(/ll/).first.should.equal?(o)
end end
describe "with a block" do describe "with a block" do

View File

@ -20,43 +20,28 @@ describe "Enumerable#grep_v" do
$&.should == "e" $&.should == "e"
end end
ruby_version_is ""..."3.0.0" do it "does not set $~ when given no block" do
it "sets $~ to the last match when given no block" do "z" =~ /z/ # Reset $~
"z" =~ /z/ # Reset $~ ["abc", "def"].grep_v(/e/).should == ["abc"]
["abc", "def"].grep_v(/e/).should == ["abc"] $&.should == "z"
# Set by the match of "def"
$&.should == "e"
["abc", "def"].grep_v(/b/)
$&.should == nil
end
end end
ruby_version_is "3.0.0" do it "does not modify Regexp.last_match without block" do
it "does not set $~ when given no block" do "z" =~ /z/ # Reset last match
"z" =~ /z/ # Reset $~ ["abc", "def"].grep_v(/e/).should == ["abc"]
["abc", "def"].grep_v(/e/).should == ["abc"] Regexp.last_match[0].should == "z"
$&.should == "z" end
end
it "does not modify Regexp.last_match without block" do it "correctly handles non-string elements" do
"z" =~ /z/ # Reset last match 'set last match' =~ /set last (.*)/
["abc", "def"].grep_v(/e/).should == ["abc"] [:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil]
Regexp.last_match[0].should == "z" $1.should == 'match'
end
it "correctly handles non-string elements" do o = Object.new
'set last match' =~ /set last (.*)/ def o.to_str
[:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil] 'hello'
$1.should == 'match'
o = Object.new
def o.to_str
'hello'
end
[o].grep_v(/mm/).first.should.equal?(o)
end end
[o].grep_v(/mm/).first.should.equal?(o)
end end
describe "without block" do describe "without block" do

View File

@ -11,14 +11,6 @@ describe "Enumerator#initialize" do
Enumerator.should have_private_instance_method(:initialize, false) Enumerator.should have_private_instance_method(:initialize, false)
end end
ruby_version_is ''...'3.0' do
it "returns self when given an object" do
suppress_warning do
@uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
end
end
end
it "returns self when given a block" do it "returns self when given a block" do
@uninitialized.send(:initialize) {}.should equal(@uninitialized) @uninitialized.send(:initialize) {}.should equal(@uninitialized)
end end

View File

@ -2,51 +2,8 @@ require_relative '../../spec_helper'
describe "Enumerator.new" do describe "Enumerator.new" do
context "no block given" do context "no block given" do
ruby_version_is '3.0' do it "raises" do
it "raises" do -> { Enumerator.new(1, :upto, 3) }.should raise_error(ArgumentError)
-> { Enumerator.new(1, :upto, 3) }.should raise_error(ArgumentError)
end
end
ruby_version_is ''...'3.0' do
it "creates a new custom enumerator with the given object, iterator and arguments" do
enum = suppress_warning { Enumerator.new(1, :upto, 3) }
enum.should be_an_instance_of(Enumerator)
end
it "creates a new custom enumerator that responds to #each" do
enum = suppress_warning { Enumerator.new(1, :upto, 3) }
enum.respond_to?(:each).should == true
end
it "creates a new custom enumerator that runs correctly" do
suppress_warning { Enumerator.new(1, :upto, 3) }.map{ |x| x }.should == [1,2,3]
end
it "aliases the second argument to :each" do
suppress_warning { Enumerator.new(1..2) }.to_a.should ==
suppress_warning { Enumerator.new(1..2, :each) }.to_a
end
it "doesn't check for the presence of the iterator method" do
suppress_warning { Enumerator.new(nil) }.should be_an_instance_of(Enumerator)
end
it "uses the latest define iterator method" do
class StrangeEach
def each
yield :foo
end
end
enum = suppress_warning { Enumerator.new(StrangeEach.new) }
enum.to_a.should == [:foo]
class StrangeEach
def each
yield :bar
end
end
enum.to_a.should == [:bar]
end
end end
end end

View File

@ -30,11 +30,9 @@ describe "ENV.delete" do
ScratchPad.recorded.should == "foo" ScratchPad.recorded.should == "foo"
end end
ruby_version_is "3.0" do it "returns the result of given block if the named environment variable does not exist" do
it "returns the result of given block if the named environment variable does not exist" do ENV.delete("foo")
ENV.delete("foo") ENV.delete("foo") { |name| "bar" }.should == "bar"
ENV.delete("foo") { |name| "bar" }.should == "bar"
end
end end
it "does not evaluate the block if the environment variable exists" do it "does not evaluate the block if the environment variable exists" do

View File

@ -1,36 +1,34 @@
require_relative 'spec_helper' require_relative 'spec_helper'
require_relative 'shared/to_hash' require_relative 'shared/to_hash'
ruby_version_is "3.0" do describe "ENV.except" do
describe "ENV.except" do before do
before do @orig_hash = ENV.to_hash
@orig_hash = ENV.to_hash end
end
after do after do
ENV.replace @orig_hash ENV.replace @orig_hash
end end
# Testing the method without arguments is covered via # Testing the method without arguments is covered via
it_behaves_like :env_to_hash, :except it_behaves_like :env_to_hash, :except
it "returns a hash without the requested subset" do it "returns a hash without the requested subset" do
ENV.clear ENV.clear
ENV['one'] = '1' ENV['one'] = '1'
ENV['two'] = '2' ENV['two'] = '2'
ENV['three'] = '3' ENV['three'] = '3'
ENV.except('one', 'three').should == { 'two' => '2' } ENV.except('one', 'three').should == { 'two' => '2' }
end end
it "ignores keys not present in the original hash" do it "ignores keys not present in the original hash" do
ENV.clear ENV.clear
ENV['one'] = '1' ENV['one'] = '1'
ENV['two'] = '2' ENV['two'] = '2'
ENV.except('one', 'three').should == { 'two' => '2' } ENV.except('one', 'three').should == { 'two' => '2' }
end
end end
end end

View File

@ -1,14 +0,0 @@
require_relative '../../spec_helper'
require_relative 'shared/key'
ruby_version_is ''...'3.0' do
describe "ENV.index" do
it_behaves_like :env_key, :index
it "warns about deprecation" do
-> do
ENV.index("foo")
end.should complain(/warning: ENV.index is deprecated; use ENV.key/)
end
end
end

View File

@ -1 +0,0 @@
require_relative '../../spec_helper'

View File

@ -1 +0,0 @@
require_relative '../../spec_helper'

View File

@ -6,7 +6,10 @@ describe "ENV.to_a" do
a = ENV.to_a a = ENV.to_a
a.is_a?(Array).should == true a.is_a?(Array).should == true
a.size.should == ENV.size a.size.should == ENV.size
ENV.each_pair { |k, v| a.should include([k, v])} a.each { |k,v| ENV[k].should == v }
a.first.should.is_a?(Array)
a.first.size.should == 2
end end
it "returns the entries in the locale encoding" do it "returns the entries in the locale encoding" do

View File

@ -125,21 +125,19 @@ describe "NoMethodError#message" do
end end
end end
ruby_version_is "3.0" do it "uses #name to display the receiver if it is a class or a module" do
it "uses #name to display the receiver if it is a class or a module" do klass = Class.new { def self.name; "MyClass"; end }
klass = Class.new { def self.name; "MyClass"; end } begin
begin klass.foo
klass.foo rescue NoMethodError => error
rescue NoMethodError => error error.message.lines.first.chomp.should =~ /^undefined method `foo' for /
error.message.lines.first.chomp.should =~ /^undefined method `foo' for / end
end
mod = Module.new { def self.name; "MyModule"; end } mod = Module.new { def self.name; "MyModule"; end }
begin begin
mod.foo mod.foo
rescue NoMethodError => error rescue NoMethodError => error
error.message.lines.first.chomp.should =~ /^undefined method `foo' for / error.message.lines.first.chomp.should =~ /^undefined method `foo' for /
end
end end
end end
end end

View File

@ -1,61 +1,59 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative 'shared/blocking' require_relative 'shared/blocking'
ruby_version_is "3.0" do require "fiber"
require "fiber"
describe "Fiber.blocking?" do describe "Fiber.blocking?" do
it_behaves_like :non_blocking_fiber, -> { Fiber.blocking? } it_behaves_like :non_blocking_fiber, -> { Fiber.blocking? }
context "when fiber is blocking" do context "when fiber is blocking" do
context "root Fiber of the main thread" do context "root Fiber of the main thread" do
it "returns 1 for blocking: true" do it "returns 1 for blocking: true" do
fiber = Fiber.new(blocking: true) { Fiber.blocking? }
blocking = fiber.resume
blocking.should == 1
end
end
context "root Fiber of a new thread" do
it "returns 1 for blocking: true" do
thread = Thread.new do
fiber = Fiber.new(blocking: true) { Fiber.blocking? } fiber = Fiber.new(blocking: true) { Fiber.blocking? }
blocking = fiber.resume blocking = fiber.resume
blocking.should == 1 blocking.should == 1
end end
end
context "root Fiber of a new thread" do thread.join
it "returns 1 for blocking: true" do
thread = Thread.new do
fiber = Fiber.new(blocking: true) { Fiber.blocking? }
blocking = fiber.resume
blocking.should == 1
end
thread.join
end
end end
end end
end end
end
describe "Fiber#blocking?" do describe "Fiber#blocking?" do
it_behaves_like :non_blocking_fiber, -> { Fiber.current.blocking? } it_behaves_like :non_blocking_fiber, -> { Fiber.current.blocking? }
context "when fiber is blocking" do context "when fiber is blocking" do
context "root Fiber of the main thread" do context "root Fiber of the main thread" do
it "returns true for blocking: true" do it "returns true for blocking: true" do
fiber = Fiber.new(blocking: true) { Fiber.current.blocking? }
blocking = fiber.resume
blocking.should == true
end
end
context "root Fiber of a new thread" do
it "returns true for blocking: true" do
thread = Thread.new do
fiber = Fiber.new(blocking: true) { Fiber.current.blocking? } fiber = Fiber.new(blocking: true) { Fiber.current.blocking? }
blocking = fiber.resume blocking = fiber.resume
blocking.should == true blocking.should == true
end end
end
context "root Fiber of a new thread" do thread.join
it "returns true for blocking: true" do
thread = Thread.new do
fiber = Fiber.new(blocking: true) { Fiber.current.blocking? }
blocking = fiber.resume
blocking.should == true
end
thread.join
end
end end
end end
end end

View File

@ -18,11 +18,9 @@ describe "Fiber#inspect" do
inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/ inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/
end end
ruby_version_is "3.0" do it "is resumed for a Fiber which was transferred" do
it "is resumed for a Fiber which was transferred" do inspected = Fiber.new { Fiber.current.inspect }.transfer
inspected = Fiber.new { Fiber.current.inspect }.transfer inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/
inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/
end
end end
it "is suspended for a Fiber which was resumed and yielded" do it "is suspended for a Fiber which was resumed and yielded" do

View File

@ -94,26 +94,12 @@ describe "Fiber#raise" do
end end
ruby_version_is ""..."3.0" do describe "Fiber#raise" do
describe "Fiber#raise" do it "transfers and raises on a transferring fiber" do
it "raises a FiberError if invoked on a transferring Fiber" do require "fiber"
require "fiber" root = Fiber.current
root = Fiber.current fiber = Fiber.new { root.transfer }
fiber = Fiber.new { root.transfer } fiber.transfer
fiber.transfer -> { fiber.raise "msg" }.should raise_error(RuntimeError, "msg")
-> { fiber.raise }.should raise_error(FiberError, "cannot resume transferred Fiber")
end
end
end
ruby_version_is "3.0" do
describe "Fiber#raise" do
it "transfers and raises on a transferring fiber" do
require "fiber"
root = Fiber.current
fiber = Fiber.new { root.transfer }
fiber.transfer
-> { fiber.raise "msg" }.should raise_error(RuntimeError, "msg")
end
end end
end end

View File

@ -28,18 +28,9 @@ describe "Fiber#resume" do
fiber.resume :second fiber.resume :second
end end
ruby_version_is '3.0' do it "raises a FiberError if the Fiber tries to resume itself" do
it "raises a FiberError if the Fiber tries to resume itself" do fiber = Fiber.new { fiber.resume }
fiber = Fiber.new { fiber.resume } -> { fiber.resume }.should raise_error(FiberError, /current fiber/)
-> { fiber.resume }.should raise_error(FiberError, /current fiber/)
end
end
ruby_version_is '' ... '3.0' do
it "raises a FiberError if the Fiber tries to resume itself" do
fiber = Fiber.new { fiber.resume }
-> { fiber.resume }.should raise_error(FiberError, /double resume/)
end
end end
it "returns control to the calling Fiber if called from one" do it "returns control to the calling Fiber if called from one" do

View File

@ -168,16 +168,14 @@ describe "File.new" do
File.should.exist?(@file) File.should.exist?(@file)
end end
ruby_version_is "3.0" do it "accepts options as a keyword argument" do
it "accepts options as a keyword argument" do @fh = File.new(@file, 'w', 0755, flags: @flags)
@fh = File.new(@file, 'w', 0755, flags: @flags) @fh.should be_kind_of(File)
@fh.should be_kind_of(File) @fh.close
@fh.close
-> { -> {
@fh = File.new(@file, 'w', 0755, {flags: @flags}) @fh = File.new(@file, 'w', 0755, {flags: @flags})
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
end
end end
it "bitwise-ORs mode and flags option" do it "bitwise-ORs mode and flags option" do

View File

@ -565,15 +565,13 @@ describe "File.open" do
File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::BINARY} File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::BINARY}
end end
ruby_version_is "3.0" do it "accepts options as a keyword argument" do
it "accepts options as a keyword argument" do @fh = File.open(@file, 'w', 0755, flags: File::CREAT)
@fh = File.open(@file, 'w', 0755, flags: File::CREAT) @fh.should be_an_instance_of(File)
@fh.should be_an_instance_of(File)
-> { -> {
File.open(@file, 'w', 0755, {flags: File::CREAT}) File.open(@file, 'w', 0755, {flags: File::CREAT})
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
end
end end
it "uses the second argument as an options Hash" do it "uses the second argument as an options Hash" do

View File

@ -1,26 +1,24 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
ruby_version_is "3.0" do describe "GC.auto_compact" do
describe "GC.auto_compact" do it "can set and get a boolean value" do
it "can set and get a boolean value" do begin
begin GC.auto_compact = GC.auto_compact
GC.auto_compact = GC.auto_compact rescue NotImplementedError # platform does not support autocompact
rescue NotImplementedError # platform does not support autocompact skip
skip end
end
original = GC.auto_compact original = GC.auto_compact
begin begin
GC.auto_compact = !original GC.auto_compact = !original
rescue NotImplementedError # platform does not support autocompact rescue NotImplementedError # platform does not support autocompact
skip skip
end end
begin begin
GC.auto_compact.should == !original GC.auto_compact.should == !original
ensure ensure
GC.auto_compact = original GC.auto_compact = original
end
end end
end end
end end

View File

@ -1,34 +1,32 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
ruby_version_is "3.0" do describe "Hash#except" do
describe "Hash#except" do before :each do
before :each do @hash = { a: 1, b: 2, c: 3 }
@hash = { a: 1, b: 2, c: 3 } end
end
it "returns a new duplicate hash without arguments" do it "returns a new duplicate hash without arguments" do
ret = @hash.except ret = @hash.except
ret.should_not equal(@hash) ret.should_not equal(@hash)
ret.should == @hash ret.should == @hash
end end
it "returns a hash without the requested subset" do it "returns a hash without the requested subset" do
@hash.except(:c, :a).should == { b: 2 } @hash.except(:c, :a).should == { b: 2 }
end end
it "ignores keys not present in the original hash" do it "ignores keys not present in the original hash" do
@hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 } @hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 }
end end
it "always returns a Hash without a default" do it "always returns a Hash without a default" do
klass = Class.new(Hash) klass = Class.new(Hash)
h = klass.new(:default) h = klass.new(:default)
h[:bar] = 12 h[:bar] = 12
h[:foo] = 42 h[:foo] = 42
r = h.except(:foo) r = h.except(:foo)
r.should == {bar: 12} r.should == {bar: 12}
r.class.should == Hash r.class.should == Hash
r.default.should == nil r.default.should == nil
end
end end
end end

View File

@ -1,9 +0,0 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative 'shared/index'
ruby_version_is ''...'3.0' do
describe "Hash#index" do
it_behaves_like :hash_index, :index
end
end

View File

@ -21,37 +21,18 @@ describe :hash_each, shared: true do
ary.sort.should == ["a", "b", "c"] ary.sort.should == ["a", "b", "c"]
end end
ruby_version_is ""..."3.0" do it "always yields an Array of 2 elements, even when given a callable of arity 2" do
it "yields 2 values and not an Array of 2 elements when given a callable of arity 2" do obj = Object.new
obj = Object.new def obj.foo(key, value)
def obj.foo(key, value) end
ScratchPad << key << value
end
ScratchPad.record([]) -> {
{ "a" => 1 }.send(@method, &obj.method(:foo)) { "a" => 1 }.send(@method, &obj.method(:foo))
ScratchPad.recorded.should == ["a", 1] }.should raise_error(ArgumentError)
ScratchPad.record([]) -> {
{ "a" => 1 }.send(@method, &-> key, value { ScratchPad << key << value }) { "a" => 1 }.send(@method, &-> key, value { })
ScratchPad.recorded.should == ["a", 1] }.should raise_error(ArgumentError)
end
end
ruby_version_is "3.0" do
it "always yields an Array of 2 elements, even when given a callable of arity 2" do
obj = Object.new
def obj.foo(key, value)
end
-> {
{ "a" => 1 }.send(@method, &obj.method(:foo))
}.should raise_error(ArgumentError)
-> {
{ "a" => 1 }.send(@method, &-> key, value { })
}.should raise_error(ArgumentError)
end
end end
it "yields an Array of 2 elements when given a callable of arity 1" do it "yields an Array of 2 elements when given a callable of arity 1" do

View File

@ -1,90 +0,0 @@
describe :hash_equal, shared: true do
it "does not compare values when keys don't match" do
value = mock('x')
value.should_not_receive(:==)
value.should_not_receive(:eql?)
{ 1 => value }.send(@method, { 2 => value }).should be_false
end
it "returns false when the numbers of keys differ without comparing any elements" do
obj = mock('x')
h = { obj => obj }
obj.should_not_receive(:==)
obj.should_not_receive(:eql?)
{}.send(@method, h).should be_false
h.send(@method, {}).should be_false
end
it "first compares keys via hash" do
x = mock('x')
x.should_receive(:hash).and_return(0)
y = mock('y')
y.should_receive(:hash).and_return(0)
{ x => 1 }.send(@method, { y => 1 }).should be_false
end
it "does not compare keys with different hash codes via eql?" do
x = mock('x')
y = mock('y')
x.should_not_receive(:eql?)
y.should_not_receive(:eql?)
x.should_receive(:hash).and_return(0)
y.should_receive(:hash).and_return(1)
def x.hash() 0 end
def y.hash() 1 end
{ x => 1 }.send(@method, { y => 1 }).should be_false
end
it "computes equality for recursive hashes" do
h = {}
h[:a] = h
h.send(@method, h[:a]).should be_true
(h == h[:a]).should be_true
end
it "computes equality for complex recursive hashes" do
a, b = {}, {}
a.merge! self: a, other: b
b.merge! self: b, other: a
a.send(@method, b).should be_true # they both have the same structure!
c = {}
c.merge! other: c, self: c
c.send(@method, a).should be_true # subtle, but they both have the same structure!
a[:delta] = c[:delta] = a
c.send(@method, a).should be_false # not quite the same structure, as a[:other][:delta] = nil
c[:delta] = 42
c.send(@method, a).should be_false
a[:delta] = 42
c.send(@method, a).should be_false
b[:delta] = 42
c.send(@method, a).should be_true
end
it "computes equality for recursive hashes & arrays" do
x, y, z = [], [], []
a, b, c = {foo: x, bar: 42}, {foo: y, bar: 42}, {foo: z, bar: 42}
x << a
y << c
z << b
b.send(@method, c).should be_true # they clearly have the same structure!
y.send(@method, z).should be_true
a.send(@method, b).should be_true # subtle, but they both have the same structure!
x.send(@method, y).should be_true
y << x
y.send(@method, z).should be_false
z << x
y.send(@method, z).should be_true
a[:foo], a[:bar] = a[:bar], a[:foo]
a.send(@method, b).should be_false
b[:bar] = b[:foo]
b.send(@method, c).should be_false
end
end

View File

@ -26,14 +26,4 @@ describe "Hash#to_a" do
ent.should be_kind_of(Array) ent.should be_kind_of(Array)
ent.should == pairs ent.should == pairs
end end
ruby_version_is ''...'3.0' do
it "returns a not tainted array if self is tainted" do
{}.taint.to_a.tainted?.should be_false
end
it "returns a trusted array if self is untrusted" do
{}.untrust.to_a.untrusted?.should be_false
end
end
end end

View File

@ -19,20 +19,12 @@ describe "Hash#to_proc" do
@proc = @hash.to_proc @proc = @hash.to_proc
end end
ruby_version_is ""..."3.0" do it "is a lambda" do
it "is not a lambda" do @proc.should.lambda?
@proc.should_not.lambda?
end
end end
ruby_version_is "3.0" do it "has an arity of 1" do
it "is a lambda" do @proc.arity.should == 1
@proc.should.lambda?
end
it "has an arity of 1" do
@proc.arity.should == 1
end
end end
it "raises ArgumentError if not passed exactly one argument" do it "raises ArgumentError if not passed exactly one argument" do

View File

@ -43,18 +43,16 @@ describe "Hash#transform_keys" do
r.class.should == Hash r.class.should == Hash
end end
ruby_version_is "3.0" do it "allows a hash argument" do
it "allows a hash argument" do @hash.transform_keys({ a: :A, b: :B, c: :C }).should == { A: 1, B: 2, C: 3 }
@hash.transform_keys({ a: :A, b: :B, c: :C }).should == { A: 1, B: 2, C: 3 } end
end
it "allows a partial transformation of keys when using a hash argument" do it "allows a partial transformation of keys when using a hash argument" do
@hash.transform_keys({ a: :A, c: :C }).should == { A: 1, b: 2, C: 3 } @hash.transform_keys({ a: :A, c: :C }).should == { A: 1, b: 2, C: 3 }
end end
it "allows a combination of hash and block argument" do it "allows a combination of hash and block argument" do
@hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 } @hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 }
end
end end
end end
@ -111,11 +109,9 @@ describe "Hash#transform_keys!" do
end end
end end
ruby_version_is "3.0" do it "allows a hash argument" do
it "allows a hash argument" do @hash.transform_keys!({ a: :A, b: :B, c: :C, d: :D })
@hash.transform_keys!({ a: :A, b: :B, c: :C, d: :D }) @hash.should == { A: 1, B: 2, C: 3, D: 4 }
@hash.should == { A: 1, B: 2, C: 3, D: 4 }
end
end end
describe "on frozen instance" do describe "on frozen instance" do
@ -132,10 +128,8 @@ describe "Hash#transform_keys!" do
@hash.should == @initial_pairs @hash.should == @initial_pairs
end end
ruby_version_is "3.0" do it "raises a FrozenError on hash argument" do
it "raises a FrozenError on hash argument" do ->{ @hash.transform_keys!({ a: :A, b: :B, c: :C }) }.should raise_error(FrozenError)
->{ @hash.transform_keys!({ a: :A, b: :B, c: :C }) }.should raise_error(FrozenError)
end
end end
context "when no block is given" do context "when no block is given" do

View File

@ -1,25 +1,5 @@
require_relative '../fixtures/classes' require_relative '../fixtures/classes'
describe :integer_arithmetic_coerce_rescue, shared: true do
it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do
b = mock("numeric with failed #coerce")
b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
# e.g. 1 + b
-> { 1.send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into Integer/)
end
it "does not rescue Exception and StandardError siblings raised in other#coerce" do
[Exception, NoMemoryError].each do |exception|
b = mock("numeric with failed #coerce")
b.should_receive(:coerce).and_raise(exception)
# e.g. 1 + b
-> { 1.send(@method, b) }.should raise_error(exception)
end
end
end
describe :integer_arithmetic_coerce_not_rescue, shared: true do describe :integer_arithmetic_coerce_not_rescue, shared: true do
it "does not rescue exception raised in other#coerce" do it "does not rescue exception raised in other#coerce" do
b = mock("numeric with failed #coerce") b = mock("numeric with failed #coerce")

View File

@ -7,15 +7,7 @@ describe "Integer#zero?" do
-1.should_not.zero? -1.should_not.zero?
end end
ruby_version_is "3.0" do it "Integer#zero? overrides Numeric#zero?" do
it "Integer#zero? overrides Numeric#zero?" do 42.method(:zero?).owner.should == Integer
42.method(:zero?).owner.should == Integer
end
end
ruby_version_is ""..."3.0" do
it "Integer#zero? uses Numeric#zero?" do
42.method(:zero?).owner.should == Numeric
end
end end
end end

View File

@ -1,47 +0,0 @@
# -*- encoding: utf-8 -*-
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is ''...'3.0' do
describe "IO#bytes" do
before :each do
@io = IOSpecs.io_fixture "lines.txt"
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
@io.close unless @io.closed?
end
it "returns an enumerator of the next bytes from the stream" do
enum = @io.bytes
enum.should be_an_instance_of(Enumerator)
@io.readline.should == "Voici la ligne une.\n"
enum.first(5).should == [81, 117, 105, 32, 195]
end
it "yields each byte" do
count = 0
ScratchPad.record []
@io.each_byte do |byte|
ScratchPad << byte
break if 4 < count += 1
end
ScratchPad.recorded.should == [86, 111, 105, 99, 105]
end
it "raises an IOError on closed stream" do
enum = IOSpecs.closed_io.bytes
-> { enum.first }.should raise_error(IOError)
end
it "raises an IOError on an enumerator for a stream that has been closed" do
enum = @io.bytes
enum.first.should == 86
@io.close
-> { enum.first }.should raise_error(IOError)
end
end
end

View File

@ -1,30 +0,0 @@
# -*- encoding: utf-8 -*-
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative 'shared/chars'
ruby_version_is ''...'3.0' do
describe "IO#chars" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
end
it_behaves_like :io_chars, :chars
end
describe "IO#chars" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
end
it_behaves_like :io_chars_empty, :chars
end
end

View File

@ -1,38 +0,0 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative 'shared/codepoints'
ruby_version_is ''...'3.0' do
# See redmine #1667
describe "IO#codepoints" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
end
it_behaves_like :io_codepoints, :codepoints
end
describe "IO#codepoints" do
before :each do
@io = IOSpecs.io_fixture "lines.txt"
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
@io.close unless @io.closed?
end
it "calls the given block" do
r = []
@io.codepoints { |c| r << c }
r[24].should == 232
r.last.should == 10
end
end
end

View File

@ -149,14 +149,12 @@ describe "IO#gets" do
@io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0] @io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
end end
ruby_version_is "3.0" do it "raises exception when options passed as Hash" do
it "raises exception when options passed as Hash" do -> { @io.gets({ chomp: true }) }.should raise_error(TypeError)
-> { @io.gets({ chomp: true }) }.should raise_error(TypeError)
-> { -> {
@io.gets("\n", 1, { chomp: true }) @io.gets("\n", 1, { chomp: true })
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
end
end end
end end
end end

View File

@ -27,17 +27,15 @@ describe "IO#initialize" do
@io.fileno.should == fd @io.fileno.should == fd
end end
ruby_version_is "3.0" do it "accepts options as keyword arguments" do
it "accepts options as keyword arguments" do fd = new_fd @name, "w:utf-8"
fd = new_fd @name, "w:utf-8"
@io.send(:initialize, fd, "w", flags: File::CREAT) @io.send(:initialize, fd, "w", flags: File::CREAT)
@io.fileno.should == fd @io.fileno.should == fd
-> { -> {
@io.send(:initialize, fd, "w", {flags: File::CREAT}) @io.send(:initialize, fd, "w", {flags: File::CREAT})
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)") }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
end
end end
it "raises a TypeError when passed an IO" do it "raises a TypeError when passed an IO" do

View File

@ -1,46 +0,0 @@
# -*- encoding: utf-8 -*-
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is ''...'3.0' do
describe "IO#lines" do
before :each do
@io = IOSpecs.io_fixture "lines.txt"
@verbose, $VERBOSE = $VERBOSE, nil
end
after :each do
$VERBOSE = @verbose
@io.close if @io
end
it "returns an Enumerator" do
@io.lines.should be_an_instance_of(Enumerator)
end
describe "when no block is given" do
it "returns an Enumerator" do
@io.lines.should be_an_instance_of(Enumerator)
end
describe "returned Enumerator" do
describe "size" do
it "should return nil" do
@io.lines.size.should == nil
end
end
end
end
it "returns a line when accessed" do
enum = @io.lines
enum.first.should == IOSpecs.lines[0]
end
it "yields each line to the passed block" do
ScratchPad.record []
@io.lines { |s| ScratchPad << s }
ScratchPad.recorded.should == IOSpecs.lines
end
end
end

View File

@ -12,43 +12,21 @@ platform_is_not :windows do
end end
end end
ruby_version_is ""..."3.0" do it "returns true for pipe by default" do
it "returns false for pipe by default" do r, w = IO.pipe
r, w = IO.pipe begin
begin r.nonblock?.should == true
r.nonblock?.should == false w.nonblock?.should == true
w.nonblock?.should == false ensure
ensure r.close
r.close w.close
w.close
end
end
it "returns false for socket by default" do
require 'socket'
TCPServer.open(0) do |socket|
socket.nonblock?.should == false
end
end end
end end
ruby_version_is "3.0" do it "returns true for socket by default" do
it "returns true for pipe by default" do require 'socket'
r, w = IO.pipe TCPServer.open(0) do |socket|
begin socket.nonblock?.should == true
r.nonblock?.should == true
w.nonblock?.should == true
ensure
r.close
w.close
end
end
it "returns true for socket by default" do
require 'socket'
TCPServer.open(0) do |socket|
socket.nonblock?.should == true
end
end end
end end
end end

View File

@ -23,15 +23,13 @@ describe "IO.read" do
IO.read(p) IO.read(p)
end end
ruby_version_is "3.0" do # https://bugs.ruby-lang.org/issues/19354
# https://bugs.ruby-lang.org/issues/19354 it "accepts options as keyword arguments" do
it "accepts options as keyword arguments" do IO.read(@fname, 3, 0, mode: "r+").should == @contents[0, 3]
IO.read(@fname, 3, 0, mode: "r+").should == @contents[0, 3]
-> { -> {
IO.read(@fname, 3, 0, {mode: "r+"}) IO.read(@fname, 3, 0, {mode: "r+"})
}.should raise_error(ArgumentError, /wrong number of arguments/) }.should raise_error(ArgumentError, /wrong number of arguments/)
end
end end
it "accepts an empty options Hash" do it "accepts an empty options Hash" do

View File

@ -73,14 +73,12 @@ describe "IO#readline" do
@io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0] @io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
end end
ruby_version_is "3.0" do it "raises exception when options passed as Hash" do
it "raises exception when options passed as Hash" do -> { @io.readline({ chomp: true }) }.should raise_error(TypeError)
-> { @io.readline({ chomp: true }) }.should raise_error(TypeError)
-> { -> {
@io.readline("\n", 1, { chomp: true }) @io.readline("\n", 1, { chomp: true })
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
end
end end
end end
end end

View File

@ -117,14 +117,12 @@ describe "IO#readlines" do
@io.readlines(chomp: true).should == IOSpecs.lines_without_newline_characters @io.readlines(chomp: true).should == IOSpecs.lines_without_newline_characters
end end
ruby_version_is "3.0" do it "raises exception when options passed as Hash" do
it "raises exception when options passed as Hash" do -> { @io.readlines({ chomp: true }) }.should raise_error(TypeError)
-> { @io.readlines({ chomp: true }) }.should raise_error(TypeError)
-> { -> {
@io.readlines("\n", 1, { chomp: true }) @io.readlines("\n", 1, { chomp: true })
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
end
end end
end end

View File

@ -21,14 +21,12 @@ describe :io_binwrite, shared: true do
IO.send(@method, @filename, "abcde").should == 5 IO.send(@method, @filename, "abcde").should == 5
end end
ruby_version_is "3.0" do it "accepts options as a keyword argument" do
it "accepts options as a keyword argument" do IO.send(@method, @filename, "hi", 0, flags: File::CREAT).should == 2
IO.send(@method, @filename, "hi", 0, flags: File::CREAT).should == 2
-> { -> {
IO.send(@method, @filename, "hi", 0, {flags: File::CREAT}) IO.send(@method, @filename, "hi", 0, {flags: File::CREAT})
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 2..3)") }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 2..3)")
end
end end
it "creates a file if missing" do it "creates a file if missing" do

View File

@ -180,16 +180,14 @@ describe :io_each, shared: true do
ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters
end end
ruby_version_is "3.0" do it "raises exception when options passed as Hash" do
it "raises exception when options passed as Hash" do -> {
-> { @io.send(@method, { chomp: true }) { |s| }
@io.send(@method, { chomp: true }) { |s| } }.should raise_error(TypeError)
}.should raise_error(TypeError)
-> { -> {
@io.send(@method, "\n", 1, { chomp: true }) { |s| } @io.send(@method, "\n", 1, { chomp: true }) { |s| }
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
end
end end
end end

View File

@ -64,15 +64,13 @@ describe :io_new, shared: true do
@io.should be_an_instance_of(IO) @io.should be_an_instance_of(IO)
end end
ruby_version_is "3.0" do it "accepts options as keyword arguments" do
it "accepts options as keyword arguments" do @io = IO.send(@method, @fd, "w", flags: File::CREAT)
@io = IO.send(@method, @fd, "w", flags: File::CREAT) @io.write("foo").should == 3
@io.write("foo").should == 3
-> { -> {
IO.send(@method, @fd, "w", {flags: File::CREAT}) IO.send(@method, @fd, "w", {flags: File::CREAT})
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)") }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
end
end end
it "accepts a :mode option" do it "accepts a :mode option" do
@ -210,21 +208,10 @@ describe :io_new, shared: true do
@io.internal_encoding.to_s.should == 'IBM866' @io.internal_encoding.to_s.should == 'IBM866'
end end
ruby_version_is ''...'3.0' do it "raises ArgumentError for nil options" do
it "accepts nil options" do -> {
@io = suppress_keyword_warning do IO.send(@method, @fd, 'w', nil)
IO.send(@method, @fd, 'w', nil) }.should raise_error(ArgumentError)
end
@io.write("foo").should == 3
end
end
ruby_version_is '3.0' do
it "raises ArgumentError for nil options" do
-> {
IO.send(@method, @fd, 'w', nil)
}.should raise_error(ArgumentError)
end
end end
it "coerces mode with #to_str" do it "coerces mode with #to_str" do
@ -395,21 +382,9 @@ describe :io_new_errors, shared: true do
}.should raise_error(ArgumentError) }.should raise_error(ArgumentError)
end end
ruby_version_is ''...'3.0' do it "raises ArgumentError if passed a hash for mode and nil for options" 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 }.should raise_error(ArgumentError)
@io = IO.send(@method, @fd, {mode: 'w'}, nil)
end
}.should raise_error(TypeError)
end
end
ruby_version_is '3.0' do
it "raises ArgumentError if passed a hash for mode and nil for options" do
-> {
@io = IO.send(@method, @fd, {mode: 'w'}, nil)
}.should raise_error(ArgumentError)
end
end end
end end

View File

@ -105,12 +105,10 @@ describe :io_readlines_options_19, shared: true do
end end
describe "when the object is an options Hash" do describe "when the object is an options Hash" do
ruby_version_is "3.0" do it "raises TypeError exception" do
it "raises TypeError exception" do -> {
-> { IO.send(@method, @name, { chomp: true }, &@object)
IO.send(@method, @name, { chomp: true }, &@object) }.should raise_error(TypeError)
}.should raise_error(TypeError)
end
end end
end end
@ -179,12 +177,10 @@ describe :io_readlines_options_19, shared: true do
end end
describe "when the second object is an options Hash" do describe "when the second object is an options Hash" do
ruby_version_is "3.0" do it "raises TypeError exception" do
it "raises TypeError exception" do -> {
-> { IO.send(@method, @name, "", { chomp: true }, &@object)
IO.send(@method, @name, "", { chomp: true }, &@object) }.should raise_error(TypeError)
}.should raise_error(TypeError)
end
end end
end end
end end

View File

@ -103,19 +103,9 @@ describe "IO#ungetc" do
-> { @io.sysread(1) }.should raise_error(IOError) -> { @io.sysread(1) }.should raise_error(IOError)
end end
ruby_version_is ""..."3.0" do it "raises TypeError if passed nil" do
it "does not affect the stream and returns nil when passed nil" do @io.getc.should == ?V
@io.getc.should == ?V proc{@io.ungetc(nil)}.should raise_error(TypeError)
@io.ungetc(nil)
@io.getc.should == ?o
end
end
ruby_version_is "3.0" do
it "raises TypeError if passed nil" do
@io.getc.should == ?V
proc{@io.ungetc(nil)}.should raise_error(TypeError)
end
end end
it "puts one or more characters back in the stream" do it "puts one or more characters back in the stream" do

View File

@ -259,25 +259,23 @@ platform_is :windows do
end end
end end
ruby_version_is "3.0" do describe "IO#write on STDOUT" do
describe "IO#write on STDOUT" do # https://bugs.ruby-lang.org/issues/14413
# https://bugs.ruby-lang.org/issues/14413 platform_is_not :windows do
platform_is_not :windows do it "raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs" do
it "raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs" do stderr_file = tmp("stderr")
stderr_file = tmp("stderr") begin
begin IO.popen([*ruby_exe, "-e", "loop { puts :ok }"], "r", err: stderr_file) do |io|
IO.popen([*ruby_exe, "-e", "loop { puts :ok }"], "r", err: stderr_file) do |io| io.gets.should == "ok\n"
io.gets.should == "ok\n" io.close
io.close
end
status = $?
status.should_not.success?
status.should.signaled?
Signal.signame(status.termsig).should == 'PIPE'
File.read(stderr_file).should.empty?
ensure
rm_r stderr_file
end end
status = $?
status.should_not.success?
status.should.signaled?
Signal.signame(status.termsig).should == 'PIPE'
File.read(stderr_file).should.empty?
ensure
rm_r stderr_file
end end
end end
end end

View File

@ -145,7 +145,7 @@ describe :kernel_integer, shared: true do
end end
end end
describe "Integer() given a String", shared: true do describe :kernel_integer_string, shared: true do
it "raises an ArgumentError if the String is a null byte" do it "raises an ArgumentError if the String is a null byte" do
-> { Integer("\0") }.should raise_error(ArgumentError) -> { Integer("\0") }.should raise_error(ArgumentError)
end end
@ -348,7 +348,7 @@ describe "Integer() given a String", shared: true do
end end
end end
describe "Integer() given a String and base", shared: true do describe :kernel_integer_string_base, shared: true do
it "raises an ArgumentError if the String is a null byte" do it "raises an ArgumentError if the String is a null byte" do
-> { Integer("\0", 2) }.should raise_error(ArgumentError) -> { Integer("\0", 2) }.should raise_error(ArgumentError)
end end
@ -784,9 +784,9 @@ describe "Kernel.Integer" do
# TODO: fix these specs # TODO: fix these specs
it_behaves_like :kernel_integer, :Integer, Kernel it_behaves_like :kernel_integer, :Integer, Kernel
it_behaves_like "Integer() given a String", :Integer it_behaves_like :kernel_integer_string, :Integer
it_behaves_like "Integer() given a String and base", :Integer it_behaves_like :kernel_integer_string_base, :Integer
it "is a public method" do it "is a public method" do
Kernel.Integer(10).should == 10 Kernel.Integer(10).should == 10
@ -798,9 +798,9 @@ describe "Kernel#Integer" do
# TODO: fix these specs # TODO: fix these specs
it_behaves_like :kernel_integer, :Integer, Object.new it_behaves_like :kernel_integer, :Integer, Object.new
it_behaves_like "Integer() given a String", :Integer it_behaves_like :kernel_integer_string, :Integer
it_behaves_like "Integer() given a String and base", :Integer it_behaves_like :kernel_integer_string_base, :Integer
it "is a private method" do it "is a private method" do
Kernel.should have_private_instance_method(:Integer) Kernel.should have_private_instance_method(:Integer)

View File

@ -19,19 +19,9 @@ describe "Kernel#__dir__" do
end end
end end
ruby_version_is ""..."3.0" do context "when used in eval with top level binding" do
context "when used in eval with top level binding" do it "returns nil" do
it "returns the real name of the directory containing the currently-executing file" do eval("__dir__", binding).should == nil
eval("__dir__", binding).should == File.realpath(File.dirname(__FILE__))
end
end
end
ruby_version_is "3.0" do
context "when used in eval with top level binding" do
it "returns nil" do
eval("__dir__", binding).should == nil
end
end end
end end
end end

View File

@ -45,26 +45,18 @@ describe "Kernel#clone" do
end end
describe "with freeze: nil" do describe "with freeze: nil" do
ruby_version_is ""..."3.0" do it "copies frozen state from the original, like #clone without arguments" do
it "raises ArgumentError" do o2 = @obj.clone(freeze: nil)
-> { @obj.clone(freeze: nil) }.should raise_error(ArgumentError, /unexpected value for freeze: NilClass/) o2.should_not.frozen?
end
@obj.freeze
o3 = @obj.clone(freeze: nil)
o3.should.frozen?
end end
ruby_version_is "3.0" do it "copies frozen?" do
it "copies frozen state from the original, like #clone without arguments" do o = "".freeze.clone(freeze: nil)
o2 = @obj.clone(freeze: nil) o.frozen?.should be_true
o2.should_not.frozen?
@obj.freeze
o3 = @obj.clone(freeze: nil)
o3.should.frozen?
end
it "copies frozen?" do
o = "".freeze.clone(freeze: nil)
o.frozen?.should be_true
end
end end
end end
@ -74,33 +66,19 @@ describe "Kernel#clone" do
@obj.clone(freeze: true).should.frozen? @obj.clone(freeze: true).should.frozen?
end end
ruby_version_is ''...'3.0' do it 'freezes the copy even if the original was not frozen' do
it 'does not freeze the copy even if the original is not frozen' do @obj.clone(freeze: true).should.frozen?
@obj.clone(freeze: true).should_not.frozen?
end
it "calls #initialize_clone with no kwargs" do
obj = KernelSpecs::CloneFreeze.new
obj.clone(freeze: true)
ScratchPad.recorded.should == [obj, {}]
end
end end
ruby_version_is '3.0' do it "calls #initialize_clone with kwargs freeze: true" do
it 'freezes the copy even if the original was not frozen' do obj = KernelSpecs::CloneFreeze.new
@obj.clone(freeze: true).should.frozen? obj.clone(freeze: true)
end ScratchPad.recorded.should == [obj, { freeze: true }]
end
it "calls #initialize_clone with kwargs freeze: true" do it "calls #initialize_clone with kwargs freeze: true even if #initialize_clone only takes a single argument" do
obj = KernelSpecs::CloneFreeze.new obj = KernelSpecs::Clone.new
obj.clone(freeze: true) -> { obj.clone(freeze: true) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)')
ScratchPad.recorded.should == [obj, { freeze: true }]
end
it "calls #initialize_clone with kwargs freeze: true even if #initialize_clone only takes a single argument" do
obj = KernelSpecs::Clone.new
-> { obj.clone(freeze: true) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)')
end
end end
end end
@ -114,25 +92,15 @@ describe "Kernel#clone" do
@obj.clone(freeze: false).should_not.frozen? @obj.clone(freeze: false).should_not.frozen?
end end
ruby_version_is ''...'3.0' do it "calls #initialize_clone with kwargs freeze: false" do
it "calls #initialize_clone with no kwargs" do obj = KernelSpecs::CloneFreeze.new
obj = KernelSpecs::CloneFreeze.new obj.clone(freeze: false)
obj.clone(freeze: false) ScratchPad.recorded.should == [obj, { freeze: false }]
ScratchPad.recorded.should == [obj, {}]
end
end end
ruby_version_is '3.0' do it "calls #initialize_clone with kwargs freeze: false even if #initialize_clone only takes a single argument" do
it "calls #initialize_clone with kwargs freeze: false" do obj = KernelSpecs::Clone.new
obj = KernelSpecs::CloneFreeze.new -> { obj.clone(freeze: false) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)')
obj.clone(freeze: false)
ScratchPad.recorded.should == [obj, { freeze: false }]
end
it "calls #initialize_clone with kwargs freeze: false even if #initialize_clone only takes a single argument" do
obj = KernelSpecs::Clone.new
-> { obj.clone(freeze: false) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)')
end
end end
end end

View File

@ -159,37 +159,18 @@ describe "Kernel#eval" do
end end
end end
ruby_version_is ""..."3.0" do it "uses (eval) filename if none is provided" do
it "uses the filename of the binding if none is provided" do eval("__FILE__").should == "(eval)"
eval("__FILE__").should == "(eval)" eval("__FILE__", binding).should == "(eval)"
suppress_warning {eval("__FILE__", binding)}.should == __FILE__ eval("__FILE__", binding, "success").should == "success"
eval("__FILE__", binding, "success").should == "success" eval("eval '__FILE__', binding").should == "(eval)"
suppress_warning {eval("eval '__FILE__', binding")}.should == "(eval)" eval("eval '__FILE__', binding", binding).should == "(eval)"
suppress_warning {eval("eval '__FILE__', binding", binding)}.should == __FILE__ eval("eval '__FILE__', binding", binding, 'success').should == '(eval)'
suppress_warning {eval("eval '__FILE__', binding", binding, 'success')}.should == 'success' eval("eval '__FILE__', binding, 'success'", binding).should == 'success'
end
it 'uses the given binding file and line for __FILE__ and __LINE__' do
suppress_warning {
eval("[__FILE__, __LINE__]", binding).should == [__FILE__, __LINE__]
}
end
end end
ruby_version_is "3.0" do it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do
it "uses (eval) filename if none is provided" do eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1]
eval("__FILE__").should == "(eval)"
eval("__FILE__", binding).should == "(eval)"
eval("__FILE__", binding, "success").should == "success"
eval("eval '__FILE__', binding").should == "(eval)"
eval("eval '__FILE__', binding", binding).should == "(eval)"
eval("eval '__FILE__', binding", binding, 'success').should == '(eval)'
eval("eval '__FILE__', binding, 'success'", binding).should == 'success'
end
it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do
eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1]
end
end end
# Found via Rubinius bug github:#149 # Found via Rubinius bug github:#149

View File

@ -18,11 +18,9 @@ describe "Kernel#initialize_clone" do
a.send(:initialize_clone, b) a.send(:initialize_clone, b)
end end
ruby_version_is "3.0" do it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do
it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do a = Object.new
a = Object.new b = Object.new
b = Object.new a.send(:initialize_clone, b, freeze: true).should == a
a.send(:initialize_clone, b, freeze: true).should == a
end
end end
end end

View File

@ -1,14 +0,0 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is ""..."3.0" do
describe "Kernel#iterator?" do
it "is a private method" do
Kernel.should have_private_instance_method(:iterator?)
end
end
describe "Kernel.iterator?" do
it "needs to be reviewed for spec completeness"
end
end

View File

@ -136,15 +136,13 @@ describe "Kernel.lambda" do
klass.new.ret.should == 1 klass.new.ret.should == 1
end end
ruby_version_is "3.0" do context "when called without a literal block" do
context "when called without a literal block" do it "warns when proc isn't a lambda" do
it "warns when proc isn't a lambda" do -> { lambda(&proc{}) }.should complain("#{__FILE__}:#{__LINE__}: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n")
-> { lambda(&proc{}) }.should complain("#{__FILE__}:#{__LINE__}: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n") end
end
it "doesn't warn when proc is lambda" do it "doesn't warn when proc is lambda" do
-> { lambda(&lambda{}) }.should_not complain(verbose: true) -> { lambda(&lambda{}) }.should_not complain(verbose: true)
end
end end
end end
end end

View File

@ -72,15 +72,13 @@ describe "Kernel#open" do
-> { open }.should raise_error(ArgumentError) -> { open }.should raise_error(ArgumentError)
end end
ruby_version_is "3.0" do it "accepts options as keyword arguments" do
it "accepts options as keyword arguments" do @file = open(@name, "r", 0666, flags: File::CREAT)
@file = open(@name, "r", 0666, flags: File::CREAT) @file.should be_kind_of(File)
@file.should be_kind_of(File)
-> { -> {
open(@name, "r", 0666, {flags: File::CREAT}) open(@name, "r", 0666, {flags: File::CREAT})
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
end
end end
describe "when given an object that responds to to_open" do describe "when given an object that responds to to_open" do
@ -158,28 +156,14 @@ describe "Kernel#open" do
open(@name, nil, nil) { |f| f.gets }.should == @content open(@name, nil, nil) { |f| f.gets }.should == @content
end end
ruby_version_is ""..."3.0" do it "is not redefined by open-uri" do
it "works correctly when redefined by open-uri" do code = <<~RUBY
code = <<~RUBY before = Kernel.instance_method(:open)
require 'open-uri' require 'open-uri'
obj = Object.new after = Kernel.instance_method(:open)
def obj.to_open; self; end p before == after
p open(obj) == obj RUBY
RUBY ruby_exe(code, args: "2>&1").should == "true\n"
ruby_exe(code, args: "2>&1").should == "true\n"
end
end
ruby_version_is "3.0" do
it "is not redefined by open-uri" do
code = <<~RUBY
before = Kernel.instance_method(:open)
require 'open-uri'
after = Kernel.instance_method(:open)
p before == after
RUBY
ruby_exe(code, args: "2>&1").should == "true\n"
end
end end
end end

View File

@ -40,19 +40,9 @@ describe "Kernel#proc" do
proc proc
end end
ruby_version_is ""..."3.0" do it "raises an ArgumentError when passed no block" do
it "can be created when called with no block" do -> {
-> { some_method { "hello" }
some_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block')
}.should complain(/Capturing the given block using Kernel#proc is deprecated/)
end
end
ruby_version_is "3.0" do
it "raises an ArgumentError when passed no block" do
-> {
some_method { "hello" }
}.should raise_error(ArgumentError, 'tried to create Proc object without a block')
end
end end
end end

View File

@ -262,13 +262,11 @@ describe :kernel_require, shared: true do
ScratchPad.recorded.should == [:loaded] ScratchPad.recorded.should == [:loaded]
end end
ruby_bug "#16926", ""..."3.0" do it "does not load a feature twice when $LOAD_PATH has been modified" do
it "does not load a feature twice when $LOAD_PATH has been modified" do $LOAD_PATH.replace [CODE_LOADING_DIR]
$LOAD_PATH.replace [CODE_LOADING_DIR] @object.require("load_fixture").should be_true
@object.require("load_fixture").should be_true $LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR]
$LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR] @object.require("load_fixture").should be_false
@object.require("load_fixture").should be_false
end
end end
end end
@ -566,23 +564,21 @@ describe :kernel_require, shared: true do
-> { @object.require("unicode_normalize") }.should raise_error(LoadError) -> { @object.require("unicode_normalize") }.should raise_error(LoadError)
end end
ruby_version_is "3.0" do it "does not load a file earlier on the $LOAD_PATH when other similar features were already loaded" do
it "does not load a file earlier on the $LOAD_PATH when other similar features were already loaded" do Dir.chdir CODE_LOADING_DIR do
Dir.chdir CODE_LOADING_DIR do @object.send(@method, "../code/load_fixture").should be_true
@object.send(@method, "../code/load_fixture").should be_true
end
ScratchPad.recorded.should == [:loaded]
$LOAD_PATH.unshift "#{CODE_LOADING_DIR}/b"
# This loads because the above load was not on the $LOAD_PATH
@object.send(@method, "load_fixture").should be_true
ScratchPad.recorded.should == [:loaded, :loaded]
$LOAD_PATH.unshift "#{CODE_LOADING_DIR}/c"
# This does not load because the above load was on the $LOAD_PATH
@object.send(@method, "load_fixture").should be_false
ScratchPad.recorded.should == [:loaded, :loaded]
end end
ScratchPad.recorded.should == [:loaded]
$LOAD_PATH.unshift "#{CODE_LOADING_DIR}/b"
# This loads because the above load was not on the $LOAD_PATH
@object.send(@method, "load_fixture").should be_true
ScratchPad.recorded.should == [:loaded, :loaded]
$LOAD_PATH.unshift "#{CODE_LOADING_DIR}/c"
# This does not load because the above load was on the $LOAD_PATH
@object.send(@method, "load_fixture").should be_false
ScratchPad.recorded.should == [:loaded, :loaded]
end end
end end

View File

@ -1,3 +1,4 @@
# truffleruby_primitives: true
require_relative '../../spec_helper' require_relative '../../spec_helper'
describe "Kernel#singleton_class" do describe "Kernel#singleton_class" do
@ -42,4 +43,32 @@ describe "Kernel#singleton_class" do
obj.freeze obj.freeze
obj.singleton_class.frozen?.should be_true obj.singleton_class.frozen?.should be_true
end end
context "for an IO object with a replaced singleton class" do
it "looks up singleton methods from the fresh singleton class after an object instance got a new one" do
proxy = -> io { io.foo }
if RUBY_ENGINE == 'truffleruby'
# We need an inline cache with only this object seen, the best way to do that is to use a Primitive
sclass = -> io { Primitive.singleton_class(io) }
else
sclass = -> io { io.singleton_class }
end
io = File.new(__FILE__)
io.define_singleton_method(:foo) { "old" }
sclass1 = sclass.call(io)
proxy.call(io).should == "old"
# IO#reopen is the only method which can replace an object's singleton class
io2 = File.new(__FILE__)
io.reopen(io2)
io.define_singleton_method(:foo) { "new" }
sclass2 = sclass.call(io)
sclass2.should_not.equal?(sclass1)
proxy.call(io).should == "new"
ensure
io2.close
io.close
end
end
end end

View File

@ -4,9 +4,11 @@ require_relative 'fixtures/classes'
describe "Kernel#taint" do describe "Kernel#taint" do
ruby_version_is ""..."3.2" do ruby_version_is ""..."3.2" do
it "is a no-op" do it "is a no-op" do
o = Object.new suppress_warning do
o.taint o = Object.new
o.should_not.tainted? o.taint
o.should_not.tainted?
end
end end
it "warns in verbose mode" do it "warns in verbose mode" do

View File

@ -4,11 +4,13 @@ require_relative 'fixtures/classes'
describe "Kernel#tainted?" do describe "Kernel#tainted?" do
ruby_version_is ""..."3.2" do ruby_version_is ""..."3.2" do
it "is a no-op" do it "is a no-op" do
o = mock('o') suppress_warning do
p = mock('p') o = mock('o')
p.taint p = mock('p')
o.should_not.tainted? p.taint
p.should_not.tainted? o.should_not.tainted?
p.should_not.tainted?
end
end end
it "warns in verbose mode" do it "warns in verbose mode" do

View File

@ -4,10 +4,12 @@ require_relative 'fixtures/classes'
describe "Kernel#trust" do describe "Kernel#trust" do
ruby_version_is ""..."3.2" do ruby_version_is ""..."3.2" do
it "is a no-op" do it "is a no-op" do
o = Object.new.untrust suppress_warning do
o.should_not.untrusted? o = Object.new.untrust
o.trust o.should_not.untrusted?
o.should_not.untrusted? o.trust
o.should_not.untrusted?
end
end end
it "warns in verbose mode" do it "warns in verbose mode" do

View File

@ -4,10 +4,12 @@ require_relative 'fixtures/classes'
describe "Kernel#untaint" do describe "Kernel#untaint" do
ruby_version_is ""..."3.2" do ruby_version_is ""..."3.2" do
it "is a no-op" do it "is a no-op" do
o = Object.new.taint suppress_warning do
o.should_not.tainted? o = Object.new.taint
o.untaint o.should_not.tainted?
o.should_not.tainted? o.untaint
o.should_not.tainted?
end
end end
it "warns in verbose mode" do it "warns in verbose mode" do

View File

@ -4,9 +4,11 @@ require_relative 'fixtures/classes'
describe "Kernel#untrust" do describe "Kernel#untrust" do
ruby_version_is ""..."3.2" do ruby_version_is ""..."3.2" do
it "is a no-op" do it "is a no-op" do
o = Object.new suppress_warning do
o.untrust o = Object.new
o.should_not.untrusted? o.untrust
o.should_not.untrusted?
end
end end
it "warns in verbose mode" do it "warns in verbose mode" do

View File

@ -4,10 +4,12 @@ require_relative 'fixtures/classes'
describe "Kernel#untrusted?" do describe "Kernel#untrusted?" do
ruby_version_is ""..."3.2" do ruby_version_is ""..."3.2" do
it "is a no-op" do it "is a no-op" do
o = mock('o') suppress_warning do
o.should_not.untrusted? o = mock('o')
o.untrust o.should_not.untrusted?
o.should_not.untrusted? o.untrust
o.should_not.untrusted?
end
end end
it "warns in verbose mode" do it "warns in verbose mode" do

View File

@ -128,36 +128,34 @@ describe "Kernel#warn" do
end end
end end
ruby_version_is "3.0" do it "accepts :category keyword with a symbol" do
it "accepts :category keyword with a symbol" do -> {
-> { $VERBOSE = true
$VERBOSE = true warn("message", category: :deprecated)
warn("message", category: :deprecated) }.should output(nil, "message\n")
}.should output(nil, "message\n") end
end
it "accepts :category keyword with nil" do it "accepts :category keyword with nil" do
-> { -> {
$VERBOSE = true $VERBOSE = true
warn("message", category: nil) warn("message", category: nil)
}.should output(nil, "message\n") }.should output(nil, "message\n")
end end
it "accepts :category keyword with object convertible to symbol" do it "accepts :category keyword with object convertible to symbol" do
o = Object.new o = Object.new
def o.to_sym; :deprecated; end def o.to_sym; :deprecated; end
-> { -> {
$VERBOSE = true $VERBOSE = true
warn("message", category: o) warn("message", category: o)
}.should output(nil, "message\n") }.should output(nil, "message\n")
end end
it "raises if :category keyword is not nil and not convertible to symbol" do it "raises if :category keyword is not nil and not convertible to symbol" do
-> { -> {
$VERBOSE = true $VERBOSE = true
warn("message", category: Object.new) warn("message", category: Object.new)
}.should raise_error(TypeError) }.should raise_error(TypeError)
end
end end
it "converts first arg using to_s" do it "converts first arg using to_s" do
@ -212,67 +210,52 @@ describe "Kernel#warn" do
-> { warn('foo', **h) }.should complain("foo\n") -> { warn('foo', **h) }.should complain("foo\n")
end end
ruby_version_is '3.0' do it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do
it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do verbose = $VERBOSE
verbose = $VERBOSE $VERBOSE = false
$VERBOSE = false class << Warning
alias_method :_warn, :warn
def warn(message)
ScratchPad.record(message)
end
end
begin
ScratchPad.clear
Kernel.warn("Chunky bacon!")
ScratchPad.recorded.should == "Chunky bacon!\n"
Kernel.warn("Deprecated bacon!", category: :deprecated)
ScratchPad.recorded.should == "Deprecated bacon!\n"
ensure
class << Warning class << Warning
alias_method :_warn, :warn remove_method :warn
def warn(message) alias_method :warn, :_warn
ScratchPad.record(message) remove_method :_warn
end
end
begin
ScratchPad.clear
Kernel.warn("Chunky bacon!")
ScratchPad.recorded.should == "Chunky bacon!\n"
Kernel.warn("Deprecated bacon!", category: :deprecated)
ScratchPad.recorded.should == "Deprecated bacon!\n"
ensure
class << Warning
remove_method :warn
alias_method :warn, :_warn
remove_method :_warn
end
$VERBOSE = verbose
end
end
it "calls Warning.warn with category: nil if Warning.warn accepts keyword arguments" do
Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil)
verbose = $VERBOSE
$VERBOSE = false
begin
Kernel.warn("Chunky bacon!")
ensure
$VERBOSE = verbose
end
end
it "calls Warning.warn with given category keyword converted to a symbol" do
Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated)
verbose = $VERBOSE
$VERBOSE = false
begin
Kernel.warn("Chunky bacon!", category: 'deprecated')
ensure
$VERBOSE = verbose
end end
$VERBOSE = verbose
end end
end end
ruby_version_is ''...'3.0' do it "calls Warning.warn with category: nil if Warning.warn accepts keyword arguments" do
it "calls Warning.warn with no keyword arguments" do Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil)
Warning.should_receive(:warn).with("Chunky bacon!\n") verbose = $VERBOSE
verbose = $VERBOSE $VERBOSE = false
$VERBOSE = false begin
begin Kernel.warn("Chunky bacon!")
Kernel.warn("Chunky bacon!") ensure
ensure $VERBOSE = verbose
$VERBOSE = verbose end
end end
it "calls Warning.warn with given category keyword converted to a symbol" do
Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated)
verbose = $VERBOSE
$VERBOSE = false
begin
Kernel.warn("Chunky bacon!", category: 'deprecated')
ensure
$VERBOSE = verbose
end end
end end

View File

@ -22,13 +22,11 @@ describe "main#private" do
end end
end end
ruby_version_is "3.0" do context "when single argument is passed and is an array" do
context "when single argument is passed and is an array" do it "sets the visibility of the given methods to private" do
it "sets the visibility of the given methods to private" do eval "private [:main_public_method, :main_public_method2]", TOPLEVEL_BINDING
eval "private [:main_public_method, :main_public_method2]", TOPLEVEL_BINDING Object.should have_private_method(:main_public_method)
Object.should have_private_method(:main_public_method) Object.should have_private_method(:main_public_method2)
Object.should have_private_method(:main_public_method2)
end
end end
end end

View File

@ -22,13 +22,11 @@ describe "main#public" do
end end
end end
ruby_version_is "3.0" do context "when single argument is passed and is an array" do
context "when single argument is passed and is an array" do it "sets the visibility of the given methods to public" do
it "sets the visibility of the given methods to public" do eval "public [:main_private_method, :main_private_method2]", TOPLEVEL_BINDING
eval "public [:main_private_method, :main_private_method2]", TOPLEVEL_BINDING Object.should_not have_private_method(:main_private_method)
Object.should_not have_private_method(:main_private_method) Object.should_not have_private_method(:main_private_method2)
Object.should_not have_private_method(:main_private_method2)
end
end end
end end

View File

@ -626,17 +626,6 @@ describe "Marshal.dump" do
load.should == (1...2) load.should == (1...2)
end end
ruby_version_is ""..."3.0" do
it "dumps a Range with extra instance variables" do
range = (1...3)
range.instance_variable_set :@foo, 42
dump = Marshal.dump(range)
load = Marshal.load(dump)
load.should == range
load.instance_variable_get(:@foo).should == 42
end
end
it "raises TypeError with an anonymous Range subclass" do it "raises TypeError with an anonymous Range subclass" do
-> { Marshal.dump(Class.new(Range).new(1, 2)) }.should raise_error(TypeError, /can't dump anonymous class/) -> { Marshal.dump(Class.new(Range).new(1, 2)) }.should raise_error(TypeError, /can't dump anonymous class/)
end end

View File

@ -623,6 +623,14 @@ describe :marshal_load, shared: true do
value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8] value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8]
value.should == [*expected, expected[0]] value.should == [*expected, expected[0]]
end end
it "raises ArgumentError when end of byte sequence reached before symbol characters end" do
Marshal.dump(:hello).should == "\x04\b:\nhello"
-> {
Marshal.send(@method, "\x04\b:\nhel")
}.should raise_error(ArgumentError, "marshal data too short")
end
end end
describe "for a String" do describe "for a String" do
@ -685,6 +693,14 @@ describe :marshal_load, shared: true do
result.encoding.should == Encoding::BINARY result.encoding.should == Encoding::BINARY
result.should == str result.should == str
end end
it "raises ArgumentError when end of byte sequence reached before string characters end" do
Marshal.dump("hello").should == "\x04\b\"\nhello"
-> {
Marshal.send(@method, "\x04\b\"\nhel")
}.should raise_error(ArgumentError, "marshal data too short")
end
end end
describe "for a Struct" do describe "for a Struct" do
@ -819,6 +835,14 @@ describe :marshal_load, shared: true do
Marshal.send(@method, "\x04\bo:\tFile\001\001:\001\005@path\"\x10/etc/passwd") Marshal.send(@method, "\x04\bo:\tFile\001\001:\001\005@path\"\x10/etc/passwd")
end.should raise_error(ArgumentError) end.should raise_error(ArgumentError)
end end
it "raises ArgumentError when end of byte sequence reached before class name end" do
Marshal.dump(Object.new).should == "\x04\bo:\vObject\x00"
-> {
Marshal.send(@method, "\x04\bo:\vObj")
}.should raise_error(ArgumentError, "marshal data too short")
end
end end
describe "for an object responding to #marshal_dump and #marshal_load" do describe "for an object responding to #marshal_dump and #marshal_load" do
@ -908,6 +932,14 @@ describe :marshal_load, shared: true do
regexp.encoding.should == Encoding::UTF_32LE regexp.encoding.should == Encoding::UTF_32LE
regexp.source.should == "a".encode("utf-32le") regexp.source.should == "a".encode("utf-32le")
end end
it "raises ArgumentError when end of byte sequence reached before source string end" do
Marshal.dump(/hello world/).should == "\x04\bI/\x10hello world\x00\x06:\x06EF"
-> {
Marshal.send(@method, "\x04\bI/\x10hel")
}.should raise_error(ArgumentError, "marshal data too short")
end
end end
describe "for a Float" do describe "for a Float" do
@ -929,6 +961,14 @@ describe :marshal_load, shared: true do
obj = 1.1867345e+22 obj = 1.1867345e+22
Marshal.send(@method, "\004\bf\0361.1867344999999999e+22\000\344@").should == obj Marshal.send(@method, "\004\bf\0361.1867344999999999e+22\000\344@").should == obj
end end
it "raises ArgumentError when end of byte sequence reached before float string representation end" do
Marshal.dump(1.3).should == "\x04\bf\b1.3"
-> {
Marshal.send(@method, "\004\bf\v1")
}.should raise_error(ArgumentError, "marshal data too short")
end
end end
describe "for an Integer" do describe "for an Integer" do
@ -1114,6 +1154,14 @@ describe :marshal_load, shared: true do
it "raises ArgumentError if given a nonexistent class" do it "raises ArgumentError if given a nonexistent class" do
-> { Marshal.send(@method, "\x04\bc\vStrung") }.should raise_error(ArgumentError) -> { Marshal.send(@method, "\x04\bc\vStrung") }.should raise_error(ArgumentError)
end end
it "raises ArgumentError when end of byte sequence reached before class name end" do
Marshal.dump(String).should == "\x04\bc\vString"
-> {
Marshal.send(@method, "\x04\bc\vStr")
}.should raise_error(ArgumentError, "marshal data too short")
end
end end
describe "for a Module" do describe "for a Module" do
@ -1128,6 +1176,14 @@ describe :marshal_load, shared: true do
it "loads an old module" do it "loads an old module" do
Marshal.send(@method, "\x04\bM\vKernel").should == Kernel Marshal.send(@method, "\x04\bM\vKernel").should == Kernel
end end
it "raises ArgumentError when end of byte sequence reached before module name end" do
Marshal.dump(Kernel).should == "\x04\bm\vKernel"
-> {
Marshal.send(@method, "\x04\bm\vKer")
}.should raise_error(ArgumentError, "marshal data too short")
end
end end
describe "for a wrapped C pointer" do describe "for a wrapped C pointer" do

View File

@ -48,11 +48,9 @@ describe "MatchData#[]" do
/(.)(.)(\d+)(\d)/.match("THX1138.")[nil..nil].should == %w|HX1138 H X 113 8| /(.)(.)(\d+)(\d)/.match("THX1138.")[nil..nil].should == %w|HX1138 H X 113 8|
end end
ruby_version_is "3.0" do it "returns instances of String when given a String subclass" do
it "returns instances of String when given a String subclass" do str = MatchDataSpecs::MyString.new("THX1138.")
str = MatchDataSpecs::MyString.new("THX1138.") /(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should be_an_instance_of(String) }
/(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should be_an_instance_of(String) }
end
end end
end end

View File

@ -17,10 +17,8 @@ describe "MatchData#post_match" do
str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1) str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1)
end end
ruby_version_is "3.0" do it "returns an instance of String when given a String subclass" do
it "returns an instance of String when given a String subclass" do str = MatchDataSpecs::MyString.new("THX1138: The Movie")
str = MatchDataSpecs::MyString.new("THX1138: The Movie") /(.)(.)(\d+)(\d)/.match(str).post_match.should be_an_instance_of(String)
/(.)(.)(\d+)(\d)/.match(str).post_match.should be_an_instance_of(String)
end
end end
end end

View File

@ -17,10 +17,8 @@ describe "MatchData#pre_match" do
str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1) str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1)
end end
ruby_version_is "3.0" do it "returns an instance of String when given a String subclass" do
it "returns an instance of String when given a String subclass" do str = MatchDataSpecs::MyString.new("THX1138: The Movie")
str = MatchDataSpecs::MyString.new("THX1138: The Movie") /(.)(.)(\d+)(\d)/.match(str).pre_match.should be_an_instance_of(String)
/(.)(.)(\d+)(\d)/.match(str).pre_match.should be_an_instance_of(String)
end
end end
end end

View File

@ -6,10 +6,8 @@ describe :matchdata_captures, shared: true do
/(.)(.)(\d+)(\d)/.match("THX1138.").send(@method).should == ["H","X","113","8"] /(.)(.)(\d+)(\d)/.match("THX1138.").send(@method).should == ["H","X","113","8"]
end end
ruby_version_is "3.0" do it "returns instances of String when given a String subclass" do
it "returns instances of String when given a String subclass" do str = MatchDataSpecs::MyString.new("THX1138: The Movie")
str = MatchDataSpecs::MyString.new("THX1138: The Movie") /(.)(.)(\d+)(\d)/.match(str).send(@method).each { |c| c.should be_an_instance_of(String) }
/(.)(.)(\d+)(\d)/.match(str).send(@method).each { |c| c.should be_an_instance_of(String) }
end
end end
end end

View File

@ -6,10 +6,8 @@ describe "MatchData#to_a" do
/(.)(.)(\d+)(\d)/.match("THX1138.").to_a.should == ["HX1138", "H", "X", "113", "8"] /(.)(.)(\d+)(\d)/.match("THX1138.").to_a.should == ["HX1138", "H", "X", "113", "8"]
end end
ruby_version_is "3.0" do it "returns instances of String when given a String subclass" do
it "returns instances of String when given a String subclass" do str = MatchDataSpecs::MyString.new("THX1138.")
str = MatchDataSpecs::MyString.new("THX1138.") /(.)(.)(\d+)(\d)/.match(str)[0..-1].to_a.each { |m| m.should be_an_instance_of(String) }
/(.)(.)(\d+)(\d)/.match(str)[0..-1].to_a.each { |m| m.should be_an_instance_of(String) }
end
end end
end end

View File

@ -6,10 +6,8 @@ describe "MatchData#to_s" do
/(.)(.)(\d+)(\d)/.match("THX1138.").to_s.should == "HX1138" /(.)(.)(\d+)(\d)/.match("THX1138.").to_s.should == "HX1138"
end end
ruby_version_is "3.0" do it "returns an instance of String when given a String subclass" do
it "returns an instance of String when given a String subclass" do str = MatchDataSpecs::MyString.new("THX1138.")
str = MatchDataSpecs::MyString.new("THX1138.") /(.)(.)(\d+)(\d)/.match(str).to_s.should be_an_instance_of(String)
/(.)(.)(\d+)(\d)/.match(str).to_s.should be_an_instance_of(String)
end
end end
end end

View File

@ -38,8 +38,7 @@ describe "Method#<<" do
double = proc { |x| x + x } double = proc { |x| x + x }
(pow_2 << double).is_a?(Proc).should == true (pow_2 << double).is_a?(Proc).should == true
ruby_version_is(''...'3.0') { (pow_2 << double).should.lambda? } (pow_2 << double).should_not.lambda?
ruby_version_is('3.0') { (pow_2 << double).should_not.lambda? }
end end
it "may accept multiple arguments" do it "may accept multiple arguments" do

View File

@ -53,20 +53,18 @@ describe :method_to_s, shared: true do
MethodSpecs::A.new.method(:baz).send(@method).should.start_with? "#<Method: MethodSpecs::A#baz" MethodSpecs::A.new.method(:baz).send(@method).should.start_with? "#<Method: MethodSpecs::A#baz"
end end
ruby_version_is '3.0' do it "returns a String containing the Module containing the method if object has a singleton class but method is not defined in the singleton class" do
it "returns a String containing the Module containing the method if object has a singleton class but method is not defined in the singleton class" do obj = MethodSpecs::MySub.new
obj = MethodSpecs::MySub.new obj.singleton_class
obj.singleton_class @m = obj.method(:bar)
@m = obj.method(:bar) @string = @m.send(@method)
@string = @m.send(@method) @string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
@string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
c = MethodSpecs::MySub.dup c = MethodSpecs::MySub.dup
m = Module.new{def bar; end} m = Module.new{def bar; end}
c.extend(m) c.extend(m)
@string = c.method(:bar).send(@method) @string = c.method(:bar).send(@method)
@string.should.start_with? "#<Method: #<Class:#{c.inspect}>(#{m.inspect})#bar" @string.should.start_with? "#<Method: #<Class:#{c.inspect}>(#{m.inspect})#bar"
end
end end
it "returns a String containing the singleton class if method is defined in the singleton class" do it "returns a String containing the singleton class if method is defined in the singleton class" do
@ -77,9 +75,7 @@ describe :method_to_s, shared: true do
@string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar" @string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar"
end end
ruby_bug '#17428', ''...'3.0' do it "shows the metaclass and the owner for a Module instance method retrieved from a class" do
it "shows the metaclass and the owner for a Module instance method retrieved from a class" do String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include")
String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include")
end
end end
end end

View File

@ -92,17 +92,9 @@ describe "Module#alias_method" do
end end
describe "returned value" do describe "returned value" do
ruby_version_is ""..."3.0" do it "returns symbol of the defined method name" do
it "returns self" do @class.send(:alias_method, :checking_return_value, :public_one).should equal(:checking_return_value)
@class.send(:alias_method, :checking_return_value, :public_one).should equal(@class) @class.send(:alias_method, 'checking_return_value', :public_one).should equal(:checking_return_value)
end
end
ruby_version_is "3.0" do
it "returns symbol of the defined method name" do
@class.send(:alias_method, :checking_return_value, :public_one).should equal(:checking_return_value)
@class.send(:alias_method, 'checking_return_value', :public_one).should equal(:checking_return_value)
end
end end
end end

View File

@ -80,19 +80,9 @@ describe "Module#attr_accessor" do
Module.should have_public_instance_method(:attr_accessor, false) Module.should have_public_instance_method(:attr_accessor, false)
end end
ruby_version_is ""..."3.0" do it "returns an array of defined method names as symbols" do
it "returns nil" do Class.new do
Class.new do (attr_accessor :foo, 'bar').should == [:foo, :foo=, :bar, :bar=]
(attr_accessor :foo, 'bar').should == nil
end
end
end
ruby_version_is "3.0" do
it "returns an array of defined method names as symbols" do
Class.new do
(attr_accessor :foo, 'bar').should == [:foo, :foo=, :bar, :bar=]
end
end end
end end

View File

@ -62,19 +62,9 @@ describe "Module#attr_reader" do
Module.should have_public_instance_method(:attr_reader, false) Module.should have_public_instance_method(:attr_reader, false)
end end
ruby_version_is ""..."3.0" do it "returns an array of defined method names as symbols" do
it "returns nil" do Class.new do
Class.new do (attr_reader :foo, 'bar').should == [:foo, :bar]
(attr_reader :foo, 'bar').should == nil
end
end
end
ruby_version_is "3.0" do
it "returns an array of defined method names as symbols" do
Class.new do
(attr_reader :foo, 'bar').should == [:foo, :bar]
end
end end
end end
end end

View File

@ -146,23 +146,11 @@ describe "Module#attr" do
Module.should have_public_instance_method(:attr, false) Module.should have_public_instance_method(:attr, false)
end end
ruby_version_is ""..."3.0" do it "returns an array of defined method names as symbols" do
it "returns nil" do Class.new do
Class.new do (attr :foo, 'bar').should == [:foo, :bar]
(attr :foo, 'bar').should == nil (attr :baz, false).should == [:baz]
(attr :baz, false).should == nil (attr :qux, true).should == [:qux, :qux=]
(attr :qux, true).should == nil
end
end
end
ruby_version_is "3.0" do
it "returns an array of defined method names as symbols" do
Class.new do
(attr :foo, 'bar').should == [:foo, :bar]
(attr :baz, false).should == [:baz]
(attr :qux, true).should == [:qux, :qux=]
end
end end
end end
end end

View File

@ -72,19 +72,9 @@ describe "Module#attr_writer" do
Module.should have_public_instance_method(:attr_writer, false) Module.should have_public_instance_method(:attr_writer, false)
end end
ruby_version_is ""..."3.0" do it "returns an array of defined method names as symbols" do
it "returns nil" do Class.new do
Class.new do (attr_writer :foo, 'bar').should == [:foo=, :bar=]
(attr_writer :foo, 'bar').should == nil
end
end
end
ruby_version_is "3.0" do
it "returns an array of defined method names as symbols" do
Class.new do
(attr_writer :foo, 'bar').should == [:foo=, :bar=]
end
end end
end end
end end

Some files were not shown because too many files have changed in this diff Show More