diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-27 20:21:25 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-27 20:21:25 +0000 |
commit | 37ef87c12b6c496001d0f199e46b4ecbfac5d394 (patch) | |
tree | 063c277e6343b299f6d47200e5b38f3af7975301 /spec/ruby/core | |
parent | ecf03376ec25fbd1ced6c0d1de110c6761e959fd (diff) | |
download | ruby-37ef87c12b6c496001d0f199e46b4ecbfac5d394.tar.gz |
Update to ruby/spec@cbe855c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core')
25 files changed, 107 insertions, 106 deletions
diff --git a/spec/ruby/core/array/clear_spec.rb b/spec/ruby/core/array/clear_spec.rb index 0789adaa4e..a33ed02b62 100644 --- a/spec/ruby/core/array/clear_spec.rb +++ b/spec/ruby/core/array/clear_spec.rb @@ -10,8 +10,7 @@ describe "Array#clear" do 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 diff --git a/spec/ruby/core/array/compact_spec.rb b/spec/ruby/core/array/compact_spec.rb index 21106d1d6f..fe8b37d86b 100644 --- a/spec/ruby/core/array/compact_spec.rb +++ b/spec/ruby/core/array/compact_spec.rb @@ -50,7 +50,7 @@ describe "Array#compact!" do 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 diff --git a/spec/ruby/core/array/filter_spec.rb b/spec/ruby/core/array/filter_spec.rb index d7c722e44c..a269662709 100644 --- a/spec/ruby/core/array/filter_spec.rb +++ b/spec/ruby/core/array/filter_spec.rb @@ -1,14 +1,16 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/select', __FILE__) -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 +ruby_version_is "2.6" do + describe "Array#filter" do + it_behaves_like :array_select, :filter end - it_behaves_like :keep_if, :filter! + 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 diff --git a/spec/ruby/core/array/reject_spec.rb b/spec/ruby/core/array/reject_spec.rb index 2dba6f58e7..d9b0ca5429 100644 --- a/spec/ruby/core/array/reject_spec.rb +++ b/spec/ruby/core/array/reject_spec.rb @@ -9,9 +9,9 @@ describe "Array#reject" do 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] diff --git a/spec/ruby/core/array/shared/clone.rb b/spec/ruby/core/array/shared/clone.rb index 6fc7ae31eb..95d0d0a3d5 100644 --- a/spec/ruby/core/array/shared/clone.rb +++ b/spec/ruby/core/array/shared/clone.rb @@ -7,8 +7,8 @@ describe :array_clone, shared: true do 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 diff --git a/spec/ruby/core/array/shared/collect.rb b/spec/ruby/core/array/shared/collect.rb index 2c75675b9d..5da73a88b4 100644 --- a/spec/ruby/core/array/shared/collect.rb +++ b/spec/ruby/core/array/shared/collect.rb @@ -5,7 +5,7 @@ describe :array_collect, shared: true do 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 @@ -70,7 +70,7 @@ describe :array_collect_b, shared: true do 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 diff --git a/spec/ruby/core/encoding/converter/last_error_spec.rb b/spec/ruby/core/encoding/converter/last_error_spec.rb index 8465935368..f8a2eeba69 100644 --- a/spec/ruby/core/encoding/converter/last_error_spec.rb +++ b/spec/ruby/core/encoding/converter/last_error_spec.rb @@ -55,14 +55,11 @@ with_feature :encoding do 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 @@ -70,16 +67,27 @@ with_feature :encoding do 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 diff --git a/spec/ruby/core/encoding/default_external_spec.rb b/spec/ruby/core/encoding/default_external_spec.rb index 2b026c793f..a4e2a3a61e 100644 --- a/spec/ruby/core/encoding/default_external_spec.rb +++ b/spec/ruby/core/encoding/default_external_spec.rb @@ -15,25 +15,8 @@ with_feature :encoding do 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 @@ -47,8 +30,14 @@ with_feature :encoding do 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 diff --git a/spec/ruby/core/encoding/default_internal_spec.rb b/spec/ruby/core/encoding/default_internal_spec.rb index 3234929eec..1e2b7e40c9 100644 --- a/spec/ruby/core/encoding/default_internal_spec.rb +++ b/spec/ruby/core/encoding/default_internal_spec.rb @@ -28,23 +28,6 @@ with_feature :encoding do 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 diff --git a/spec/ruby/core/enumerable/filter_spec.rb b/spec/ruby/core/enumerable/filter_spec.rb index 7f4bdd6d59..b5cd0e1613 100644 --- a/spec/ruby/core/enumerable/filter_spec.rb +++ b/spec/ruby/core/enumerable/filter_spec.rb @@ -2,6 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) require File.expand_path('../shared/find_all', __FILE__) -describe "Enumerable#filter" do - it_behaves_like(:enumerable_find_all , :filter) +ruby_version_is "2.6" do + describe "Enumerable#filter" do + it_behaves_like(:enumerable_find_all , :filter) + end end diff --git a/spec/ruby/core/env/shared/to_hash.rb b/spec/ruby/core/env/shared/to_hash.rb index 3bfbc415f7..254054c14d 100644 --- a/spec/ruby/core/env/shared/to_hash.rb +++ b/spec/ruby/core/env/shared/to_hash.rb @@ -17,6 +17,6 @@ describe :env_to_hash, shared: true do 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 diff --git a/spec/ruby/core/exception/no_method_error_spec.rb b/spec/ruby/core/exception/no_method_error_spec.rb index 321b2b4a8f..502300c139 100644 --- a/spec/ruby/core/exception/no_method_error_spec.rb +++ b/spec/ruby/core/exception/no_method_error_spec.rb @@ -26,7 +26,7 @@ describe "NoMethodError#args" do 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 diff --git a/spec/ruby/core/hash/clone_spec.rb b/spec/ruby/core/hash/clone_spec.rb index 188ae1c807..c9e7b1fe65 100644 --- a/spec/ruby/core/hash/clone_spec.rb +++ b/spec/ruby/core/hash/clone_spec.rb @@ -7,7 +7,7 @@ describe "Hash#clone" do clone = hash.clone clone.should == hash - clone.object_id.should_not == hash.object_id + clone.should_not equal hash end end diff --git a/spec/ruby/core/hash/compare_by_identity_spec.rb b/spec/ruby/core/hash/compare_by_identity_spec.rb index 34541037b9..6e6f294e10 100644 --- a/spec/ruby/core/hash/compare_by_identity_spec.rb +++ b/spec/ruby/core/hash/compare_by_identity_spec.rb @@ -105,7 +105,7 @@ describe "Hash#compare_by_identity" do @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 diff --git a/spec/ruby/core/hash/filter_spec.rb b/spec/ruby/core/hash/filter_spec.rb index 46c7bea8e8..bf9102cd6a 100644 --- a/spec/ruby/core/hash/filter_spec.rb +++ b/spec/ruby/core/hash/filter_spec.rb @@ -1,10 +1,12 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/select', __FILE__) -describe "Hash#filter" do - it_behaves_like :hash_select, :filter -end +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! + describe "Hash#filter!" do + it_behaves_like :hash_select!, :filter! + end end diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb index 223e3cde06..30f1b56db1 100644 --- a/spec/ruby/core/io/read_spec.rb +++ b/spec/ruby/core/io/read_spec.rb @@ -257,7 +257,7 @@ describe "IO#read" do it "returns the given buffer" do buf = "" - @io.read(nil, buf).object_id.should == buf.object_id + @io.read(nil, buf).should equal buf end it "coerces the second argument to string and uses it as a buffer" do @@ -265,7 +265,7 @@ describe "IO#read" do obj = mock("buff") obj.should_receive(:to_str).any_number_of_times.and_return(buf) - @io.read(15, obj).object_id.should_not == obj.object_id + @io.read(15, obj).should_not equal obj buf.should == @contents end diff --git a/spec/ruby/core/kernel/Float_spec.rb b/spec/ruby/core/kernel/Float_spec.rb index ee20190094..824c54eac0 100644 --- a/spec/ruby/core/kernel/Float_spec.rb +++ b/spec/ruby/core/kernel/Float_spec.rb @@ -6,7 +6,7 @@ describe :kernel_float, shared: true do float = 1.12 float2 = @object.send(:Float, float) float2.should == float - float2.object_id.should == float.object_id + float2.should equal float end it "returns a Float for Fixnums" do diff --git a/spec/ruby/core/kernel/Integer_spec.rb b/spec/ruby/core/kernel/Integer_spec.rb index 979283eb23..d2e989af9f 100644 --- a/spec/ruby/core/kernel/Integer_spec.rb +++ b/spec/ruby/core/kernel/Integer_spec.rb @@ -10,18 +10,29 @@ describe :kernel_integer, shared: true do Integer(100).should == 100 end - it "raises a TypeError when to_int returns not-an-Integer object and to_i returns nil" do - obj = mock("object") - obj.should_receive(:to_int).and_return("1") - obj.should_receive(:to_i).and_return(nil) - lambda { Integer(obj) }.should raise_error(TypeError) + ruby_version_is ""..."2.6" do + it "uncritically return the value of to_int even if it is not an Integer" do + obj = mock("object") + obj.should_receive(:to_int).and_return("1") + obj.should_not_receive(:to_i) + Integer(obj).should == "1" + end end - it "return a result of to_i when to_int does not return an Integer" do - obj = mock("object") - obj.should_receive(:to_int).and_return("1") - obj.should_receive(:to_i).and_return(42) - Integer(obj).should == 42 + ruby_version_is "2.6" do + it "raises a TypeError when to_int returns not-an-Integer object and to_i returns nil" do + obj = mock("object") + obj.should_receive(:to_int).and_return("1") + obj.should_receive(:to_i).and_return(nil) + lambda { Integer(obj) }.should raise_error(TypeError) + end + + it "return a result of to_i when to_int does not return an Integer" do + obj = mock("object") + obj.should_receive(:to_int).and_return("1") + obj.should_receive(:to_i).and_return(42) + Integer(obj).should == 42 + end end it "raises a TypeError when passed nil" do diff --git a/spec/ruby/core/matchdata/inspect_spec.rb b/spec/ruby/core/matchdata/inspect_spec.rb index 3cf968b6f5..eb71d45523 100644 --- a/spec/ruby/core/matchdata/inspect_spec.rb +++ b/spec/ruby/core/matchdata/inspect_spec.rb @@ -14,4 +14,10 @@ describe "MatchData#inspect" do # it makes perfect sense. See JRUBY-4558 for example. @match_data.inspect.should == '#<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">' end + + it "returns a human readable representation of named captures" do + match_data = "abc def ghi".match(/(?<first>\w+)\s+(?<last>\w+)\s+(\w+)/) + + match_data.inspect.should == '#<MatchData "abc def ghi" first:"abc" last:"def">' + end end diff --git a/spec/ruby/core/proc/block_pass_spec.rb b/spec/ruby/core/proc/block_pass_spec.rb index e956885654..8e700e87ba 100644 --- a/spec/ruby/core/proc/block_pass_spec.rb +++ b/spec/ruby/core/proc/block_pass_spec.rb @@ -8,14 +8,14 @@ describe "Proc as a block pass argument" do it "remains the same object if re-vivified by the target method" do p = Proc.new {} p2 = revivify(&p) - p.object_id.should == p2.object_id + p.should equal p2 p.should == p2 end it "remains the same object if reconstructed with Proc.new" do p = Proc.new {} p2 = Proc.new(&p) - p.object_id.should == p2.object_id + p.should equal p2 p.should == p2 end end @@ -28,14 +28,14 @@ describe "Proc as an implicit block pass argument" do it "remains the same object if re-vivified by the target method" do p = Proc.new {} p2 = revivify(&p) - p.object_id.should == p2.object_id + p.should equal p2 p.should == p2 end it "remains the same object if reconstructed with Proc.new" do p = Proc.new {} p2 = Proc.new(&p) - p.object_id.should == p2.object_id + p.should equal p2 p.should == p2 end end diff --git a/spec/ruby/core/string/chr_spec.rb b/spec/ruby/core/string/chr_spec.rb index c7834b78b7..a5e0cc4c88 100644 --- a/spec/ruby/core/string/chr_spec.rb +++ b/spec/ruby/core/string/chr_spec.rb @@ -4,7 +4,7 @@ with_feature :encoding do describe "String#chr" do it "returns a copy of self" do s = 'e' - s.object_id.should_not == s.chr.object_id + s.should_not equal s.chr end it "returns a String" do diff --git a/spec/ruby/core/string/clear_spec.rb b/spec/ruby/core/string/clear_spec.rb index c1bab8f39e..3db8b54cb0 100644 --- a/spec/ruby/core/string/clear_spec.rb +++ b/spec/ruby/core/string/clear_spec.rb @@ -14,7 +14,7 @@ with_feature :encoding do it "returns self after emptying it" do cleared = @s.clear cleared.should == "" - cleared.object_id.should == @s.object_id + cleared.should equal @s end it "preserves its encoding" do diff --git a/spec/ruby/core/string/freeze_spec.rb b/spec/ruby/core/string/freeze_spec.rb index bd7c2fbc73..476f50fbed 100644 --- a/spec/ruby/core/string/freeze_spec.rb +++ b/spec/ruby/core/string/freeze_spec.rb @@ -3,12 +3,11 @@ require File.expand_path('../../../spec_helper', __FILE__) describe "String#freeze" do it "produces the same object whenever called on an instance of a literal in the source" do - ids = Array.new(2) { "abc".freeze.object_id } - ids.first.should == ids.last + "abc".freeze.should equal "abc".freeze end it "doesn't produce the same object for different instances of literals in the source" do - "abc".object_id.should_not == "abc".object_id + "abc".should_not equal "abc" end it "being a special form doesn't change the value of defined?" do diff --git a/spec/ruby/core/time/at_spec.rb b/spec/ruby/core/time/at_spec.rb index 6883a8d074..58cacbf8f5 100644 --- a/spec/ruby/core/time/at_spec.rb +++ b/spec/ruby/core/time/at_spec.rb @@ -48,7 +48,7 @@ describe "Time.at" do it "creates a dup time object with the value given by time" do t1 = Time.new t2 = Time.at(t1) - t1.object_id.should_not == t2.object_id + t1.should_not equal t2 end it "returns a UTC time if the argument is UTC" do diff --git a/spec/ruby/core/time/succ_spec.rb b/spec/ruby/core/time/succ_spec.rb index 6831200741..ade72165ec 100644 --- a/spec/ruby/core/time/succ_spec.rb +++ b/spec/ruby/core/time/succ_spec.rb @@ -14,6 +14,6 @@ describe "Time#succ" do -> { t2 = t1.succ }.should complain(/Time#succ is obsolete/) - t1.object_id.should_not == t2.object_id + t1.should_not equal t2 end end |