зеркало из https://github.com/github/ruby.git
Update to ruby/spec@30e1c35
This commit is contained in:
Родитель
f73fa29927
Коммит
515bd42144
|
@ -1,7 +1,7 @@
|
|||
inherit_from: .rubocop_todo.yml
|
||||
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.7
|
||||
TargetRubyVersion: 3.0
|
||||
DisplayCopNames: true
|
||||
Exclude:
|
||||
- command_line/fixtures/bad_syntax.rb
|
||||
|
|
|
@ -138,12 +138,12 @@ Here is a list of the most commonly-used guards:
|
|||
#### Version guards
|
||||
|
||||
```ruby
|
||||
ruby_version_is ""..."2.6" do
|
||||
# Specs for RUBY_VERSION < 2.6
|
||||
ruby_version_is ""..."3.2" do
|
||||
# Specs for RUBY_VERSION < 3.2
|
||||
end
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
# Specs for RUBY_VERSION >= 2.6
|
||||
ruby_version_is "3.2" do
|
||||
# Specs for RUBY_VERSION >= 3.2
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -191,11 +191,11 @@ end
|
|||
#### Combining guards
|
||||
|
||||
```ruby
|
||||
guard -> { platform_is :windows and ruby_version_is ""..."2.6" } do
|
||||
# Windows and RUBY_VERSION < 2.6
|
||||
guard -> { platform_is :windows and ruby_version_is ""..."3.2" } do
|
||||
# Windows and RUBY_VERSION < 3.2
|
||||
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
|
||||
end
|
||||
```
|
||||
|
|
|
@ -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)
|
||||
* [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor)
|
||||
|
||||
ruby/spec describes the behavior of Ruby 2.7 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.
|
||||
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 (3.0.x, 3.1.x, 3.2.x, etc), and those are tested in CI.
|
||||
|
||||
### 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.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.7.8 - [Suite](https://github.com/ruby/spec/commit/93787e6035c925b593a9c0c6fb0e7e07a6f1df1f) using [MSpec](https://github.com/ruby/mspec/commit/1d8cf64722d8a7529f7cd205be5f16a89b7a67fd)
|
||||
|
||||
### Running the specs
|
||||
|
||||
|
|
|
@ -1,48 +1,46 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
describe "The --backtrace-limit command line option" do
|
||||
it "limits top-level backtraces to a given number of entries" do
|
||||
file = fixture(__FILE__ , "backtrace.rb")
|
||||
out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
|
||||
out = out.gsub(__dir__, '')
|
||||
describe "The --backtrace-limit command line option" do
|
||||
it "limits top-level backtraces to a given number of entries" do
|
||||
file = fixture(__FILE__ , "backtrace.rb")
|
||||
out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
|
||||
out = out.gsub(__dir__, '')
|
||||
|
||||
out.should == <<-MSG
|
||||
out.should == <<-MSG
|
||||
top
|
||||
/fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
|
||||
\tfrom /fixtures/backtrace.rb:6:in `b'
|
||||
\tfrom /fixtures/backtrace.rb:10:in `c'
|
||||
\t ... 2 levels...
|
||||
MSG
|
||||
end
|
||||
MSG
|
||||
end
|
||||
|
||||
it "affects Exception#full_message" do
|
||||
file = fixture(__FILE__ , "backtrace.rb")
|
||||
out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
|
||||
out = out.gsub(__dir__, '')
|
||||
it "affects Exception#full_message" do
|
||||
file = fixture(__FILE__ , "backtrace.rb")
|
||||
out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
|
||||
out = out.gsub(__dir__, '')
|
||||
|
||||
out.should == <<-MSG
|
||||
out.should == <<-MSG
|
||||
full_message
|
||||
/fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
|
||||
\tfrom /fixtures/backtrace.rb:6:in `b'
|
||||
\tfrom /fixtures/backtrace.rb:10:in `c'
|
||||
\t ... 2 levels...
|
||||
MSG
|
||||
end
|
||||
MSG
|
||||
end
|
||||
|
||||
it "does not affect Exception#backtrace" do
|
||||
file = fixture(__FILE__ , "backtrace.rb")
|
||||
out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
|
||||
out = out.gsub(__dir__, '')
|
||||
it "does not affect Exception#backtrace" do
|
||||
file = fixture(__FILE__ , "backtrace.rb")
|
||||
out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
|
||||
out = out.gsub(__dir__, '')
|
||||
|
||||
out.should == <<-MSG
|
||||
out.should == <<-MSG
|
||||
backtrace
|
||||
/fixtures/backtrace.rb:2:in `a'
|
||||
/fixtures/backtrace.rb:6:in `b'
|
||||
/fixtures/backtrace.rb:10:in `c'
|
||||
/fixtures/backtrace.rb:14:in `d'
|
||||
/fixtures/backtrace.rb:29:in `<main>'
|
||||
MSG
|
||||
end
|
||||
MSG
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -50,15 +50,7 @@ describe "Array#drop" do
|
|||
-> { [1, 2].drop(obj) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it 'returns a subclass instance for Array subclasses' do
|
||||
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
|
||||
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
|
||||
|
|
|
@ -18,15 +18,7 @@ describe "Array#drop_while" do
|
|||
[1, 2, 3, false, 5].drop_while { |n| n }.should == [false, 5]
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' 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(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
|
||||
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
|
||||
|
|
|
@ -75,24 +75,12 @@ describe "Array#flatten" do
|
|||
[[obj]].flatten(1)
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "returns subclass instance for Array subclasses" do
|
||||
ArraySpecs::MyArray[].flatten.should be_an_instance_of(ArraySpecs::MyArray)
|
||||
ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(ArraySpecs::MyArray)
|
||||
ArraySpecs::MyArray[1, [2], 3].flatten.should be_an_instance_of(ArraySpecs::MyArray)
|
||||
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)
|
||||
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
|
||||
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
|
||||
|
||||
it "is not destructive" do
|
||||
|
|
|
@ -76,20 +76,10 @@ describe "Array#* with an integer" do
|
|||
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "returns a subclass instance" do
|
||||
(@array * 0).should be_an_instance_of(ArraySpecs::MyArray)
|
||||
(@array * 1).should be_an_instance_of(ArraySpecs::MyArray)
|
||||
(@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
|
||||
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
|
||||
|
||||
it "does not call #initialize on the subclass instance" do
|
||||
|
|
|
@ -397,56 +397,28 @@ describe :array_slice, shared: true do
|
|||
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "returns a subclass instance with [n, m]" do
|
||||
@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
|
||||
it "returns a Array instance with [n, m]" do
|
||||
@array.send(@method, 0, 2).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
ruby_version_is '3.0' do
|
||||
it "returns a Array instance with [n, m]" do
|
||||
@array.send(@method, 0, 2).should be_an_instance_of(Array)
|
||||
end
|
||||
it "returns a Array instance with [-n, m]" do
|
||||
@array.send(@method, -3, 2).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it "returns a Array instance with [-n, m]" do
|
||||
@array.send(@method, -3, 2).should be_an_instance_of(Array)
|
||||
end
|
||||
it "returns a Array instance with [n..m]" do
|
||||
@array.send(@method, 1..3).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it "returns a Array instance with [n..m]" do
|
||||
@array.send(@method, 1..3).should be_an_instance_of(Array)
|
||||
end
|
||||
it "returns a Array instance with [n...m]" do
|
||||
@array.send(@method, 1...3).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it "returns a Array instance with [n...m]" do
|
||||
@array.send(@method, 1...3).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
|
||||
|
||||
it "returns a Array instance with [-n..-m]" do
|
||||
@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
|
||||
it "returns a Array instance with [-n...-m]" do
|
||||
@array.send(@method, -3...-1).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
describe "can be sliced with Enumerator::ArithmeticSequence" do
|
||||
before :each do
|
||||
@array = [0, 1, 2, 3, 4, 5]
|
||||
end
|
||||
describe "can be sliced with Enumerator::ArithmeticSequence" do
|
||||
before :each do
|
||||
@array = [0, 1, 2, 3, 4, 5]
|
||||
end
|
||||
|
||||
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(2)")).should == [0, 2, 4]
|
||||
@array.send(@method, eval("(0..).step(10)")).should == [0]
|
||||
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(2)")).should == [0, 2, 4]
|
||||
@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(2)")).should == [2, 4]
|
||||
@array.send(@method, eval("(2..).step(10)")).should == [2]
|
||||
@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(10)")).should == [2]
|
||||
|
||||
@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(10)")).should == [3]
|
||||
end
|
||||
@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(10)")).should == [3]
|
||||
end
|
||||
|
||||
it "has beginless range and positive steps" do
|
||||
# end with zero index
|
||||
@array.send(@method, (..0).step(1)).should == [0]
|
||||
@array.send(@method, (...0).step(1)).should == []
|
||||
it "has beginless range and positive steps" do
|
||||
# end with zero index
|
||||
@array.send(@method, (..0).step(1)).should == [0]
|
||||
@array.send(@method, (...0).step(1)).should == []
|
||||
|
||||
@array.send(@method, (..0).step(2)).should == [0]
|
||||
@array.send(@method, (...0).step(2)).should == []
|
||||
@array.send(@method, (..0).step(2)).should == [0]
|
||||
@array.send(@method, (...0).step(2)).should == []
|
||||
|
||||
@array.send(@method, (..0).step(10)).should == [0]
|
||||
@array.send(@method, (...0).step(10)).should == []
|
||||
@array.send(@method, (..0).step(10)).should == [0]
|
||||
@array.send(@method, (...0).step(10)).should == []
|
||||
|
||||
# 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]
|
||||
# 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]
|
||||
|
||||
@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
|
||||
@array.send(@method, (..-2).step(1)).should == [0, 1, 2, 3, 4,]
|
||||
@array.send(@method, (...-2).step(1)).should == [0, 1, 2, 3]
|
||||
# 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]
|
||||
|
||||
@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, 4]
|
||||
@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]
|
||||
end
|
||||
@array.send(@method, (..-2).step(10)).should == [0]
|
||||
@array.send(@method, (...-2).step(10)).should == [0]
|
||||
end
|
||||
|
||||
it "has endless range and negative steps" do
|
||||
@array.send(@method, eval("(0..).step(-1)")).should == [0]
|
||||
@array.send(@method, eval("(0..).step(-2)")).should == [0]
|
||||
@array.send(@method, eval("(0..).step(-10)")).should == [0]
|
||||
it "has endless range and negative steps" do
|
||||
@array.send(@method, eval("(0..).step(-1)")).should == [0]
|
||||
@array.send(@method, eval("(0..).step(-2)")).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(-2)")).should == [2, 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("(-3..).step(-1)")).should == [3, 2, 1, 0]
|
||||
@array.send(@method, eval("(-3..).step(-2)")).should == [3, 1]
|
||||
end
|
||||
@array.send(@method, eval("(-3..).step(-1)")).should == [3, 2, 1, 0]
|
||||
@array.send(@method, eval("(-3..).step(-2)")).should == [3, 1]
|
||||
end
|
||||
|
||||
it "has closed range and positive steps" do
|
||||
# start and end with 0
|
||||
@array.send(@method, eval("(0..0).step(1)")).should == [0]
|
||||
@array.send(@method, eval("(0...0).step(1)")).should == []
|
||||
it "has closed range and positive steps" do
|
||||
# start and end with 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(2)")).should == [0]
|
||||
@array.send(@method, eval("(0...0).step(2)")).should == []
|
||||
@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(10)")).should == [0]
|
||||
@array.send(@method, eval("(0...0).step(10)")).should == []
|
||||
@array.send(@method, eval("(0..0).step(10)")).should == [0]
|
||||
@array.send(@method, eval("(0...0).step(10)")).should == []
|
||||
|
||||
# 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]
|
||||
# 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]
|
||||
|
||||
@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, 3]
|
||||
@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
|
||||
@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]
|
||||
# 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]
|
||||
|
||||
@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
|
||||
@array.send(@method, eval("(-4..4).step(1)")).should == [2, 3, 4]
|
||||
@array.send(@method, eval("(-4...4).step(1)")).should == [2, 3]
|
||||
# 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]
|
||||
|
||||
@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, 4]
|
||||
@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
|
||||
@array.send(@method, eval("(-4..-2).step(1)")).should == [2, 3, 4]
|
||||
@array.send(@method, eval("(-4...-2).step(1)")).should == [2, 3]
|
||||
# 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]
|
||||
|
||||
@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, 4]
|
||||
@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]
|
||||
end
|
||||
@array.send(@method, eval("(-4..-2).step(10)")).should == [2]
|
||||
@array.send(@method, eval("(-4...-2).step(10)")).should == [2]
|
||||
end
|
||||
|
||||
it "has closed range and negative steps" do
|
||||
# start and end with 0
|
||||
@array.send(@method, eval("(0..0).step(-1)")).should == [0]
|
||||
@array.send(@method, eval("(0...0).step(-1)")).should == []
|
||||
it "has closed range and negative steps" do
|
||||
# start and end with 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(-2)")).should == [0]
|
||||
@array.send(@method, eval("(0...0).step(-2)")).should == []
|
||||
@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(-10)")).should == [0]
|
||||
@array.send(@method, eval("(0...0).step(-10)")).should == []
|
||||
@array.send(@method, eval("(0..0).step(-10)")).should == [0]
|
||||
@array.send(@method, eval("(0...0).step(-10)")).should == []
|
||||
|
||||
# start and end with positive index
|
||||
@array.send(@method, eval("(1..3).step(-1)")).should == []
|
||||
@array.send(@method, eval("(1...3).step(-1)")).should == []
|
||||
# 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(-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
|
||||
@array.send(@method, eval("(1..-2).step(-1)")).should == []
|
||||
@array.send(@method, eval("(1...-2).step(-1)")).should == []
|
||||
# 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(-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
|
||||
@array.send(@method, eval("(-4..4).step(-1)")).should == []
|
||||
@array.send(@method, eval("(-4...4).step(-1)")).should == []
|
||||
# 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(-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
|
||||
@array.send(@method, eval("(-4..-2).step(-1)")).should == []
|
||||
@array.send(@method, eval("(-4...-2).step(-1)")).should == []
|
||||
# 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(-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 == []
|
||||
end
|
||||
@array.send(@method, eval("(-4..-2).step(-10)")).should == []
|
||||
@array.send(@method, eval("(-4...-2).step(-10)")).should == []
|
||||
end
|
||||
|
||||
it "has inverted closed range and positive steps" do
|
||||
# start and end with positive index
|
||||
@array.send(@method, eval("(3..1).step(1)")).should == []
|
||||
@array.send(@method, eval("(3...1).step(1)")).should == []
|
||||
it "has inverted closed range and positive steps" do
|
||||
# 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(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
|
||||
@array.send(@method, eval("(-2..1).step(1)")).should == []
|
||||
@array.send(@method, eval("(-2...1).step(1)")).should == []
|
||||
# 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(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
|
||||
@array.send(@method, eval("(4..-4).step(1)")).should == []
|
||||
@array.send(@method, eval("(4...-4).step(1)")).should == []
|
||||
# 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(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
|
||||
@array.send(@method, eval("(-2..-4).step(1)")).should == []
|
||||
@array.send(@method, eval("(-2...-4).step(1)")).should == []
|
||||
# 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(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 == []
|
||||
end
|
||||
@array.send(@method, eval("(-2..-4).step(10)")).should == []
|
||||
@array.send(@method, eval("(-2...-4).step(10)")).should == []
|
||||
end
|
||||
|
||||
it "has range with bounds outside of array" do
|
||||
# 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(2)) }.should raise_error(RangeError)
|
||||
it "has range with bounds outside of array" do
|
||||
# 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(2)) }.should raise_error(RangeError)
|
||||
|
||||
# end is greater than length with positive steps
|
||||
@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..8).step(2)) }.should raise_error(RangeError)
|
||||
# end is greater than length with positive steps
|
||||
@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..8).step(2)) }.should raise_error(RangeError)
|
||||
|
||||
# begin is greater than length with negative steps
|
||||
@array.send(@method, (6..1).step(-2)).should == [5, 3, 1]
|
||||
@array.send(@method, (7..2).step(-2)).should == [5, 3]
|
||||
-> { @array.send(@method, (8..2).step(-2)) }.should raise_error(RangeError)
|
||||
end
|
||||
# begin is greater than length with negative steps
|
||||
@array.send(@method, (6..1).step(-2)).should == [5, 3, 1]
|
||||
@array.send(@method, (7..2).step(-2)).should == [5, 3]
|
||||
-> { @array.send(@method, (8..2).step(-2)) }.should raise_error(RangeError)
|
||||
end
|
||||
|
||||
it "has endless range with start outside of array's bounds" do
|
||||
@array.send(@method, eval("(6..).step(1)")).should == []
|
||||
@array.send(@method, eval("(7..).step(1)")).should == nil
|
||||
it "has endless range with start outside of array's bounds" do
|
||||
@array.send(@method, eval("(6..).step(1)")).should == []
|
||||
@array.send(@method, eval("(7..).step(1)")).should == nil
|
||||
|
||||
@array.send(@method, eval("(6..).step(2)")).should == []
|
||||
-> { @array.send(@method, eval("(7..).step(2)")) }.should raise_error(RangeError)
|
||||
end
|
||||
@array.send(@method, eval("(6..).step(2)")).should == []
|
||||
-> { @array.send(@method, eval("(7..).step(2)")) }.should raise_error(RangeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -187,56 +187,28 @@ describe "Array#slice!" do
|
|||
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "returns a subclass instance with [n, m]" do
|
||||
@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
|
||||
it "returns a Array instance with [n, m]" do
|
||||
@array.slice!(0, 2).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
ruby_version_is '3.0' do
|
||||
it "returns a Array instance with [n, m]" do
|
||||
@array.slice!(0, 2).should be_an_instance_of(Array)
|
||||
end
|
||||
it "returns a Array instance with [-n, m]" do
|
||||
@array.slice!(-3, 2).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it "returns a Array instance with [-n, m]" do
|
||||
@array.slice!(-3, 2).should be_an_instance_of(Array)
|
||||
end
|
||||
it "returns a Array instance with [n..m]" do
|
||||
@array.slice!(1..3).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it "returns a Array instance with [n..m]" do
|
||||
@array.slice!(1..3).should be_an_instance_of(Array)
|
||||
end
|
||||
it "returns a Array instance with [n...m]" do
|
||||
@array.slice!(1...3).should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it "returns a Array instance with [n...m]" do
|
||||
@array.slice!(1...3).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
|
||||
|
||||
it "returns a Array instance with [-n..-m]" do
|
||||
@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
|
||||
it "returns a Array instance with [-n...-m]" do
|
||||
@array.slice!(-3...-1).should be_an_instance_of(Array)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,15 +26,7 @@ describe "Array#take" do
|
|||
->{ [1].take(-3) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it 'returns a subclass instance for Array subclasses' do
|
||||
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
|
||||
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
|
||||
|
|
|
@ -15,16 +15,8 @@ describe "Array#take_while" do
|
|||
[1, 2, false, 4].take_while{ |element| element }.should == [1, 2]
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' 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(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
|
||||
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
|
||||
|
||||
|
|
|
@ -85,16 +85,8 @@ describe "Array#uniq" do
|
|||
[false, nil, 42].uniq { :bar }.should == [false]
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "returns subclass instance on Array subclasses" do
|
||||
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
|
||||
it "returns Array instance on Array subclasses" do
|
||||
ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it "properly handles an identical item even when its #eql? isn't reflexive" do
|
||||
|
|
|
@ -23,58 +23,29 @@ describe "Binding#eval" do
|
|||
bind2.local_variables.should == []
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "inherits __LINE__ from the enclosing scope" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
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
|
||||
it "starts with line 1 if single argument is given" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
bind.eval("__LINE__").should == 1
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "starts with line 1 if single argument is given" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
bind.eval("__LINE__").should == 1
|
||||
end
|
||||
it "preserves __LINE__ across multiple calls to eval" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
bind.eval("__LINE__").should == 1
|
||||
bind.eval("__LINE__").should == 1
|
||||
end
|
||||
|
||||
it "preserves __LINE__ across multiple calls to eval" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
bind.eval("__LINE__").should == 1
|
||||
bind.eval("__LINE__").should == 1
|
||||
end
|
||||
it "increments __LINE__ on each line of a multiline eval" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
bind.eval("#foo\n__LINE__").should == 2
|
||||
end
|
||||
|
||||
it "increments __LINE__ on each line of a multiline eval" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
bind.eval("#foo\n__LINE__").should == 2
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "inherits __FILE__ from the enclosing scope" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
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
|
||||
it "uses (eval) as __FILE__ if single argument given" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
bind.eval("__FILE__").should == '(eval)'
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "uses (eval) as __FILE__ if single argument given" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
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
|
||||
it "uses 1 as __LINE__" do
|
||||
obj = BindingSpecs::Demo.new(1)
|
||||
bind = obj.get_binding
|
||||
suppress_warning { bind.eval("__LINE__") }.should == 1
|
||||
end
|
||||
|
||||
it "uses the __FILE__ that is passed in" do
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
ruby_version_is ''...'3.0' 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
|
||||
ruby_version_is ''...'3.2' do
|
||||
describe "Data" do
|
||||
it "does not exist anymore" do
|
||||
Object.should_not have_constant(:Data)
|
||||
|
|
|
@ -260,7 +260,7 @@ describe "Dir.glob" do
|
|||
Dir.glob('**/.*', base: "deeply/nested").sort.should == expected
|
||||
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
|
||||
it "handles **/.* with base keyword argument and FNM_DOTMATCH" do
|
||||
expected = %w[
|
||||
|
|
|
@ -27,24 +27,22 @@ describe :dir_glob, shared: true do
|
|||
-> {Dir.send(@method, "file_o*\0file_t*")}.should raise_error ArgumentError, /nul-separated/
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "result is sorted by default" do
|
||||
result = Dir.send(@method, '*')
|
||||
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
|
||||
it "result is sorted by default" do
|
||||
result = Dir.send(@method, '*')
|
||||
result.should == result.sort
|
||||
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
|
||||
result = Dir.send(@method, '*', sort: 0)
|
||||
result.should == result.sort
|
||||
|
|
|
@ -18,11 +18,9 @@ describe "Encoding.default_external" do
|
|||
Encoding.default_external.should == Encoding::SHIFT_JIS
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
platform_is :windows do
|
||||
it 'is UTF-8 by default on Windows' do
|
||||
Encoding.default_external.should == Encoding::UTF_8
|
||||
end
|
||||
platform_is :windows do
|
||||
it 'is UTF-8 by default on Windows' do
|
||||
Encoding.default_external.should == Encoding::UTF_8
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,43 +40,28 @@ describe "Enumerable#grep" do
|
|||
$~.should == nil
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0.0" do
|
||||
it "sets $~ to the last match when given no block" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].grep(/b/).should == ["abc"]
|
||||
|
||||
# Set by the failed match of "def"
|
||||
$~.should == nil
|
||||
|
||||
["abc", "def"].grep(/e/)
|
||||
$&.should == "e"
|
||||
end
|
||||
it "does not set $~ when given no block" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].grep(/b/).should == ["abc"]
|
||||
$&.should == "z"
|
||||
end
|
||||
|
||||
ruby_version_is "3.0.0" do
|
||||
it "does not set $~ when given no block" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].grep(/b/).should == ["abc"]
|
||||
$&.should == "z"
|
||||
end
|
||||
it "does not modify Regexp.last_match without block" do
|
||||
"z" =~ /z/ # Reset last match
|
||||
["abc", "def"].grep(/b/).should == ["abc"]
|
||||
Regexp.last_match[0].should == "z"
|
||||
end
|
||||
|
||||
it "does not modify Regexp.last_match without block" do
|
||||
"z" =~ /z/ # Reset last match
|
||||
["abc", "def"].grep(/b/).should == ["abc"]
|
||||
Regexp.last_match[0].should == "z"
|
||||
end
|
||||
it "correctly handles non-string elements" do
|
||||
'set last match' =~ /set last (.*)/
|
||||
[:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c]
|
||||
$1.should == 'match'
|
||||
|
||||
it "correctly handles non-string elements" do
|
||||
'set last match' =~ /set last (.*)/
|
||||
[:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c]
|
||||
$1.should == 'match'
|
||||
|
||||
o = Object.new
|
||||
def o.to_str
|
||||
'hello'
|
||||
end
|
||||
[o].grep(/ll/).first.should.equal?(o)
|
||||
o = Object.new
|
||||
def o.to_str
|
||||
'hello'
|
||||
end
|
||||
[o].grep(/ll/).first.should.equal?(o)
|
||||
end
|
||||
|
||||
describe "with a block" do
|
||||
|
|
|
@ -20,43 +20,28 @@ describe "Enumerable#grep_v" do
|
|||
$&.should == "e"
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0.0" do
|
||||
it "sets $~ to the last match when given no block" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].grep_v(/e/).should == ["abc"]
|
||||
|
||||
# Set by the match of "def"
|
||||
$&.should == "e"
|
||||
|
||||
["abc", "def"].grep_v(/b/)
|
||||
$&.should == nil
|
||||
end
|
||||
it "does not set $~ when given no block" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].grep_v(/e/).should == ["abc"]
|
||||
$&.should == "z"
|
||||
end
|
||||
|
||||
ruby_version_is "3.0.0" do
|
||||
it "does not set $~ when given no block" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].grep_v(/e/).should == ["abc"]
|
||||
$&.should == "z"
|
||||
end
|
||||
it "does not modify Regexp.last_match without block" do
|
||||
"z" =~ /z/ # Reset last match
|
||||
["abc", "def"].grep_v(/e/).should == ["abc"]
|
||||
Regexp.last_match[0].should == "z"
|
||||
end
|
||||
|
||||
it "does not modify Regexp.last_match without block" do
|
||||
"z" =~ /z/ # Reset last match
|
||||
["abc", "def"].grep_v(/e/).should == ["abc"]
|
||||
Regexp.last_match[0].should == "z"
|
||||
end
|
||||
it "correctly handles non-string elements" do
|
||||
'set last match' =~ /set last (.*)/
|
||||
[:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil]
|
||||
$1.should == 'match'
|
||||
|
||||
it "correctly handles non-string elements" do
|
||||
'set last match' =~ /set last (.*)/
|
||||
[:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil]
|
||||
$1.should == 'match'
|
||||
|
||||
o = Object.new
|
||||
def o.to_str
|
||||
'hello'
|
||||
end
|
||||
[o].grep_v(/mm/).first.should.equal?(o)
|
||||
o = Object.new
|
||||
def o.to_str
|
||||
'hello'
|
||||
end
|
||||
[o].grep_v(/mm/).first.should.equal?(o)
|
||||
end
|
||||
|
||||
describe "without block" do
|
||||
|
|
|
@ -11,14 +11,6 @@ describe "Enumerator#initialize" do
|
|||
Enumerator.should have_private_instance_method(:initialize, false)
|
||||
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
|
||||
@uninitialized.send(:initialize) {}.should equal(@uninitialized)
|
||||
end
|
||||
|
|
|
@ -2,51 +2,8 @@ require_relative '../../spec_helper'
|
|||
|
||||
describe "Enumerator.new" do
|
||||
context "no block given" do
|
||||
ruby_version_is '3.0' do
|
||||
it "raises" do
|
||||
-> { 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
|
||||
it "raises" do
|
||||
-> { Enumerator.new(1, :upto, 3) }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -30,11 +30,9 @@ describe "ENV.delete" do
|
|||
ScratchPad.recorded.should == "foo"
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "returns the result of given block if the named environment variable does not exist" do
|
||||
ENV.delete("foo")
|
||||
ENV.delete("foo") { |name| "bar" }.should == "bar"
|
||||
end
|
||||
it "returns the result of given block if the named environment variable does not exist" do
|
||||
ENV.delete("foo")
|
||||
ENV.delete("foo") { |name| "bar" }.should == "bar"
|
||||
end
|
||||
|
||||
it "does not evaluate the block if the environment variable exists" do
|
||||
|
|
|
@ -1,36 +1,34 @@
|
|||
require_relative 'spec_helper'
|
||||
require_relative 'shared/to_hash'
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
describe "ENV.except" do
|
||||
before do
|
||||
@orig_hash = ENV.to_hash
|
||||
end
|
||||
describe "ENV.except" do
|
||||
before do
|
||||
@orig_hash = ENV.to_hash
|
||||
end
|
||||
|
||||
after do
|
||||
ENV.replace @orig_hash
|
||||
end
|
||||
after do
|
||||
ENV.replace @orig_hash
|
||||
end
|
||||
|
||||
# Testing the method without arguments is covered via
|
||||
it_behaves_like :env_to_hash, :except
|
||||
# Testing the method without arguments is covered via
|
||||
it_behaves_like :env_to_hash, :except
|
||||
|
||||
it "returns a hash without the requested subset" do
|
||||
ENV.clear
|
||||
it "returns a hash without the requested subset" do
|
||||
ENV.clear
|
||||
|
||||
ENV['one'] = '1'
|
||||
ENV['two'] = '2'
|
||||
ENV['three'] = '3'
|
||||
ENV['one'] = '1'
|
||||
ENV['two'] = '2'
|
||||
ENV['three'] = '3'
|
||||
|
||||
ENV.except('one', 'three').should == { 'two' => '2' }
|
||||
end
|
||||
ENV.except('one', 'three').should == { 'two' => '2' }
|
||||
end
|
||||
|
||||
it "ignores keys not present in the original hash" do
|
||||
ENV.clear
|
||||
it "ignores keys not present in the original hash" do
|
||||
ENV.clear
|
||||
|
||||
ENV['one'] = '1'
|
||||
ENV['two'] = '2'
|
||||
ENV['one'] = '1'
|
||||
ENV['two'] = '2'
|
||||
|
||||
ENV.except('one', 'three').should == { 'two' => '2' }
|
||||
end
|
||||
ENV.except('one', 'three').should == { 'two' => '2' }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -1 +0,0 @@
|
|||
require_relative '../../spec_helper'
|
|
@ -1 +0,0 @@
|
|||
require_relative '../../spec_helper'
|
|
@ -6,7 +6,10 @@ describe "ENV.to_a" do
|
|||
a = ENV.to_a
|
||||
a.is_a?(Array).should == true
|
||||
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
|
||||
|
||||
it "returns the entries in the locale encoding" do
|
||||
|
|
|
@ -125,21 +125,19 @@ describe "NoMethodError#message" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" 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 }
|
||||
begin
|
||||
klass.foo
|
||||
rescue NoMethodError => error
|
||||
error.message.lines.first.chomp.should =~ /^undefined method `foo' for /
|
||||
end
|
||||
it "uses #name to display the receiver if it is a class or a module" do
|
||||
klass = Class.new { def self.name; "MyClass"; end }
|
||||
begin
|
||||
klass.foo
|
||||
rescue NoMethodError => error
|
||||
error.message.lines.first.chomp.should =~ /^undefined method `foo' for /
|
||||
end
|
||||
|
||||
mod = Module.new { def self.name; "MyModule"; end }
|
||||
begin
|
||||
mod.foo
|
||||
rescue NoMethodError => error
|
||||
error.message.lines.first.chomp.should =~ /^undefined method `foo' for /
|
||||
end
|
||||
mod = Module.new { def self.name; "MyModule"; end }
|
||||
begin
|
||||
mod.foo
|
||||
rescue NoMethodError => error
|
||||
error.message.lines.first.chomp.should =~ /^undefined method `foo' for /
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,61 +1,59 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'shared/blocking'
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
require "fiber"
|
||||
require "fiber"
|
||||
|
||||
describe "Fiber.blocking?" do
|
||||
it_behaves_like :non_blocking_fiber, -> { Fiber.blocking? }
|
||||
describe "Fiber.blocking?" do
|
||||
it_behaves_like :non_blocking_fiber, -> { Fiber.blocking? }
|
||||
|
||||
context "when fiber is blocking" do
|
||||
context "root Fiber of the main thread" do
|
||||
it "returns 1 for blocking: true" do
|
||||
context "when fiber is blocking" do
|
||||
context "root Fiber of the main thread" 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? }
|
||||
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? }
|
||||
blocking = fiber.resume
|
||||
|
||||
blocking.should == 1
|
||||
end
|
||||
|
||||
thread.join
|
||||
end
|
||||
thread.join
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Fiber#blocking?" do
|
||||
it_behaves_like :non_blocking_fiber, -> { Fiber.current.blocking? }
|
||||
describe "Fiber#blocking?" do
|
||||
it_behaves_like :non_blocking_fiber, -> { Fiber.current.blocking? }
|
||||
|
||||
context "when fiber is blocking" do
|
||||
context "root Fiber of the main thread" do
|
||||
it "returns true for blocking: true" do
|
||||
context "when fiber is blocking" do
|
||||
context "root Fiber of the main thread" 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? }
|
||||
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? }
|
||||
blocking = fiber.resume
|
||||
|
||||
blocking.should == true
|
||||
end
|
||||
|
||||
thread.join
|
||||
end
|
||||
thread.join
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,11 +18,9 @@ describe "Fiber#inspect" do
|
|||
inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "is resumed for a Fiber which was transferred" do
|
||||
inspected = Fiber.new { Fiber.current.inspect }.transfer
|
||||
inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/
|
||||
end
|
||||
it "is resumed for a Fiber which was transferred" do
|
||||
inspected = Fiber.new { Fiber.current.inspect }.transfer
|
||||
inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/
|
||||
end
|
||||
|
||||
it "is suspended for a Fiber which was resumed and yielded" do
|
||||
|
|
|
@ -94,26 +94,12 @@ describe "Fiber#raise" do
|
|||
end
|
||||
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
describe "Fiber#raise" do
|
||||
it "raises a FiberError if invoked on a transferring Fiber" do
|
||||
require "fiber"
|
||||
root = Fiber.current
|
||||
fiber = Fiber.new { root.transfer }
|
||||
fiber.transfer
|
||||
-> { 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
|
||||
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
|
||||
|
|
|
@ -28,18 +28,9 @@ describe "Fiber#resume" do
|
|||
fiber.resume :second
|
||||
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, /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
|
||||
it "raises a FiberError if the Fiber tries to resume itself" do
|
||||
fiber = Fiber.new { fiber.resume }
|
||||
-> { fiber.resume }.should raise_error(FiberError, /current fiber/)
|
||||
end
|
||||
|
||||
it "returns control to the calling Fiber if called from one" do
|
||||
|
|
|
@ -168,16 +168,14 @@ describe "File.new" do
|
|||
File.should.exist?(@file)
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "accepts options as a keyword argument" do
|
||||
@fh = File.new(@file, 'w', 0755, flags: @flags)
|
||||
@fh.should be_kind_of(File)
|
||||
@fh.close
|
||||
it "accepts options as a keyword argument" do
|
||||
@fh = File.new(@file, 'w', 0755, flags: @flags)
|
||||
@fh.should be_kind_of(File)
|
||||
@fh.close
|
||||
|
||||
-> {
|
||||
@fh = File.new(@file, 'w', 0755, {flags: @flags})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
|
||||
end
|
||||
-> {
|
||||
@fh = File.new(@file, 'w', 0755, {flags: @flags})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
|
||||
end
|
||||
|
||||
it "bitwise-ORs mode and flags option" do
|
||||
|
|
|
@ -565,15 +565,13 @@ describe "File.open" do
|
|||
File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::BINARY}
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "accepts options as a keyword argument" do
|
||||
@fh = File.open(@file, 'w', 0755, flags: File::CREAT)
|
||||
@fh.should be_an_instance_of(File)
|
||||
it "accepts options as a keyword argument" do
|
||||
@fh = File.open(@file, 'w', 0755, flags: File::CREAT)
|
||||
@fh.should be_an_instance_of(File)
|
||||
|
||||
-> {
|
||||
File.open(@file, 'w', 0755, {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
|
||||
end
|
||||
-> {
|
||||
File.open(@file, 'w', 0755, {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
|
||||
end
|
||||
|
||||
it "uses the second argument as an options Hash" do
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
describe "GC.auto_compact" do
|
||||
it "can set and get a boolean value" do
|
||||
begin
|
||||
GC.auto_compact = GC.auto_compact
|
||||
rescue NotImplementedError # platform does not support autocompact
|
||||
skip
|
||||
end
|
||||
describe "GC.auto_compact" do
|
||||
it "can set and get a boolean value" do
|
||||
begin
|
||||
GC.auto_compact = GC.auto_compact
|
||||
rescue NotImplementedError # platform does not support autocompact
|
||||
skip
|
||||
end
|
||||
|
||||
original = GC.auto_compact
|
||||
begin
|
||||
GC.auto_compact = !original
|
||||
rescue NotImplementedError # platform does not support autocompact
|
||||
skip
|
||||
end
|
||||
original = GC.auto_compact
|
||||
begin
|
||||
GC.auto_compact = !original
|
||||
rescue NotImplementedError # platform does not support autocompact
|
||||
skip
|
||||
end
|
||||
|
||||
begin
|
||||
GC.auto_compact.should == !original
|
||||
ensure
|
||||
GC.auto_compact = original
|
||||
end
|
||||
begin
|
||||
GC.auto_compact.should == !original
|
||||
ensure
|
||||
GC.auto_compact = original
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +1,32 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
describe "Hash#except" do
|
||||
before :each do
|
||||
@hash = { a: 1, b: 2, c: 3 }
|
||||
end
|
||||
describe "Hash#except" do
|
||||
before :each do
|
||||
@hash = { a: 1, b: 2, c: 3 }
|
||||
end
|
||||
|
||||
it "returns a new duplicate hash without arguments" do
|
||||
ret = @hash.except
|
||||
ret.should_not equal(@hash)
|
||||
ret.should == @hash
|
||||
end
|
||||
it "returns a new duplicate hash without arguments" do
|
||||
ret = @hash.except
|
||||
ret.should_not equal(@hash)
|
||||
ret.should == @hash
|
||||
end
|
||||
|
||||
it "returns a hash without the requested subset" do
|
||||
@hash.except(:c, :a).should == { b: 2 }
|
||||
end
|
||||
it "returns a hash without the requested subset" do
|
||||
@hash.except(:c, :a).should == { b: 2 }
|
||||
end
|
||||
|
||||
it "ignores keys not present in the original hash" do
|
||||
@hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 }
|
||||
end
|
||||
it "ignores keys not present in the original hash" do
|
||||
@hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 }
|
||||
end
|
||||
|
||||
it "always returns a Hash without a default" do
|
||||
klass = Class.new(Hash)
|
||||
h = klass.new(:default)
|
||||
h[:bar] = 12
|
||||
h[:foo] = 42
|
||||
r = h.except(:foo)
|
||||
r.should == {bar: 12}
|
||||
r.class.should == Hash
|
||||
r.default.should == nil
|
||||
end
|
||||
it "always returns a Hash without a default" do
|
||||
klass = Class.new(Hash)
|
||||
h = klass.new(:default)
|
||||
h[:bar] = 12
|
||||
h[:foo] = 42
|
||||
r = h.except(:foo)
|
||||
r.should == {bar: 12}
|
||||
r.class.should == Hash
|
||||
r.default.should == nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -21,37 +21,18 @@ describe :hash_each, shared: true do
|
|||
ary.sort.should == ["a", "b", "c"]
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "yields 2 values and not an Array of 2 elements when given a callable of arity 2" do
|
||||
obj = Object.new
|
||||
def obj.foo(key, value)
|
||||
ScratchPad << key << value
|
||||
end
|
||||
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
|
||||
|
||||
ScratchPad.record([])
|
||||
-> {
|
||||
{ "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 })
|
||||
ScratchPad.recorded.should == ["a", 1]
|
||||
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
|
||||
-> {
|
||||
{ "a" => 1 }.send(@method, &-> key, value { })
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "yields an Array of 2 elements when given a callable of arity 1" do
|
||||
|
|
|
@ -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
|
|
@ -26,14 +26,4 @@ describe "Hash#to_a" do
|
|||
ent.should be_kind_of(Array)
|
||||
ent.should == pairs
|
||||
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
|
||||
|
|
|
@ -19,20 +19,12 @@ describe "Hash#to_proc" do
|
|||
@proc = @hash.to_proc
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "is not a lambda" do
|
||||
@proc.should_not.lambda?
|
||||
end
|
||||
it "is a lambda" do
|
||||
@proc.should.lambda?
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "is a lambda" do
|
||||
@proc.should.lambda?
|
||||
end
|
||||
|
||||
it "has an arity of 1" do
|
||||
@proc.arity.should == 1
|
||||
end
|
||||
it "has an arity of 1" do
|
||||
@proc.arity.should == 1
|
||||
end
|
||||
|
||||
it "raises ArgumentError if not passed exactly one argument" do
|
||||
|
|
|
@ -43,18 +43,16 @@ describe "Hash#transform_keys" do
|
|||
r.class.should == Hash
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "allows a hash argument" do
|
||||
@hash.transform_keys({ a: :A, b: :B, c: :C }).should == { A: 1, B: 2, C: 3 }
|
||||
end
|
||||
it "allows a hash argument" do
|
||||
@hash.transform_keys({ a: :A, b: :B, c: :C }).should == { A: 1, B: 2, C: 3 }
|
||||
end
|
||||
|
||||
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 }
|
||||
end
|
||||
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 }
|
||||
end
|
||||
|
||||
it "allows a combination of hash and block argument" do
|
||||
@hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 }
|
||||
end
|
||||
it "allows a combination of hash and block argument" do
|
||||
@hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -111,11 +109,9 @@ describe "Hash#transform_keys!" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "allows a hash argument" do
|
||||
@hash.transform_keys!({ a: :A, b: :B, c: :C, d: :D })
|
||||
@hash.should == { A: 1, B: 2, C: 3, D: 4 }
|
||||
end
|
||||
it "allows a hash argument" do
|
||||
@hash.transform_keys!({ a: :A, b: :B, c: :C, d: :D })
|
||||
@hash.should == { A: 1, B: 2, C: 3, D: 4 }
|
||||
end
|
||||
|
||||
describe "on frozen instance" do
|
||||
|
@ -132,10 +128,8 @@ describe "Hash#transform_keys!" do
|
|||
@hash.should == @initial_pairs
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "raises a FrozenError on hash argument" do
|
||||
->{ @hash.transform_keys!({ a: :A, b: :B, c: :C }) }.should raise_error(FrozenError)
|
||||
end
|
||||
it "raises a FrozenError on hash argument" do
|
||||
->{ @hash.transform_keys!({ a: :A, b: :B, c: :C }) }.should raise_error(FrozenError)
|
||||
end
|
||||
|
||||
context "when no block is given" do
|
||||
|
|
|
@ -1,25 +1,5 @@
|
|||
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
|
||||
it "does not rescue exception raised in other#coerce" do
|
||||
b = mock("numeric with failed #coerce")
|
||||
|
|
|
@ -7,15 +7,7 @@ describe "Integer#zero?" do
|
|||
-1.should_not.zero?
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "Integer#zero? overrides Numeric#zero?" do
|
||||
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
|
||||
it "Integer#zero? overrides Numeric#zero?" do
|
||||
42.method(:zero?).owner.should == Integer
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -149,14 +149,12 @@ describe "IO#gets" do
|
|||
@io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "raises exception when options passed as Hash" do
|
||||
-> { @io.gets({ chomp: true }) }.should raise_error(TypeError)
|
||||
it "raises exception when options passed as Hash" do
|
||||
-> { @io.gets({ chomp: true }) }.should raise_error(TypeError)
|
||||
|
||||
-> {
|
||||
@io.gets("\n", 1, { chomp: true })
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
|
||||
end
|
||||
-> {
|
||||
@io.gets("\n", 1, { chomp: true })
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,17 +27,15 @@ describe "IO#initialize" do
|
|||
@io.fileno.should == fd
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "accepts options as keyword arguments" do
|
||||
fd = new_fd @name, "w:utf-8"
|
||||
it "accepts options as keyword arguments" do
|
||||
fd = new_fd @name, "w:utf-8"
|
||||
|
||||
@io.send(:initialize, fd, "w", flags: File::CREAT)
|
||||
@io.fileno.should == fd
|
||||
@io.send(:initialize, fd, "w", flags: File::CREAT)
|
||||
@io.fileno.should == fd
|
||||
|
||||
-> {
|
||||
@io.send(:initialize, fd, "w", {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
|
||||
end
|
||||
-> {
|
||||
@io.send(:initialize, fd, "w", {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed an IO" do
|
||||
|
|
|
@ -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
|
|
@ -12,43 +12,21 @@ platform_is_not :windows do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "returns false for pipe by default" do
|
||||
r, w = IO.pipe
|
||||
begin
|
||||
r.nonblock?.should == false
|
||||
w.nonblock?.should == false
|
||||
ensure
|
||||
r.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
|
||||
it "returns true for pipe by default" do
|
||||
r, w = IO.pipe
|
||||
begin
|
||||
r.nonblock?.should == true
|
||||
w.nonblock?.should == true
|
||||
ensure
|
||||
r.close
|
||||
w.close
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "returns true for pipe by default" do
|
||||
r, w = IO.pipe
|
||||
begin
|
||||
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
|
||||
it "returns true for socket by default" do
|
||||
require 'socket'
|
||||
TCPServer.open(0) do |socket|
|
||||
socket.nonblock?.should == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,15 +23,13 @@ describe "IO.read" do
|
|||
IO.read(p)
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
# https://bugs.ruby-lang.org/issues/19354
|
||||
it "accepts options as keyword arguments" do
|
||||
IO.read(@fname, 3, 0, mode: "r+").should == @contents[0, 3]
|
||||
# https://bugs.ruby-lang.org/issues/19354
|
||||
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 raise_error(ArgumentError, /wrong number of arguments/)
|
||||
end
|
||||
-> {
|
||||
IO.read(@fname, 3, 0, {mode: "r+"})
|
||||
}.should raise_error(ArgumentError, /wrong number of arguments/)
|
||||
end
|
||||
|
||||
it "accepts an empty options Hash" do
|
||||
|
|
|
@ -73,14 +73,12 @@ describe "IO#readline" do
|
|||
@io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "raises exception when options passed as Hash" do
|
||||
-> { @io.readline({ chomp: true }) }.should raise_error(TypeError)
|
||||
it "raises exception when options passed as Hash" do
|
||||
-> { @io.readline({ chomp: true }) }.should raise_error(TypeError)
|
||||
|
||||
-> {
|
||||
@io.readline("\n", 1, { chomp: true })
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
|
||||
end
|
||||
-> {
|
||||
@io.readline("\n", 1, { chomp: true })
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -117,14 +117,12 @@ describe "IO#readlines" do
|
|||
@io.readlines(chomp: true).should == IOSpecs.lines_without_newline_characters
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "raises exception when options passed as Hash" do
|
||||
-> { @io.readlines({ chomp: true }) }.should raise_error(TypeError)
|
||||
it "raises exception when options passed as Hash" do
|
||||
-> { @io.readlines({ chomp: true }) }.should raise_error(TypeError)
|
||||
|
||||
-> {
|
||||
@io.readlines("\n", 1, { chomp: true })
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
|
||||
end
|
||||
-> {
|
||||
@io.readlines("\n", 1, { chomp: true })
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,14 +21,12 @@ describe :io_binwrite, shared: true do
|
|||
IO.send(@method, @filename, "abcde").should == 5
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "accepts options as a keyword argument" do
|
||||
IO.send(@method, @filename, "hi", 0, flags: File::CREAT).should == 2
|
||||
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 raise_error(ArgumentError, "wrong number of arguments (given 4, expected 2..3)")
|
||||
end
|
||||
-> {
|
||||
IO.send(@method, @filename, "hi", 0, {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 2..3)")
|
||||
end
|
||||
|
||||
it "creates a file if missing" do
|
||||
|
|
|
@ -180,16 +180,14 @@ describe :io_each, shared: true do
|
|||
ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "raises exception when options passed as Hash" do
|
||||
-> {
|
||||
@io.send(@method, { chomp: true }) { |s| }
|
||||
}.should raise_error(TypeError)
|
||||
it "raises exception when options passed as Hash" do
|
||||
-> {
|
||||
@io.send(@method, { chomp: true }) { |s| }
|
||||
}.should raise_error(TypeError)
|
||||
|
||||
-> {
|
||||
@io.send(@method, "\n", 1, { chomp: true }) { |s| }
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
|
||||
end
|
||||
-> {
|
||||
@io.send(@method, "\n", 1, { chomp: true }) { |s| }
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -64,15 +64,13 @@ describe :io_new, shared: true do
|
|||
@io.should be_an_instance_of(IO)
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "accepts options as keyword arguments" do
|
||||
@io = IO.send(@method, @fd, "w", flags: File::CREAT)
|
||||
@io.write("foo").should == 3
|
||||
it "accepts options as keyword arguments" do
|
||||
@io = IO.send(@method, @fd, "w", flags: File::CREAT)
|
||||
@io.write("foo").should == 3
|
||||
|
||||
-> {
|
||||
IO.send(@method, @fd, "w", {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
|
||||
end
|
||||
-> {
|
||||
IO.send(@method, @fd, "w", {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
|
||||
end
|
||||
|
||||
it "accepts a :mode option" do
|
||||
|
@ -210,21 +208,10 @@ describe :io_new, shared: true do
|
|||
@io.internal_encoding.to_s.should == 'IBM866'
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "accepts nil options" do
|
||||
@io = suppress_keyword_warning do
|
||||
IO.send(@method, @fd, 'w', nil)
|
||||
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
|
||||
it "raises ArgumentError for nil options" do
|
||||
-> {
|
||||
IO.send(@method, @fd, 'w', nil)
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "coerces mode with #to_str" do
|
||||
|
@ -395,21 +382,9 @@ describe :io_new_errors, shared: true do
|
|||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "raises TypeError if passed a hash for mode and nil for options" do
|
||||
-> {
|
||||
suppress_keyword_warning do
|
||||
@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
|
||||
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
|
||||
|
|
|
@ -105,12 +105,10 @@ describe :io_readlines_options_19, shared: true do
|
|||
end
|
||||
|
||||
describe "when the object is an options Hash" do
|
||||
ruby_version_is "3.0" do
|
||||
it "raises TypeError exception" do
|
||||
-> {
|
||||
IO.send(@method, @name, { chomp: true }, &@object)
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
it "raises TypeError exception" do
|
||||
-> {
|
||||
IO.send(@method, @name, { chomp: true }, &@object)
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -179,12 +177,10 @@ describe :io_readlines_options_19, shared: true do
|
|||
end
|
||||
|
||||
describe "when the second object is an options Hash" do
|
||||
ruby_version_is "3.0" do
|
||||
it "raises TypeError exception" do
|
||||
-> {
|
||||
IO.send(@method, @name, "", { chomp: true }, &@object)
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
it "raises TypeError exception" do
|
||||
-> {
|
||||
IO.send(@method, @name, "", { chomp: true }, &@object)
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -103,19 +103,9 @@ describe "IO#ungetc" do
|
|||
-> { @io.sysread(1) }.should raise_error(IOError)
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "does not affect the stream and returns nil when passed nil" do
|
||||
@io.getc.should == ?V
|
||||
@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
|
||||
it "raises TypeError if passed nil" do
|
||||
@io.getc.should == ?V
|
||||
proc{@io.ungetc(nil)}.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "puts one or more characters back in the stream" do
|
||||
|
|
|
@ -259,25 +259,23 @@ platform_is :windows do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
describe "IO#write on STDOUT" do
|
||||
# https://bugs.ruby-lang.org/issues/14413
|
||||
platform_is_not :windows do
|
||||
it "raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs" do
|
||||
stderr_file = tmp("stderr")
|
||||
begin
|
||||
IO.popen([*ruby_exe, "-e", "loop { puts :ok }"], "r", err: stderr_file) do |io|
|
||||
io.gets.should == "ok\n"
|
||||
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
|
||||
describe "IO#write on STDOUT" do
|
||||
# https://bugs.ruby-lang.org/issues/14413
|
||||
platform_is_not :windows do
|
||||
it "raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs" do
|
||||
stderr_file = tmp("stderr")
|
||||
begin
|
||||
IO.popen([*ruby_exe, "-e", "loop { puts :ok }"], "r", err: stderr_file) do |io|
|
||||
io.gets.should == "ok\n"
|
||||
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
|
||||
end
|
||||
|
|
|
@ -145,7 +145,7 @@ describe :kernel_integer, shared: true do
|
|||
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
|
||||
-> { Integer("\0") }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
@ -348,7 +348,7 @@ describe "Integer() given a String", shared: true do
|
|||
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
|
||||
-> { Integer("\0", 2) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
@ -784,9 +784,9 @@ describe "Kernel.Integer" do
|
|||
|
||||
# TODO: fix these specs
|
||||
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
|
||||
Kernel.Integer(10).should == 10
|
||||
|
@ -798,9 +798,9 @@ describe "Kernel#Integer" do
|
|||
|
||||
# TODO: fix these specs
|
||||
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
|
||||
Kernel.should have_private_instance_method(:Integer)
|
||||
|
|
|
@ -19,19 +19,9 @@ describe "Kernel#__dir__" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
context "when used in eval with top level binding" do
|
||||
it "returns the real name of the directory containing the currently-executing file" do
|
||||
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
|
||||
context "when used in eval with top level binding" do
|
||||
it "returns nil" do
|
||||
eval("__dir__", binding).should == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,26 +45,18 @@ describe "Kernel#clone" do
|
|||
end
|
||||
|
||||
describe "with freeze: nil" do
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "raises ArgumentError" do
|
||||
-> { @obj.clone(freeze: nil) }.should raise_error(ArgumentError, /unexpected value for freeze: NilClass/)
|
||||
end
|
||||
it "copies frozen state from the original, like #clone without arguments" do
|
||||
o2 = @obj.clone(freeze: nil)
|
||||
o2.should_not.frozen?
|
||||
|
||||
@obj.freeze
|
||||
o3 = @obj.clone(freeze: nil)
|
||||
o3.should.frozen?
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "copies frozen state from the original, like #clone without arguments" do
|
||||
o2 = @obj.clone(freeze: nil)
|
||||
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
|
||||
it "copies frozen?" do
|
||||
o = "".freeze.clone(freeze: nil)
|
||||
o.frozen?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -74,33 +66,19 @@ describe "Kernel#clone" do
|
|||
@obj.clone(freeze: true).should.frozen?
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it 'does not freeze the copy even if the original is not frozen' do
|
||||
@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
|
||||
it 'freezes the copy even if the original was not frozen' do
|
||||
@obj.clone(freeze: true).should.frozen?
|
||||
end
|
||||
|
||||
ruby_version_is '3.0' do
|
||||
it 'freezes the copy even if the original was not frozen' do
|
||||
@obj.clone(freeze: true).should.frozen?
|
||||
end
|
||||
it "calls #initialize_clone with kwargs freeze: true" do
|
||||
obj = KernelSpecs::CloneFreeze.new
|
||||
obj.clone(freeze: true)
|
||||
ScratchPad.recorded.should == [obj, { freeze: true }]
|
||||
end
|
||||
|
||||
it "calls #initialize_clone with kwargs freeze: true" do
|
||||
obj = KernelSpecs::CloneFreeze.new
|
||||
obj.clone(freeze: true)
|
||||
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
|
||||
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
|
||||
|
||||
|
@ -114,25 +92,15 @@ describe "Kernel#clone" do
|
|||
@obj.clone(freeze: false).should_not.frozen?
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "calls #initialize_clone with no kwargs" do
|
||||
obj = KernelSpecs::CloneFreeze.new
|
||||
obj.clone(freeze: false)
|
||||
ScratchPad.recorded.should == [obj, {}]
|
||||
end
|
||||
it "calls #initialize_clone with kwargs freeze: false" do
|
||||
obj = KernelSpecs::CloneFreeze.new
|
||||
obj.clone(freeze: false)
|
||||
ScratchPad.recorded.should == [obj, { freeze: false }]
|
||||
end
|
||||
|
||||
ruby_version_is '3.0' do
|
||||
it "calls #initialize_clone with kwargs freeze: false" do
|
||||
obj = KernelSpecs::CloneFreeze.new
|
||||
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
|
||||
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
|
||||
|
||||
|
|
|
@ -159,37 +159,18 @@ describe "Kernel#eval" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "uses the filename of the binding if none is provided" do
|
||||
eval("__FILE__").should == "(eval)"
|
||||
suppress_warning {eval("__FILE__", binding)}.should == __FILE__
|
||||
eval("__FILE__", binding, "success").should == "success"
|
||||
suppress_warning {eval("eval '__FILE__', binding")}.should == "(eval)"
|
||||
suppress_warning {eval("eval '__FILE__', binding", binding)}.should == __FILE__
|
||||
suppress_warning {eval("eval '__FILE__', binding", binding, 'success')}.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
|
||||
it "uses (eval) filename if none is provided" do
|
||||
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
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "uses (eval) filename if none is provided" do
|
||||
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
|
||||
it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do
|
||||
eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1]
|
||||
end
|
||||
|
||||
# Found via Rubinius bug github:#149
|
||||
|
|
|
@ -18,11 +18,9 @@ describe "Kernel#initialize_clone" do
|
|||
a.send(:initialize_clone, b)
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do
|
||||
a = Object.new
|
||||
b = Object.new
|
||||
a.send(:initialize_clone, b, freeze: true).should == a
|
||||
end
|
||||
it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do
|
||||
a = Object.new
|
||||
b = Object.new
|
||||
a.send(:initialize_clone, b, freeze: true).should == a
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -136,15 +136,13 @@ describe "Kernel.lambda" do
|
|||
klass.new.ret.should == 1
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
context "when called without a literal block" 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")
|
||||
end
|
||||
context "when called without a literal block" 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")
|
||||
end
|
||||
|
||||
it "doesn't warn when proc is lambda" do
|
||||
-> { lambda(&lambda{}) }.should_not complain(verbose: true)
|
||||
end
|
||||
it "doesn't warn when proc is lambda" do
|
||||
-> { lambda(&lambda{}) }.should_not complain(verbose: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -72,15 +72,13 @@ describe "Kernel#open" do
|
|||
-> { open }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "accepts options as keyword arguments" do
|
||||
@file = open(@name, "r", 0666, flags: File::CREAT)
|
||||
@file.should be_kind_of(File)
|
||||
it "accepts options as keyword arguments" do
|
||||
@file = open(@name, "r", 0666, flags: File::CREAT)
|
||||
@file.should be_kind_of(File)
|
||||
|
||||
-> {
|
||||
open(@name, "r", 0666, {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
|
||||
end
|
||||
-> {
|
||||
open(@name, "r", 0666, {flags: File::CREAT})
|
||||
}.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "works correctly when redefined by open-uri" do
|
||||
code = <<~RUBY
|
||||
it "is not redefined by open-uri" do
|
||||
code = <<~RUBY
|
||||
before = Kernel.instance_method(:open)
|
||||
require 'open-uri'
|
||||
obj = Object.new
|
||||
def obj.to_open; self; end
|
||||
p open(obj) == obj
|
||||
RUBY
|
||||
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
|
||||
after = Kernel.instance_method(:open)
|
||||
p before == after
|
||||
RUBY
|
||||
ruby_exe(code, args: "2>&1").should == "true\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -40,19 +40,9 @@ describe "Kernel#proc" do
|
|||
proc
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "can be created when called with no block" do
|
||||
-> {
|
||||
some_method { "hello" }
|
||||
}.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
|
||||
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
|
||||
|
|
|
@ -262,13 +262,11 @@ describe :kernel_require, shared: true do
|
|||
ScratchPad.recorded.should == [:loaded]
|
||||
end
|
||||
|
||||
ruby_bug "#16926", ""..."3.0" do
|
||||
it "does not load a feature twice when $LOAD_PATH has been modified" do
|
||||
$LOAD_PATH.replace [CODE_LOADING_DIR]
|
||||
@object.require("load_fixture").should be_true
|
||||
$LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR]
|
||||
@object.require("load_fixture").should be_false
|
||||
end
|
||||
it "does not load a feature twice when $LOAD_PATH has been modified" do
|
||||
$LOAD_PATH.replace [CODE_LOADING_DIR]
|
||||
@object.require("load_fixture").should be_true
|
||||
$LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR]
|
||||
@object.require("load_fixture").should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -566,23 +564,21 @@ describe :kernel_require, shared: true do
|
|||
-> { @object.require("unicode_normalize") }.should raise_error(LoadError)
|
||||
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
|
||||
Dir.chdir CODE_LOADING_DIR do
|
||||
@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]
|
||||
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
|
||||
@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
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# truffleruby_primitives: true
|
||||
require_relative '../../spec_helper'
|
||||
|
||||
describe "Kernel#singleton_class" do
|
||||
|
@ -42,4 +43,32 @@ describe "Kernel#singleton_class" do
|
|||
obj.freeze
|
||||
obj.singleton_class.frozen?.should be_true
|
||||
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
|
||||
|
|
|
@ -4,9 +4,11 @@ require_relative 'fixtures/classes'
|
|||
describe "Kernel#taint" do
|
||||
ruby_version_is ""..."3.2" do
|
||||
it "is a no-op" do
|
||||
o = Object.new
|
||||
o.taint
|
||||
o.should_not.tainted?
|
||||
suppress_warning do
|
||||
o = Object.new
|
||||
o.taint
|
||||
o.should_not.tainted?
|
||||
end
|
||||
end
|
||||
|
||||
it "warns in verbose mode" do
|
||||
|
|
|
@ -4,11 +4,13 @@ require_relative 'fixtures/classes'
|
|||
describe "Kernel#tainted?" do
|
||||
ruby_version_is ""..."3.2" do
|
||||
it "is a no-op" do
|
||||
o = mock('o')
|
||||
p = mock('p')
|
||||
p.taint
|
||||
o.should_not.tainted?
|
||||
p.should_not.tainted?
|
||||
suppress_warning do
|
||||
o = mock('o')
|
||||
p = mock('p')
|
||||
p.taint
|
||||
o.should_not.tainted?
|
||||
p.should_not.tainted?
|
||||
end
|
||||
end
|
||||
|
||||
it "warns in verbose mode" do
|
||||
|
|
|
@ -4,10 +4,12 @@ require_relative 'fixtures/classes'
|
|||
describe "Kernel#trust" do
|
||||
ruby_version_is ""..."3.2" do
|
||||
it "is a no-op" do
|
||||
o = Object.new.untrust
|
||||
o.should_not.untrusted?
|
||||
o.trust
|
||||
o.should_not.untrusted?
|
||||
suppress_warning do
|
||||
o = Object.new.untrust
|
||||
o.should_not.untrusted?
|
||||
o.trust
|
||||
o.should_not.untrusted?
|
||||
end
|
||||
end
|
||||
|
||||
it "warns in verbose mode" do
|
||||
|
|
|
@ -4,10 +4,12 @@ require_relative 'fixtures/classes'
|
|||
describe "Kernel#untaint" do
|
||||
ruby_version_is ""..."3.2" do
|
||||
it "is a no-op" do
|
||||
o = Object.new.taint
|
||||
o.should_not.tainted?
|
||||
o.untaint
|
||||
o.should_not.tainted?
|
||||
suppress_warning do
|
||||
o = Object.new.taint
|
||||
o.should_not.tainted?
|
||||
o.untaint
|
||||
o.should_not.tainted?
|
||||
end
|
||||
end
|
||||
|
||||
it "warns in verbose mode" do
|
||||
|
|
|
@ -4,9 +4,11 @@ require_relative 'fixtures/classes'
|
|||
describe "Kernel#untrust" do
|
||||
ruby_version_is ""..."3.2" do
|
||||
it "is a no-op" do
|
||||
o = Object.new
|
||||
o.untrust
|
||||
o.should_not.untrusted?
|
||||
suppress_warning do
|
||||
o = Object.new
|
||||
o.untrust
|
||||
o.should_not.untrusted?
|
||||
end
|
||||
end
|
||||
|
||||
it "warns in verbose mode" do
|
||||
|
|
|
@ -4,10 +4,12 @@ require_relative 'fixtures/classes'
|
|||
describe "Kernel#untrusted?" do
|
||||
ruby_version_is ""..."3.2" do
|
||||
it "is a no-op" do
|
||||
o = mock('o')
|
||||
o.should_not.untrusted?
|
||||
o.untrust
|
||||
o.should_not.untrusted?
|
||||
suppress_warning do
|
||||
o = mock('o')
|
||||
o.should_not.untrusted?
|
||||
o.untrust
|
||||
o.should_not.untrusted?
|
||||
end
|
||||
end
|
||||
|
||||
it "warns in verbose mode" do
|
||||
|
|
|
@ -128,36 +128,34 @@ describe "Kernel#warn" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "accepts :category keyword with a symbol" do
|
||||
-> {
|
||||
$VERBOSE = true
|
||||
warn("message", category: :deprecated)
|
||||
}.should output(nil, "message\n")
|
||||
end
|
||||
it "accepts :category keyword with a symbol" do
|
||||
-> {
|
||||
$VERBOSE = true
|
||||
warn("message", category: :deprecated)
|
||||
}.should output(nil, "message\n")
|
||||
end
|
||||
|
||||
it "accepts :category keyword with nil" do
|
||||
-> {
|
||||
$VERBOSE = true
|
||||
warn("message", category: nil)
|
||||
}.should output(nil, "message\n")
|
||||
end
|
||||
it "accepts :category keyword with nil" do
|
||||
-> {
|
||||
$VERBOSE = true
|
||||
warn("message", category: nil)
|
||||
}.should output(nil, "message\n")
|
||||
end
|
||||
|
||||
it "accepts :category keyword with object convertible to symbol" do
|
||||
o = Object.new
|
||||
def o.to_sym; :deprecated; end
|
||||
-> {
|
||||
$VERBOSE = true
|
||||
warn("message", category: o)
|
||||
}.should output(nil, "message\n")
|
||||
end
|
||||
it "accepts :category keyword with object convertible to symbol" do
|
||||
o = Object.new
|
||||
def o.to_sym; :deprecated; end
|
||||
-> {
|
||||
$VERBOSE = true
|
||||
warn("message", category: o)
|
||||
}.should output(nil, "message\n")
|
||||
end
|
||||
|
||||
it "raises if :category keyword is not nil and not convertible to symbol" do
|
||||
-> {
|
||||
$VERBOSE = true
|
||||
warn("message", category: Object.new)
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
it "raises if :category keyword is not nil and not convertible to symbol" do
|
||||
-> {
|
||||
$VERBOSE = true
|
||||
warn("message", category: Object.new)
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "converts first arg using to_s" do
|
||||
|
@ -212,67 +210,52 @@ describe "Kernel#warn" do
|
|||
-> { warn('foo', **h) }.should complain("foo\n")
|
||||
end
|
||||
|
||||
ruby_version_is '3.0' do
|
||||
it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do
|
||||
verbose = $VERBOSE
|
||||
$VERBOSE = false
|
||||
it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do
|
||||
verbose = $VERBOSE
|
||||
$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
|
||||
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
|
||||
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
|
||||
remove_method :warn
|
||||
alias_method :warn, :_warn
|
||||
remove_method :_warn
|
||||
end
|
||||
$VERBOSE = verbose
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is ''...'3.0' do
|
||||
it "calls Warning.warn with no keyword arguments" do
|
||||
Warning.should_receive(:warn).with("Chunky bacon!\n")
|
||||
verbose = $VERBOSE
|
||||
$VERBOSE = false
|
||||
begin
|
||||
Kernel.warn("Chunky bacon!")
|
||||
ensure
|
||||
$VERBOSE = verbose
|
||||
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
|
||||
|
||||
|
|
|
@ -22,13 +22,11 @@ describe "main#private" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
context "when single argument is passed and is an array" do
|
||||
it "sets the visibility of the given methods to private" do
|
||||
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_method2)
|
||||
end
|
||||
context "when single argument is passed and is an array" do
|
||||
it "sets the visibility of the given methods to private" do
|
||||
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_method2)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,13 +22,11 @@ describe "main#public" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
context "when single argument is passed and is an array" do
|
||||
it "sets the visibility of the given methods to public" do
|
||||
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_method2)
|
||||
end
|
||||
context "when single argument is passed and is an array" do
|
||||
it "sets the visibility of the given methods to public" do
|
||||
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_method2)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -626,17 +626,6 @@ describe "Marshal.dump" do
|
|||
load.should == (1...2)
|
||||
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
|
||||
-> { Marshal.dump(Class.new(Range).new(1, 2)) }.should raise_error(TypeError, /can't dump anonymous class/)
|
||||
end
|
||||
|
|
|
@ -623,6 +623,14 @@ describe :marshal_load, shared: true do
|
|||
value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8]
|
||||
value.should == [*expected, expected[0]]
|
||||
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
|
||||
|
||||
describe "for a String" do
|
||||
|
@ -685,6 +693,14 @@ describe :marshal_load, shared: true do
|
|||
result.encoding.should == Encoding::BINARY
|
||||
result.should == str
|
||||
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
|
||||
|
||||
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")
|
||||
end.should raise_error(ArgumentError)
|
||||
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
|
||||
|
||||
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.source.should == "a".encode("utf-32le")
|
||||
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
|
||||
|
||||
describe "for a Float" do
|
||||
|
@ -929,6 +961,14 @@ describe :marshal_load, shared: true do
|
|||
obj = 1.1867345e+22
|
||||
Marshal.send(@method, "\004\bf\0361.1867344999999999e+22\000\344@").should == obj
|
||||
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
|
||||
|
||||
describe "for an Integer" do
|
||||
|
@ -1114,6 +1154,14 @@ describe :marshal_load, shared: true do
|
|||
it "raises ArgumentError if given a nonexistent class" do
|
||||
-> { Marshal.send(@method, "\x04\bc\vStrung") }.should raise_error(ArgumentError)
|
||||
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
|
||||
|
||||
describe "for a Module" do
|
||||
|
@ -1128,6 +1176,14 @@ describe :marshal_load, shared: true do
|
|||
it "loads an old module" do
|
||||
Marshal.send(@method, "\x04\bM\vKernel").should == Kernel
|
||||
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
|
||||
|
||||
describe "for a wrapped C pointer" do
|
||||
|
|
|
@ -48,11 +48,9 @@ describe "MatchData#[]" do
|
|||
/(.)(.)(\d+)(\d)/.match("THX1138.")[nil..nil].should == %w|HX1138 H X 113 8|
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "returns instances of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138.")
|
||||
/(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should be_an_instance_of(String) }
|
||||
end
|
||||
it "returns instances of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138.")
|
||||
/(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should be_an_instance_of(String) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,10 +17,8 @@ describe "MatchData#post_match" do
|
|||
str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1)
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "returns an instance of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
|
||||
/(.)(.)(\d+)(\d)/.match(str).post_match.should be_an_instance_of(String)
|
||||
end
|
||||
it "returns an instance of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
|
||||
/(.)(.)(\d+)(\d)/.match(str).post_match.should be_an_instance_of(String)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,10 +17,8 @@ describe "MatchData#pre_match" do
|
|||
str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1)
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "returns an instance of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
|
||||
/(.)(.)(\d+)(\d)/.match(str).pre_match.should be_an_instance_of(String)
|
||||
end
|
||||
it "returns an instance of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
|
||||
/(.)(.)(\d+)(\d)/.match(str).pre_match.should be_an_instance_of(String)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,10 +6,8 @@ describe :matchdata_captures, shared: true do
|
|||
/(.)(.)(\d+)(\d)/.match("THX1138.").send(@method).should == ["H","X","113","8"]
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "returns instances of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
|
||||
/(.)(.)(\d+)(\d)/.match(str).send(@method).each { |c| c.should be_an_instance_of(String) }
|
||||
end
|
||||
it "returns instances of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138: The Movie")
|
||||
/(.)(.)(\d+)(\d)/.match(str).send(@method).each { |c| c.should be_an_instance_of(String) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,10 +6,8 @@ describe "MatchData#to_a" do
|
|||
/(.)(.)(\d+)(\d)/.match("THX1138.").to_a.should == ["HX1138", "H", "X", "113", "8"]
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "returns instances of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138.")
|
||||
/(.)(.)(\d+)(\d)/.match(str)[0..-1].to_a.each { |m| m.should be_an_instance_of(String) }
|
||||
end
|
||||
it "returns instances of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138.")
|
||||
/(.)(.)(\d+)(\d)/.match(str)[0..-1].to_a.each { |m| m.should be_an_instance_of(String) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,10 +6,8 @@ describe "MatchData#to_s" do
|
|||
/(.)(.)(\d+)(\d)/.match("THX1138.").to_s.should == "HX1138"
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
it "returns an instance of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138.")
|
||||
/(.)(.)(\d+)(\d)/.match(str).to_s.should be_an_instance_of(String)
|
||||
end
|
||||
it "returns an instance of String when given a String subclass" do
|
||||
str = MatchDataSpecs::MyString.new("THX1138.")
|
||||
/(.)(.)(\d+)(\d)/.match(str).to_s.should be_an_instance_of(String)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,8 +38,7 @@ describe "Method#<<" do
|
|||
double = proc { |x| x + x }
|
||||
|
||||
(pow_2 << double).is_a?(Proc).should == true
|
||||
ruby_version_is(''...'3.0') { (pow_2 << double).should.lambda? }
|
||||
ruby_version_is('3.0') { (pow_2 << double).should_not.lambda? }
|
||||
(pow_2 << double).should_not.lambda?
|
||||
end
|
||||
|
||||
it "may accept multiple arguments" do
|
||||
|
|
|
@ -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"
|
||||
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
|
||||
obj = MethodSpecs::MySub.new
|
||||
obj.singleton_class
|
||||
@m = obj.method(:bar)
|
||||
@string = @m.send(@method)
|
||||
@string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
|
||||
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.singleton_class
|
||||
@m = obj.method(:bar)
|
||||
@string = @m.send(@method)
|
||||
@string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
|
||||
|
||||
c = MethodSpecs::MySub.dup
|
||||
m = Module.new{def bar; end}
|
||||
c.extend(m)
|
||||
@string = c.method(:bar).send(@method)
|
||||
@string.should.start_with? "#<Method: #<Class:#{c.inspect}>(#{m.inspect})#bar"
|
||||
end
|
||||
c = MethodSpecs::MySub.dup
|
||||
m = Module.new{def bar; end}
|
||||
c.extend(m)
|
||||
@string = c.method(:bar).send(@method)
|
||||
@string.should.start_with? "#<Method: #<Class:#{c.inspect}>(#{m.inspect})#bar"
|
||||
end
|
||||
|
||||
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"
|
||||
end
|
||||
|
||||
ruby_bug '#17428', ''...'3.0' 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")
|
||||
end
|
||||
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")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -92,17 +92,9 @@ describe "Module#alias_method" do
|
|||
end
|
||||
|
||||
describe "returned value" do
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "returns self" do
|
||||
@class.send(:alias_method, :checking_return_value, :public_one).should equal(@class)
|
||||
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
|
||||
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
|
||||
|
||||
|
|
|
@ -80,19 +80,9 @@ describe "Module#attr_accessor" do
|
|||
Module.should have_public_instance_method(:attr_accessor, false)
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "returns nil" do
|
||||
Class.new do
|
||||
(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
|
||||
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
|
||||
|
||||
|
|
|
@ -62,19 +62,9 @@ describe "Module#attr_reader" do
|
|||
Module.should have_public_instance_method(:attr_reader, false)
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "returns nil" do
|
||||
Class.new do
|
||||
(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
|
||||
it "returns an array of defined method names as symbols" do
|
||||
Class.new do
|
||||
(attr_reader :foo, 'bar').should == [:foo, :bar]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -146,23 +146,11 @@ describe "Module#attr" do
|
|||
Module.should have_public_instance_method(:attr, false)
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "returns nil" do
|
||||
Class.new do
|
||||
(attr :foo, 'bar').should == nil
|
||||
(attr :baz, false).should == nil
|
||||
(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
|
||||
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
|
||||
|
|
|
@ -72,19 +72,9 @@ describe "Module#attr_writer" do
|
|||
Module.should have_public_instance_method(:attr_writer, false)
|
||||
end
|
||||
|
||||
ruby_version_is ""..."3.0" do
|
||||
it "returns nil" do
|
||||
Class.new do
|
||||
(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
|
||||
it "returns an array of defined method names as symbols" do
|
||||
Class.new do
|
||||
(attr_writer :foo, 'bar').should == [:foo=, :bar=]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче