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 | |
parent | ecf03376ec25fbd1ced6c0d1de110c6761e959fd (diff) |
Update to ruby/spec@cbe855c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
38 files changed, 185 insertions, 177 deletions
diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md index f3a8a539a8..7c9363da37 100644 --- a/spec/ruby/CONTRIBUTING.md +++ b/spec/ruby/CONTRIBUTING.md @@ -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 diff --git a/spec/ruby/README.md b/spec/ruby/README.md index 9c13ede75c..9f01c324b1 100644 --- a/spec/ruby/README.md +++ b/spec/ruby/README.md @@ -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 diff --git a/spec/ruby/command_line/dash_upper_e_spec.rb b/spec/ruby/command_line/dash_upper_e_spec.rb index 716f1304b7..e39491ca8b 100644 --- a/spec/ruby/command_line/dash_upper_e_spec.rb +++ b/spec/ruby/command_line/dash_upper_e_spec.rb @@ -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', 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 diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index 91cffce2e6..14f790a583 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -44,11 +44,11 @@ describe "Predefined global $~" do it "is set to contain the MatchData object of the last match if successful" do md = /foo/.match 'foo' $~.should be_kind_of(MatchData) - $~.object_id.should == md.object_id + $~.should equal md /bar/ =~ 'bar' $~.should be_kind_of(MatchData) - $~.object_id.should_not == md.object_id + $~.should_not equal md end it "is set to nil if the last match was unsuccessful" do @@ -828,7 +828,7 @@ end describe "Global variable $\"" do it "is an alias for $LOADED_FEATURES" do - $".object_id.should == $LOADED_FEATURES.object_id + $".should equal $LOADED_FEATURES end it "is read-only" do diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb index dbec2652ed..d1090e1771 100644 --- a/spec/ruby/language/string_spec.rb +++ b/spec/ruby/language/string_spec.rb @@ -42,6 +42,15 @@ describe "Ruby character strings" do "#@ip#@ip".should == 'xxxxxx' end + it "don't get confused by partial interpolation character sequences" do + "#@".should == '#@' + "#@ ".should == '#@ ' + "#@@".should == '#@@' + "#@@ ".should == '#@@ ' + "#$ ".should == '#$ ' + "#\$".should == '#$' + end + it "taints the result of interpolation when an interpolated value is tainted" do "#{"".taint}".tainted?.should be_true diff --git a/spec/ruby/library/csv/generate_spec.rb b/spec/ruby/library/csv/generate_spec.rb index f583b5f536..b264decb0e 100644 --- a/spec/ruby/library/csv/generate_spec.rb +++ b/spec/ruby/library/csv/generate_spec.rb @@ -26,7 +26,7 @@ describe "CSV.generate" do csv.add_row [1, 2, 3] csv << [4, 5, 6] end - csv_str.object_id.should == str.object_id + csv_str.should equal str str.should == "1,2,3\n4,5,6\n" end end diff --git a/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb b/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb index 6c465936c1..574a2d7911 100644 --- a/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb +++ b/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb @@ -1,5 +1,6 @@ require 'erb' require File.expand_path('../../../../spec_helper', __FILE__) +require File.expand_path('../../fixtures/classes', __FILE__) describe "ERB::DefMethod.def_erb_method" do @@ -50,11 +51,7 @@ END MY_INPUT4_FOR_ERB = input class MyClass4ForErb extend ERB::DefMethod - if RUBY_VERSION >= '2.6' - erb = ERB.new(MY_INPUT4_FOR_ERB, trim_mode: '<>') - else - erb = ERB.new(MY_INPUT4_FOR_ERB, nil, '<>') - end + erb = ERBSpecs.new_erb(MY_INPUT4_FOR_ERB, trim_mode: '<>') def_erb_method('render()', erb) def initialize(items) @items = items diff --git a/spec/ruby/library/erb/fixtures/classes.rb b/spec/ruby/library/erb/fixtures/classes.rb new file mode 100644 index 0000000000..03da889941 --- /dev/null +++ b/spec/ruby/library/erb/fixtures/classes.rb @@ -0,0 +1,9 @@ +module ERBSpecs + def self.new_erb(input, trim_mode: nil) + if ruby_version_is "2.6" + ERB.new(input, trim_mode: trim_mode) + else + ERB.new(input, nil, trim_mode) + end + end +end diff --git a/spec/ruby/library/erb/new_spec.rb b/spec/ruby/library/erb/new_spec.rb index 156873a598..274c11d9b5 100644 --- a/spec/ruby/library/erb/new_spec.rb +++ b/spec/ruby/library/erb/new_spec.rb @@ -1,5 +1,6 @@ require 'erb' require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) describe "ERB.new" do before :all do @@ -31,33 +32,21 @@ END it "compiles eRuby script into ruby code when trim mode is 0 or not specified" do expected = "<ul>\n\n\n\n<li>1</li>\n\n\n\n<li>2</li>\n\n\n\n<li>3</li>\n\n\n</ul>\n" [0, '', nil].each do |trim_mode| - if RUBY_VERSION >= '2.6' - ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected - else - ERB.new(@eruby_str, nil, trim_mode).result.should == expected - end + ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected end end it "removes '\n' when trim_mode is 1 or '>'" do expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n" [1, '>'].each do |trim_mode| - if RUBY_VERSION >= '2.6' - ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected - else - ERB.new(@eruby_str, nil, trim_mode).result.should == expected - end + ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected end end it "removes spaces at beginning of line and '\n' when trim_mode is 2 or '<>'" do expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n" [2, '<>'].each do |trim_mode| - if RUBY_VERSION >= '2.6' - ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected - else - ERB.new(@eruby_str, nil, trim_mode).result.should == expected - end + ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected end end @@ -73,11 +62,7 @@ END </ul> END - if RUBY_VERSION >= '2.6' - ERB.new(input, trim_mode: '-').result.should == expected - else - ERB.new(input, nil, '-').result.should == expected - end + ERBSpecs.new_erb(input, trim_mode: '-').result.should == expected end @@ -91,39 +76,23 @@ END END lambda { - if RUBY_VERSION >= '2.6' - ERB.new(input, trim_mode: '-').result - else - ERB.new(input, nil, '-').result - end + ERBSpecs.new_erb(input, trim_mode: '-').result }.should raise_error(SyntaxError) end it "regards lines starting with '%' as '<% ... %>' when trim_mode is '%'" do expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n\n</ul>\n%%\n" - if RUBY_VERSION >= '2.6' - ERB.new(@eruby_str2, trim_mode: "%").result.should == expected - else - ERB.new(@eruby_str2, nil, "%").result.should == expected - end + ERBSpecs.new_erb(@eruby_str2, trim_mode: "%").result.should == expected end it "regards lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%>'" do expected = "<ul>\n <li>1 <li>2 <li>3 </ul>\n%%\n" - if RUBY_VERSION >= '2.6' - ERB.new(@eruby_str2, trim_mode: '%>').result.should == expected - else - ERB.new(@eruby_str2, nil, '%>').result.should == expected - end + ERBSpecs.new_erb(@eruby_str2, trim_mode: '%>').result.should == expected end it "regard lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%<>'" do expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n</ul>\n%%\n" - if RUBY_VERSION >= '2.6' - ERB.new(@eruby_str2, trim_mode: '%<>').result.should == expected - else - ERB.new(@eruby_str2, nil, '%<>').result.should == expected - end + ERBSpecs.new_erb(@eruby_str2, trim_mode: '%<>').result.should == expected end @@ -138,11 +107,7 @@ END %%% END - if RUBY_VERSION >= '2.6' - ERB.new(input, trim_mode: '%-').result.should == expected - else - ERB.new(input, nil, '%-').result.should == expected - end + ERBSpecs.new_erb(input, trim_mode: '%-').result.should == expected end it "changes '_erbout' variable name in the produced source" do @@ -164,12 +129,8 @@ END <b><%#= item %></b> <%# end %> END - ERB.new(input).result.should == "\n<b></b>\n\n" - if RUBY_VERSION >= '2.6' - ERB.new(input, trim_mode: '<>').result.should == "<b></b>\n" - else - ERB.new(input, nil, '<>').result.should == "<b></b>\n" - end + ERBSpecs.new_erb(input).result.should == "\n<b></b>\n\n" + ERBSpecs.new_erb(input, trim_mode: '<>').result.should == "<b></b>\n" end it "forget local variables defined previous one" do diff --git a/spec/ruby/library/set/filter_spec.rb b/spec/ruby/library/set/filter_spec.rb index 3ac0c660b2..ada261421a 100644 --- a/spec/ruby/library/set/filter_spec.rb +++ b/spec/ruby/library/set/filter_spec.rb @@ -1,6 +1,8 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/select', __FILE__) -describe "Set#filter!" do - it_behaves_like :set_select_bang, :filter! +ruby_version_is "2.6" do + describe "Set#filter!" do + it_behaves_like :set_select_bang, :filter! + end end diff --git a/spec/ruby/library/set/sortedset/filter_spec.rb b/spec/ruby/library/set/sortedset/filter_spec.rb index 59e264ed84..16346a5b76 100644 --- a/spec/ruby/library/set/sortedset/filter_spec.rb +++ b/spec/ruby/library/set/sortedset/filter_spec.rb @@ -2,6 +2,8 @@ require File.expand_path('../../../../spec_helper', __FILE__) require File.expand_path('../shared/select', __FILE__) require 'set' -describe "SortedSet#filter!" do - it_behaves_like :sorted_set_select_bang, :filter! +ruby_version_is "2.6" do + describe "SortedSet#filter!" do + it_behaves_like :sorted_set_select_bang, :filter! + end end diff --git a/spec/ruby/optional/capi/gc_spec.rb b/spec/ruby/optional/capi/gc_spec.rb index ee9e11d11c..5534ff48c1 100644 --- a/spec/ruby/optional/capi/gc_spec.rb +++ b/spec/ruby/optional/capi/gc_spec.rb @@ -9,9 +9,9 @@ describe "CApiGCSpecs" do it "correctly gets the value from a registered address" do @f.registered_tagged_address.should == 10 - @f.registered_tagged_address.object_id.should == @f.registered_tagged_address.object_id + @f.registered_tagged_address.should equal(@f.registered_tagged_address) @f.registered_reference_address.should == "Globally registered data" - @f.registered_reference_address.object_id.should == @f.registered_reference_address.object_id + @f.registered_reference_address.should equal(@f.registered_reference_address) end describe "rb_gc_enable" do diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 024a153b1a..cb80838968 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -188,7 +188,7 @@ describe "C-API String function" do str1 = "hi" str2 = @s.rb_str_new3 str1 str1.should == str2 - str1.object_id.should_not == str2.object_id + str1.should_not equal str2 end end @@ -217,7 +217,7 @@ describe "C-API String function" do str1 = "hi" str2 = @s.rb_str_dup str1 str1.should == str2 - str1.object_id.should_not == str2.object_id + str1.should_not equal str2 end end |