1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2022-04-25 14:53:54 +02:00
parent 6ae81d49b5
commit 45cf4f2187
277 changed files with 3844 additions and 7624 deletions

View file

@ -1,11 +1,12 @@
inherit_from: .rubocop_todo.yml inherit_from: .rubocop_todo.yml
AllCops: AllCops:
TargetRubyVersion: 2.6 TargetRubyVersion: 2.7
DisplayCopNames: true DisplayCopNames: true
Exclude: Exclude:
- command_line/fixtures/bad_syntax.rb - command_line/fixtures/bad_syntax.rb
DisabledByDefault: true DisabledByDefault: true
NewCops: disable
Layout/TrailingWhitespace: Layout/TrailingWhitespace:
Enabled: true Enabled: true
@ -56,12 +57,52 @@ Lint/UnusedMethodArgument:
Lint/UselessAssignment: Lint/UselessAssignment:
Enabled: false Enabled: false
Lint/UselessComparison: Lint/BinaryOperatorWithIdenticalOperands:
Enabled: false Enabled: false
Lint/EmptyConditionalBody:
Enabled: false # buggy
Lint/Void: Lint/Void:
Enabled: false Enabled: false
Lint/ConstantDefinitionInBlock:
Enabled: false
Lint/RaiseException:
Enabled: false
Lint/FloatComparison:
Enabled: false
Lint/DeprecatedClassMethods:
Enabled: false
Lint/UnreachableLoop:
Enabled: false
Lint/MissingSuper:
Enabled: false
Lint/UselessMethodDefinition:
Enabled: false
Lint/UselessTimes:
Enabled: false
Lint/MixedRegexpCaptureTypes:
Enabled: false
Lint/DuplicateElsifCondition:
Enabled: false
Lint/OutOfRangeRegexpRef:
Enabled: false
Lint/ElseLayout:
Exclude:
- 'language/if_spec.rb'
Lint/EmptyExpression: Lint/EmptyExpression:
Exclude: Exclude:
- 'language/**/*.rb' - 'language/**/*.rb'

View file

@ -180,7 +180,7 @@ First, file a bug at https://bugs.ruby-lang.org/.
It is better to use a `ruby_version_is` guard if there was a release with the fix. It is better to use a `ruby_version_is` guard if there was a release with the fix.
```ruby ```ruby
ruby_bug '#13669', ''...'2.7' do ruby_bug '#13669', ''...'3.2' do
it "works like this" do it "works like this" do
# Specify the expected behavior here, not the bug # Specify the expected behavior here, not the bug
end end

View file

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

View file

@ -19,29 +19,26 @@ describe "The -W command line option with 2" do
it_behaves_like :command_line_verbose, "-W2" it_behaves_like :command_line_verbose, "-W2"
end end
# Regarding the defaults, see core/warning/element_reference_spec.rb describe "The -W command line option with :deprecated" do
ruby_version_is "2.7" do it "enables deprecation warnings" do
describe "The -W command line option with :deprecated" do ruby_exe('p Warning[:deprecated]', options: '-W:deprecated').should == "true\n"
it "enables deprecation warnings" do end
ruby_exe('p Warning[:deprecated]', options: '-W:deprecated').should == "true\n" end
end
end describe "The -W command line option with :no-deprecated" do
it "suppresses deprecation warnings" do
describe "The -W command line option with :no-deprecated" do ruby_exe('p Warning[:deprecated]', options: '-w -W:no-deprecated').should == "false\n"
it "suppresses deprecation warnings" do end
ruby_exe('p Warning[:deprecated]', options: '-w -W:no-deprecated').should == "false\n" end
end
end describe "The -W command line option with :experimental" do
it "enables experimental warnings" do
describe "The -W command line option with :experimental" do ruby_exe('p Warning[:experimental]', options: '-W:experimental').should == "true\n"
it "enables experimental warnings" do end
ruby_exe('p Warning[:experimental]', options: '-W:experimental').should == "true\n" end
end
end describe "The -W command line option with :no-experimental" do
it "suppresses experimental warnings" do
describe "The -W command line option with :no-experimental" do ruby_exe('p Warning[:experimental]', options: '-w -W:no-experimental').should == "false\n"
it "suppresses experimental warnings" do
ruby_exe('p Warning[:experimental]', options: '-w -W:no-experimental').should == "false\n"
end
end end
end end

View file

@ -4,9 +4,7 @@ require_relative 'shared/verbose'
describe "The -w command line option" do describe "The -w command line option" do
it_behaves_like :command_line_verbose, "-w" it_behaves_like :command_line_verbose, "-w"
ruby_version_is "2.7" do it "enables both deprecated and experimental warnings" do
it "enables both deprecated and experimental warnings" do ruby_exe('p Warning[:deprecated]; p Warning[:experimental]', options: '-w').should == "true\ntrue\n"
ruby_exe('p Warning[:deprecated]; p Warning[:experimental]', options: '-w').should == "true\ntrue\n"
end
end end
end end

View file

@ -1 +1 @@
p "abc".object_id == "abc".object_id p "abc".equal?("abc")

View file

@ -59,24 +59,22 @@ describe "Processing RUBYOPT" do
ruby_exe("p $VERBOSE", escape: true).chomp.should == "true" ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
end end
ruby_version_is "2.7" do it "suppresses deprecation warnings for '-W:no-deprecated'" do
it "suppresses deprecation warnings for '-W:no-deprecated'" do ENV["RUBYOPT"] = '-W:no-deprecated'
ENV["RUBYOPT"] = '-W:no-deprecated' result = ruby_exe('$; = ""', args: '2>&1')
result = ruby_exe('$; = ""', args: '2>&1') result.should == ""
result.should == "" end
end
it "suppresses experimental warnings for '-W:no-experimental'" do it "suppresses experimental warnings for '-W:no-experimental'" do
ENV["RUBYOPT"] = '-W:no-experimental' ENV["RUBYOPT"] = '-W:no-experimental'
result = ruby_exe('case 0; in a; end', args: '2>&1') result = ruby_exe('case 0; in a; end', args: '2>&1')
result.should == "" result.should == ""
end end
it "suppresses deprecation and experimental warnings for '-W:no-deprecated -W:no-experimental'" do it "suppresses deprecation and experimental warnings for '-W:no-deprecated -W:no-experimental'" do
ENV["RUBYOPT"] = '-W:no-deprecated -W:no-experimental' ENV["RUBYOPT"] = '-W:no-deprecated -W:no-experimental'
result = ruby_exe('case ($; = ""); in a; end', args: '2>&1') result = ruby_exe('case ($; = ""); in a; end', args: '2>&1')
result.should == "" result.should == ""
end
end end
it "requires the file for '-r'" do it "requires the file for '-r'" do

View file

@ -20,30 +20,10 @@ describe "Array#clear" do
a.size.should == 0 a.size.should == 0
end end
ruby_version_is ''...'2.7' do
it "keeps tainted status" do
a = [1]
a.taint
a.tainted?.should be_true
a.clear
a.tainted?.should be_true
end
end
it "does not accept any arguments" do it "does not accept any arguments" do
-> { [1].clear(true) }.should raise_error(ArgumentError) -> { [1].clear(true) }.should raise_error(ArgumentError)
end end
ruby_version_is ''...'2.7' do
it "keeps untrusted status" do
a = [1]
a.untrust
a.untrusted?.should be_true
a.clear
a.untrusted?.should be_true
end
end
it "raises a FrozenError on a frozen array" do it "raises a FrozenError on a frozen array" do
a = [1] a = [1]
a.freeze a.freeze

View file

@ -21,20 +21,6 @@ describe "Array#compact" do
it "does not return subclass instance for Array subclasses" do it "does not return subclass instance for Array subclasses" do
ArraySpecs::MyArray[1, 2, 3, nil].compact.should be_an_instance_of(Array) ArraySpecs::MyArray[1, 2, 3, nil].compact.should be_an_instance_of(Array)
end end
ruby_version_is ''...'2.7' do
it "does not keep tainted status even if all elements are removed" do
a = [nil, nil]
a.taint
a.compact.tainted?.should be_false
end
it "does not keep untrusted status even if all elements are removed" do
a = [nil, nil]
a.untrust
a.compact.untrusted?.should be_false
end
end
end end
describe "Array#compact!" do describe "Array#compact!" do
@ -59,22 +45,6 @@ describe "Array#compact!" do
[1, 2, false, 3].compact!.should == nil [1, 2, false, 3].compact!.should == nil
end end
ruby_version_is ''...'2.7' do
it "keeps tainted status even if all elements are removed" do
a = [nil, nil]
a.taint
a.compact!
a.tainted?.should be_true
end
it "keeps untrusted status even if all elements are removed" do
a = [nil, nil]
a.untrust
a.compact!
a.untrusted?.should be_true
end
end
it "raises a FrozenError on a frozen array" do it "raises a FrozenError on a frozen array" do
-> { ArraySpecs.frozen_array.compact! }.should raise_error(FrozenError) -> { ArraySpecs.frozen_array.compact! }.should raise_error(FrozenError)
end end

View file

@ -41,64 +41,6 @@ describe "Array#concat" do
-> { ArraySpecs.frozen_array.concat([]) }.should raise_error(FrozenError) -> { ArraySpecs.frozen_array.concat([]) }.should raise_error(FrozenError)
end end
ruby_version_is ''...'2.7' do
it "keeps tainted status" do
ary = [1, 2]
ary.taint
ary.concat([3])
ary.tainted?.should be_true
ary.concat([])
ary.tainted?.should be_true
end
it "is not infected by the other" do
ary = [1,2]
other = [3]; other.taint
ary.tainted?.should be_false
ary.concat(other)
ary.tainted?.should be_false
end
it "keeps the tainted status of elements" do
ary = [ Object.new, Object.new, Object.new ]
ary.each {|x| x.taint }
ary.concat([ Object.new ])
ary[0].tainted?.should be_true
ary[1].tainted?.should be_true
ary[2].tainted?.should be_true
ary[3].tainted?.should be_false
end
it "keeps untrusted status" do
ary = [1, 2]
ary.untrust
ary.concat([3])
ary.untrusted?.should be_true
ary.concat([])
ary.untrusted?.should be_true
end
it "is not infected untrustedness by the other" do
ary = [1,2]
other = [3]; other.untrust
ary.untrusted?.should be_false
ary.concat(other)
ary.untrusted?.should be_false
end
it "keeps the untrusted status of elements" do
ary = [ Object.new, Object.new, Object.new ]
ary.each {|x| x.untrust }
ary.concat([ Object.new ])
ary[0].untrusted?.should be_true
ary[1].untrusted?.should be_true
ary[2].untrusted?.should be_true
ary[3].untrusted?.should be_false
end
end
it "appends elements to an Array with enough capacity that has been shifted" do it "appends elements to an Array with enough capacity that has been shifted" do
ary = [1, 2, 3, 4, 5] ary = [1, 2, 3, 4, 5]
2.times { ary.shift } 2.times { ary.shift }

View file

@ -1,11 +1,9 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
ruby_version_is "2.7" do describe "Array#deconstruct" do
describe "Array#deconstruct" do it "returns self" do
it "returns self" do array = [1]
array = [1]
array.deconstruct.should equal array array.deconstruct.should equal array
end
end end
end end

View file

@ -38,26 +38,4 @@ describe "Array#delete_at" do
it "raises a FrozenError on a frozen array" do it "raises a FrozenError on a frozen array" do
-> { [1,2,3].freeze.delete_at(0) }.should raise_error(FrozenError) -> { [1,2,3].freeze.delete_at(0) }.should raise_error(FrozenError)
end end
ruby_version_is ''...'2.7' do
it "keeps tainted status" do
ary = [1, 2]
ary.taint
ary.tainted?.should be_true
ary.delete_at(0)
ary.tainted?.should be_true
ary.delete_at(0) # now empty
ary.tainted?.should be_true
end
it "keeps untrusted status" do
ary = [1, 2]
ary.untrust
ary.untrusted?.should be_true
ary.delete_at(0)
ary.untrusted?.should be_true
ary.delete_at(0) # now empty
ary.untrusted?.should be_true
end
end
end end

View file

@ -47,22 +47,6 @@ describe "Array#delete_if" do
-> { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(FrozenError) -> { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(FrozenError)
end end
ruby_version_is ''...'2.7' do
it "keeps tainted status" do
@a.taint
@a.tainted?.should be_true
@a.delete_if{ true }
@a.tainted?.should be_true
end
it "keeps untrusted status" do
@a.untrust
@a.untrusted?.should be_true
@a.delete_if{ true }
@a.untrusted?.should be_true
end
end
it_behaves_like :enumeratorized_with_origin_size, :delete_if, [1,2,3] it_behaves_like :enumeratorized_with_origin_size, :delete_if, [1,2,3]
it_behaves_like :delete_if, :delete_if it_behaves_like :delete_if, :delete_if
end end

View file

@ -43,26 +43,4 @@ describe "Array#delete" do
it "raises a FrozenError on a frozen array" do it "raises a FrozenError on a frozen array" do
-> { [1, 2, 3].freeze.delete(1) }.should raise_error(FrozenError) -> { [1, 2, 3].freeze.delete(1) }.should raise_error(FrozenError)
end end
ruby_version_is ''...'2.7' do
it "keeps tainted status" do
a = [1, 2]
a.taint
a.tainted?.should be_true
a.delete(2)
a.tainted?.should be_true
a.delete(1) # now empty
a.tainted?.should be_true
end
it "keeps untrusted status" do
a = [1, 2]
a.untrust
a.untrusted?.should be_true
a.delete(2)
a.untrusted?.should be_true
a.delete(1) # now empty
a.untrusted?.should be_true
end
end
end end

View file

@ -481,50 +481,48 @@ describe "Array#[]= with [m..]" do
end end
end end
ruby_version_is "2.7" do describe "Array#[]= with [..n] and [...n]" do
describe "Array#[]= with [..n] and [...n]" do it "just sets the section defined by range to nil even if the rhs is nil" do
it "just sets the section defined by range to nil even if the rhs is nil" do a = [1, 2, 3, 4, 5]
a = [1, 2, 3, 4, 5] a[(..2)] = nil
a[eval("(..2)")] = nil a.should == [nil, 4, 5]
a.should == [nil, 4, 5] a[(...2)] = nil
a[eval("(...2)")] = nil a.should == [nil, 5]
a.should == [nil, 5] end
end
it "just sets the section defined by range to nil if n < 0 and the rhs is nil" do it "just sets the section defined by range to nil if n < 0 and the rhs is nil" do
a = [1, 2, 3, 4, 5] a = [1, 2, 3, 4, 5]
a[eval("(..-3)")] = nil a[(..-3)] = nil
a.should == [nil, 4, 5] a.should == [nil, 4, 5]
a[eval("(...-1)")] = [nil, 5] a[(...-1)] = [nil, 5]
end end
it "replaces the section defined by range" do it "replaces the section defined by range" do
a = [6, 5, 4, 3, 2, 1] a = [6, 5, 4, 3, 2, 1]
a[eval("(...3)")] = 9 a[(...3)] = 9
a.should == [9, 3, 2, 1] a.should == [9, 3, 2, 1]
a[eval("(..2)")] = [7, 7, 7, 7, 7] a[(..2)] = [7, 7, 7, 7, 7]
a.should == [7, 7, 7, 7, 7, 1] a.should == [7, 7, 7, 7, 7, 1]
end end
it "replaces the section if n < 0" do it "replaces the section if n < 0" do
a = [1, 2, 3, 4, 5] a = [1, 2, 3, 4, 5]
a[eval("(..-2)")] = [7, 8, 9] a[(..-2)] = [7, 8, 9]
a.should == [7, 8, 9, 5] a.should == [7, 8, 9, 5]
end end
it "replaces everything if n > the array size" do it "replaces everything if n > the array size" do
a = [1, 2, 3] a = [1, 2, 3]
a[eval("(...7)")] = [4] a[(...7)] = [4]
a.should == [4] a.should == [4]
end end
it "inserts at the beginning if n < negative the array size" do it "inserts at the beginning if n < negative the array size" do
a = [1, 2, 3] a = [1, 2, 3]
a[eval("(..-7)")] = [4] a[(..-7)] = [4]
a.should == [4, 1, 2, 3] a.should == [4, 1, 2, 3]
a[eval("(...-10)")] = [6] a[(...-10)] = [6]
a.should == [6, 4, 1, 2, 3] a.should == [6, 4, 1, 2, 3]
end
end end
end end

View file

@ -323,10 +323,8 @@ describe "Array#fill with (filler, range)" do
[1, 2, 3, 4].fill(eval("(3...)")) { |x| x + 2 }.should == [1, 2, 3, 5] [1, 2, 3, 4].fill(eval("(3...)")) { |x| x + 2 }.should == [1, 2, 3, 5]
end end
ruby_version_is "2.7" do it "works with beginless ranges" do
it "works with beginless ranges" do [1, 2, 3, 4].fill('x', (..2)).should == ["x", "x", "x", 4]
[1, 2, 3, 4].fill('x', eval("(..2)")).should == ["x", "x", "x", 4] [1, 2, 3, 4].fill((...2)) { |x| x + 2 }.should == [2, 3, 3, 4]
[1, 2, 3, 4].fill(eval("(...2)")) { |x| x + 2 }.should == [2, 3, 3, 4]
end
end end
end end

View file

@ -147,16 +147,6 @@ describe "Array#flatten" do
end end
end end
ruby_version_is ''...'2.7' do
it "returns a tainted array if self is tainted" do
[].taint.flatten.tainted?.should be_true
end
it "returns an untrusted array if self is untrusted" do
[].untrust.flatten.untrusted?.should be_true
end
end
it "performs respond_to? and method_missing-aware checks when coercing elements to array" do it "performs respond_to? and method_missing-aware checks when coercing elements to array" do
bo = BasicObject.new bo = BasicObject.new
[bo].flatten.should == [bo] [bo].flatten.should == [bo]

View file

@ -6,16 +6,14 @@ describe "Array#&" do
it_behaves_like :array_intersection, :& it_behaves_like :array_intersection, :&
end end
ruby_version_is "2.7" do describe "Array#intersection" do
describe "Array#intersection" do it_behaves_like :array_intersection, :intersection
it_behaves_like :array_intersection, :intersection
it "accepts multiple arguments" do it "accepts multiple arguments" do
[1, 2, 3, 4].intersection([1, 2, 3], [2, 3, 4]).should == [2, 3] [1, 2, 3, 4].intersection([1, 2, 3], [2, 3, 4]).should == [2, 3]
end end
it "preserves elements order from original array" do it "preserves elements order from original array" do
[1, 2, 3, 4].intersection([3, 2, 1]).should == [1, 2, 3] [1, 2, 3, 4].intersection([3, 2, 1]).should == [1, 2, 3]
end
end end
end end

View file

@ -97,46 +97,6 @@ describe "Array#* with an integer" do
ScratchPad.recorded.should be_nil ScratchPad.recorded.should be_nil
end end
end end
ruby_version_is ''...'2.7' do
it "copies the taint status of the original array even if the passed count is 0" do
ary = [1, 2, 3]
ary.taint
(ary * 0).should.tainted?
end
it "copies the taint status of the original array even if the array is empty" do
ary = []
ary.taint
(ary * 3).should.tainted?
end
it "copies the taint status of the original array if the passed count is not 0" do
ary = [1, 2, 3]
ary.taint
(ary * 1).should.tainted?
(ary * 2).should.tainted?
end
it "copies the untrusted status of the original array even if the passed count is 0" do
ary = [1, 2, 3]
ary.untrust
(ary * 0).should.untrusted?
end
it "copies the untrusted status of the original array even if the array is empty" do
ary = []
ary.untrust
(ary * 3).should.untrusted?
end
it "copies the untrusted status of the original array if the passed count is not 0" do
ary = [1, 2, 3]
ary.untrust
(ary * 1).should.untrusted?
(ary * 2).should.untrusted?
end
end
end end
describe "Array#* with a string" do describe "Array#* with a string" do

View file

@ -15,18 +15,6 @@ describe "Array#pack with format 'P'" do
["hello"].pack("P").unpack("P5").should == ["hello"] ["hello"].pack("P").unpack("P5").should == ["hello"]
end end
ruby_version_is ''...'2.7' do
it "taints the input string" do
input_string = "hello"
[input_string].pack("P")
input_string.tainted?.should be_true
end
it "does not taint the output string in normal cases" do
["hello"].pack("P").tainted?.should be_false
end
end
it "with nil gives a null pointer" do it "with nil gives a null pointer" do
[nil].pack("P").unpack("J").should == [0] [nil].pack("P").unpack("J").should == [0]
end end
@ -44,18 +32,6 @@ describe "Array#pack with format 'p'" do
["hello"].pack("p").unpack("p").should == ["hello"] ["hello"].pack("p").unpack("p").should == ["hello"]
end end
ruby_version_is ''...'2.7' do
it "taints the input string" do
input_string = "hello"
[input_string].pack("p")
input_string.tainted?.should be_true
end
it "does not taint the output string in normal cases" do
["hello"].pack("p").tainted?.should be_false
end
end
it "with nil gives a null pointer" do it "with nil gives a null pointer" do
[nil].pack("p").unpack("J").should == [0] [nil].pack("p").unpack("J").should == [0]
end end

View file

@ -32,12 +32,6 @@ describe :array_pack_basic_non_float, shared: true do
d.should_receive(:to_str).and_return("x"+pack_format) d.should_receive(:to_str).and_return("x"+pack_format)
[@obj, @obj].pack(d).should be_an_instance_of(String) [@obj, @obj].pack(d).should be_an_instance_of(String)
end end
ruby_version_is ''...'2.7' do
it "taints the output string if the format string is tainted" do
[@obj, @obj].pack("x"+pack_format.taint).tainted?.should be_true
end
end
end end
describe :array_pack_basic_float, shared: true do describe :array_pack_basic_float, shared: true do
@ -50,12 +44,6 @@ describe :array_pack_basic_float, shared: true do
d.should_receive(:to_str).and_return("x"+pack_format) d.should_receive(:to_str).and_return("x"+pack_format)
[1.2, 4.7].pack(d).should be_an_instance_of(String) [1.2, 4.7].pack(d).should be_an_instance_of(String)
end end
ruby_version_is ''...'2.7' do
it "taints the output string if the format string is tainted" do
[3.2, 2.8].pack("x"+pack_format.taint).tainted?.should be_true
end
end
end end
describe :array_pack_no_platform, shared: true do describe :array_pack_no_platform, shared: true do

View file

@ -1,35 +1,2 @@
describe :array_pack_taint, shared: true do describe :array_pack_taint, shared: true do
ruby_version_is ''...'2.7' do
it "returns a tainted string when a pack argument is tainted" do
["abcd".taint, 0x20].pack(pack_format("3C")).tainted?.should be_true
end
it "does not return a tainted string when the array is tainted" do
["abcd", 0x20].taint.pack(pack_format("3C")).tainted?.should be_false
end
it "returns a tainted string when the format is tainted" do
["abcd", 0x20].pack(pack_format("3C").taint).tainted?.should be_true
end
it "returns a tainted string when an empty format is tainted" do
["abcd", 0x20].pack("".taint).tainted?.should be_true
end
it "returns a untrusted string when the format is untrusted" do
["abcd", 0x20].pack(pack_format("3C").untrust).untrusted?.should be_true
end
it "returns a untrusted string when the empty format is untrusted" do
["abcd", 0x20].pack("".untrust).untrusted?.should be_true
end
it "returns a untrusted string when a pack argument is untrusted" do
["abcd".untrust, 0x20].pack(pack_format("3C")).untrusted?.should be_true
end
it "returns a trusted string when the array is untrusted" do
["abcd", 0x20].untrust.pack(pack_format("3C")).untrusted?.should be_false
end
end
end end

View file

@ -40,20 +40,4 @@ describe "Array#+" do
it "does not call to_ary on array subclasses" do it "does not call to_ary on array subclasses" do
([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2] ([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2]
end end
ruby_version_is ''...'2.7' do
it "does not get infected even if an original array is tainted" do
([1, 2] + [3, 4]).tainted?.should be_false
([1, 2].taint + [3, 4]).tainted?.should be_false
([1, 2] + [3, 4].taint).tainted?.should be_false
([1, 2].taint + [3, 4].taint).tainted?.should be_false
end
it "does not infected even if an original array is untrusted" do
([1, 2] + [3, 4]).untrusted?.should be_false
([1, 2].untrust + [3, 4]).untrusted?.should be_false
([1, 2] + [3, 4].untrust).untrusted?.should be_false
([1, 2].untrust + [3, 4].untrust).untrusted?.should be_false
end
end
end end

View file

@ -30,16 +30,6 @@ describe "Array#pop" do
array.pop.should == [1, 'two', 3.0, array, array, array, array] array.pop.should == [1, 'two', 3.0, array, array, array, array]
end end
ruby_version_is ''...'2.7' do
it "keeps taint status" do
a = [1, 2].taint
a.pop
a.tainted?.should be_true
a.pop
a.tainted?.should be_true
end
end
it "raises a FrozenError on a frozen array" do it "raises a FrozenError on a frozen array" do
-> { ArraySpecs.frozen_array.pop }.should raise_error(FrozenError) -> { ArraySpecs.frozen_array.pop }.should raise_error(FrozenError)
end end
@ -48,16 +38,6 @@ describe "Array#pop" do
-> { ArraySpecs.empty_frozen_array.pop }.should raise_error(FrozenError) -> { ArraySpecs.empty_frozen_array.pop }.should raise_error(FrozenError)
end end
ruby_version_is ''...'2.7' do
it "keeps untrusted status" do
a = [1, 2].untrust
a.pop
a.untrusted?.should be_true
a.pop
a.untrusted?.should be_true
end
end
describe "passed a number n as an argument" do describe "passed a number n as an argument" do
it "removes and returns an array with the last n elements of the array" do it "removes and returns an array with the last n elements of the array" do
a = [1, 2, 3, 4, 5, 6] a = [1, 2, 3, 4, 5, 6]
@ -136,41 +116,9 @@ describe "Array#pop" do
ArraySpecs::MyArray[1, 2, 3].pop(2).should be_an_instance_of(Array) ArraySpecs::MyArray[1, 2, 3].pop(2).should be_an_instance_of(Array)
end end
ruby_version_is ''...'2.7' do
it "returns an untainted array even if the array is tainted" do
ary = [1, 2].taint
ary.pop(2).tainted?.should be_false
ary.pop(0).tainted?.should be_false
end
it "keeps taint status" do
a = [1, 2].taint
a.pop(2)
a.tainted?.should be_true
a.pop(2)
a.tainted?.should be_true
end
it "returns a trusted array even if the array is untrusted" do
ary = [1, 2].untrust
ary.pop(2).untrusted?.should be_false
ary.pop(0).untrusted?.should be_false
end
end
it "raises a FrozenError on a frozen array" do it "raises a FrozenError on a frozen array" do
-> { ArraySpecs.frozen_array.pop(2) }.should raise_error(FrozenError) -> { ArraySpecs.frozen_array.pop(2) }.should raise_error(FrozenError)
-> { ArraySpecs.frozen_array.pop(0) }.should raise_error(FrozenError) -> { ArraySpecs.frozen_array.pop(0) }.should raise_error(FrozenError)
end end
ruby_version_is ''...'2.7' do
it "keeps untrusted status" do
a = [1, 2].untrust
a.pop(2)
a.untrusted?.should be_true
a.pop(2)
a.untrusted?.should be_true
end
end
end end
end end

View file

@ -17,28 +17,4 @@ describe :array_clone, shared: true do
b.should == a b.should == a
b.__id__.should_not == a.__id__ b.__id__.should_not == a.__id__
end end
ruby_version_is ''...'2.7' do
it "copies taint status from the original" do
a = [1, 2, 3, 4]
b = [1, 2, 3, 4]
a.taint
aa = a.send @method
bb = b.send @method
aa.should.tainted?
bb.should_not.tainted?
end
it "copies untrusted status from the original" do
a = [1, 2, 3, 4]
b = [1, 2, 3, 4]
a.untrust
aa = a.send @method
bb = b.send @method
aa.should.untrusted?
bb.should_not.untrusted?
end
end
end end

View file

@ -42,20 +42,6 @@ describe :array_collect, shared: true do
}.should raise_error(ArgumentError) }.should raise_error(ArgumentError)
end end
ruby_version_is ''...'2.7' do
it "does not copy tainted status" do
a = [1, 2, 3]
a.taint
a.send(@method){|x| x}.tainted?.should be_false
end
it "does not copy untrusted status" do
a = [1, 2, 3]
a.untrust
a.send(@method){|x| x}.untrusted?.should be_false
end
end
before :all do before :all do
@object = [1, 2, 3, 4] @object = [1, 2, 3, 4]
end end
@ -96,23 +82,6 @@ describe :array_collect_b, shared: true do
a.should == ["1!", "2!", "3!"] a.should == ["1!", "2!", "3!"]
end end
ruby_version_is ''...'2.7' do
it "keeps tainted status" do
a = [1, 2, 3]
a.taint
a.tainted?.should be_true
a.send(@method){|x| x}
a.tainted?.should be_true
end
it "keeps untrusted status" do
a = [1, 2, 3]
a.untrust
a.send(@method){|x| x}
a.untrusted?.should be_true
end
end
describe "when frozen" do describe "when frozen" do
it "raises a FrozenError" do it "raises a FrozenError" do
-> { ArraySpecs.frozen_array.send(@method) {} }.should raise_error(FrozenError) -> { ArraySpecs.frozen_array.send(@method) {} }.should raise_error(FrozenError)

View file

@ -64,32 +64,6 @@ describe :array_inspect, shared: true do
ArraySpecs.empty_recursive_array.send(@method).should == "[[...]]" ArraySpecs.empty_recursive_array.send(@method).should == "[[...]]"
end end
ruby_version_is ''...'2.7' do
it "taints the result if the Array is non-empty and tainted" do
[1, 2].taint.send(@method).tainted?.should be_true
end
it "does not taint the result if the Array is tainted but empty" do
[].taint.send(@method).tainted?.should be_false
end
it "taints the result if an element is tainted" do
["str".taint].send(@method).tainted?.should be_true
end
it "untrusts the result if the Array is untrusted" do
[1, 2].untrust.send(@method).untrusted?.should be_true
end
it "does not untrust the result if the Array is untrusted but empty" do
[].untrust.send(@method).untrusted?.should be_false
end
it "untrusts the result if an element is untrusted" do
["str".untrust].send(@method).untrusted?.should be_true
end
end
describe "with encoding" do describe "with encoding" do
before :each do before :each do
@default_external_encoding = Encoding.default_external @default_external_encoding = Encoding.default_external

View file

@ -58,36 +58,6 @@ describe :array_join_with_default_separator, shared: true do
-> { ArraySpecs.empty_recursive_array.send(@method) }.should raise_error(ArgumentError) -> { ArraySpecs.empty_recursive_array.send(@method) }.should raise_error(ArgumentError)
end end
ruby_version_is ''...'2.7' do
it "taints the result if the Array is tainted and non-empty" do
[1, 2].taint.send(@method).tainted?.should be_true
end
it "does not taint the result if the Array is tainted but empty" do
[].taint.send(@method).tainted?.should be_false
end
it "taints the result if the result of coercing an element is tainted" do
s = mock("taint")
s.should_receive(:to_s).and_return("str".taint)
[s].send(@method).tainted?.should be_true
end
it "untrusts the result if the Array is untrusted and non-empty" do
[1, 2].untrust.send(@method).untrusted?.should be_true
end
it "does not untrust the result if the Array is untrusted but empty" do
[].untrust.send(@method).untrusted?.should be_false
end
it "untrusts the result if the result of coercing an element is untrusted" do
s = mock("untrust")
s.should_receive(:to_s).and_return("str".untrust)
[s].send(@method).untrusted?.should be_true
end
end
it "uses the first encoding when other strings are compatible" do it "uses the first encoding when other strings are compatible" do
ary1 = ArraySpecs.array_with_7bit_utf8_and_usascii_strings ary1 = ArraySpecs.array_with_7bit_utf8_and_usascii_strings
ary2 = ArraySpecs.array_with_usascii_and_7bit_utf8_strings ary2 = ArraySpecs.array_with_usascii_and_7bit_utf8_strings
@ -114,18 +84,16 @@ describe :array_join_with_default_separator, shared: true do
-> { ary_utf8_bad_binary.send(@method) }.should raise_error(EncodingError) -> { ary_utf8_bad_binary.send(@method) }.should raise_error(EncodingError)
end end
ruby_version_is "2.7" do context "when $, is not nil" do
context "when $, is not nil" do before do
before do suppress_warning do
suppress_warning do $, = '*'
$, = '*'
end
end end
end
it "warns" do it "warns" do
-> { [].join }.should complain(/warning: \$, is set to non-nil value/) -> { [].join }.should complain(/warning: \$, is set to non-nil value/)
-> { [].join(nil) }.should complain(/warning: \$, is set to non-nil value/) -> { [].join(nil) }.should complain(/warning: \$, is set to non-nil value/)
end
end end
end end
end end
@ -141,42 +109,4 @@ describe :array_join_with_string_separator, shared: true do
[1, [2, [3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6" [1, [2, [3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6"
[1, [2, ArraySpecs::MyArray[3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6" [1, [2, ArraySpecs::MyArray[3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6"
end end
ruby_version_is ''...'2.7' do
describe "with a tainted separator" do
before :each do
@sep = ":".taint
end
it "does not taint the result if the array is empty" do
[].send(@method, @sep).tainted?.should be_false
end
it "does not taint the result if the array has only one element" do
[1].send(@method, @sep).tainted?.should be_false
end
it "taints the result if the array has two or more elements" do
[1, 2].send(@method, @sep).tainted?.should be_true
end
end
describe "with an untrusted separator" do
before :each do
@sep = ":".untrust
end
it "does not untrust the result if the array is empty" do
[].send(@method, @sep).untrusted?.should be_false
end
it "does not untrust the result if the array has only one element" do
[1].send(@method, @sep).untrusted?.should be_false
end
it "untrusts the result if the array has two or more elements" do
[1, 2].send(@method, @sep).untrusted?.should be_true
end
end
end
end end

View file

@ -556,34 +556,34 @@ describe :array_slice, shared: true do
it "has beginless range and positive steps" do it "has beginless range and positive steps" do
# end with zero index # end with zero index
@array.send(@method, eval("(..0).step(1)")).should == [0] @array.send(@method, (..0).step(1)).should == [0]
@array.send(@method, eval("(...0).step(1)")).should == [] @array.send(@method, (...0).step(1)).should == []
@array.send(@method, eval("(..0).step(2)")).should == [0] @array.send(@method, (..0).step(2)).should == [0]
@array.send(@method, eval("(...0).step(2)")).should == [] @array.send(@method, (...0).step(2)).should == []
@array.send(@method, eval("(..0).step(10)")).should == [0] @array.send(@method, (..0).step(10)).should == [0]
@array.send(@method, eval("(...0).step(10)")).should == [] @array.send(@method, (...0).step(10)).should == []
# end with positive index # end with positive index
@array.send(@method, eval("(..3).step(1)")).should == [0, 1, 2, 3] @array.send(@method, (..3).step(1)).should == [0, 1, 2, 3]
@array.send(@method, eval("(...3).step(1)")).should == [0, 1, 2] @array.send(@method, (...3).step(1)).should == [0, 1, 2]
@array.send(@method, eval("(..3).step(2)")).should == [0, 2] @array.send(@method, (..3).step(2)).should == [0, 2]
@array.send(@method, eval("(...3).step(2)")).should == [0, 2] @array.send(@method, (...3).step(2)).should == [0, 2]
@array.send(@method, eval("(..3).step(10)")).should == [0] @array.send(@method, (..3).step(10)).should == [0]
@array.send(@method, eval("(...3).step(10)")).should == [0] @array.send(@method, (...3).step(10)).should == [0]
# end with negative index # end with negative index
@array.send(@method, eval("(..-2).step(1)")).should == [0, 1, 2, 3, 4,] @array.send(@method, (..-2).step(1)).should == [0, 1, 2, 3, 4,]
@array.send(@method, eval("(...-2).step(1)")).should == [0, 1, 2, 3] @array.send(@method, (...-2).step(1)).should == [0, 1, 2, 3]
@array.send(@method, eval("(..-2).step(2)")).should == [0, 2, 4] @array.send(@method, (..-2).step(2)).should == [0, 2, 4]
@array.send(@method, eval("(...-2).step(2)")).should == [0, 2] @array.send(@method, (...-2).step(2)).should == [0, 2]
@array.send(@method, eval("(..-2).step(10)")).should == [0] @array.send(@method, (..-2).step(10)).should == [0]
@array.send(@method, eval("(...-2).step(10)")).should == [0] @array.send(@method, (...-2).step(10)).should == [0]
end end
it "has endless range and negative steps" do it "has endless range and negative steps" do
@ -770,26 +770,24 @@ describe :array_slice, shared: true do
end end
end end
ruby_version_is "2.7" do it "can accept beginless ranges" do
it "can accept beginless ranges" do a = [0, 1, 2, 3, 4, 5]
a = [0, 1, 2, 3, 4, 5] a.send(@method, (..3)).should == [0, 1, 2, 3]
a.send(@method, eval("(..3)")).should == [0, 1, 2, 3] a.send(@method, (...3)).should == [0, 1, 2]
a.send(@method, eval("(...3)")).should == [0, 1, 2] a.send(@method, (..-3)).should == [0, 1, 2, 3]
a.send(@method, eval("(..-3)")).should == [0, 1, 2, 3] a.send(@method, (...-3)).should == [0, 1, 2]
a.send(@method, eval("(...-3)")).should == [0, 1, 2] a.send(@method, (..0)).should == [0]
a.send(@method, eval("(..0)")).should == [0] a.send(@method, (...0)).should == []
a.send(@method, eval("(...0)")).should == [] a.send(@method, (..9)).should == [0, 1, 2, 3, 4, 5]
a.send(@method, eval("(..9)")).should == [0, 1, 2, 3, 4, 5] a.send(@method, (...9)).should == [0, 1, 2, 3, 4, 5]
a.send(@method, eval("(...9)")).should == [0, 1, 2, 3, 4, 5] a.send(@method, (..-9)).should == []
a.send(@method, eval("(..-9)")).should == [] a.send(@method, (...-9)).should == []
a.send(@method, eval("(...-9)")).should == [] end
end
it "can accept nil...nil ranges" do it "can accept nil...nil ranges" do
a = [0, 1, 2, 3, 4, 5] a = [0, 1, 2, 3, 4, 5]
a.send(@method, eval("(nil...nil)")).should == a a.send(@method, eval("(nil...nil)")).should == a
a.send(@method, eval("(...nil)")).should == a a.send(@method, (...nil)).should == a
a.send(@method, eval("(nil..)")).should == a a.send(@method, eval("(nil..)")).should == a
end
end end
end end

View file

@ -116,21 +116,5 @@ describe "Array#shift" do
it "does not return subclass instances with Array subclass" do it "does not return subclass instances with Array subclass" do
ArraySpecs::MyArray[1, 2, 3].shift(2).should be_an_instance_of(Array) ArraySpecs::MyArray[1, 2, 3].shift(2).should be_an_instance_of(Array)
end end
ruby_version_is ''...'2.7' do
it "returns an untainted array even if the array is tainted" do
ary = [1, 2].taint
ary.shift(2).tainted?.should be_false
ary.shift(0).tainted?.should be_false
end
it "keeps taint status" do
a = [1, 2].taint
a.shift(2)
a.tainted?.should be_true
a.shift(2)
a.tainted?.should be_true
end
end
end end
end end

View file

@ -172,16 +172,14 @@ describe "Array#slice!" do
a.should == [1, 2] a.should == [1, 2]
end end
ruby_version_is "2.7" do it "works with beginless ranges" do
it "works with beginless ranges" do a = [0,1,2,3,4]
a = [0,1,2,3,4] a.slice!((..3)).should == [0, 1, 2, 3]
a.slice!(eval("(..3)")).should == [0, 1, 2, 3] a.should == [4]
a.should == [4]
a = [0,1,2,3,4] a = [0,1,2,3,4]
a.slice!(eval("(...-2)")).should == [0, 1, 2] a.slice!((...-2)).should == [0, 1, 2]
a.should == [3, 4] a.should == [3, 4]
end
end end
describe "with a subclass of Array" do describe "with a subclass of Array" do

View file

@ -39,76 +39,32 @@ describe "Array#uniq" do
[x, y].uniq.should == [x, y] [x, y].uniq.should == [x, y]
end end
ruby_version_is '2.7' do it "compares elements with matching hash codes with #eql?" do
it "compares elements with matching hash codes with #eql?" do a = Array.new(2) do
a = Array.new(2) do obj = mock('0')
obj = mock('0') obj.should_receive(:hash).at_least(1).and_return(0)
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o) def obj.eql?(o)
false false
end
obj
end end
a.uniq.should == a obj
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
true
end
obj
end
a.uniq.size.should == 1
end end
end
ruby_version_is ''...'2.7' do a.uniq.should == a
it "compares elements with matching hash codes with #eql?" do
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o) a = Array.new(2) do
# It's undefined whether the impl does a[0].eql?(a[1]) or obj = mock('0')
# a[1].eql?(a[0]) so we taint both. obj.should_receive(:hash).at_least(1).and_return(0)
taint
o.taint
false
end
obj def obj.eql?(o)
true
end end
a.uniq.should == a obj
a[0].should.tainted?
a[1].should.tainted?
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
# It's undefined whether the impl does a[0].eql?(a[1]) or
# a[1].eql?(a[0]) so we taint both.
taint
o.taint
true
end
obj
end
a.uniq.size.should == 1
a[0].should.tainted?
a[1].should.tainted?
end end
a.uniq.size.should == 1
end end
it "compares elements based on the value returned from the block" do it "compares elements based on the value returned from the block" do

View file

@ -66,10 +66,8 @@ describe "Array#values_at" do
[1, 2, 3, 4].values_at(eval("(3...)")).should == [4] [1, 2, 3, 4].values_at(eval("(3...)")).should == [4]
end end
ruby_version_is "2.7" do it "works when given beginless ranges" do
it "works when given beginless ranges" do [1, 2, 3, 4].values_at((..2)).should == [1, 2, 3]
[1, 2, 3, 4].values_at(eval("(..2)")).should == [1, 2, 3] [1, 2, 3, 4].values_at((...2)).should == [1, 2]
[1, 2, 3, 4].values_at(eval("(...2)")).should == [1, 2]
end
end end
end end

View file

@ -49,15 +49,7 @@ describe "RUBY_RELEASE_DATE" do
end end
describe "RUBY_REVISION" do describe "RUBY_REVISION" do
ruby_version_is ""..."2.7" do it "is a String" do
it "is an Integer" do RUBY_REVISION.should be_kind_of(String)
RUBY_REVISION.should be_kind_of(Integer)
end
end
ruby_version_is "2.7" do
it "is a String" do
RUBY_REVISION.should be_kind_of(String)
end
end end
end end

View file

@ -2,14 +2,6 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
describe 'Comparable#clamp' do describe 'Comparable#clamp' do
ruby_version_is ""..."2.7" do
it 'raises an Argument error unless given 2 parameters' do
c = ComparableSpecs::Weird.new(0)
-> { c.clamp(c) }.should raise_error(ArgumentError)
-> { c.clamp(c, c, c) }.should raise_error(ArgumentError)
end
end
it 'raises an Argument error unless the 2 parameters are correctly ordered' do it 'raises an Argument error unless the 2 parameters are correctly ordered' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1) one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2) two = ComparableSpecs::WithOnlyCompareDefined.new(2)
@ -48,41 +40,39 @@ describe 'Comparable#clamp' do
c.clamp(one, two).should equal(two) c.clamp(one, two).should equal(two)
end end
ruby_version_is "2.7" do it 'returns self if within the given range parameters' do
it 'returns self if within the given range parameters' do one = ComparableSpecs::WithOnlyCompareDefined.new(1)
one = ComparableSpecs::WithOnlyCompareDefined.new(1) two = ComparableSpecs::WithOnlyCompareDefined.new(2)
two = ComparableSpecs::WithOnlyCompareDefined.new(2) three = ComparableSpecs::WithOnlyCompareDefined.new(3)
three = ComparableSpecs::WithOnlyCompareDefined.new(3) c = ComparableSpecs::Weird.new(2)
c = ComparableSpecs::Weird.new(2)
c.clamp(one..two).should equal(c) c.clamp(one..two).should equal(c)
c.clamp(two..two).should equal(c) c.clamp(two..two).should equal(c)
c.clamp(one..three).should equal(c) c.clamp(one..three).should equal(c)
c.clamp(two..three).should equal(c) c.clamp(two..three).should equal(c)
end end
it 'returns the minimum value of the range parameters if smaller than it' do it 'returns the minimum value of the range parameters if smaller than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1) one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2) two = ComparableSpecs::WithOnlyCompareDefined.new(2)
c = ComparableSpecs::Weird.new(0) c = ComparableSpecs::Weird.new(0)
c.clamp(one..two).should equal(one) c.clamp(one..two).should equal(one)
end end
it 'returns the maximum value of the range parameters if greater than it' do it 'returns the maximum value of the range parameters if greater than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1) one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2) two = ComparableSpecs::WithOnlyCompareDefined.new(2)
c = ComparableSpecs::Weird.new(3) c = ComparableSpecs::Weird.new(3)
c.clamp(one..two).should equal(two) c.clamp(one..two).should equal(two)
end end
it 'raises an Argument error if the range parameter is exclusive' do it 'raises an Argument error if the range parameter is exclusive' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1) one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2) two = ComparableSpecs::WithOnlyCompareDefined.new(2)
c = ComparableSpecs::Weird.new(3) c = ComparableSpecs::Weird.new(3)
-> { c.clamp(one...two) }.should raise_error(ArgumentError) -> { c.clamp(one...two) }.should raise_error(ArgumentError)
end
end end
end end

View file

@ -1,27 +1,25 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
describe "Complex#<=>" do describe "Complex#<=>" do
ruby_version_is "2.7" do it "returns nil if either self or argument has imaginary part" do
it "returns nil if either self or argument has imaginary part" do (Complex(5, 1) <=> Complex(2)).should be_nil
(Complex(5, 1) <=> Complex(2)).should be_nil (Complex(1) <=> Complex(2, 1)).should be_nil
(Complex(1) <=> Complex(2, 1)).should be_nil (5 <=> Complex(2, 1)).should be_nil
(5 <=> Complex(2, 1)).should be_nil end
end
it "returns nil if argument is not numeric" do it "returns nil if argument is not numeric" do
(Complex(5, 1) <=> "cmp").should be_nil (Complex(5, 1) <=> "cmp").should be_nil
(Complex(1) <=> "cmp").should be_nil (Complex(1) <=> "cmp").should be_nil
(Complex(1) <=> Object.new).should be_nil (Complex(1) <=> Object.new).should be_nil
end end
it "returns 0, 1, or -1 if self and argument do not have imaginary part" do it "returns 0, 1, or -1 if self and argument do not have imaginary part" do
(Complex(5) <=> Complex(2)).should == 1 (Complex(5) <=> Complex(2)).should == 1
(Complex(2) <=> Complex(3)).should == -1 (Complex(2) <=> Complex(3)).should == -1
(Complex(2) <=> Complex(2)).should == 0 (Complex(2) <=> Complex(2)).should == 0
(Complex(5) <=> 2).should == 1 (Complex(5) <=> 2).should == 1
(Complex(2) <=> 3).should == -1 (Complex(2) <=> 3).should == -1
(Complex(2) <=> 2).should == 0 (Complex(2) <=> 2).should == 0
end
end end
end end

View file

@ -105,14 +105,6 @@ describe "Dir#children" do
dirs.each { |d| d.encoding.should == Encoding::UTF_8 } dirs.each { |d| d.encoding.should == Encoding::UTF_8 }
end end
ruby_version_is ""..."2.7" do
it "accepts nil options" do
@dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested", nil)
dirs = @dir.to_a.sort
dirs.each { |d| d.encoding.should == Encoding.find("filesystem") }
end
end
it "returns children encoded with the filesystem encoding by default" do it "returns children encoded with the filesystem encoding by default" do
# This spec depends on the locale not being US-ASCII because if it is, the # This spec depends on the locale not being US-ASCII because if it is, the
# children that are not ascii_only? will be BINARY encoded. # children that are not ascii_only? will be BINARY encoded.

View file

@ -15,13 +15,6 @@ describe "Dir.each_child" do
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8} dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
end end
ruby_version_is ""..."2.7" do
it "accepts nil options" do
dirs = Dir.each_child("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
end
end
it "yields all names in an existing directory to the provided block" do it "yields all names in an existing directory to the provided block" do
a, b = [], [] a, b = [], []

View file

@ -40,13 +40,6 @@ describe "Dir.entries" do
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8} dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
end end
ruby_version_is ""..."2.7" do
it "accepts nil options" do
dirs = Dir.entries("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
end
end
it "returns entries encoded with the filesystem encoding by default" do it "returns entries encoded with the filesystem encoding by default" do
# This spec depends on the locale not being US-ASCII because if it is, the # This spec depends on the locale not being US-ASCII because if it is, the
# entries that are not ascii_only? will be BINARY encoded. # entries that are not ascii_only? will be BINARY encoded.

View file

@ -51,13 +51,6 @@ describe "Dir.foreach" do
end end
end end
ruby_version_is ""..."2.7" do
it "accepts nil options" do
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
end
end
describe "when no block is given" do describe "when no block is given" do
it "returns an Enumerator" do it "returns an Enumerator" do
Dir.foreach(DirSpecs.mock_dir).should be_an_instance_of(Enumerator) Dir.foreach(DirSpecs.mock_dir).should be_an_instance_of(Enumerator)

View file

@ -23,19 +23,8 @@ describe :dir_glob, shared: true do
Dir.send(@method, obj).should == %w[file_one.ext] Dir.send(@method, obj).should == %w[file_one.ext]
end end
ruby_version_is ""..."2.7" do it "raises an ArgumentError if the string contains \\0" do
it "splits the string on \\0 if there is only one string given and warns" do -> {Dir.send(@method, "file_o*\0file_t*")}.should raise_error ArgumentError, /nul-separated/
-> {
Dir.send(@method, "file_o*\0file_t*").should ==
%w!file_one.ext file_two.ext!
}.should complain(/warning: use glob patterns list instead of nul-separated patterns/)
end
end
ruby_version_is "2.7" do
it "raises an ArgumentError if the string contains \\0" do
-> {Dir.send(@method, "file_o*\0file_t*")}.should raise_error ArgumentError, /nul-separated/
end
end end
ruby_version_is "3.0" do ruby_version_is "3.0" do

View file

@ -40,10 +40,8 @@ describe "Encoding.list" do
Encoding.list.should.include?(Encoding::UTF_8) Encoding.list.should.include?(Encoding::UTF_8)
end end
ruby_version_is "2.7" do it 'includes CESU-8 encoding' do
it 'includes CESU-8 encoding' do Encoding.list.should.include?(Encoding::CESU_8)
Encoding.list.should.include?(Encoding::CESU_8)
end
end end
# TODO: Find example that illustrates this # TODO: Find example that illustrates this

View file

@ -1,26 +1,24 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
ruby_version_is '2.7' do describe 'Enumerable#filter_map' do
describe 'Enumerable#filter_map' do before :each do
before :each do @numerous = EnumerableSpecs::Numerous.new(*(1..8).to_a)
@numerous = EnumerableSpecs::Numerous.new(*(1..8).to_a) end
end
it 'returns an empty array if there are no elements' do it 'returns an empty array if there are no elements' do
EnumerableSpecs::Empty.new.filter_map { true }.should == [] EnumerableSpecs::Empty.new.filter_map { true }.should == []
end end
it 'returns an array with truthy results of passing each element to block' do it 'returns an array with truthy results of passing each element to block' do
@numerous.filter_map { |i| i * 2 if i.even? }.should == [4, 8, 12, 16] @numerous.filter_map { |i| i * 2 if i.even? }.should == [4, 8, 12, 16]
@numerous.filter_map { |i| i * 2 }.should == [2, 4, 6, 8, 10, 12, 14, 16] @numerous.filter_map { |i| i * 2 }.should == [2, 4, 6, 8, 10, 12, 14, 16]
@numerous.filter_map { 0 }.should == [0, 0, 0, 0, 0, 0, 0, 0] @numerous.filter_map { 0 }.should == [0, 0, 0, 0, 0, 0, 0, 0]
@numerous.filter_map { false }.should == [] @numerous.filter_map { false }.should == []
@numerous.filter_map { nil }.should == [] @numerous.filter_map { nil }.should == []
end end
it 'returns an enumerator when no block given' do it 'returns an enumerator when no block given' do
@numerous.filter_map.should be_an_instance_of(Enumerator) @numerous.filter_map.should be_an_instance_of(Enumerator)
end
end end
end end

View file

@ -33,15 +33,5 @@ describe "Enumerable#group_by" do
[3, 4, 5] => [[3, 4, 5]] } [3, 4, 5] => [[3, 4, 5]] }
end end
ruby_version_is ''...'2.7' do
it "returns a tainted hash if self is tainted" do
EnumerableSpecs::Empty.new.taint.group_by {}.tainted?.should be_true
end
it "returns an untrusted hash if self is untrusted" do
EnumerableSpecs::Empty.new.untrust.group_by {}.untrusted?.should be_true
end
end
it_behaves_like :enumerable_enumeratorized_with_origin_size, :group_by it_behaves_like :enumerable_enumeratorized_with_origin_size, :group_by
end end

View file

@ -13,14 +13,4 @@ describe :enumerable_entries, shared: true do
count.send(@method, :hello, "world").should == [1, 2, 3] count.send(@method, :hello, "world").should == [1, 2, 3]
count.arguments_passed.should == [:hello, "world"] count.arguments_passed.should == [:hello, "world"]
end end
ruby_version_is ''...'2.7' do
it "returns a tainted array if self is tainted" do
EnumerableSpecs::Empty.new.taint.send(@method).tainted?.should be_true
end
it "returns an untrusted array if self is untrusted" do
EnumerableSpecs::Empty.new.untrust.send(@method).untrusted?.should be_true
end
end
end end

View file

@ -17,7 +17,8 @@ describe :enumerable_inject, shared: true do
end end
it "ignores the block if two arguments" do it "ignores the block if two arguments" do
EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-){ raise "we never get here"}.should == 4 EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-) { raise "we never get here"}.should == 4
[].send(@method, 3, :+) { raise "we never get here"}.should == 3
end end
it "can take a symbol argument" do it "can take a symbol argument" do

View file

@ -1,36 +1,34 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
ruby_version_is "2.7" do describe "Enumerable#tally" do
describe "Enumerable#tally" do before :each do
before :each do ScratchPad.record []
ScratchPad.record [] end
end
it "returns a hash with counts according to the value" do it "returns a hash with counts according to the value" do
enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
enum.tally.should == { 'foo' => 2, 'bar' => 1, 'baz' => 1} enum.tally.should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
end end
it "returns a hash without default" do it "returns a hash without default" do
hash = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz').tally hash = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz').tally
hash.default_proc.should be_nil hash.default_proc.should be_nil
hash.default.should be_nil hash.default.should be_nil
end end
it "returns an empty hash for empty enumerables" do it "returns an empty hash for empty enumerables" do
EnumerableSpecs::Empty.new.tally.should == {} EnumerableSpecs::Empty.new.tally.should == {}
end end
it "counts values as gathered array when yielded with multiple arguments" do it "counts values as gathered array when yielded with multiple arguments" do
EnumerableSpecs::YieldsMixed2.new.tally.should == EnumerableSpecs::YieldsMixed2.gathered_yields.group_by(&:itself).transform_values(&:size) EnumerableSpecs::YieldsMixed2.new.tally.should == EnumerableSpecs::YieldsMixed2.gathered_yields.group_by(&:itself).transform_values(&:size)
end end
it "does not call given block" do it "does not call given block" do
enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
enum.tally { |v| ScratchPad << v } enum.tally { |v| ScratchPad << v }
ScratchPad.recorded.should == [] ScratchPad.recorded.should == []
end
end end
end end

View file

@ -31,76 +31,32 @@ describe 'Enumerable#uniq' do
[x, y].to_enum.uniq.should == [x, y] [x, y].to_enum.uniq.should == [x, y]
end end
ruby_version_is '2.7' do it "compares elements with matching hash codes with #eql?" do
it "compares elements with matching hash codes with #eql?" do a = Array.new(2) do
a = Array.new(2) do obj = mock('0')
obj = mock('0') obj.should_receive(:hash).at_least(1).and_return(0)
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o) def obj.eql?(o)
false false
end
obj
end end
a.uniq.should == a obj
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
true
end
obj
end
a.to_enum.uniq.size.should == 1
end end
end
ruby_version_is ''...'2.7' do a.uniq.should == a
it "compares elements with matching hash codes with #eql?" do
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o) a = Array.new(2) do
# It's undefined whether the impl does a[0].eql?(a[1]) or obj = mock('0')
# a[1].eql?(a[0]) so we taint both. obj.should_receive(:hash).at_least(1).and_return(0)
taint
o.taint
false
end
obj def obj.eql?(o)
true
end end
a.uniq.should == a obj
a[0].should.tainted?
a[1].should.tainted?
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
# It's undefined whether the impl does a[0].eql?(a[1]) or
# a[1].eql?(a[0]) so we taint both.
taint
o.taint
true
end
obj
end
a.to_enum.uniq.size.should == 1
a[0].should.tainted?
a[1].should.tainted?
end end
a.to_enum.uniq.size.should == 1
end end
context 'when yielded with multiple arguments' do context 'when yielded with multiple arguments' do

View file

@ -7,12 +7,10 @@ describe "Enumerator::ArithmeticSequence#begin" do
(1...10).step.begin.should == 1 (1...10).step.begin.should == 1
end end
ruby_version_is "2.7" do context "with beginless" do
context "with beginless" do it "returns nil as begin of the sequence" do
it "returns nil as begin of the sequence" do (..10).step(1).begin.should == nil
eval("(..10).step(1)").begin.should == nil (...10).step(1).begin.should == nil
eval("(...10).step(1)").begin.should == nil
end
end end
end end
end end

View file

@ -1,29 +1,27 @@
require_relative '../../../spec_helper' require_relative '../../../spec_helper'
ruby_version_is "2.7" do describe "Enumerator::Lazy#eager" do
describe "Enumerator::Lazy#eager" do it "returns a non-lazy Enumerator converted from the lazy enumerator" do
it "returns a non-lazy Enumerator converted from the lazy enumerator" do enum = [1, 2, 3].lazy
enum = [1, 2, 3].lazy
enum.class.should == Enumerator::Lazy enum.class.should == Enumerator::Lazy
enum.eager.class.should == Enumerator enum.eager.class.should == Enumerator
end
it "does not enumerate an enumerator" do
ScratchPad.record []
sequence = [1, 2, 3]
enum_lazy = Enumerator::Lazy.new(sequence) do |yielder, value|
yielder << value
ScratchPad << value
end end
it "does not enumerate an enumerator" do ScratchPad.recorded.should == []
ScratchPad.record [] enum = enum_lazy.eager
ScratchPad.recorded.should == []
sequence = [1, 2, 3] enum.map { |i| i }.should == [1, 2, 3]
enum_lazy = Enumerator::Lazy.new(sequence) do |yielder, value| ScratchPad.recorded.should == [1, 2, 3]
yielder << value
ScratchPad << value
end
ScratchPad.recorded.should == []
enum = enum_lazy.eager
ScratchPad.recorded.should == []
enum.map { |i| i }.should == [1, 2, 3]
ScratchPad.recorded.should == [1, 2, 3]
end
end end
end end

View file

@ -3,14 +3,12 @@
require_relative '../../../spec_helper' require_relative '../../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
ruby_version_is "2.7" do describe "Enumerator::Lazy#filter_map" do
describe "Enumerator::Lazy#filter_map" do it "maps only truthy results" do
it "maps only truthy results" do (1..Float::INFINITY).lazy.filter_map { |i| i if i.odd? }.first(4).should == [1, 3, 5, 7]
(1..Float::INFINITY).lazy.filter_map { |i| i if i.odd? }.first(4).should == [1, 3, 5, 7] end
end
it "does not map false results" do it "does not map false results" do
(1..Float::INFINITY).lazy.filter_map { |i| i.odd? ? i : false }.first(4).should == [1, 3, 5, 7] (1..Float::INFINITY).lazy.filter_map { |i| i.odd? ? i : false }.first(4).should == [1, 3, 5, 7]
end
end end
end end

View file

@ -3,36 +3,34 @@
require_relative '../../../spec_helper' require_relative '../../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
ruby_version_is "2.7" do describe "Enumerator::Lazy#with_index" do
describe "Enumerator::Lazy#with_index" do it "enumerates with an index" do
it "enumerates with an index" do (0..Float::INFINITY).lazy.with_index.map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]]
(0..Float::INFINITY).lazy.with_index.map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]] end
end
it "enumerates with an index starting at a given offset" do it "enumerates with an index starting at a given offset" do
(0..Float::INFINITY).lazy.with_index(3).map { |i, idx| [i, idx] }.first(3).should == [[0, 3], [1, 4], [2, 5]] (0..Float::INFINITY).lazy.with_index(3).map { |i, idx| [i, idx] }.first(3).should == [[0, 3], [1, 4], [2, 5]]
end end
it "enumerates with an index starting at 0 when offset is nil" do it "enumerates with an index starting at 0 when offset is nil" do
(0..Float::INFINITY).lazy.with_index(nil).map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]] (0..Float::INFINITY).lazy.with_index(nil).map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]]
end end
it "raises TypeError when offset does not convert to Integer" do it "raises TypeError when offset does not convert to Integer" do
-> { (0..Float::INFINITY).lazy.with_index(false).map { |i, idx| i }.first(3) }.should raise_error(TypeError) -> { (0..Float::INFINITY).lazy.with_index(false).map { |i, idx| i }.first(3) }.should raise_error(TypeError)
end end
it "enumerates with a given block" do it "enumerates with a given block" do
result = [] result = []
(0..Float::INFINITY).lazy.with_index { |i, idx| result << [i * 2, idx] }.first(3) (0..Float::INFINITY).lazy.with_index { |i, idx| result << [i * 2, idx] }.first(3)
result.should == [[0,0],[2,1],[4,2]] result.should == [[0,0],[2,1],[4,2]]
end end
it "resets after a new call to each" do it "resets after a new call to each" do
enum = (0..2).lazy.with_index.map { |i, idx| [i, idx] } enum = (0..2).lazy.with_index.map { |i, idx| [i, idx] }
result = [] result = []
enum.each { |i, idx| result << [i, idx] } enum.each { |i, idx| result << [i, idx] }
enum.each { |i, idx| result << [i, idx] } enum.each { |i, idx| result << [i, idx] }
result.should == [[0,0], [1,1], [2,2], [0,0], [1,1], [2,2]] result.should == [[0,0], [1,1], [2,2], [0,0], [1,1], [2,2]]
end
end end
end end

View file

@ -77,14 +77,12 @@ describe "Enumerator.new" do
enum.take(3).should == [1, 2, 3] enum.take(3).should == [1, 2, 3]
end end
ruby_version_is "2.7" do it "defines iteration with block, yielder argument and treating it as a proc" do
it "defines iteration with block, yielder argument and treating it as a proc" do enum = Enumerator.new do |yielder|
enum = Enumerator.new do |yielder| "a\nb\nc".each_line(&yielder)
"a\nb\nc".each_line(&yielder)
end
enum.to_a.should == ["a\n", "b\n", "c"]
end end
enum.to_a.should == ["a\n", "b\n", "c"]
end end
describe 'yielded values' do describe 'yielded values' do

View file

@ -1,36 +1,34 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
ruby_version_is "2.7" do describe "Enumerator.produce" do
describe "Enumerator.produce" do it "creates an infinite enumerator" do
it "creates an infinite enumerator" do enum = Enumerator.produce(0) { |prev| prev + 1 }
enum = Enumerator.produce(0) { |prev| prev + 1 } enum.take(5).should == [0, 1, 2, 3, 4]
enum.take(5).should == [0, 1, 2, 3, 4] end
it "terminates iteration when block raises StopIteration exception" do
enum = Enumerator.produce(0) do | prev|
raise StopIteration if prev >= 2
prev + 1
end end
it "terminates iteration when block raises StopIteration exception" do enum.to_a.should == [0, 1, 2]
enum = Enumerator.produce(0) do | prev| end
raise StopIteration if prev >= 2
prev + 1
end
enum.to_a.should == [0, 1, 2] context "when initial value skipped" do
it "uses nil instead" do
ScratchPad.record []
enum = Enumerator.produce { |prev| ScratchPad << prev; (prev || 0) + 1 }
enum.take(3).should == [1, 2, 3]
ScratchPad.recorded.should == [nil, 1, 2]
end end
context "when initial value skipped" do it "starts enumerable from result of first block call" do
it "uses nil instead" do array = "a\nb\nc\nd".lines
ScratchPad.record [] lines = Enumerator.produce { array.shift }.take_while { |s| s }
enum = Enumerator.produce { |prev| ScratchPad << prev; (prev || 0) + 1 }
enum.take(3).should == [1, 2, 3] lines.should == ["a\n", "b\n", "c\n", "d"]
ScratchPad.recorded.should == [nil, 1, 2]
end
it "starts enumerable from result of first block call" do
array = "a\nb\nc\nd".lines
lines = Enumerator.produce { array.shift }.take_while { |s| s }
lines.should == ["a\n", "b\n", "c\n", "d"]
end
end end
end end
end end

View file

@ -1,18 +1,16 @@
require_relative '../../../spec_helper' require_relative '../../../spec_helper'
ruby_version_is "2.7" do describe "Enumerator::Yielder#to_proc" do
describe "Enumerator::Yielder#to_proc" do it "returns a Proc object that takes an argument and yields it to the block" do
it "returns a Proc object that takes an argument and yields it to the block" do ScratchPad.record []
ScratchPad.record [] y = Enumerator::Yielder.new { |*args| ScratchPad << args; "foobar" }
y = Enumerator::Yielder.new { |*args| ScratchPad << args; "foobar" }
callable = y.to_proc callable = y.to_proc
callable.class.should == Proc callable.class.should == Proc
result = callable.call(1, 2) result = callable.call(1, 2)
ScratchPad.recorded.should == [[1, 2]] ScratchPad.recorded.should == [[1, 2]]
result.should == "foobar" result.should == "foobar"
end
end end
end end

View file

@ -1,8 +1,6 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative 'shared/update' require_relative 'shared/update'
ruby_version_is "2.7" do describe "ENV.merge!" do
describe "ENV.merge!" do it_behaves_like :env_update, :merge!
it_behaves_like :env_update, :merge!
end
end end

View file

@ -39,23 +39,21 @@ describe :env_update, shared: true do
ENV["bar"].should == "5" ENV["bar"].should == "5"
end end
ruby_version_is "2.7" do # BUG: https://bugs.ruby-lang.org/issues/16192
# BUG: https://bugs.ruby-lang.org/issues/16192 it "does not evaluate the block when the name is new" do
it "does not evaluate the block when the name is new" do ENV.delete("bar")
ENV.delete("bar") ENV.send @method, {"foo" => "0"}
ENV.send @method, {"foo" => "0"} ENV.send(@method, "bar" => "1") { |key, old, new| fail "Should not get here" }
ENV.send(@method, "bar" => "1") { |key, old, new| fail "Should not get here" } ENV["bar"].should == "1"
ENV["bar"].should == "1" end
end
# BUG: https://bugs.ruby-lang.org/issues/16192 # BUG: https://bugs.ruby-lang.org/issues/16192
it "does not use the block's return value as the value when the name is new" do it "does not use the block's return value as the value when the name is new" do
ENV.delete("bar") ENV.delete("bar")
ENV.send @method, {"foo" => "0"} ENV.send @method, {"foo" => "0"}
ENV.send(@method, "bar" => "1") { |key, old, new| "Should not use this value" } ENV.send(@method, "bar" => "1") { |key, old, new| "Should not use this value" }
ENV["foo"].should == "0" ENV["foo"].should == "0"
ENV["bar"].should == "1" ENV["bar"].should == "1"
end
end end
it "returns ENV when block given" do it "returns ENV when block given" do

View file

@ -1,26 +1,22 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
describe "FrozenError.new" do describe "FrozenError.new" do
ruby_version_is "2.7" do it "should take optional receiver argument" do
it "should take optional receiver argument" do o = Object.new
o = Object.new FrozenError.new("msg", receiver: o).receiver.should equal(o)
FrozenError.new("msg", receiver: o).receiver.should equal(o)
end
end end
end end
describe "FrozenError#receiver" do describe "FrozenError#receiver" do
ruby_version_is "2.7" do it "should return frozen object that modification was attempted on" do
it "should return frozen object that modification was attempted on" do o = Object.new.freeze
o = Object.new.freeze begin
begin def o.x; end
def o.x; end rescue => e
rescue => e e.should be_kind_of(FrozenError)
e.should be_kind_of(FrozenError) e.receiver.should equal(o)
e.receiver.should equal(o) else
else raise
raise
end
end end
end end
end end

View file

@ -5,13 +5,11 @@ describe "FalseClass#to_s" do
false.to_s.should == "false" false.to_s.should == "false"
end end
ruby_version_is "2.7" do it "returns a frozen string" do
it "returns a frozen string" do false.to_s.should.frozen?
false.to_s.should.frozen? end
end
it "always returns the same string" do it "always returns the same string" do
false.to_s.should equal(false.to_s) false.to_s.should equal(false.to_s)
end
end end
end end

View file

@ -2,101 +2,99 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
require_relative '../../shared/kernel/raise' require_relative '../../shared/kernel/raise'
ruby_version_is "2.7" do describe "Fiber#raise" do
describe "Fiber#raise" do it_behaves_like :kernel_raise, :raise, FiberSpecs::NewFiberToRaise
it_behaves_like :kernel_raise, :raise, FiberSpecs::NewFiberToRaise
end
describe "Fiber#raise" do
it 'raises RuntimeError by default' do
-> { FiberSpecs::NewFiberToRaise.raise }.should raise_error(RuntimeError)
end
it "raises FiberError if Fiber is not born" do
fiber = Fiber.new { true }
-> { fiber.raise }.should raise_error(FiberError, "cannot raise exception on unborn fiber")
end
it "raises FiberError if Fiber is dead" do
fiber = Fiber.new { true }
fiber.resume
-> { fiber.raise }.should raise_error(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
end
it 'accepts error class' do
-> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError }.should raise_error(FiberSpecs::CustomError)
end
it 'accepts error message' do
-> { FiberSpecs::NewFiberToRaise.raise "error message" }.should raise_error(RuntimeError, "error message")
end
it 'does not accept array of backtrace information only' do
-> { FiberSpecs::NewFiberToRaise.raise ['foo'] }.should raise_error(TypeError)
end
it 'does not accept integer' do
-> { FiberSpecs::NewFiberToRaise.raise 100 }.should raise_error(TypeError)
end
it 'accepts error class with error message' do
-> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error' }.should raise_error(FiberSpecs::CustomError, 'test error')
end
it 'accepts error class with with error message and backtrace information' do
-> {
FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error', ['foo', 'boo']
}.should raise_error(FiberSpecs::CustomError) { |e|
e.message.should == 'test error'
e.backtrace.should == ['foo', 'boo']
}
end
it 'does not accept only error message and backtrace information' do
-> { FiberSpecs::NewFiberToRaise.raise 'test error', ['foo', 'boo'] }.should raise_error(TypeError)
end
it "raises a FiberError if invoked from a different Thread" do
fiber = Fiber.new { Fiber.yield }
fiber.resume
Thread.new do
-> {
fiber.raise
}.should raise_error(FiberError, "fiber called across threads")
end.join
end
it "kills Fiber" do
fiber = Fiber.new { Fiber.yield :first; :second }
fiber.resume
-> { fiber.raise }.should raise_error
-> { fiber.resume }.should raise_error(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
end
it "returns to calling fiber after raise" do
fiber_one = Fiber.new do
Fiber.yield :yield_one
:unreachable
end
fiber_two = Fiber.new do
results = []
results << fiber_one.resume
begin
fiber_one.raise
rescue
results << :rescued
end
results
end
fiber_two.resume.should == [:yield_one, :rescued]
end
end
end end
ruby_version_is "2.7"..."3.0" do describe "Fiber#raise" do
it 'raises RuntimeError by default' do
-> { FiberSpecs::NewFiberToRaise.raise }.should raise_error(RuntimeError)
end
it "raises FiberError if Fiber is not born" do
fiber = Fiber.new { true }
-> { fiber.raise }.should raise_error(FiberError, "cannot raise exception on unborn fiber")
end
it "raises FiberError if Fiber is dead" do
fiber = Fiber.new { true }
fiber.resume
-> { fiber.raise }.should raise_error(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
end
it 'accepts error class' do
-> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError }.should raise_error(FiberSpecs::CustomError)
end
it 'accepts error message' do
-> { FiberSpecs::NewFiberToRaise.raise "error message" }.should raise_error(RuntimeError, "error message")
end
it 'does not accept array of backtrace information only' do
-> { FiberSpecs::NewFiberToRaise.raise ['foo'] }.should raise_error(TypeError)
end
it 'does not accept integer' do
-> { FiberSpecs::NewFiberToRaise.raise 100 }.should raise_error(TypeError)
end
it 'accepts error class with error message' do
-> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error' }.should raise_error(FiberSpecs::CustomError, 'test error')
end
it 'accepts error class with with error message and backtrace information' do
-> {
FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error', ['foo', 'boo']
}.should raise_error(FiberSpecs::CustomError) { |e|
e.message.should == 'test error'
e.backtrace.should == ['foo', 'boo']
}
end
it 'does not accept only error message and backtrace information' do
-> { FiberSpecs::NewFiberToRaise.raise 'test error', ['foo', 'boo'] }.should raise_error(TypeError)
end
it "raises a FiberError if invoked from a different Thread" do
fiber = Fiber.new { Fiber.yield }
fiber.resume
Thread.new do
-> {
fiber.raise
}.should raise_error(FiberError, "fiber called across threads")
end.join
end
it "kills Fiber" do
fiber = Fiber.new { Fiber.yield :first; :second }
fiber.resume
-> { fiber.raise }.should raise_error
-> { fiber.resume }.should raise_error(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
end
it "returns to calling fiber after raise" do
fiber_one = Fiber.new do
Fiber.yield :yield_one
:unreachable
end
fiber_two = Fiber.new do
results = []
results << fiber_one.resume
begin
fiber_one.raise
rescue
results << :rescued
end
results
end
fiber_two.resume.should == [:yield_one, :rescued]
end
end
ruby_version_is ""..."3.0" do
describe "Fiber#raise" do describe "Fiber#raise" do
it "raises a FiberError if invoked on a transferring Fiber" do it "raises a FiberError if invoked on a transferring Fiber" do
require "fiber" require "fiber"

View file

@ -1,54 +1,52 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
ruby_version_is "2.7" do describe "File.absolute_path?" do
describe "File.absolute_path?" do before :each do
before :each do @abs = File.expand_path(__FILE__)
@abs = File.expand_path(__FILE__) end
it "returns true if it's an absolute pathname" do
File.absolute_path?(@abs).should be_true
end
it "returns false if it's a relative path" do
File.absolute_path?(File.basename(__FILE__)).should be_false
end
it "returns false if it's a tricky relative path" do
File.absolute_path?("C:foo\\bar").should be_false
end
it "does not expand '~' to a home directory." do
File.absolute_path?('~').should be_false
end
it "does not expand '~user' to a home directory." do
path = File.dirname(@abs)
Dir.chdir(path) do
File.absolute_path?('~user').should be_false
end end
end
it "returns true if it's an absolute pathname" do it "calls #to_path on its argument" do
File.absolute_path?(@abs).should be_true mock = mock_to_path(File.expand_path(__FILE__))
File.absolute_path?(mock).should be_true
end
platform_is_not :windows do
it "takes into consideration the platform's root" do
File.absolute_path?("C:\\foo\\bar").should be_false
File.absolute_path?("C:/foo/bar").should be_false
File.absolute_path?("/foo/bar\\baz").should be_true
end end
end
it "returns false if it's a relative path" do platform_is :windows do
File.absolute_path?(File.basename(__FILE__)).should be_false it "takes into consideration the platform path separator(s)" do
end File.absolute_path?("C:\\foo\\bar").should be_true
File.absolute_path?("C:/foo/bar").should be_true
it "returns false if it's a tricky relative path" do File.absolute_path?("/foo/bar\\baz").should be_false
File.absolute_path?("C:foo\\bar").should be_false
end
it "does not expand '~' to a home directory." do
File.absolute_path?('~').should be_false
end
it "does not expand '~user' to a home directory." do
path = File.dirname(@abs)
Dir.chdir(path) do
File.absolute_path?('~user').should be_false
end
end
it "calls #to_path on its argument" do
mock = mock_to_path(File.expand_path(__FILE__))
File.absolute_path?(mock).should be_true
end
platform_is_not :windows do
it "takes into consideration the platform's root" do
File.absolute_path?("C:\\foo\\bar").should be_false
File.absolute_path?("C:/foo/bar").should be_false
File.absolute_path?("/foo/bar\\baz").should be_true
end
end
platform_is :windows do
it "takes into consideration the platform path separator(s)" do
File.absolute_path?("C:\\foo\\bar").should be_true
File.absolute_path?("C:/foo/bar").should be_true
File.absolute_path?("/foo/bar\\baz").should be_false
end
end end
end end
end end

View file

@ -33,14 +33,14 @@ describe "File.extname" do
end end
describe "for a filename ending with a dot" do describe "for a filename ending with a dot" do
guard -> { platform_is :windows or ruby_version_is ""..."2.7" } do platform_is :windows do
it "returns ''" do it "returns ''" do
File.extname(".foo.").should == "" File.extname(".foo.").should == ""
File.extname("foo.").should == "" File.extname("foo.").should == ""
end end
end end
guard -> { platform_is_not :windows and ruby_version_is "2.7" } do platform_is_not :windows do
it "returns '.'" do it "returns '.'" do
File.extname(".foo.").should == "." File.extname(".foo.").should == "."
File.extname("foo.").should == "." File.extname("foo.").should == "."

View file

@ -42,26 +42,13 @@ describe "Hash.[]" do
Hash[ary].should == { a: :b } Hash[ary].should == { a: :b }
end end
ruby_version_is "" ... "2.7" do it "raises for elements that are not arrays" do
it "ignores elements that are not arrays" do -> {
-> { Hash[[:a]].should == {}
Hash[[:a]].should == {} }.should raise_error(ArgumentError)
}.should complain(/ignoring wrong elements/) -> {
-> { Hash[[:nil]].should == {}
Hash[[:nil]].should == {} }.should raise_error(ArgumentError)
}.should complain(/ignoring wrong elements/)
end
end
ruby_version_is "2.7" do
it "raises for elements that are not arrays" do
-> {
Hash[[:a]].should == {}
}.should raise_error(ArgumentError)
-> {
Hash[[:nil]].should == {}
}.should raise_error(ArgumentError)
end
end end
it "raises an ArgumentError for arrays of more than 2 elements" do it "raises an ArgumentError for arrays of more than 2 elements" do

View file

@ -1,25 +1,23 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
ruby_version_is "2.7" do describe "Hash#deconstruct_keys" do
describe "Hash#deconstruct_keys" do it "returns self" do
it "returns self" do hash = {a: 1, b: 2}
hash = {a: 1, b: 2}
hash.deconstruct_keys([:a, :b]).should equal hash hash.deconstruct_keys([:a, :b]).should equal hash
end end
it "requires one argument" do it "requires one argument" do
-> { -> {
{a: 1}.deconstruct_keys {a: 1}.deconstruct_keys
}.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/) }.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
end end
it "ignores argument" do it "ignores argument" do
hash = {a: 1, b: 2} hash = {a: 1, b: 2}
hash.deconstruct_keys([:a]).should == {a: 1, b: 2} hash.deconstruct_keys([:a]).should == {a: 1, b: 2}
hash.deconstruct_keys(0 ).should == {a: 1, b: 2} hash.deconstruct_keys(0 ).should == {a: 1, b: 2}
hash.deconstruct_keys('' ).should == {a: 1, b: 2} hash.deconstruct_keys('' ).should == {a: 1, b: 2}
end
end end
end end

View file

@ -31,13 +31,6 @@ describe "Hash#reject" do
HashSpecs::MyHash[1 => 2, 3 => 4].reject { false }.should be_kind_of(Hash) HashSpecs::MyHash[1 => 2, 3 => 4].reject { false }.should be_kind_of(Hash)
HashSpecs::MyHash[1 => 2, 3 => 4].reject { true }.should be_kind_of(Hash) HashSpecs::MyHash[1 => 2, 3 => 4].reject { true }.should be_kind_of(Hash)
end end
ruby_version_is ''...'2.7' do
it "does not taint the resulting hash" do
h = { a: 1 }.taint
h.reject {false}.should_not.tainted?
end
end
end end
it "processes entries with the same order as reject!" do it "processes entries with the same order as reject!" do

View file

@ -1,61 +1,59 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
ruby_version_is "2.7" do describe "Hash.ruby2_keywords_hash?" do
describe "Hash.ruby2_keywords_hash?" do it "returns false if the Hash is not a keywords Hash" do
it "returns false if the Hash is not a keywords Hash" do Hash.ruby2_keywords_hash?({}).should == false
Hash.ruby2_keywords_hash?({}).should == false
end
it "returns true if the Hash is a keywords Hash marked by Module#ruby2_keywords" do
obj = Class.new {
ruby2_keywords def m(*args)
args.last
end
}.new
Hash.ruby2_keywords_hash?(obj.m(a: 1)).should == true
end
it "raises TypeError for non-Hash" do
-> { Hash.ruby2_keywords_hash?(nil) }.should raise_error(TypeError)
end
end end
describe "Hash.ruby2_keywords_hash" do it "returns true if the Hash is a keywords Hash marked by Module#ruby2_keywords" do
it "returns a copy of a Hash and marks the copy as a keywords Hash" do obj = Class.new {
h = {a: 1}.freeze ruby2_keywords def m(*args)
kw = Hash.ruby2_keywords_hash(h) args.last
Hash.ruby2_keywords_hash?(h).should == false end
Hash.ruby2_keywords_hash?(kw).should == true }.new
kw.should == h Hash.ruby2_keywords_hash?(obj.m(a: 1)).should == true
end end
it "returns an instance of the subclass if called on an instance of a subclass of Hash" do it "raises TypeError for non-Hash" do
h = HashSpecs::MyHash.new -> { Hash.ruby2_keywords_hash?(nil) }.should raise_error(TypeError)
h[:a] = 1 end
kw = Hash.ruby2_keywords_hash(h) end
kw.class.should == HashSpecs::MyHash
Hash.ruby2_keywords_hash?(h).should == false describe "Hash.ruby2_keywords_hash" do
Hash.ruby2_keywords_hash?(kw).should == true it "returns a copy of a Hash and marks the copy as a keywords Hash" do
kw.should == h h = {a: 1}.freeze
end kw = Hash.ruby2_keywords_hash(h)
Hash.ruby2_keywords_hash?(h).should == false
it "copies instance variables" do Hash.ruby2_keywords_hash?(kw).should == true
h = {a: 1} kw.should == h
h.instance_variable_set(:@foo, 42) end
kw = Hash.ruby2_keywords_hash(h)
kw.instance_variable_get(:@foo).should == 42 it "returns an instance of the subclass if called on an instance of a subclass of Hash" do
end h = HashSpecs::MyHash.new
h[:a] = 1
it "copies the hash internals" do kw = Hash.ruby2_keywords_hash(h)
h = {a: 1} kw.class.should == HashSpecs::MyHash
kw = Hash.ruby2_keywords_hash(h) Hash.ruby2_keywords_hash?(h).should == false
h[:a] = 2 Hash.ruby2_keywords_hash?(kw).should == true
kw[:a].should == 1 kw.should == h
end end
it "raises TypeError for non-Hash" do it "copies instance variables" do
-> { Hash.ruby2_keywords_hash(nil) }.should raise_error(TypeError) h = {a: 1}
end h.instance_variable_set(:@foo, 42)
kw = Hash.ruby2_keywords_hash(h)
kw.instance_variable_get(:@foo).should == 42
end
it "copies the hash internals" do
h = {a: 1}
kw = Hash.ruby2_keywords_hash(h)
h[:a] = 2
kw[:a].should == 1
end
it "raises TypeError for non-Hash" do
-> { Hash.ruby2_keywords_hash(nil) }.should raise_error(TypeError)
end end
end end

View file

@ -149,80 +149,34 @@ describe :hash_eql_additional, shared: true do
h.send(@method, HashSpecs::MyHash[h]).should be_true h.send(@method, HashSpecs::MyHash[h]).should be_true
end end
ruby_version_is '2.7' do # Why isn't this true of eql? too ?
# Why isn't this true of eql? too ? it "compares keys with matching hash codes via eql?" do
it "compares keys with matching hash codes via eql?" do a = Array.new(2) do
a = Array.new(2) do obj = mock('0')
obj = mock('0') obj.should_receive(:hash).at_least(1).and_return(0)
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o) def obj.eql?(o)
return true if self.equal?(o) return true if self.equal?(o)
false false
end
obj
end end
{ a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false obj
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
true
end
obj
end
{ a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true
end end
end
ruby_version_is ''...'2.7' do { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false
# Why isn't this true of eql? too ?
it "compares keys with matching hash codes via eql?" do
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
# It's undefined whether the impl does a[0].eql?(a[1]) or a = Array.new(2) do
# a[1].eql?(a[0]) so we taint both. obj = mock('0')
def obj.eql?(o) obj.should_receive(:hash).at_least(1).and_return(0)
return true if self.equal?(o)
taint
o.taint
false
end
obj def obj.eql?(o)
true
end end
{ a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false obj
a[0].tainted?.should be_true
a[1].tainted?.should be_true
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
# It's undefined whether the impl does a[0].send(@method, a[1]) or
# a[1].send(@method, a[0]) so we taint both.
taint
o.taint
true
end
obj
end
{ a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true
a[0].tainted?.should be_true
a[1].tainted?.should be_true
end end
{ a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true
end end
it "compares the values in self to values in other hash" do it "compares the values in self to values in other hash" do

View file

@ -76,18 +76,6 @@ describe :hash_to_s, shared: true do
y.send(@method).should == "{1=>{0=>{...}}}" y.send(@method).should == "{1=>{0=>{...}}}"
end end
ruby_version_is ''...'2.7' do
it "returns a tainted string if self is tainted and not empty" do
{}.taint.send(@method).tainted?.should be_false
{ nil => nil }.taint.send(@method).tainted?.should be_true
end
it "returns an untrusted string if self is untrusted and not empty" do
{}.untrust.send(@method).untrusted?.should be_false
{ nil => nil }.untrust.send(@method).untrusted?.should be_true
end
end
it "does not raise if inspected result is not default external encoding" do it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be") utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))

View file

@ -27,17 +27,7 @@ describe "Hash#to_a" do
ent.should == pairs ent.should == pairs
end end
ruby_version_is ''...'2.7' do ruby_version_is ''...'3.0' do
it "returns a tainted array if self is tainted" do
{}.taint.to_a.tainted?.should be_true
end
it "returns an untrusted array if self is untrusted" do
{}.untrust.to_a.untrusted?.should be_true
end
end
ruby_version_is '2.7'...'3.0' do
it "returns a not tainted array if self is tainted" do it "returns a not tainted array if self is tainted" do
{}.taint.to_a.tainted?.should be_false {}.taint.to_a.tainted?.should be_false
end end

View file

@ -245,16 +245,14 @@ describe "Integer#chr with an encoding argument" do
end end
end end
ruby_version_is "2.7" do it 'returns a String encoding self interpreted as a codepoint in the CESU-8 encoding' do
it 'returns a String encoding self interpreted as a codepoint in the CESU-8 encoding' do # see more details here https://en.wikipedia.org/wiki/CESU-8
# see more details here https://en.wikipedia.org/wiki/CESU-8 # code points from U+0000 to U+FFFF is encoded in the same way as in UTF-8
# code points from U+0000 to U+FFFF is encoded in the same way as in UTF-8 0x0045.chr(Encoding::CESU_8).bytes.should == 0x0045.chr(Encoding::UTF_8).bytes
0x0045.chr(Encoding::CESU_8).bytes.should == 0x0045.chr(Encoding::UTF_8).bytes
# code points in range from U+10000 to U+10FFFF is CESU-8 data containing a 6-byte surrogate pair, # code points in range from U+10000 to U+10FFFF is CESU-8 data containing a 6-byte surrogate pair,
# which decodes to a 4-byte UTF-8 string # which decodes to a 4-byte UTF-8 string
0x10400.chr(Encoding::CESU_8).bytes.should != 0x10400.chr(Encoding::UTF_8).bytes 0x10400.chr(Encoding::CESU_8).bytes.should != 0x10400.chr(Encoding::UTF_8).bytes
0x10400.chr(Encoding::CESU_8).bytes.to_a.should == [0xED, 0xA0, 0x81, 0xED, 0xB0, 0x80] 0x10400.chr(Encoding::CESU_8).bytes.to_a.should == [0xED, 0xA0, 0x81, 0xED, 0xB0, 0x80]
end
end end
end end

View file

@ -79,81 +79,79 @@ describe "Integer#[]" do
3[bignum_value.to_f].should == 0 3[bignum_value.to_f].should == 0
end end
ruby_version_is "2.7" do context "when index and length passed" do
context "when index and length passed" do it "returns specified number of bits from specified position" do
it "returns specified number of bits from specified position" do 0b101001101[2, 4].should == 0b0011
0b101001101[2, 4].should == 0b0011 0b101001101[2, 5].should == 0b10011
0b101001101[2, 5].should == 0b10011 0b101001101[2, 7].should == 0b1010011
0b101001101[2, 7].should == 0b1010011
end
it "ensures n[i, len] equals to (n >> i) & ((1 << len) - 1)" do
n = 0b101001101; i = 2; len = 4
n[i, len].should == (n >> i) & ((1 << len) - 1)
end
it "moves start position to the most significant bits when negative index passed" do
0b000001[-1, 4].should == 0b10
0b000001[-2, 4].should == 0b100
0b000001[-3, 4].should == 0b1000
end
it "ignores negative length" do
0b101001101[1, -1].should == 0b10100110
0b101001101[2, -1].should == 0b1010011
0b101001101[3, -1].should == 0b101001
0b101001101[3, -5].should == 0b101001
0b101001101[3, -15].should == 0b101001
0b101001101[3, -125].should == 0b101001
end
end end
context "when range passed" do it "ensures n[i, len] equals to (n >> i) & ((1 << len) - 1)" do
it "returns bits specified by range" do n = 0b101001101; i = 2; len = 4
0b101001101[2..5].should == 0b0011 n[i, len].should == (n >> i) & ((1 << len) - 1)
0b101001101[2..6].should == 0b10011 end
0b101001101[2..8].should == 0b1010011
it "moves start position to the most significant bits when negative index passed" do
0b000001[-1, 4].should == 0b10
0b000001[-2, 4].should == 0b100
0b000001[-3, 4].should == 0b1000
end
it "ignores negative length" do
0b101001101[1, -1].should == 0b10100110
0b101001101[2, -1].should == 0b1010011
0b101001101[3, -1].should == 0b101001
0b101001101[3, -5].should == 0b101001
0b101001101[3, -15].should == 0b101001
0b101001101[3, -125].should == 0b101001
end
end
context "when range passed" do
it "returns bits specified by range" do
0b101001101[2..5].should == 0b0011
0b101001101[2..6].should == 0b10011
0b101001101[2..8].should == 0b1010011
end
it "ensures n[i..j] equals to (n >> i) & ((1 << (j - i + 1)) - 1)" do
n = 0b101001101; i = 2; j = 5
n[i..j].should == (n >> i) & ((1 << (j - i + 1)) - 1)
end
it "ensures n[i..] equals to (n >> i)" do
eval("0b101001101[3..]").should == 0b101001101 >> 3
end
it "moves lower boundary to the most significant bits when negative value passed" do
0b000001[-1, 4].should == 0b10
0b000001[-2, 4].should == 0b100
0b000001[-3, 4].should == 0b1000
end
it "ignores upper boundary smaller than lower boundary" do
0b101001101[4..1].should == 0b10100
0b101001101[4..2].should == 0b10100
0b101001101[-4..-5].should == 0b1010011010000
end
it "raises FloatDomainError if any boundary is infinity" do
-> { 0x0001[3..Float::INFINITY] }.should raise_error(FloatDomainError, /Infinity/)
-> { 0x0001[-Float::INFINITY..3] }.should raise_error(FloatDomainError, /-Infinity/)
end
context "when passed (..i)" do
it "returns 0 if all i bits equal 0" do
eval("0b10000[..1]").should == 0
eval("0b10000[..2]").should == 0
eval("0b10000[..3]").should == 0
end end
it "ensures n[i..j] equals to (n >> i) & ((1 << (j - i + 1)) - 1)" do it "raises ArgumentError if any of i bit equals 1" do
n = 0b101001101; i = 2; j = 5 -> {
n[i..j].should == (n >> i) & ((1 << (j - i + 1)) - 1) eval("0b111110[..3]")
end }.should raise_error(ArgumentError, /The beginless range for Integer#\[\] results in infinity/)
it "ensures n[i..] equals to (n >> i)" do
eval("0b101001101[3..]").should == 0b101001101 >> 3
end
it "moves lower boundary to the most significant bits when negative value passed" do
0b000001[-1, 4].should == 0b10
0b000001[-2, 4].should == 0b100
0b000001[-3, 4].should == 0b1000
end
it "ignores upper boundary smaller than lower boundary" do
0b101001101[4..1].should == 0b10100
0b101001101[4..2].should == 0b10100
0b101001101[-4..-5].should == 0b1010011010000
end
it "raises FloatDomainError if any boundary is infinity" do
-> { 0x0001[3..Float::INFINITY] }.should raise_error(FloatDomainError, /Infinity/)
-> { 0x0001[-Float::INFINITY..3] }.should raise_error(FloatDomainError, /-Infinity/)
end
context "when passed (..i)" do
it "returns 0 if all i bits equal 0" do
eval("0b10000[..1]").should == 0
eval("0b10000[..2]").should == 0
eval("0b10000[..3]").should == 0
end
it "raises ArgumentError if any of i bit equals 1" do
-> {
eval("0b111110[..3]")
}.should raise_error(ArgumentError, /The beginless range for Integer#\[\] results in infinity/)
end
end end
end end
end end

View file

@ -9,6 +9,52 @@ describe "Integer#fdiv" do
8.fdiv(bignum_value).should be_close(8.673617379884035e-19, TOLERANCE) 8.fdiv(bignum_value).should be_close(8.673617379884035e-19, TOLERANCE)
end end
it "performs floating-point division between self bignum and a bignum" do
num = 1000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146009
den = 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
num.fdiv(den).should == 500.0
end
it "rounds to the correct value for bignums" do
den = 9 * 10**342
num = 1 * 10**344
num.fdiv(den).should == 11.11111111111111
num = 1 * 10**343
num.fdiv(den).should == 1.1111111111111112
num = 1 * 10**342
num.fdiv(den).should == 0.1111111111111111
num = 2 * 10**342
num.fdiv(den).should == 0.2222222222222222
num = 3 * 10**342
num.fdiv(den).should == 0.3333333333333333
num = 4 * 10**342
num.fdiv(den).should == 0.4444444444444444
num = 5 * 10**342
num.fdiv(den).should == 0.5555555555555556
num = 6 * 10**342
num.fdiv(den).should == 0.6666666666666666
num = 7 * 10**342
num.fdiv(den).should == 0.7777777777777778
num = 8 * 10**342
num.fdiv(den).should == 0.8888888888888888
num = 9 * 10**342
num.fdiv(den).should == 1.0
num = -5 * 10**342
num.fdiv(den).should == -0.5555555555555556
end
it "performs floating-point division between self and a Float" do it "performs floating-point division between self and a Float" do
8.fdiv(9.0).should be_close(0.888888888888889, TOLERANCE) 8.fdiv(9.0).should be_close(0.888888888888889, TOLERANCE)
end end

View file

@ -38,14 +38,6 @@ describe "IO#gets" do
IOSpecs.lines.each { |line| line.should == @io.gets } IOSpecs.lines.each { |line| line.should == @io.gets }
end end
ruby_version_is ''...'2.7' do
it "returns tainted strings" do
while line = @io.gets
line.should.tainted?
end
end
end
it "updates lineno with each invocation" do it "updates lineno with each invocation" do
while @io.gets while @io.gets
@io.lineno.should == @count += 1 @io.lineno.should == @count += 1
@ -64,14 +56,6 @@ describe "IO#gets" do
@io.gets(nil).should == IOSpecs.lines.join("") @io.gets(nil).should == IOSpecs.lines.join("")
end end
ruby_version_is ''...'2.7' do
it "returns tainted strings" do
while line = @io.gets(nil)
line.should.tainted?
end
end
end
it "updates lineno with each invocation" do it "updates lineno with each invocation" do
while @io.gets(nil) while @io.gets(nil)
@io.lineno.should == @count += 1 @io.lineno.should == @count += 1
@ -100,14 +84,6 @@ describe "IO#gets" do
@io.gets.should == IOSpecs.lines[4] @io.gets.should == IOSpecs.lines[4]
end end
ruby_version_is ''...'2.7' do
it "returns tainted strings" do
while line = @io.gets("")
line.should.tainted?
end
end
end
it "updates lineno with each invocation" do it "updates lineno with each invocation" do
while @io.gets("") while @io.gets("")
@io.lineno.should == @count += 1 @io.lineno.should == @count += 1
@ -126,14 +102,6 @@ describe "IO#gets" do
@io.gets("la linea").should == "Voici la ligne une.\nQui \303\250 la linea" @io.gets("la linea").should == "Voici la ligne une.\nQui \303\250 la linea"
end end
ruby_version_is ''...'2.7' do
it "returns tainted strings" do
while line = @io.gets("la")
line.should.tainted?
end
end
end
it "updates lineno with each invocation" do it "updates lineno with each invocation" do
while (@io.gets("la")) while (@io.gets("la"))
@io.lineno.should == @count += 1 @io.lineno.should == @count += 1

View file

@ -12,66 +12,64 @@ describe "IO#set_encoding_by_bom" do
rm_r @name rm_r @name
end end
ruby_version_is "2.7" do it "returns the result encoding if found BOM UTF-8 sequence" do
it "returns the result encoding if found BOM UTF-8 sequence" do File.binwrite(@name, "\u{FEFF}abc")
File.binwrite(@name, "\u{FEFF}abc")
@io.set_encoding_by_bom.should == Encoding::UTF_8 @io.set_encoding_by_bom.should == Encoding::UTF_8
@io.external_encoding.should == Encoding::UTF_8 @io.external_encoding.should == Encoding::UTF_8
end end
it "returns the result encoding if found BOM UTF_16LE sequence" do it "returns the result encoding if found BOM UTF_16LE sequence" do
File.binwrite(@name, "\xFF\xFEabc") File.binwrite(@name, "\xFF\xFEabc")
@io.set_encoding_by_bom.should == Encoding::UTF_16LE @io.set_encoding_by_bom.should == Encoding::UTF_16LE
@io.external_encoding.should == Encoding::UTF_16LE @io.external_encoding.should == Encoding::UTF_16LE
end end
it "returns the result encoding if found BOM UTF_16BE sequence" do it "returns the result encoding if found BOM UTF_16BE sequence" do
File.binwrite(@name, "\xFE\xFFabc") File.binwrite(@name, "\xFE\xFFabc")
@io.set_encoding_by_bom.should == Encoding::UTF_16BE @io.set_encoding_by_bom.should == Encoding::UTF_16BE
@io.external_encoding.should == Encoding::UTF_16BE @io.external_encoding.should == Encoding::UTF_16BE
end end
it "returns the result encoding if found BOM UTF_32LE sequence" do it "returns the result encoding if found BOM UTF_32LE sequence" do
File.binwrite(@name, "\xFF\xFE\x00\x00abc") File.binwrite(@name, "\xFF\xFE\x00\x00abc")
@io.set_encoding_by_bom.should == Encoding::UTF_32LE @io.set_encoding_by_bom.should == Encoding::UTF_32LE
@io.external_encoding.should == Encoding::UTF_32LE @io.external_encoding.should == Encoding::UTF_32LE
end end
it "returns the result encoding if found BOM UTF_32BE sequence" do it "returns the result encoding if found BOM UTF_32BE sequence" do
File.binwrite(@name, "\x00\x00\xFE\xFFabc") File.binwrite(@name, "\x00\x00\xFE\xFFabc")
@io.set_encoding_by_bom.should == Encoding::UTF_32BE @io.set_encoding_by_bom.should == Encoding::UTF_32BE
@io.external_encoding.should == Encoding::UTF_32BE @io.external_encoding.should == Encoding::UTF_32BE
end end
it "returns nil if found BOM sequence not provided" do it "returns nil if found BOM sequence not provided" do
File.write(@name, "abc") File.write(@name, "abc")
@io.set_encoding_by_bom.should == nil @io.set_encoding_by_bom.should == nil
end end
it 'returns exception if io not in binary mode' do it 'returns exception if io not in binary mode' do
not_binary_io = new_io(@name, 'r') not_binary_io = new_io(@name, 'r')
-> { not_binary_io.set_encoding_by_bom }.should raise_error(ArgumentError, 'ASCII incompatible encoding needs binmode') -> { not_binary_io.set_encoding_by_bom }.should raise_error(ArgumentError, 'ASCII incompatible encoding needs binmode')
ensure ensure
not_binary_io.close not_binary_io.close
end end
it 'returns exception if encoding already set' do it 'returns exception if encoding already set' do
@io.set_encoding("utf-8") @io.set_encoding("utf-8")
-> { @io.set_encoding_by_bom }.should raise_error(ArgumentError, 'encoding is set to UTF-8 already') -> { @io.set_encoding_by_bom }.should raise_error(ArgumentError, 'encoding is set to UTF-8 already')
end end
it 'returns exception if encoding conversion is already set' do it 'returns exception if encoding conversion is already set' do
@io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE) @io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
-> { @io.set_encoding_by_bom }.should raise_error(ArgumentError, 'encoding conversion is set') -> { @io.set_encoding_by_bom }.should raise_error(ArgumentError, 'encoding conversion is set')
end
end end
end end

View file

@ -36,20 +36,10 @@ describe "IO#ungetbyte" do
@io.getbyte.should == 97 @io.getbyte.should == 97
end end
ruby_version_is ''...'2.6.1' do it "never raises RangeError" do
it "is an RangeError if the integer is not in 8bit" do for i in [4095, 0x4f7574206f6620636861722072616e67ff] do
for i in [4095, 0x4f7574206f6620636861722072616e6765] do @io.ungetbyte(i).should be_nil
-> { @io.ungetbyte(i) }.should raise_error(RangeError) @io.getbyte.should == 255
end
end
end
ruby_version_is '2.6.1' do
it "never raises RangeError" do
for i in [4095, 0x4f7574206f6620636861722072616e67ff] do
@io.ungetbyte(i).should be_nil
@io.getbyte.should == 255
end
end end
end end

View file

@ -34,12 +34,10 @@ describe 'Kernel#caller_locations' do
locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s) locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
end end
ruby_version_is "2.7" do it "works with beginless ranges" do
it "works with beginless ranges" do locations1 = caller_locations(0)
locations1 = caller_locations(0) locations2 = caller_locations((...5))
locations2 = caller_locations(eval("(...5)")) locations2.map(&:to_s)[eval("(2..)")].should == locations1[(...5)].map(&:to_s)[eval("(2..)")]
locations2.map(&:to_s)[eval("(2..)")].should == locations1[eval("(...5)")].map(&:to_s)[eval("(2..)")]
end
end end
it "can be called with a range whose end is negative" do it "can be called with a range whose end is negative" do

View file

@ -50,12 +50,10 @@ describe 'Kernel#caller' do
locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s) locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
end end
ruby_version_is "2.7" do it "works with beginless ranges" do
it "works with beginless ranges" do locations1 = KernelSpecs::CallerTest.locations(0)
locations1 = KernelSpecs::CallerTest.locations(0) locations2 = KernelSpecs::CallerTest.locations((..5))
locations2 = KernelSpecs::CallerTest.locations(eval("(..5)")) locations2.map(&:to_s)[eval("(2..)")].should == locations1[(..5)].map(&:to_s)[eval("(2..)")]
locations2.map(&:to_s)[eval("(2..)")].should == locations1[eval("(..5)")].map(&:to_s)[eval("(2..)")]
end
end end
guard -> { Kernel.instance_method(:tap).source_location } do guard -> { Kernel.instance_method(:tap).source_location } do

View file

@ -206,11 +206,4 @@ describe "Kernel#clone" do
cloned.bar.should == ['a'] cloned.bar.should == ['a']
end end
ruby_version_is ''...'2.7' do
it 'copies tainted?' do
o = ''.taint.clone
o.tainted?.should be_true
end
end
end end

View file

@ -6,16 +6,6 @@ describe "Kernel#inspect" do
Object.new.inspect.should be_an_instance_of(String) Object.new.inspect.should be_an_instance_of(String)
end end
ruby_version_is ''...'2.7' do
it "returns a tainted string if self is tainted" do
Object.new.taint.inspect.tainted?.should be_true
end
it "returns an untrusted string if self is untrusted" do
Object.new.untrust.inspect.untrusted?.should be_true
end
end
it "does not call #to_s if it is defined" do it "does not call #to_s if it is defined" do
# We must use a bare Object here # We must use a bare Object here
obj = Object.new obj = Object.new

View file

@ -34,4 +34,28 @@ describe "Kernel#method" do
m.should be_an_instance_of(Method) m.should be_an_instance_of(Method)
m.call(1, 2, 3).should == "Done handled_privately([1, 2, 3])" m.call(1, 2, 3).should == "Done handled_privately([1, 2, 3])"
end end
it "can call a #method_missing accepting zero or one arguments" do
cls = Class.new do
def respond_to_missing?(name, *)
name == :foo or super
end
def method_missing
:no_args
end
end
m = cls.new.method(:foo)
-> { m.call }.should raise_error(ArgumentError)
cls = Class.new do
def respond_to_missing?(name, *)
name == :bar or super
end
def method_missing(m)
m
end
end
m = cls.new.method(:bar)
m.call.should == :bar
end
end end

View file

@ -40,15 +40,7 @@ describe "Kernel#proc" do
proc proc
end end
ruby_version_is ""..."2.7" do ruby_version_is ""..."3.0" do
it "uses the implicit block from an enclosing method" do
prc = some_method { "hello" }
prc.call.should == "hello"
end
end
ruby_version_is "2.7"..."3.0" do
it "can be created when called with no block" do it "can be created when called with no block" do
-> { -> {
some_method { "hello" } some_method { "hello" }

View file

@ -52,18 +52,6 @@ describe :kernel_dup_clone, shared: true do
o2.original.should equal(o) o2.original.should equal(o)
end end
ruby_version_is ''...'2.7' do
it "preserves tainted state from the original" do
o = ObjectSpecDupInitCopy.new
o2 = o.send(@method)
o.taint
o3 = o.send(@method)
o2.should_not.tainted?
o3.should.tainted?
end
end
it "does not preserve the object_id" do it "does not preserve the object_id" do
o1 = ObjectSpecDupInitCopy.new o1 = ObjectSpecDupInitCopy.new
old_object_id = o1.object_id old_object_id = o1.object_id
@ -71,18 +59,6 @@ describe :kernel_dup_clone, shared: true do
o2.object_id.should_not == old_object_id o2.object_id.should_not == old_object_id
end end
ruby_version_is ''...'2.7' do
it "preserves untrusted state from the original" do
o = ObjectSpecDupInitCopy.new
o2 = o.send(@method)
o.untrust
o3 = o.send(@method)
o2.should_not.untrusted?
o3.should.untrusted?
end
end
it "returns nil for NilClass" do it "returns nil for NilClass" do
nil.send(@method).should == nil nil.send(@method).should == nil
end end

View file

@ -251,7 +251,7 @@ describe :kernel_require, shared: true do
ScratchPad.recorded.should == [:loaded] ScratchPad.recorded.should == [:loaded]
end end
ruby_bug "#16926", "2.7"..."3.0" do ruby_bug "#16926", ""..."3.0" do
it "does not load a feature twice when $LOAD_PATH has been modified" do it "does not load a feature twice when $LOAD_PATH has been modified" do
$LOAD_PATH.replace [CODE_LOADING_DIR] $LOAD_PATH.replace [CODE_LOADING_DIR]
@object.require("load_fixture").should be_true @object.require("load_fixture").should be_true
@ -547,9 +547,7 @@ describe :kernel_require, shared: true do
end end
provided = %w[complex enumerator rational thread] provided = %w[complex enumerator rational thread]
ruby_version_is "2.7" do provided << 'ruby2_keywords'
provided << 'ruby2_keywords'
end
it "#{provided.join(', ')} are already required" do it "#{provided.join(', ')} are already required" do
features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems') features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')

View file

@ -2,50 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
describe "Kernel#taint" do describe "Kernel#taint" do
ruby_version_is ''...'2.7' do ruby_version_is ""..."3.0" do
it "returns self" do
o = Object.new
o.taint.should equal(o)
end
it "sets the tainted bit" do
o = Object.new
o.taint
o.should.tainted?
end
it "raises FrozenError on an untainted, frozen object" do
o = Object.new.freeze
-> { o.taint }.should raise_error(FrozenError)
end
it "does not raise an error on a tainted, frozen object" do
o = Object.new.taint.freeze
o.taint.should equal(o)
end
it "has no effect on immediate values" do
[nil, true, false].each do |v|
v.taint
v.should_not.tainted?
end
end
it "no raises a RuntimeError on symbols" do
v = :sym
-> { v.taint }.should_not raise_error(RuntimeError)
v.should_not.tainted?
end
it "no raises error on integer values" do
[1].each do |v|
-> { v.taint }.should_not raise_error(RuntimeError)
v.should_not.tainted?
end
end
end
ruby_version_is "2.7"..."3.0" do
it "is a no-op" do it "is a no-op" do
o = Object.new o = Object.new
o.taint o.taint

View file

@ -2,17 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
describe "Kernel#tainted?" do describe "Kernel#tainted?" do
ruby_version_is ''...'2.7' do ruby_version_is ""..."3.0" do
it "returns true if Object is tainted" do
o = mock('o')
p = mock('p')
p.taint
o.should_not.tainted?
p.should.tainted?
end
end
ruby_version_is "2.7"..."3.0" do
it "is a no-op" do it "is a no-op" do
o = mock('o') o = mock('o')
p = mock('p') p = mock('p')

View file

@ -5,14 +5,4 @@ describe "Kernel#to_s" do
it "returns a String containing the name of self's class" do it "returns a String containing the name of self's class" do
Object.new.to_s.should =~ /Object/ Object.new.to_s.should =~ /Object/
end end
ruby_version_is ''...'2.7' do
it "returns a tainted result if self is tainted" do
Object.new.taint.to_s.tainted?.should be_true
end
it "returns an untrusted result if self is untrusted" do
Object.new.untrust.to_s.untrusted?.should be_true
end
end
end end

View file

@ -2,30 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
describe "Kernel#trust" do describe "Kernel#trust" do
ruby_version_is ''...'2.7' do ruby_version_is ""..."3.0" do
it "returns self" do
o = Object.new
o.trust.should equal(o)
end
it "clears the untrusted bit" do
o = Object.new.untrust
o.trust
o.should_not.untrusted?
end
it "raises FrozenError on an untrusted, frozen object" do
o = Object.new.untrust.freeze
-> { o.trust }.should raise_error(FrozenError)
end
it "does not raise an error on a trusted, frozen object" do
o = Object.new.freeze
o.trust.should equal(o)
end
end
ruby_version_is "2.7"..."3.0" do
it "is a no-op" do it "is a no-op" do
o = Object.new.untrust o = Object.new.untrust
o.should_not.untrusted? o.should_not.untrusted?

View file

@ -2,30 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
describe "Kernel#untaint" do describe "Kernel#untaint" do
ruby_version_is ''...'2.7' do ruby_version_is ""..."3.0" do
it "returns self" do
o = Object.new
o.untaint.should equal(o)
end
it "clears the tainted bit" do
o = Object.new.taint
o.untaint
o.should_not.tainted?
end
it "raises FrozenError on a tainted, frozen object" do
o = Object.new.taint.freeze
-> { o.untaint }.should raise_error(FrozenError)
end
it "does not raise an error on an untainted, frozen object" do
o = Object.new.freeze
o.untaint.should equal(o)
end
end
ruby_version_is "2.7"..."3.0" do
it "is a no-op" do it "is a no-op" do
o = Object.new.taint o = Object.new.taint
o.should_not.tainted? o.should_not.tainted?

View file

@ -2,30 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
describe "Kernel#untrust" do describe "Kernel#untrust" do
ruby_version_is ''...'2.7' do ruby_version_is ""..."3.0" do
it "returns self" do
o = Object.new
o.untrust.should equal(o)
end
it "sets the untrusted bit" do
o = Object.new
o.untrust
o.should.untrusted?
end
it "raises FrozenError on a trusted, frozen object" do
o = Object.new.freeze
-> { o.untrust }.should raise_error(FrozenError)
end
it "does not raise an error on an untrusted, frozen object" do
o = Object.new.untrust.freeze
o.untrust.should equal(o)
end
end
ruby_version_is "2.7"..."3.0" do
it "is a no-op" do it "is a no-op" do
o = Object.new o = Object.new
o.untrust o.untrust

View file

@ -2,33 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
describe "Kernel#untrusted?" do describe "Kernel#untrusted?" do
ruby_version_is ''...'2.7' do ruby_version_is ""..."3.0" do
it "returns the untrusted status of an object" do
o = mock('o')
o.should_not.untrusted?
o.untrust
o.should.untrusted?
end
it "has no effect on immediate values" do
a = nil
b = true
c = false
a.untrust
b.untrust
c.untrust
a.should_not.untrusted?
b.should_not.untrusted?
c.should_not.untrusted?
end
it "has effect on immediate values" do
d = 1
-> { d.untrust }.should_not raise_error(RuntimeError)
end
end
ruby_version_is "2.7"..."3.0" do
it "is a no-op" do it "is a no-op" do
o = mock('o') o = mock('o')
o.should_not.untrusted? o.should_not.untrusted?

View file

@ -1,11 +1,9 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative 'fixtures/classes'
ruby_version_is "2.7" do describe "main.ruby2_keywords" do
describe "main.ruby2_keywords" do it "is the same as Object.ruby2_keywords" do
it "is the same as Object.ruby2_keywords" do main = TOPLEVEL_BINDING.receiver
main = TOPLEVEL_BINDING.receiver main.should have_private_method(:ruby2_keywords)
main.should have_private_method(:ruby2_keywords)
end
end end
end end

View file

@ -604,30 +604,4 @@ describe "Marshal.dump" do
m = Mutex.new m = Mutex.new
-> { Marshal.dump(m) }.should raise_error(TypeError) -> { Marshal.dump(m) }.should raise_error(TypeError)
end end
ruby_version_is ''...'2.7' do
it "returns an untainted string if object is untainted" do
Marshal.dump(Object.new).tainted?.should be_false
end
it "returns a tainted string if object is tainted" do
Marshal.dump(Object.new.taint).tainted?.should be_true
end
it "returns a tainted string if nested object is tainted" do
Marshal.dump([[Object.new.taint]]).tainted?.should be_true
end
it "returns a trusted string if object is trusted" do
Marshal.dump(Object.new).untrusted?.should be_false
end
it "returns an untrusted string if object is untrusted" do
Marshal.dump(Object.new.untrust).untrusted?.should be_true
end
it "returns an untrusted string if nested object is untrusted" do
Marshal.dump([[Object.new.untrust]]).untrusted?.should be_true
end
end
end end

View file

@ -306,89 +306,6 @@ describe :marshal_load, shared: true do
end end
end end
ruby_version_is ''...'2.7' do
it "returns an untainted object if source is untainted" do
x = Object.new
y = Marshal.send(@method, Marshal.dump(x))
y.tainted?.should be_false
end
describe "when source is tainted" do
it "returns a tainted object" do
x = Object.new
x.taint
s = Marshal.dump(x)
y = Marshal.send(@method, s)
y.tainted?.should be_true
# note that round-trip via Marshal does not preserve
# the taintedness at each level of the nested structure
y = Marshal.send(@method, Marshal.dump([[x]]))
y.tainted?.should be_true
y.first.tainted?.should be_true
y.first.first.tainted?.should be_true
end
it "does not taint Symbols" do
x = [:x]
y = Marshal.send(@method, Marshal.dump(x).taint)
y.tainted?.should be_true
y.first.tainted?.should be_false
end
it "does not taint Fixnums" do
x = [1]
y = Marshal.send(@method, Marshal.dump(x).taint)
y.tainted?.should be_true
y.first.tainted?.should be_false
end
it "does not taint Bignums" do
x = [bignum_value]
y = Marshal.send(@method, Marshal.dump(x).taint)
y.tainted?.should be_true
y.first.tainted?.should be_false
end
it "does not taint Floats" do
x = [1.2]
y = Marshal.send(@method, Marshal.dump(x).taint)
y.tainted?.should be_true
y.first.tainted?.should be_false
end
end
it "preserves taintedness of nested structure" do
x = Object.new
a = [[x]]
x.taint
y = Marshal.send(@method, Marshal.dump(a))
y.tainted?.should be_true
y.first.tainted?.should be_true
y.first.first.tainted?.should be_true
end
it "returns a trusted object if source is trusted" do
x = Object.new
y = Marshal.send(@method, Marshal.dump(x))
y.untrusted?.should be_false
end
it "returns an untrusted object if source is untrusted" do
x = Object.new
x.untrust
y = Marshal.send(@method, Marshal.dump(x))
y.untrusted?.should be_true
# note that round-trip via Marshal does not preserve
# the untrustedness at each level of the nested structure
y = Marshal.send(@method, Marshal.dump([[x]]))
y.untrusted?.should be_true
y.first.untrusted?.should be_true
y.first.first.untrusted?.should be_true
end
end
# Note: Ruby 1.9 should be compatible with older marshal format # Note: Ruby 1.9 should be compatible with older marshal format
MarshalSpec::DATA.each do |description, (object, marshal, attributes)| MarshalSpec::DATA.each do |description, (object, marshal, attributes)|
it "loads a #{description}" do it "loads a #{description}" do

View file

@ -1,10 +1,8 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
describe "MatchData.allocate" do describe "MatchData.allocate" do
ruby_version_is "2.7" do it "is undefined" do
it "is undefined" do # https://bugs.ruby-lang.org/issues/16294
# https://bugs.ruby-lang.org/issues/16294 -> { MatchData.allocate }.should raise_error(NoMethodError)
-> { MatchData.allocate }.should raise_error(NoMethodError)
end
end end
end end

View file

@ -16,6 +16,12 @@ describe "MatchData#[]" do
it "supports accessors [start, length]" do it "supports accessors [start, length]" do
/(.)(.)(\d+)(\d)/.match("THX1138.")[1, 2].should == %w|H X| /(.)(.)(\d+)(\d)/.match("THX1138.")[1, 2].should == %w|H X|
/(.)(.)(\d+)(\d)/.match("THX1138.")[-3, 2].should == %w|X 113| /(.)(.)(\d+)(\d)/.match("THX1138.")[-3, 2].should == %w|X 113|
# negative index is larger than the number of match values
/(.)(.)(\d+)(\d)/.match("THX1138.")[-30, 2].should == nil
# length argument larger than number of match values is capped to match value length
/(.)(.)(\d+)(\d)/.match("THX1138.")[3, 10].should == %w|113 8|
end end
it "supports ranges [start..end]" do it "supports ranges [start..end]" do

View file

@ -7,24 +7,6 @@ describe "MatchData#post_match" do
$'.should == ': The Movie' $'.should == ': The Movie'
end end
ruby_version_is ''...'2.7' do
it "keeps taint status from the source string" do
str = "THX1138: The Movie"
str.taint
res = /(.)(.)(\d+)(\d)/.match(str).post_match
res.tainted?.should be_true
$'.tainted?.should be_true
end
it "keeps untrusted status from the source string" do
str = "THX1138: The Movie"
str.untrust
res = /(.)(.)(\d+)(\d)/.match(str).post_match
res.untrusted?.should be_true
$'.untrusted?.should be_true
end
end
it "sets the encoding to the encoding of the source String" do it "sets the encoding to the encoding of the source String" do
str = "abc".force_encoding Encoding::EUC_JP str = "abc".force_encoding Encoding::EUC_JP
str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP) str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP)

View file

@ -7,24 +7,6 @@ describe "MatchData#pre_match" do
$`.should == 'T' $`.should == 'T'
end end
ruby_version_is ''...'2.7' do
it "keeps taint status from the source string" do
str = "THX1138: The Movie"
str.taint
res = /(.)(.)(\d+)(\d)/.match(str).pre_match
res.tainted?.should be_true
$`.tainted?.should be_true
end
it "keeps untrusted status from the source string" do
str = "THX1138: The Movie"
str.untrust
res = /(.)(.)(\d+)(\d)/.match(str).pre_match
res.untrusted?.should be_true
$`.untrusted?.should be_true
end
end
it "sets the encoding to the encoding of the source String" do it "sets the encoding to the encoding of the source String" do
str = "abc".force_encoding Encoding::EUC_JP str = "abc".force_encoding Encoding::EUC_JP
str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP) str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP)

View file

@ -24,19 +24,17 @@ describe :method_to_s, shared: true do
@string.should =~ /\#bar/ @string.should =~ /\#bar/
end end
ruby_version_is "2.7" do it "returns a String containing method arguments" do
it "returns a String containing method arguments" do obj = MethodSpecs::Methods.new
obj = MethodSpecs::Methods.new obj.method(:zero).send(@method).should.include?("()")
obj.method(:zero).send(@method).should.include?("()") obj.method(:one_req).send(@method).should.include?("(a)")
obj.method(:one_req).send(@method).should.include?("(a)") obj.method(:one_req_named).send(@method).should.include?("(a:)")
obj.method(:one_req_named).send(@method).should.include?("(a:)") obj.method(:zero_with_block).send(@method).should.include?("(&blk)")
obj.method(:zero_with_block).send(@method).should.include?("(&blk)") obj.method(:one_opt).send(@method).should.include?("(a=...)")
obj.method(:one_opt).send(@method).should.include?("(a=...)") obj.method(:one_opt_named).send(@method).should.include?("(a: ...)")
obj.method(:one_opt_named).send(@method).should.include?("(a: ...)") obj.method(:zero_with_splat).send(@method).should.include?("(*a)")
obj.method(:zero_with_splat).send(@method).should.include?("(*a)") obj.method(:zero_with_double_splat).send(@method).should.include?("(**a)")
obj.method(:zero_with_double_splat).send(@method).should.include?("(**a)") obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)")
obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)")
end
end end
it "returns a String containing the Module the method is defined in" do it "returns a String containing the Module the method is defined in" do
@ -79,11 +77,9 @@ describe :method_to_s, shared: true do
@string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar" @string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar"
end end
ruby_version_is '2.7' do ruby_bug '#17428', ''...'3.0' do
ruby_bug '#17428', '2.7'...'3.0' do it "shows the metaclass and the owner for a Module instance method retrieved from a class" do
it "shows the metaclass and the owner for a Module instance method retrieved from a class" do String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include")
String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include")
end
end end
end end
end end

View file

@ -47,20 +47,6 @@ describe "Module#append_features" do
end end
ruby_version_is ''...'2.7' do
it "copies own tainted status to the given module" do
other = Module.new
Module.new.taint.send :append_features, other
other.tainted?.should be_true
end
it "copies own untrusted status to the given module" do
other = Module.new
Module.new.untrust.send :append_features, other
other.untrusted?.should be_true
end
end
describe "when other is frozen" do describe "when other is frozen" do
before :each do before :each do
@receiver = Module.new @receiver = Module.new

View file

@ -18,16 +18,14 @@ describe "Module#autoload?" do
ModuleSpecs::Autoload::Child.autoload?(:AnotherAutoload).should == "another_autoload.rb" ModuleSpecs::Autoload::Child.autoload?(:AnotherAutoload).should == "another_autoload.rb"
end end
ruby_version_is "2.7" do it "returns nil if an ancestor defined that autoload but recursion is disabled" do
it "returns nil if an ancestor defined that autoload but recursion is disabled" do ModuleSpecs::Autoload::Parent.autoload :InheritedAutoload, "inherited_autoload.rb"
ModuleSpecs::Autoload::Parent.autoload :InheritedAutoload, "inherited_autoload.rb" ModuleSpecs::Autoload::Child.autoload?(:InheritedAutoload, false).should be_nil
ModuleSpecs::Autoload::Child.autoload?(:InheritedAutoload, false).should be_nil end
end
it "returns the name of the file that will be loaded if recursion is disabled but the autoload is defined on the class itself" do it "returns the name of the file that will be loaded if recursion is disabled but the autoload is defined on the class itself" do
ModuleSpecs::Autoload::Child.autoload :ChildAutoload, "child_autoload.rb" ModuleSpecs::Autoload::Child.autoload :ChildAutoload, "child_autoload.rb"
ModuleSpecs::Autoload::Child.autoload?(:ChildAutoload, false).should == "child_autoload.rb" ModuleSpecs::Autoload::Child.autoload?(:ChildAutoload, false).should == "child_autoload.rb"
end
end end
end end
@ -514,9 +512,7 @@ describe "Module#autoload" do
it "does not load the file when accessing the constants table of the module" do it "does not load the file when accessing the constants table of the module" do
ModuleSpecs::Autoload.autoload :P, @non_existent ModuleSpecs::Autoload.autoload :P, @non_existent
ModuleSpecs::Autoload.const_defined?(:P).should be_true ModuleSpecs::Autoload.const_defined?(:P).should be_true
ruby_bug "[Bug #15780]", ""..."2.7" do ModuleSpecs::Autoload.const_defined?("P").should be_true
ModuleSpecs::Autoload.const_defined?("P").should be_true
end
end end
it "loads the file when opening a module that is the autoloaded constant" do it "loads the file when opening a module that is the autoloaded constant" do

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