Skip to content

Commit

Permalink
Update to ruby/spec@cbe855c
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Feb 27, 2018
1 parent 249c43a commit 3847b78
Show file tree
Hide file tree
Showing 56 changed files with 438 additions and 299 deletions.
2 changes: 2 additions & 0 deletions spec/ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ guard -> { max_uint <= fixnum_max } do
end
```

Custom guards are better than a simple `if` as they allow [mspec commands](https://github.com/ruby/mspec/issues/30#issuecomment-312487779) to work properly.

In general, the usage of guards should be minimized as possible.

There are no guards to define implementation-specific behavior because
Expand Down
6 changes: 3 additions & 3 deletions spec/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ The language specs are grouped by keyword while the core and standard library sp

ruby/spec is known to be tested in these implementations for every commit:
* [MRI](http://rubyci.org/) on 30 platforms and 4 versions
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) on Travis for both 1.7 and 9.x
* [TruffleRuby](https://github.com/graalvm/truffleruby) on Travis
* [Opal](https://github.com/opal/opal/tree/master/spec) on Travis
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x
* [TruffleRuby](https://github.com/oracle/truffleruby)
* [Opal](https://github.com/opal/opal/tree/master/spec)

ruby/spec describes the behavior of Ruby 2.2 and more recent Ruby versions.
More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec
Expand Down
25 changes: 25 additions & 0 deletions spec/ruby/command_line/dash_upper_e_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
describe "ruby -E" do
it "sets the external encoding with '-E external'" do
result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
result.should == "EUC-JP"
end

it "also sets the filesystem encoding with '-E external'" do
result = ruby_exe("print Encoding.find('filesystem')", options: '-E euc-jp')
result.should == "EUC-JP"
end

it "sets the external encoding with '-E external:'" do
result = ruby_exe("print Encoding.default_external", options: '-E Shift_JIS:')
result.should == "Shift_JIS"
end

it "sets the internal encoding with '-E :internal'" do
ruby_exe("print Encoding.default_internal", options: '-E :SHIFT_JIS').
should == 'Shift_JIS'
end

it "sets the external and internal encodings with '-E external:internal'" do
ruby_exe("puts Encoding.default_external, Encoding.default_internal", options: '-E euc-jp:SHIFT_JIS').
should == "EUC-JP\nShift_JIS\n"
end

it "raises a RuntimeError if used with -U" do
ruby_exe("p 1",
options: '-Eascii:ascii -U',
Expand Down
3 changes: 1 addition & 2 deletions spec/ruby/core/array/clear_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

it "returns self" do
a = [1]
oid = a.object_id
a.clear.object_id.should == oid
a.should equal a.clear
end

it "leaves the Array empty" do
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/array/compact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

it "returns self if some nil elements are removed" do
a = ['a', nil, 'b', false, 'c']
a.compact!.object_id.should == a.object_id
a.compact!.should equal a
end

it "returns nil if there are no nil elements to remove" do
Expand Down
16 changes: 16 additions & 0 deletions spec/ruby/core/array/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/select', __FILE__)

ruby_version_is "2.6" do
describe "Array#filter" do
it_behaves_like :array_select, :filter
end

describe "Array#filter!" do
it "returns nil if no changes were made in the array" do
[1, 2, 3].filter! { true }.should be_nil
end

it_behaves_like :keep_if, :filter!
end
end
4 changes: 2 additions & 2 deletions spec/ruby/core/array/reject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
ary = [1, 2, 3, 4, 5]
ary.reject { true }.should == []
ary.reject { false }.should == ary
ary.reject { false }.object_id.should_not == ary.object_id
ary.reject { false }.should_not equal ary
ary.reject { nil }.should == ary
ary.reject { nil }.object_id.should_not == ary.object_id
ary.reject { nil }.should_not equal ary
ary.reject { 5 }.should == []
ary.reject { |i| i < 3 }.should == [3, 4, 5]
ary.reject { |i| i % 2 == 0 }.should == [1, 3, 5]
Expand Down
26 changes: 2 additions & 24 deletions spec/ruby/core/array/select_spec.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/enumeratorize', __FILE__)
require File.expand_path('../shared/keep_if', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
require File.expand_path('../shared/select', __FILE__)

describe "Array#select" do
it_behaves_like :enumeratorize, :select
it_behaves_like :enumeratorized_with_origin_size, :select, [1,2,3]

it "returns a new array of elements for which block is true" do
[1, 3, 4, 5, 6, 9].select { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
end

it "does not return subclass instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].select { true }.should be_an_instance_of(Array)
end

it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
empty.select { true }.should == empty
empty.select { false }.should == []

array = ArraySpecs.recursive_array
array.select { true }.should == [1, 'two', 3.0, array, array, array, array, array]
array.select { false }.should == []
end
it_behaves_like :array_select, :select
end

describe "Array#select!" do
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/array/shared/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
it "produces a shallow copy where the references are directly copied" do
a = [mock('1'), mock('2')]
b = a.send @method
b.first.object_id.should == a.first.object_id
b.last.object_id.should == a.last.object_id
b.first.should equal a.first
b.last.should equal a.last
end

it "creates a new array containing all elements or the original" do
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/array/shared/collect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
a = ['a', 'b', 'c', 'd']
b = a.send(@method) { |i| i + '!' }
b.should == ["a!", "b!", "c!", "d!"]
b.object_id.should_not == a.object_id
b.should_not equal a
end

it "does not return subclass instance" do
Expand Down Expand Up @@ -70,7 +70,7 @@
it "returns self" do
a = [1, 2, 3, 4, 5]
b = a.send(@method) {|i| i+1 }
a.object_id.should == b.object_id
a.should equal b
end

it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
Expand Down
32 changes: 32 additions & 0 deletions spec/ruby/core/array/shared/select.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
require File.expand_path('../../shared/enumeratorize', __FILE__)
require File.expand_path('../../shared/keep_if', __FILE__)
require File.expand_path('../../../enumerable/shared/enumeratorized', __FILE__)

describe :array_select, shared: true do
it_should_behave_like :enumeratorize

before :each do
@object = [1,2,3]
end
it_should_behave_like :enumeratorized_with_origin_size

it "returns a new array of elements for which block is true" do
[1, 3, 4, 5, 6, 9].send(@method) { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
end

it "does not return subclass instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].send(@method) { true }.should be_an_instance_of(Array)
end

it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
empty.send(@method) { true }.should == empty
empty.send(@method) { false }.should == []

array = ArraySpecs.recursive_array
array.send(@method) { true }.should == [1, 'two', 3.0, array, array, array, array, array]
array.send(@method) { false }.should == []
end
end
40 changes: 24 additions & 16 deletions spec/ruby/core/encoding/converter/last_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,39 @@
it "returns an Encoding::InvalidByteSequenceError when the last call to #convert produced one" do
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
exception = nil
lambda do
begin
ec.convert("\xf1abcd")
rescue Encoding::InvalidByteSequenceError => e
exception = e
raise e
end
end.should raise_error(Encoding::InvalidByteSequenceError)
-> {
ec.convert("\xf1abcd")
}.should raise_error(Encoding::InvalidByteSequenceError) { |e|
exception = e
}
ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
ec.last_error.message.should == exception.message
end

it "returns an Encoding::UndefinedConversionError when the last call to #convert produced one" do
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
exception = nil
lambda do
begin
ec.convert("\u{9899}")
rescue Encoding::UndefinedConversionError => e
exception = e
raise e
end
end.should raise_error(Encoding::UndefinedConversionError)
-> {
ec.convert("\u{9899}")
}.should raise_error(Encoding::UndefinedConversionError) { |e|
exception = e
}
ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
ec.last_error.message.should == exception.message
ec.last_error.message.should include "from UTF-8 to ISO-8859-1"
end

it "returns the last error of #convert with a message showing the transcoding path" do
ec = Encoding::Converter.new("iso-8859-1", "Big5")
exception = nil
-> {
ec.convert("\xE9") # é in ISO-8859-1
}.should raise_error(Encoding::UndefinedConversionError) { |e|
exception = e
}
ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
ec.last_error.message.should == exception.message
ec.last_error.message.should include "from ISO-8859-1 to UTF-8 to Big5"
end
end
end
31 changes: 10 additions & 21 deletions spec/ruby/core/encoding/default_external_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,8 @@
end

it "returns the default external encoding" do
Encoding.default_external = Encoding::UTF_8
Encoding.default_external.should == Encoding::UTF_8
end

describe "with command line options" do
it "is not changed by the -U option" do
result = ruby_exe("print Encoding.default_external", options: '-U')
result.should == Encoding.default_external.name
end

it "returns the encoding specified by '-E external'" do
result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
result.should == "EUC-JP"
end

it "returns the encoding specified by '-E external:'" do
result = ruby_exe("print Encoding.default_external", options: '-E Shift_JIS:')
result.should == "Shift_JIS"
end
Encoding.default_external = Encoding::SHIFT_JIS
Encoding.default_external.should == Encoding::SHIFT_JIS
end
end

Expand All @@ -47,8 +30,14 @@
end

it "sets the default external encoding" do
Encoding.default_external = Encoding::UTF_8
Encoding.default_external.should == Encoding::UTF_8
Encoding.default_external = Encoding::SHIFT_JIS
Encoding.default_external.should == Encoding::SHIFT_JIS
Encoding.find('external').should == Encoding::SHIFT_JIS
end

it "also sets the filesystem encoding" do
Encoding.default_external = Encoding::SHIFT_JIS
Encoding.find('filesystem').should == Encoding::SHIFT_JIS
end

it "can accept a name of an encoding as a String" do
Expand Down
17 changes: 0 additions & 17 deletions spec/ruby/core/encoding/default_internal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@
Encoding.default_internal = Encoding::ASCII_8BIT
Encoding.default_internal.should == Encoding::ASCII_8BIT
end

describe "with command line options" do
it "returns Encoding::UTF_8 if ruby was invoked with -U" do
ruby_exe("print Encoding.default_internal", options: '-U').
should == 'UTF-8'
end

it "uses the encoding specified when ruby is invoked with an '-E :internal' argument" do
ruby_exe("print Encoding.default_internal", options: '-E :SHIFT_JIS').
should == 'Shift_JIS'
end

it "uses the encoding specified when ruby is invoked with an '-E external:internal' argument" do
ruby_exe("print Encoding.default_internal", options: '-E UTF-8:SHIFT_JIS').
should == 'Shift_JIS'
end
end
end

describe "Encoding.default_internal=" do
Expand Down
9 changes: 9 additions & 0 deletions spec/ruby/core/enumerable/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/find_all', __FILE__)

ruby_version_is "2.6" do
describe "Enumerable#filter" do
it_behaves_like(:enumerable_find_all , :filter)
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/env/shared/to_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

it "duplicates the ENV when converting to a Hash" do
h = ENV.send(@method)
h.object_id.should_not == ENV.object_id
h.should_not equal ENV
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/exception/no_method_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
NoMethodErrorSpecs::NoMethodErrorB.new.foo(1,a)
rescue Exception => e
e.args.should == [1,a]
e.args[1].object_id.should == a.object_id
e.args[1].should equal a
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/file/shared/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
File.open(@dir, File::RDWR | File::TMPFILE) do |f|
-> { f.send(@method) }.should raise_error(IOError)
end
rescue Errno::EOPNOTSUPP
rescue Errno::EOPNOTSUPP, Errno::EINVAL
# EOPNOTSUPP: no support from the filesystem
1.should == 1
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/hash/clone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
clone = hash.clone

clone.should == hash
clone.object_id.should_not == hash.object_id
clone.should_not equal hash
end
end

2 changes: 1 addition & 1 deletion spec/ruby/core/hash/compare_by_identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def o.hash; 123; end
@idh[foo] = true
@idh[foo] = true
@idh.size.should == 1
@idh.keys.first.object_id.should == foo.object_id
@idh.keys.first.should equal foo
end

ruby_bug "#12855", "2.2.0"..."2.4.1" do
Expand Down
12 changes: 12 additions & 0 deletions spec/ruby/core/hash/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/select', __FILE__)

ruby_version_is "2.6" do
describe "Hash#filter" do
it_behaves_like :hash_select, :filter
end

describe "Hash#filter!" do
it_behaves_like :hash_select!, :filter!
end
end

0 comments on commit 3847b78

Please sign in to comment.