diff --git a/command_line/backtrace_limit_spec.rb b/command_line/backtrace_limit_spec.rb index 56afa8efef..bc40a542a0 100644 --- a/command_line/backtrace_limit_spec.rb +++ b/command_line/backtrace_limit_spec.rb @@ -1,48 +1,46 @@ require_relative '../spec_helper' -ruby_version_is "3.0" do - describe "The --backtrace-limit command line option" do - it "limits top-level backtraces to a given number of entries" do - file = fixture(__FILE__ , "backtrace.rb") - out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1) - out = out.gsub(__dir__, '') +describe "The --backtrace-limit command line option" do + it "limits top-level backtraces to a given number of entries" do + file = fixture(__FILE__ , "backtrace.rb") + out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1) + out = out.gsub(__dir__, '') - out.should == <<-MSG + out.should == <<-MSG top /fixtures/backtrace.rb:2:in `a': oops (RuntimeError) \tfrom /fixtures/backtrace.rb:6:in `b' \tfrom /fixtures/backtrace.rb:10:in `c' \t ... 2 levels... - MSG - end + MSG + end - it "affects Exception#full_message" do - file = fixture(__FILE__ , "backtrace.rb") - out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1") - out = out.gsub(__dir__, '') + it "affects Exception#full_message" do + file = fixture(__FILE__ , "backtrace.rb") + out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1") + out = out.gsub(__dir__, '') - out.should == <<-MSG + out.should == <<-MSG full_message /fixtures/backtrace.rb:2:in `a': oops (RuntimeError) \tfrom /fixtures/backtrace.rb:6:in `b' \tfrom /fixtures/backtrace.rb:10:in `c' \t ... 2 levels... - MSG - end + MSG + end - it "does not affect Exception#backtrace" do - file = fixture(__FILE__ , "backtrace.rb") - out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1") - out = out.gsub(__dir__, '') + it "does not affect Exception#backtrace" do + file = fixture(__FILE__ , "backtrace.rb") + out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1") + out = out.gsub(__dir__, '') - out.should == <<-MSG + out.should == <<-MSG backtrace /fixtures/backtrace.rb:2:in `a' /fixtures/backtrace.rb:6:in `b' /fixtures/backtrace.rb:10:in `c' /fixtures/backtrace.rb:14:in `d' /fixtures/backtrace.rb:29:in `
' - MSG - end + MSG end end diff --git a/core/argf/bytes_spec.rb b/core/argf/bytes_spec.rb deleted file mode 100644 index bf35ded1db..0000000000 --- a/core/argf/bytes_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/each_byte' - -ruby_version_is ''...'3.0' do - describe "ARGF.bytes" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :argf_each_byte, :bytes - end -end diff --git a/core/argf/chars_spec.rb b/core/argf/chars_spec.rb deleted file mode 100644 index 6af73cdabb..0000000000 --- a/core/argf/chars_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/each_char' - -ruby_version_is ''...'3.0' do - describe "ARGF.chars" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :argf_each_char, :chars - end -end diff --git a/core/argf/codepoints_spec.rb b/core/argf/codepoints_spec.rb deleted file mode 100644 index bb28c17fbb..0000000000 --- a/core/argf/codepoints_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/each_codepoint' - -ruby_version_is ''...'3.0' do - describe "ARGF.codepoints" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :argf_each_codepoint, :codepoints - end -end diff --git a/core/argf/lines_spec.rb b/core/argf/lines_spec.rb deleted file mode 100644 index e964dbd0d3..0000000000 --- a/core/argf/lines_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/each_line' - -ruby_version_is ''...'3.0' do - describe "ARGF.lines" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :argf_each_line, :lines - end -end diff --git a/core/array/drop_spec.rb b/core/array/drop_spec.rb index f911fd9018..0ea748e47d 100644 --- a/core/array/drop_spec.rb +++ b/core/array/drop_spec.rb @@ -50,15 +50,7 @@ -> { [1, 2].drop(obj) }.should raise_error(TypeError) end - ruby_version_is ''...'3.0' do - it 'returns a subclass instance for Array subclasses' do - ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should be_an_instance_of(ArraySpecs::MyArray) - end - end - - ruby_version_is '3.0' do - it 'returns a Array instance for Array subclasses' do - ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should be_an_instance_of(Array) - end + it 'returns a Array instance for Array subclasses' do + ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should be_an_instance_of(Array) end end diff --git a/core/array/drop_while_spec.rb b/core/array/drop_while_spec.rb index 94064528aa..bd46e8b882 100644 --- a/core/array/drop_while_spec.rb +++ b/core/array/drop_while_spec.rb @@ -18,15 +18,7 @@ [1, 2, 3, false, 5].drop_while { |n| n }.should == [false, 5] end - ruby_version_is ''...'3.0' do - it 'returns a subclass instance for Array subclasses' do - ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should be_an_instance_of(ArraySpecs::MyArray) - end - end - - ruby_version_is '3.0' do - it 'returns a Array instance for Array subclasses' do - ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should be_an_instance_of(Array) - end + it 'returns a Array instance for Array subclasses' do + ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should be_an_instance_of(Array) end end diff --git a/core/array/flatten_spec.rb b/core/array/flatten_spec.rb index 1770b5389a..8c97000c79 100644 --- a/core/array/flatten_spec.rb +++ b/core/array/flatten_spec.rb @@ -75,24 +75,12 @@ [[obj]].flatten(1) end - ruby_version_is ''...'3.0' do - it "returns subclass instance for Array subclasses" do - ArraySpecs::MyArray[].flatten.should be_an_instance_of(ArraySpecs::MyArray) - ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(ArraySpecs::MyArray) - ArraySpecs::MyArray[1, [2], 3].flatten.should be_an_instance_of(ArraySpecs::MyArray) - ArraySpecs::MyArray[1, [2, 3], 4].flatten.should == ArraySpecs::MyArray[1, 2, 3, 4] - [ArraySpecs::MyArray[1, 2, 3]].flatten.should be_an_instance_of(Array) - end - end - - ruby_version_is '3.0' do - it "returns Array instance for Array subclasses" do - ArraySpecs::MyArray[].flatten.should be_an_instance_of(Array) - ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(Array) - ArraySpecs::MyArray[1, [2], 3].flatten.should be_an_instance_of(Array) - ArraySpecs::MyArray[1, [2, 3], 4].flatten.should == [1, 2, 3, 4] - [ArraySpecs::MyArray[1, 2, 3]].flatten.should be_an_instance_of(Array) - end + it "returns Array instance for Array subclasses" do + ArraySpecs::MyArray[].flatten.should be_an_instance_of(Array) + ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(Array) + ArraySpecs::MyArray[1, [2], 3].flatten.should be_an_instance_of(Array) + ArraySpecs::MyArray[1, [2, 3], 4].flatten.should == [1, 2, 3, 4] + [ArraySpecs::MyArray[1, 2, 3]].flatten.should be_an_instance_of(Array) end it "is not destructive" do diff --git a/core/array/multiply_spec.rb b/core/array/multiply_spec.rb index 23d5c99f3a..eca51142fb 100644 --- a/core/array/multiply_spec.rb +++ b/core/array/multiply_spec.rb @@ -76,20 +76,10 @@ def obj.to_str() "2" end @array = ArraySpecs::MyArray[1, 2, 3, 4, 5] end - ruby_version_is ''...'3.0' do - it "returns a subclass instance" do - (@array * 0).should be_an_instance_of(ArraySpecs::MyArray) - (@array * 1).should be_an_instance_of(ArraySpecs::MyArray) - (@array * 2).should be_an_instance_of(ArraySpecs::MyArray) - end - end - - ruby_version_is '3.0' do - it "returns an Array instance" do - (@array * 0).should be_an_instance_of(Array) - (@array * 1).should be_an_instance_of(Array) - (@array * 2).should be_an_instance_of(Array) - end + it "returns an Array instance" do + (@array * 0).should be_an_instance_of(Array) + (@array * 1).should be_an_instance_of(Array) + (@array * 2).should be_an_instance_of(Array) end it "does not call #initialize on the subclass instance" do diff --git a/core/array/shared/slice.rb b/core/array/shared/slice.rb index 8fb33738b9..d2866970a5 100644 --- a/core/array/shared/slice.rb +++ b/core/array/shared/slice.rb @@ -397,56 +397,28 @@ def to.to_int() -2 end @array = ArraySpecs::MyArray[1, 2, 3, 4, 5] end - ruby_version_is ''...'3.0' do - it "returns a subclass instance with [n, m]" do - @array.send(@method, 0, 2).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [-n, m]" do - @array.send(@method, -3, 2).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [n..m]" do - @array.send(@method, 1..3).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [n...m]" do - @array.send(@method, 1...3).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [-n..-m]" do - @array.send(@method, -3..-1).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [-n...-m]" do - @array.send(@method, -3...-1).should be_an_instance_of(ArraySpecs::MyArray) - end + it "returns a Array instance with [n, m]" do + @array.send(@method, 0, 2).should be_an_instance_of(Array) end - ruby_version_is '3.0' do - it "returns a Array instance with [n, m]" do - @array.send(@method, 0, 2).should be_an_instance_of(Array) - end - - it "returns a Array instance with [-n, m]" do - @array.send(@method, -3, 2).should be_an_instance_of(Array) - end + it "returns a Array instance with [-n, m]" do + @array.send(@method, -3, 2).should be_an_instance_of(Array) + end - it "returns a Array instance with [n..m]" do - @array.send(@method, 1..3).should be_an_instance_of(Array) - end + it "returns a Array instance with [n..m]" do + @array.send(@method, 1..3).should be_an_instance_of(Array) + end - it "returns a Array instance with [n...m]" do - @array.send(@method, 1...3).should be_an_instance_of(Array) - end + it "returns a Array instance with [n...m]" do + @array.send(@method, 1...3).should be_an_instance_of(Array) + end - it "returns a Array instance with [-n..-m]" do - @array.send(@method, -3..-1).should be_an_instance_of(Array) - end + it "returns a Array instance with [-n..-m]" do + @array.send(@method, -3..-1).should be_an_instance_of(Array) + end - it "returns a Array instance with [-n...-m]" do - @array.send(@method, -3...-1).should be_an_instance_of(Array) - end + it "returns a Array instance with [-n...-m]" do + @array.send(@method, -3...-1).should be_an_instance_of(Array) end it "returns an empty array when m == n with [m...n]" do @@ -534,239 +506,237 @@ def to.to_int() -2 end a.send(@method, eval("(-9...)")).should == nil end - ruby_version_is "3.0" do - describe "can be sliced with Enumerator::ArithmeticSequence" do - before :each do - @array = [0, 1, 2, 3, 4, 5] - end + describe "can be sliced with Enumerator::ArithmeticSequence" do + before :each do + @array = [0, 1, 2, 3, 4, 5] + end - it "has endless range and positive steps" do - @array.send(@method, eval("(0..).step(1)")).should == [0, 1, 2, 3, 4, 5] - @array.send(@method, eval("(0..).step(2)")).should == [0, 2, 4] - @array.send(@method, eval("(0..).step(10)")).should == [0] + it "has endless range and positive steps" do + @array.send(@method, eval("(0..).step(1)")).should == [0, 1, 2, 3, 4, 5] + @array.send(@method, eval("(0..).step(2)")).should == [0, 2, 4] + @array.send(@method, eval("(0..).step(10)")).should == [0] - @array.send(@method, eval("(2..).step(1)")).should == [2, 3, 4, 5] - @array.send(@method, eval("(2..).step(2)")).should == [2, 4] - @array.send(@method, eval("(2..).step(10)")).should == [2] + @array.send(@method, eval("(2..).step(1)")).should == [2, 3, 4, 5] + @array.send(@method, eval("(2..).step(2)")).should == [2, 4] + @array.send(@method, eval("(2..).step(10)")).should == [2] - @array.send(@method, eval("(-3..).step(1)")).should == [3, 4, 5] - @array.send(@method, eval("(-3..).step(2)")).should == [3, 5] - @array.send(@method, eval("(-3..).step(10)")).should == [3] - end + @array.send(@method, eval("(-3..).step(1)")).should == [3, 4, 5] + @array.send(@method, eval("(-3..).step(2)")).should == [3, 5] + @array.send(@method, eval("(-3..).step(10)")).should == [3] + end - it "has beginless range and positive steps" do - # end with zero index - @array.send(@method, (..0).step(1)).should == [0] - @array.send(@method, (...0).step(1)).should == [] + it "has beginless range and positive steps" do + # end with zero index + @array.send(@method, (..0).step(1)).should == [0] + @array.send(@method, (...0).step(1)).should == [] - @array.send(@method, (..0).step(2)).should == [0] - @array.send(@method, (...0).step(2)).should == [] + @array.send(@method, (..0).step(2)).should == [0] + @array.send(@method, (...0).step(2)).should == [] - @array.send(@method, (..0).step(10)).should == [0] - @array.send(@method, (...0).step(10)).should == [] + @array.send(@method, (..0).step(10)).should == [0] + @array.send(@method, (...0).step(10)).should == [] - # end with positive index - @array.send(@method, (..3).step(1)).should == [0, 1, 2, 3] - @array.send(@method, (...3).step(1)).should == [0, 1, 2] + # end with positive index + @array.send(@method, (..3).step(1)).should == [0, 1, 2, 3] + @array.send(@method, (...3).step(1)).should == [0, 1, 2] - @array.send(@method, (..3).step(2)).should == [0, 2] - @array.send(@method, (...3).step(2)).should == [0, 2] + @array.send(@method, (..3).step(2)).should == [0, 2] + @array.send(@method, (...3).step(2)).should == [0, 2] - @array.send(@method, (..3).step(10)).should == [0] - @array.send(@method, (...3).step(10)).should == [0] + @array.send(@method, (..3).step(10)).should == [0] + @array.send(@method, (...3).step(10)).should == [0] - # end with negative index - @array.send(@method, (..-2).step(1)).should == [0, 1, 2, 3, 4,] - @array.send(@method, (...-2).step(1)).should == [0, 1, 2, 3] + # end with negative index + @array.send(@method, (..-2).step(1)).should == [0, 1, 2, 3, 4,] + @array.send(@method, (...-2).step(1)).should == [0, 1, 2, 3] - @array.send(@method, (..-2).step(2)).should == [0, 2, 4] - @array.send(@method, (...-2).step(2)).should == [0, 2] + @array.send(@method, (..-2).step(2)).should == [0, 2, 4] + @array.send(@method, (...-2).step(2)).should == [0, 2] - @array.send(@method, (..-2).step(10)).should == [0] - @array.send(@method, (...-2).step(10)).should == [0] - end + @array.send(@method, (..-2).step(10)).should == [0] + @array.send(@method, (...-2).step(10)).should == [0] + end - it "has endless range and negative steps" do - @array.send(@method, eval("(0..).step(-1)")).should == [0] - @array.send(@method, eval("(0..).step(-2)")).should == [0] - @array.send(@method, eval("(0..).step(-10)")).should == [0] + it "has endless range and negative steps" do + @array.send(@method, eval("(0..).step(-1)")).should == [0] + @array.send(@method, eval("(0..).step(-2)")).should == [0] + @array.send(@method, eval("(0..).step(-10)")).should == [0] - @array.send(@method, eval("(2..).step(-1)")).should == [2, 1, 0] - @array.send(@method, eval("(2..).step(-2)")).should == [2, 0] + @array.send(@method, eval("(2..).step(-1)")).should == [2, 1, 0] + @array.send(@method, eval("(2..).step(-2)")).should == [2, 0] - @array.send(@method, eval("(-3..).step(-1)")).should == [3, 2, 1, 0] - @array.send(@method, eval("(-3..).step(-2)")).should == [3, 1] - end + @array.send(@method, eval("(-3..).step(-1)")).should == [3, 2, 1, 0] + @array.send(@method, eval("(-3..).step(-2)")).should == [3, 1] + end - it "has closed range and positive steps" do - # start and end with 0 - @array.send(@method, eval("(0..0).step(1)")).should == [0] - @array.send(@method, eval("(0...0).step(1)")).should == [] + it "has closed range and positive steps" do + # start and end with 0 + @array.send(@method, eval("(0..0).step(1)")).should == [0] + @array.send(@method, eval("(0...0).step(1)")).should == [] - @array.send(@method, eval("(0..0).step(2)")).should == [0] - @array.send(@method, eval("(0...0).step(2)")).should == [] + @array.send(@method, eval("(0..0).step(2)")).should == [0] + @array.send(@method, eval("(0...0).step(2)")).should == [] - @array.send(@method, eval("(0..0).step(10)")).should == [0] - @array.send(@method, eval("(0...0).step(10)")).should == [] + @array.send(@method, eval("(0..0).step(10)")).should == [0] + @array.send(@method, eval("(0...0).step(10)")).should == [] - # start and end with positive index - @array.send(@method, eval("(1..3).step(1)")).should == [1, 2, 3] - @array.send(@method, eval("(1...3).step(1)")).should == [1, 2] + # start and end with positive index + @array.send(@method, eval("(1..3).step(1)")).should == [1, 2, 3] + @array.send(@method, eval("(1...3).step(1)")).should == [1, 2] - @array.send(@method, eval("(1..3).step(2)")).should == [1, 3] - @array.send(@method, eval("(1...3).step(2)")).should == [1] + @array.send(@method, eval("(1..3).step(2)")).should == [1, 3] + @array.send(@method, eval("(1...3).step(2)")).should == [1] - @array.send(@method, eval("(1..3).step(10)")).should == [1] - @array.send(@method, eval("(1...3).step(10)")).should == [1] + @array.send(@method, eval("(1..3).step(10)")).should == [1] + @array.send(@method, eval("(1...3).step(10)")).should == [1] - # start with positive index, end with negative index - @array.send(@method, eval("(1..-2).step(1)")).should == [1, 2, 3, 4] - @array.send(@method, eval("(1...-2).step(1)")).should == [1, 2, 3] + # start with positive index, end with negative index + @array.send(@method, eval("(1..-2).step(1)")).should == [1, 2, 3, 4] + @array.send(@method, eval("(1...-2).step(1)")).should == [1, 2, 3] - @array.send(@method, eval("(1..-2).step(2)")).should == [1, 3] - @array.send(@method, eval("(1...-2).step(2)")).should == [1, 3] + @array.send(@method, eval("(1..-2).step(2)")).should == [1, 3] + @array.send(@method, eval("(1...-2).step(2)")).should == [1, 3] - @array.send(@method, eval("(1..-2).step(10)")).should == [1] - @array.send(@method, eval("(1...-2).step(10)")).should == [1] + @array.send(@method, eval("(1..-2).step(10)")).should == [1] + @array.send(@method, eval("(1...-2).step(10)")).should == [1] - # start with negative index, end with positive index - @array.send(@method, eval("(-4..4).step(1)")).should == [2, 3, 4] - @array.send(@method, eval("(-4...4).step(1)")).should == [2, 3] + # start with negative index, end with positive index + @array.send(@method, eval("(-4..4).step(1)")).should == [2, 3, 4] + @array.send(@method, eval("(-4...4).step(1)")).should == [2, 3] - @array.send(@method, eval("(-4..4).step(2)")).should == [2, 4] - @array.send(@method, eval("(-4...4).step(2)")).should == [2] + @array.send(@method, eval("(-4..4).step(2)")).should == [2, 4] + @array.send(@method, eval("(-4...4).step(2)")).should == [2] - @array.send(@method, eval("(-4..4).step(10)")).should == [2] - @array.send(@method, eval("(-4...4).step(10)")).should == [2] + @array.send(@method, eval("(-4..4).step(10)")).should == [2] + @array.send(@method, eval("(-4...4).step(10)")).should == [2] - # start with negative index, end with negative index - @array.send(@method, eval("(-4..-2).step(1)")).should == [2, 3, 4] - @array.send(@method, eval("(-4...-2).step(1)")).should == [2, 3] + # start with negative index, end with negative index + @array.send(@method, eval("(-4..-2).step(1)")).should == [2, 3, 4] + @array.send(@method, eval("(-4...-2).step(1)")).should == [2, 3] - @array.send(@method, eval("(-4..-2).step(2)")).should == [2, 4] - @array.send(@method, eval("(-4...-2).step(2)")).should == [2] + @array.send(@method, eval("(-4..-2).step(2)")).should == [2, 4] + @array.send(@method, eval("(-4...-2).step(2)")).should == [2] - @array.send(@method, eval("(-4..-2).step(10)")).should == [2] - @array.send(@method, eval("(-4...-2).step(10)")).should == [2] - end + @array.send(@method, eval("(-4..-2).step(10)")).should == [2] + @array.send(@method, eval("(-4...-2).step(10)")).should == [2] + end - it "has closed range and negative steps" do - # start and end with 0 - @array.send(@method, eval("(0..0).step(-1)")).should == [0] - @array.send(@method, eval("(0...0).step(-1)")).should == [] + it "has closed range and negative steps" do + # start and end with 0 + @array.send(@method, eval("(0..0).step(-1)")).should == [0] + @array.send(@method, eval("(0...0).step(-1)")).should == [] - @array.send(@method, eval("(0..0).step(-2)")).should == [0] - @array.send(@method, eval("(0...0).step(-2)")).should == [] + @array.send(@method, eval("(0..0).step(-2)")).should == [0] + @array.send(@method, eval("(0...0).step(-2)")).should == [] - @array.send(@method, eval("(0..0).step(-10)")).should == [0] - @array.send(@method, eval("(0...0).step(-10)")).should == [] + @array.send(@method, eval("(0..0).step(-10)")).should == [0] + @array.send(@method, eval("(0...0).step(-10)")).should == [] - # start and end with positive index - @array.send(@method, eval("(1..3).step(-1)")).should == [] - @array.send(@method, eval("(1...3).step(-1)")).should == [] + # start and end with positive index + @array.send(@method, eval("(1..3).step(-1)")).should == [] + @array.send(@method, eval("(1...3).step(-1)")).should == [] - @array.send(@method, eval("(1..3).step(-2)")).should == [] - @array.send(@method, eval("(1...3).step(-2)")).should == [] + @array.send(@method, eval("(1..3).step(-2)")).should == [] + @array.send(@method, eval("(1...3).step(-2)")).should == [] - @array.send(@method, eval("(1..3).step(-10)")).should == [] - @array.send(@method, eval("(1...3).step(-10)")).should == [] + @array.send(@method, eval("(1..3).step(-10)")).should == [] + @array.send(@method, eval("(1...3).step(-10)")).should == [] - # start with positive index, end with negative index - @array.send(@method, eval("(1..-2).step(-1)")).should == [] - @array.send(@method, eval("(1...-2).step(-1)")).should == [] + # start with positive index, end with negative index + @array.send(@method, eval("(1..-2).step(-1)")).should == [] + @array.send(@method, eval("(1...-2).step(-1)")).should == [] - @array.send(@method, eval("(1..-2).step(-2)")).should == [] - @array.send(@method, eval("(1...-2).step(-2)")).should == [] + @array.send(@method, eval("(1..-2).step(-2)")).should == [] + @array.send(@method, eval("(1...-2).step(-2)")).should == [] - @array.send(@method, eval("(1..-2).step(-10)")).should == [] - @array.send(@method, eval("(1...-2).step(-10)")).should == [] + @array.send(@method, eval("(1..-2).step(-10)")).should == [] + @array.send(@method, eval("(1...-2).step(-10)")).should == [] - # start with negative index, end with positive index - @array.send(@method, eval("(-4..4).step(-1)")).should == [] - @array.send(@method, eval("(-4...4).step(-1)")).should == [] + # start with negative index, end with positive index + @array.send(@method, eval("(-4..4).step(-1)")).should == [] + @array.send(@method, eval("(-4...4).step(-1)")).should == [] - @array.send(@method, eval("(-4..4).step(-2)")).should == [] - @array.send(@method, eval("(-4...4).step(-2)")).should == [] + @array.send(@method, eval("(-4..4).step(-2)")).should == [] + @array.send(@method, eval("(-4...4).step(-2)")).should == [] - @array.send(@method, eval("(-4..4).step(-10)")).should == [] - @array.send(@method, eval("(-4...4).step(-10)")).should == [] + @array.send(@method, eval("(-4..4).step(-10)")).should == [] + @array.send(@method, eval("(-4...4).step(-10)")).should == [] - # start with negative index, end with negative index - @array.send(@method, eval("(-4..-2).step(-1)")).should == [] - @array.send(@method, eval("(-4...-2).step(-1)")).should == [] + # start with negative index, end with negative index + @array.send(@method, eval("(-4..-2).step(-1)")).should == [] + @array.send(@method, eval("(-4...-2).step(-1)")).should == [] - @array.send(@method, eval("(-4..-2).step(-2)")).should == [] - @array.send(@method, eval("(-4...-2).step(-2)")).should == [] + @array.send(@method, eval("(-4..-2).step(-2)")).should == [] + @array.send(@method, eval("(-4...-2).step(-2)")).should == [] - @array.send(@method, eval("(-4..-2).step(-10)")).should == [] - @array.send(@method, eval("(-4...-2).step(-10)")).should == [] - end + @array.send(@method, eval("(-4..-2).step(-10)")).should == [] + @array.send(@method, eval("(-4...-2).step(-10)")).should == [] + end - it "has inverted closed range and positive steps" do - # start and end with positive index - @array.send(@method, eval("(3..1).step(1)")).should == [] - @array.send(@method, eval("(3...1).step(1)")).should == [] + it "has inverted closed range and positive steps" do + # start and end with positive index + @array.send(@method, eval("(3..1).step(1)")).should == [] + @array.send(@method, eval("(3...1).step(1)")).should == [] - @array.send(@method, eval("(3..1).step(2)")).should == [] - @array.send(@method, eval("(3...1).step(2)")).should == [] + @array.send(@method, eval("(3..1).step(2)")).should == [] + @array.send(@method, eval("(3...1).step(2)")).should == [] - @array.send(@method, eval("(3..1).step(10)")).should == [] - @array.send(@method, eval("(3...1).step(10)")).should == [] + @array.send(@method, eval("(3..1).step(10)")).should == [] + @array.send(@method, eval("(3...1).step(10)")).should == [] - # start with negative index, end with positive index - @array.send(@method, eval("(-2..1).step(1)")).should == [] - @array.send(@method, eval("(-2...1).step(1)")).should == [] + # start with negative index, end with positive index + @array.send(@method, eval("(-2..1).step(1)")).should == [] + @array.send(@method, eval("(-2...1).step(1)")).should == [] - @array.send(@method, eval("(-2..1).step(2)")).should == [] - @array.send(@method, eval("(-2...1).step(2)")).should == [] + @array.send(@method, eval("(-2..1).step(2)")).should == [] + @array.send(@method, eval("(-2...1).step(2)")).should == [] - @array.send(@method, eval("(-2..1).step(10)")).should == [] - @array.send(@method, eval("(-2...1).step(10)")).should == [] + @array.send(@method, eval("(-2..1).step(10)")).should == [] + @array.send(@method, eval("(-2...1).step(10)")).should == [] - # start with positive index, end with negative index - @array.send(@method, eval("(4..-4).step(1)")).should == [] - @array.send(@method, eval("(4...-4).step(1)")).should == [] + # start with positive index, end with negative index + @array.send(@method, eval("(4..-4).step(1)")).should == [] + @array.send(@method, eval("(4...-4).step(1)")).should == [] - @array.send(@method, eval("(4..-4).step(2)")).should == [] - @array.send(@method, eval("(4...-4).step(2)")).should == [] + @array.send(@method, eval("(4..-4).step(2)")).should == [] + @array.send(@method, eval("(4...-4).step(2)")).should == [] - @array.send(@method, eval("(4..-4).step(10)")).should == [] - @array.send(@method, eval("(4...-4).step(10)")).should == [] + @array.send(@method, eval("(4..-4).step(10)")).should == [] + @array.send(@method, eval("(4...-4).step(10)")).should == [] - # start with negative index, end with negative index - @array.send(@method, eval("(-2..-4).step(1)")).should == [] - @array.send(@method, eval("(-2...-4).step(1)")).should == [] + # start with negative index, end with negative index + @array.send(@method, eval("(-2..-4).step(1)")).should == [] + @array.send(@method, eval("(-2...-4).step(1)")).should == [] - @array.send(@method, eval("(-2..-4).step(2)")).should == [] - @array.send(@method, eval("(-2...-4).step(2)")).should == [] + @array.send(@method, eval("(-2..-4).step(2)")).should == [] + @array.send(@method, eval("(-2...-4).step(2)")).should == [] - @array.send(@method, eval("(-2..-4).step(10)")).should == [] - @array.send(@method, eval("(-2...-4).step(10)")).should == [] - end + @array.send(@method, eval("(-2..-4).step(10)")).should == [] + @array.send(@method, eval("(-2...-4).step(10)")).should == [] + end - it "has range with bounds outside of array" do - # end is equal to array's length - @array.send(@method, (0..6).step(1)).should == [0, 1, 2, 3, 4, 5] - -> { @array.send(@method, (0..6).step(2)) }.should raise_error(RangeError) + it "has range with bounds outside of array" do + # end is equal to array's length + @array.send(@method, (0..6).step(1)).should == [0, 1, 2, 3, 4, 5] + -> { @array.send(@method, (0..6).step(2)) }.should raise_error(RangeError) - # end is greater than length with positive steps - @array.send(@method, (1..6).step(2)).should == [1, 3, 5] - @array.send(@method, (2..7).step(2)).should == [2, 4] - -> { @array.send(@method, (2..8).step(2)) }.should raise_error(RangeError) + # end is greater than length with positive steps + @array.send(@method, (1..6).step(2)).should == [1, 3, 5] + @array.send(@method, (2..7).step(2)).should == [2, 4] + -> { @array.send(@method, (2..8).step(2)) }.should raise_error(RangeError) - # begin is greater than length with negative steps - @array.send(@method, (6..1).step(-2)).should == [5, 3, 1] - @array.send(@method, (7..2).step(-2)).should == [5, 3] - -> { @array.send(@method, (8..2).step(-2)) }.should raise_error(RangeError) - end + # begin is greater than length with negative steps + @array.send(@method, (6..1).step(-2)).should == [5, 3, 1] + @array.send(@method, (7..2).step(-2)).should == [5, 3] + -> { @array.send(@method, (8..2).step(-2)) }.should raise_error(RangeError) + end - it "has endless range with start outside of array's bounds" do - @array.send(@method, eval("(6..).step(1)")).should == [] - @array.send(@method, eval("(7..).step(1)")).should == nil + it "has endless range with start outside of array's bounds" do + @array.send(@method, eval("(6..).step(1)")).should == [] + @array.send(@method, eval("(7..).step(1)")).should == nil - @array.send(@method, eval("(6..).step(2)")).should == [] - -> { @array.send(@method, eval("(7..).step(2)")) }.should raise_error(RangeError) - end + @array.send(@method, eval("(6..).step(2)")).should == [] + -> { @array.send(@method, eval("(7..).step(2)")) }.should raise_error(RangeError) end end diff --git a/core/array/slice_spec.rb b/core/array/slice_spec.rb index 8e1499855a..731c129251 100644 --- a/core/array/slice_spec.rb +++ b/core/array/slice_spec.rb @@ -187,56 +187,28 @@ def to.to_int() -2 end @array = ArraySpecs::MyArray[1, 2, 3, 4, 5] end - ruby_version_is ''...'3.0' do - it "returns a subclass instance with [n, m]" do - @array.slice!(0, 2).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [-n, m]" do - @array.slice!(-3, 2).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [n..m]" do - @array.slice!(1..3).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [n...m]" do - @array.slice!(1...3).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [-n..-m]" do - @array.slice!(-3..-1).should be_an_instance_of(ArraySpecs::MyArray) - end - - it "returns a subclass instance with [-n...-m]" do - @array.slice!(-3...-1).should be_an_instance_of(ArraySpecs::MyArray) - end + it "returns a Array instance with [n, m]" do + @array.slice!(0, 2).should be_an_instance_of(Array) end - ruby_version_is '3.0' do - it "returns a Array instance with [n, m]" do - @array.slice!(0, 2).should be_an_instance_of(Array) - end - - it "returns a Array instance with [-n, m]" do - @array.slice!(-3, 2).should be_an_instance_of(Array) - end + it "returns a Array instance with [-n, m]" do + @array.slice!(-3, 2).should be_an_instance_of(Array) + end - it "returns a Array instance with [n..m]" do - @array.slice!(1..3).should be_an_instance_of(Array) - end + it "returns a Array instance with [n..m]" do + @array.slice!(1..3).should be_an_instance_of(Array) + end - it "returns a Array instance with [n...m]" do - @array.slice!(1...3).should be_an_instance_of(Array) - end + it "returns a Array instance with [n...m]" do + @array.slice!(1...3).should be_an_instance_of(Array) + end - it "returns a Array instance with [-n..-m]" do - @array.slice!(-3..-1).should be_an_instance_of(Array) - end + it "returns a Array instance with [-n..-m]" do + @array.slice!(-3..-1).should be_an_instance_of(Array) + end - it "returns a Array instance with [-n...-m]" do - @array.slice!(-3...-1).should be_an_instance_of(Array) - end + it "returns a Array instance with [-n...-m]" do + @array.slice!(-3...-1).should be_an_instance_of(Array) end end end diff --git a/core/array/take_spec.rb b/core/array/take_spec.rb index 4fb6f0ce75..c4f0ac9aa4 100644 --- a/core/array/take_spec.rb +++ b/core/array/take_spec.rb @@ -26,15 +26,7 @@ ->{ [1].take(-3) }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it 'returns a subclass instance for Array subclasses' do - ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should be_an_instance_of(ArraySpecs::MyArray) - end - end - - ruby_version_is '3.0' do - it 'returns a Array instance for Array subclasses' do - ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should be_an_instance_of(Array) - end + it 'returns a Array instance for Array subclasses' do + ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should be_an_instance_of(Array) end end diff --git a/core/array/take_while_spec.rb b/core/array/take_while_spec.rb index 73f25493c8..8f50260b42 100644 --- a/core/array/take_while_spec.rb +++ b/core/array/take_while_spec.rb @@ -15,16 +15,8 @@ [1, 2, false, 4].take_while{ |element| element }.should == [1, 2] end - ruby_version_is ''...'3.0' do - it 'returns a subclass instance for Array subclasses' do - ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should be_an_instance_of(ArraySpecs::MyArray) - end - end - - ruby_version_is '3.0' do - it 'returns a Array instance for Array subclasses' do - ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should be_an_instance_of(Array) - end + it 'returns a Array instance for Array subclasses' do + ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should be_an_instance_of(Array) end end diff --git a/core/array/uniq_spec.rb b/core/array/uniq_spec.rb index 905ab59634..d5d826db15 100644 --- a/core/array/uniq_spec.rb +++ b/core/array/uniq_spec.rb @@ -85,16 +85,8 @@ def obj.eql?(o) [false, nil, 42].uniq { :bar }.should == [false] end - ruby_version_is ''...'3.0' do - it "returns subclass instance on Array subclasses" do - ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(ArraySpecs::MyArray) - end - end - - ruby_version_is '3.0' do - it "returns Array instance on Array subclasses" do - ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(Array) - end + it "returns Array instance on Array subclasses" do + ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(Array) end it "properly handles an identical item even when its #eql? isn't reflexive" do diff --git a/core/binding/eval_spec.rb b/core/binding/eval_spec.rb index 4bb3da7a6c..1b3b670b5e 100644 --- a/core/binding/eval_spec.rb +++ b/core/binding/eval_spec.rb @@ -23,58 +23,29 @@ bind2.local_variables.should == [] end - ruby_version_is ""..."3.0" do - it "inherits __LINE__ from the enclosing scope" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - suppress_warning {bind.eval("__LINE__")}.should == obj.get_line_of_binding - end - - it "preserves __LINE__ across multiple calls to eval" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - suppress_warning {bind.eval("__LINE__")}.should == obj.get_line_of_binding - suppress_warning {bind.eval("__LINE__")}.should == obj.get_line_of_binding - end - - it "increments __LINE__ on each line of a multiline eval" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - suppress_warning {bind.eval("#foo\n__LINE__")}.should == obj.get_line_of_binding + 1 - end - - it "inherits __LINE__ from the enclosing scope even if the Binding is created with #send" do - obj = BindingSpecs::Demo.new(1) - bind, line = obj.get_binding_with_send_and_line - suppress_warning {bind.eval("__LINE__")}.should == line - end + it "starts with line 1 if single argument is given" do + obj = BindingSpecs::Demo.new(1) + bind = obj.get_binding + bind.eval("__LINE__").should == 1 end - ruby_version_is "3.0" do - it "starts with line 1 if single argument is given" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__LINE__").should == 1 - end - - it "preserves __LINE__ across multiple calls to eval" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__LINE__").should == 1 - bind.eval("__LINE__").should == 1 - end + it "preserves __LINE__ across multiple calls to eval" do + obj = BindingSpecs::Demo.new(1) + bind = obj.get_binding + bind.eval("__LINE__").should == 1 + bind.eval("__LINE__").should == 1 + end - it "increments __LINE__ on each line of a multiline eval" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("#foo\n__LINE__").should == 2 - end + it "increments __LINE__ on each line of a multiline eval" do + obj = BindingSpecs::Demo.new(1) + bind = obj.get_binding + bind.eval("#foo\n__LINE__").should == 2 + end - it "starts with line 1 if the Binding is created with #send" do - obj = BindingSpecs::Demo.new(1) - bind, line = obj.get_binding_with_send_and_line - bind.eval("__LINE__").should == 1 - end + it "starts with line 1 if the Binding is created with #send" do + obj = BindingSpecs::Demo.new(1) + bind, line = obj.get_binding_with_send_and_line + bind.eval("__LINE__").should == 1 end it "starts with a __LINE__ of 1 if a filename is passed" do @@ -89,32 +60,16 @@ bind.eval("#foo\n__LINE__", "(test)", 88).should == 89 end - ruby_version_is ""..."3.0" do - it "inherits __FILE__ from the enclosing scope" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - suppress_warning { bind.eval("__FILE__") }.should == obj.get_file_of_binding - end - - it "inherits __LINE__ from the enclosing scope" do - obj = BindingSpecs::Demo.new(1) - bind, line = obj.get_binding_and_line - suppress_warning { bind.eval("__LINE__") }.should == line - end + it "uses (eval) as __FILE__ if single argument given" do + obj = BindingSpecs::Demo.new(1) + bind = obj.get_binding + bind.eval("__FILE__").should == '(eval)' end - ruby_version_is "3.0" do - it "uses (eval) as __FILE__ if single argument given" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__FILE__").should == '(eval)' - end - - it "uses 1 as __LINE__" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - suppress_warning { bind.eval("__LINE__") }.should == 1 - end + it "uses 1 as __LINE__" do + obj = BindingSpecs::Demo.new(1) + bind = obj.get_binding + suppress_warning { bind.eval("__LINE__") }.should == 1 end it "uses the __FILE__ that is passed in" do diff --git a/core/data/constants_spec.rb b/core/data/constants_spec.rb index d9d55b50f9..87a981f666 100644 --- a/core/data/constants_spec.rb +++ b/core/data/constants_spec.rb @@ -1,19 +1,5 @@ require_relative '../../spec_helper' -ruby_version_is ''...'3.0' do - describe "Data" do - it "is a subclass of Object" do - suppress_warning do - Data.superclass.should == Object - end - end - - it "is deprecated" do - -> { Data }.should complain(/constant ::Data is deprecated/) - end - end -end - ruby_version_is '3.0'...'3.2' do describe "Data" do it "does not exist anymore" do diff --git a/core/dir/shared/glob.rb b/core/dir/shared/glob.rb index 33b2828c27..aa8e4e337f 100644 --- a/core/dir/shared/glob.rb +++ b/core/dir/shared/glob.rb @@ -27,21 +27,19 @@ -> {Dir.send(@method, "file_o*\0file_t*")}.should raise_error ArgumentError, /nul-separated/ end - ruby_version_is "3.0" do - it "result is sorted by default" do - result = Dir.send(@method, '*') - result.should == result.sort - end + it "result is sorted by default" do + result = Dir.send(@method, '*') + result.should == result.sort + end - it "result is sorted with sort: true" do - result = Dir.send(@method, '*', sort: true) - result.should == result.sort - end + it "result is sorted with sort: true" do + result = Dir.send(@method, '*', sort: true) + result.should == result.sort + end - it "sort: false returns same files" do - result = Dir.send(@method,'*', sort: false) - result.sort.should == Dir.send(@method, '*').sort - end + it "sort: false returns same files" do + result = Dir.send(@method,'*', sort: false) + result.sort.should == Dir.send(@method, '*').sort end ruby_version_is "3.0"..."3.1" do diff --git a/core/encoding/default_external_spec.rb b/core/encoding/default_external_spec.rb index 682d49d37c..9aae4976e0 100644 --- a/core/encoding/default_external_spec.rb +++ b/core/encoding/default_external_spec.rb @@ -18,11 +18,9 @@ Encoding.default_external.should == Encoding::SHIFT_JIS end - ruby_version_is "3.0" do - platform_is :windows do - it 'is UTF-8 by default on Windows' do - Encoding.default_external.should == Encoding::UTF_8 - end + platform_is :windows do + it 'is UTF-8 by default on Windows' do + Encoding.default_external.should == Encoding::UTF_8 end end end diff --git a/core/enumerable/grep_spec.rb b/core/enumerable/grep_spec.rb index b81075291f..989358f01b 100644 --- a/core/enumerable/grep_spec.rb +++ b/core/enumerable/grep_spec.rb @@ -40,43 +40,28 @@ class EnumerableSpecGrep2; def ===(obj); /^ca/ =~ obj; end; end $~.should == nil end - ruby_version_is ""..."3.0.0" do - it "sets $~ to the last match when given no block" do - "z" =~ /z/ # Reset $~ - ["abc", "def"].grep(/b/).should == ["abc"] - - # Set by the failed match of "def" - $~.should == nil - - ["abc", "def"].grep(/e/) - $&.should == "e" - end + it "does not set $~ when given no block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].grep(/b/).should == ["abc"] + $&.should == "z" end - ruby_version_is "3.0.0" do - it "does not set $~ when given no block" do - "z" =~ /z/ # Reset $~ - ["abc", "def"].grep(/b/).should == ["abc"] - $&.should == "z" - end - - it "does not modify Regexp.last_match without block" do - "z" =~ /z/ # Reset last match - ["abc", "def"].grep(/b/).should == ["abc"] - Regexp.last_match[0].should == "z" - end + it "does not modify Regexp.last_match without block" do + "z" =~ /z/ # Reset last match + ["abc", "def"].grep(/b/).should == ["abc"] + Regexp.last_match[0].should == "z" + end - it "correctly handles non-string elements" do - 'set last match' =~ /set last (.*)/ - [:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c] - $1.should == 'match' + it "correctly handles non-string elements" do + 'set last match' =~ /set last (.*)/ + [:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c] + $1.should == 'match' - o = Object.new - def o.to_str - 'hello' - end - [o].grep(/ll/).first.should.equal?(o) + o = Object.new + def o.to_str + 'hello' end + [o].grep(/ll/).first.should.equal?(o) end describe "with a block" do diff --git a/core/enumerable/grep_v_spec.rb b/core/enumerable/grep_v_spec.rb index 35fde27eb6..ba19216968 100644 --- a/core/enumerable/grep_v_spec.rb +++ b/core/enumerable/grep_v_spec.rb @@ -20,43 +20,28 @@ def (@odd_matcher = BasicObject.new).===(obj) $&.should == "e" end - ruby_version_is ""..."3.0.0" do - it "sets $~ to the last match when given no block" do - "z" =~ /z/ # Reset $~ - ["abc", "def"].grep_v(/e/).should == ["abc"] - - # Set by the match of "def" - $&.should == "e" - - ["abc", "def"].grep_v(/b/) - $&.should == nil - end + it "does not set $~ when given no block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].grep_v(/e/).should == ["abc"] + $&.should == "z" end - ruby_version_is "3.0.0" do - it "does not set $~ when given no block" do - "z" =~ /z/ # Reset $~ - ["abc", "def"].grep_v(/e/).should == ["abc"] - $&.should == "z" - end - - it "does not modify Regexp.last_match without block" do - "z" =~ /z/ # Reset last match - ["abc", "def"].grep_v(/e/).should == ["abc"] - Regexp.last_match[0].should == "z" - end + it "does not modify Regexp.last_match without block" do + "z" =~ /z/ # Reset last match + ["abc", "def"].grep_v(/e/).should == ["abc"] + Regexp.last_match[0].should == "z" + end - it "correctly handles non-string elements" do - 'set last match' =~ /set last (.*)/ - [:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil] - $1.should == 'match' + it "correctly handles non-string elements" do + 'set last match' =~ /set last (.*)/ + [:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil] + $1.should == 'match' - o = Object.new - def o.to_str - 'hello' - end - [o].grep_v(/mm/).first.should.equal?(o) + o = Object.new + def o.to_str + 'hello' end + [o].grep_v(/mm/).first.should.equal?(o) end describe "without block" do diff --git a/core/enumerator/initialize_spec.rb b/core/enumerator/initialize_spec.rb index 217af1d3bc..5e937aff2b 100644 --- a/core/enumerator/initialize_spec.rb +++ b/core/enumerator/initialize_spec.rb @@ -11,14 +11,6 @@ Enumerator.should have_private_instance_method(:initialize, false) end - ruby_version_is ''...'3.0' do - it "returns self when given an object" do - suppress_warning do - @uninitialized.send(:initialize, Object.new).should equal(@uninitialized) - end - end - end - it "returns self when given a block" do @uninitialized.send(:initialize) {}.should equal(@uninitialized) end diff --git a/core/enumerator/new_spec.rb b/core/enumerator/new_spec.rb index c439469525..671912224f 100644 --- a/core/enumerator/new_spec.rb +++ b/core/enumerator/new_spec.rb @@ -2,51 +2,8 @@ describe "Enumerator.new" do context "no block given" do - ruby_version_is '3.0' do - it "raises" do - -> { Enumerator.new(1, :upto, 3) }.should raise_error(ArgumentError) - end - end - - ruby_version_is ''...'3.0' do - it "creates a new custom enumerator with the given object, iterator and arguments" do - enum = suppress_warning { Enumerator.new(1, :upto, 3) } - enum.should be_an_instance_of(Enumerator) - end - - it "creates a new custom enumerator that responds to #each" do - enum = suppress_warning { Enumerator.new(1, :upto, 3) } - enum.respond_to?(:each).should == true - end - - it "creates a new custom enumerator that runs correctly" do - suppress_warning { Enumerator.new(1, :upto, 3) }.map{ |x| x }.should == [1,2,3] - end - - it "aliases the second argument to :each" do - suppress_warning { Enumerator.new(1..2) }.to_a.should == - suppress_warning { Enumerator.new(1..2, :each) }.to_a - end - - it "doesn't check for the presence of the iterator method" do - suppress_warning { Enumerator.new(nil) }.should be_an_instance_of(Enumerator) - end - - it "uses the latest define iterator method" do - class StrangeEach - def each - yield :foo - end - end - enum = suppress_warning { Enumerator.new(StrangeEach.new) } - enum.to_a.should == [:foo] - class StrangeEach - def each - yield :bar - end - end - enum.to_a.should == [:bar] - end + it "raises" do + -> { Enumerator.new(1, :upto, 3) }.should raise_error(ArgumentError) end end diff --git a/core/env/delete_spec.rb b/core/env/delete_spec.rb index 5e7891f74d..3d69e4b022 100644 --- a/core/env/delete_spec.rb +++ b/core/env/delete_spec.rb @@ -30,11 +30,9 @@ ScratchPad.recorded.should == "foo" end - ruby_version_is "3.0" do - it "returns the result of given block if the named environment variable does not exist" do - ENV.delete("foo") - ENV.delete("foo") { |name| "bar" }.should == "bar" - end + it "returns the result of given block if the named environment variable does not exist" do + ENV.delete("foo") + ENV.delete("foo") { |name| "bar" }.should == "bar" end it "does not evaluate the block if the environment variable exists" do diff --git a/core/env/except_spec.rb b/core/env/except_spec.rb index cfe5865abe..fb8f3b7536 100644 --- a/core/env/except_spec.rb +++ b/core/env/except_spec.rb @@ -1,36 +1,34 @@ require_relative 'spec_helper' require_relative 'shared/to_hash' -ruby_version_is "3.0" do - describe "ENV.except" do - before do - @orig_hash = ENV.to_hash - end +describe "ENV.except" do + before do + @orig_hash = ENV.to_hash + end - after do - ENV.replace @orig_hash - end + after do + ENV.replace @orig_hash + end - # Testing the method without arguments is covered via - it_behaves_like :env_to_hash, :except + # Testing the method without arguments is covered via + it_behaves_like :env_to_hash, :except - it "returns a hash without the requested subset" do - ENV.clear + it "returns a hash without the requested subset" do + ENV.clear - ENV['one'] = '1' - ENV['two'] = '2' - ENV['three'] = '3' + ENV['one'] = '1' + ENV['two'] = '2' + ENV['three'] = '3' - ENV.except('one', 'three').should == { 'two' => '2' } - end + ENV.except('one', 'three').should == { 'two' => '2' } + end - it "ignores keys not present in the original hash" do - ENV.clear + it "ignores keys not present in the original hash" do + ENV.clear - ENV['one'] = '1' - ENV['two'] = '2' + ENV['one'] = '1' + ENV['two'] = '2' - ENV.except('one', 'three').should == { 'two' => '2' } - end + ENV.except('one', 'three').should == { 'two' => '2' } end end diff --git a/core/env/index_spec.rb b/core/env/index_spec.rb deleted file mode 100644 index 301a66ab4e..0000000000 --- a/core/env/index_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'shared/key' - -ruby_version_is ''...'3.0' do - describe "ENV.index" do - it_behaves_like :env_key, :index - - it "warns about deprecation" do - -> do - ENV.index("foo") - end.should complain(/warning: ENV.index is deprecated; use ENV.key/) - end - end -end diff --git a/core/env/indexes_spec.rb b/core/env/indexes_spec.rb deleted file mode 100644 index e724feaa39..0000000000 --- a/core/env/indexes_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../spec_helper' diff --git a/core/env/indices_spec.rb b/core/env/indices_spec.rb deleted file mode 100644 index e724feaa39..0000000000 --- a/core/env/indices_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../spec_helper' diff --git a/core/exception/no_method_error_spec.rb b/core/exception/no_method_error_spec.rb index f84f3418a4..4621e36f44 100644 --- a/core/exception/no_method_error_spec.rb +++ b/core/exception/no_method_error_spec.rb @@ -125,21 +125,19 @@ def inspect end end - ruby_version_is "3.0" do - it "uses #name to display the receiver if it is a class or a module" do - klass = Class.new { def self.name; "MyClass"; end } - begin - klass.foo - rescue NoMethodError => error - error.message.lines.first.chomp.should =~ /^undefined method `foo' for / - end + it "uses #name to display the receiver if it is a class or a module" do + klass = Class.new { def self.name; "MyClass"; end } + begin + klass.foo + rescue NoMethodError => error + error.message.lines.first.chomp.should =~ /^undefined method `foo' for / + end - mod = Module.new { def self.name; "MyModule"; end } - begin - mod.foo - rescue NoMethodError => error - error.message.lines.first.chomp.should =~ /^undefined method `foo' for / - end + mod = Module.new { def self.name; "MyModule"; end } + begin + mod.foo + rescue NoMethodError => error + error.message.lines.first.chomp.should =~ /^undefined method `foo' for / end end end diff --git a/core/fiber/blocking_spec.rb b/core/fiber/blocking_spec.rb index eeee5a71c1..ebefa116af 100644 --- a/core/fiber/blocking_spec.rb +++ b/core/fiber/blocking_spec.rb @@ -1,61 +1,59 @@ require_relative '../../spec_helper' require_relative 'shared/blocking' -ruby_version_is "3.0" do - require "fiber" +require "fiber" - describe "Fiber.blocking?" do - it_behaves_like :non_blocking_fiber, -> { Fiber.blocking? } +describe "Fiber.blocking?" do + it_behaves_like :non_blocking_fiber, -> { Fiber.blocking? } - context "when fiber is blocking" do - context "root Fiber of the main thread" do - it "returns 1 for blocking: true" do + context "when fiber is blocking" do + context "root Fiber of the main thread" do + it "returns 1 for blocking: true" do + fiber = Fiber.new(blocking: true) { Fiber.blocking? } + blocking = fiber.resume + + blocking.should == 1 + end + end + + context "root Fiber of a new thread" do + it "returns 1 for blocking: true" do + thread = Thread.new do fiber = Fiber.new(blocking: true) { Fiber.blocking? } blocking = fiber.resume blocking.should == 1 end + + thread.join end + end + end +end - context "root Fiber of a new thread" do - it "returns 1 for blocking: true" do - thread = Thread.new do - fiber = Fiber.new(blocking: true) { Fiber.blocking? } - blocking = fiber.resume +describe "Fiber#blocking?" do + it_behaves_like :non_blocking_fiber, -> { Fiber.current.blocking? } - blocking.should == 1 - end + context "when fiber is blocking" do + context "root Fiber of the main thread" do + it "returns true for blocking: true" do + fiber = Fiber.new(blocking: true) { Fiber.current.blocking? } + blocking = fiber.resume - thread.join - end + blocking.should == true end end - end - describe "Fiber#blocking?" do - it_behaves_like :non_blocking_fiber, -> { Fiber.current.blocking? } - - context "when fiber is blocking" do - context "root Fiber of the main thread" do - it "returns true for blocking: true" do + context "root Fiber of a new thread" do + it "returns true for blocking: true" do + thread = Thread.new do fiber = Fiber.new(blocking: true) { Fiber.current.blocking? } blocking = fiber.resume blocking.should == true end - end - context "root Fiber of a new thread" do - it "returns true for blocking: true" do - thread = Thread.new do - fiber = Fiber.new(blocking: true) { Fiber.current.blocking? } - blocking = fiber.resume - - blocking.should == true - end - - thread.join - end + thread.join end end end diff --git a/core/fiber/inspect_spec.rb b/core/fiber/inspect_spec.rb index ee53af3a39..f20a153fc2 100644 --- a/core/fiber/inspect_spec.rb +++ b/core/fiber/inspect_spec.rb @@ -18,11 +18,9 @@ inspected.should =~ /\A#\z/ end - ruby_version_is "3.0" do - it "is resumed for a Fiber which was transferred" do - inspected = Fiber.new { Fiber.current.inspect }.transfer - inspected.should =~ /\A#\z/ - end + it "is resumed for a Fiber which was transferred" do + inspected = Fiber.new { Fiber.current.inspect }.transfer + inspected.should =~ /\A#\z/ end it "is suspended for a Fiber which was resumed and yielded" do diff --git a/core/fiber/raise_spec.rb b/core/fiber/raise_spec.rb index 09c4c1b524..eb4b39c8be 100644 --- a/core/fiber/raise_spec.rb +++ b/core/fiber/raise_spec.rb @@ -94,26 +94,12 @@ end -ruby_version_is ""..."3.0" do - describe "Fiber#raise" do - it "raises a FiberError if invoked on a transferring Fiber" do - require "fiber" - root = Fiber.current - fiber = Fiber.new { root.transfer } - fiber.transfer - -> { fiber.raise }.should raise_error(FiberError, "cannot resume transferred Fiber") - end - end -end - -ruby_version_is "3.0" do - describe "Fiber#raise" do - it "transfers and raises on a transferring fiber" do - require "fiber" - root = Fiber.current - fiber = Fiber.new { root.transfer } - fiber.transfer - -> { fiber.raise "msg" }.should raise_error(RuntimeError, "msg") - end +describe "Fiber#raise" do + it "transfers and raises on a transferring fiber" do + require "fiber" + root = Fiber.current + fiber = Fiber.new { root.transfer } + fiber.transfer + -> { fiber.raise "msg" }.should raise_error(RuntimeError, "msg") end end diff --git a/core/fiber/resume_spec.rb b/core/fiber/resume_spec.rb index 273bc866af..ab9a6799ab 100644 --- a/core/fiber/resume_spec.rb +++ b/core/fiber/resume_spec.rb @@ -28,18 +28,9 @@ fiber.resume :second end - ruby_version_is '3.0' do - it "raises a FiberError if the Fiber tries to resume itself" do - fiber = Fiber.new { fiber.resume } - -> { fiber.resume }.should raise_error(FiberError, /current fiber/) - end - end - - ruby_version_is '' ... '3.0' do - it "raises a FiberError if the Fiber tries to resume itself" do - fiber = Fiber.new { fiber.resume } - -> { fiber.resume }.should raise_error(FiberError, /double resume/) - end + it "raises a FiberError if the Fiber tries to resume itself" do + fiber = Fiber.new { fiber.resume } + -> { fiber.resume }.should raise_error(FiberError, /current fiber/) end it "returns control to the calling Fiber if called from one" do diff --git a/core/file/new_spec.rb b/core/file/new_spec.rb index a1ca46979e..715ac1aaf3 100644 --- a/core/file/new_spec.rb +++ b/core/file/new_spec.rb @@ -168,16 +168,14 @@ File.should.exist?(@file) end - ruby_version_is "3.0" do - it "accepts options as a keyword argument" do - @fh = File.new(@file, 'w', 0755, flags: @flags) - @fh.should be_kind_of(File) - @fh.close + it "accepts options as a keyword argument" do + @fh = File.new(@file, 'w', 0755, flags: @flags) + @fh.should be_kind_of(File) + @fh.close - -> { - @fh = File.new(@file, 'w', 0755, {flags: @flags}) - }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") - end + -> { + @fh = File.new(@file, 'w', 0755, {flags: @flags}) + }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") end it "bitwise-ORs mode and flags option" do diff --git a/core/file/open_spec.rb b/core/file/open_spec.rb index 0c6d6cd19c..0346224b93 100644 --- a/core/file/open_spec.rb +++ b/core/file/open_spec.rb @@ -565,15 +565,13 @@ File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::BINARY} end - ruby_version_is "3.0" do - it "accepts options as a keyword argument" do - @fh = File.open(@file, 'w', 0755, flags: File::CREAT) - @fh.should be_an_instance_of(File) + it "accepts options as a keyword argument" do + @fh = File.open(@file, 'w', 0755, flags: File::CREAT) + @fh.should be_an_instance_of(File) - -> { - File.open(@file, 'w', 0755, {flags: File::CREAT}) - }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") - end + -> { + File.open(@file, 'w', 0755, {flags: File::CREAT}) + }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") end it "uses the second argument as an options Hash" do diff --git a/core/gc/auto_compact_spec.rb b/core/gc/auto_compact_spec.rb index 4f9d043171..33ad1cb56c 100644 --- a/core/gc/auto_compact_spec.rb +++ b/core/gc/auto_compact_spec.rb @@ -1,26 +1,24 @@ require_relative '../../spec_helper' -ruby_version_is "3.0" do - describe "GC.auto_compact" do - it "can set and get a boolean value" do - begin - GC.auto_compact = GC.auto_compact - rescue NotImplementedError # platform does not support autocompact - skip - end +describe "GC.auto_compact" do + it "can set and get a boolean value" do + begin + GC.auto_compact = GC.auto_compact + rescue NotImplementedError # platform does not support autocompact + skip + end - original = GC.auto_compact - begin - GC.auto_compact = !original - rescue NotImplementedError # platform does not support autocompact - skip - end + original = GC.auto_compact + begin + GC.auto_compact = !original + rescue NotImplementedError # platform does not support autocompact + skip + end - begin - GC.auto_compact.should == !original - ensure - GC.auto_compact = original - end + begin + GC.auto_compact.should == !original + ensure + GC.auto_compact = original end end end diff --git a/core/hash/except_spec.rb b/core/hash/except_spec.rb index 82cfced72f..ac84f9975c 100644 --- a/core/hash/except_spec.rb +++ b/core/hash/except_spec.rb @@ -1,34 +1,32 @@ require_relative '../../spec_helper' -ruby_version_is "3.0" do - describe "Hash#except" do - before :each do - @hash = { a: 1, b: 2, c: 3 } - end +describe "Hash#except" do + before :each do + @hash = { a: 1, b: 2, c: 3 } + end - it "returns a new duplicate hash without arguments" do - ret = @hash.except - ret.should_not equal(@hash) - ret.should == @hash - end + it "returns a new duplicate hash without arguments" do + ret = @hash.except + ret.should_not equal(@hash) + ret.should == @hash + end - it "returns a hash without the requested subset" do - @hash.except(:c, :a).should == { b: 2 } - end + it "returns a hash without the requested subset" do + @hash.except(:c, :a).should == { b: 2 } + end - it "ignores keys not present in the original hash" do - @hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 } - end + it "ignores keys not present in the original hash" do + @hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 } + end - it "always returns a Hash without a default" do - klass = Class.new(Hash) - h = klass.new(:default) - h[:bar] = 12 - h[:foo] = 42 - r = h.except(:foo) - r.should == {bar: 12} - r.class.should == Hash - r.default.should == nil - end + it "always returns a Hash without a default" do + klass = Class.new(Hash) + h = klass.new(:default) + h[:bar] = 12 + h[:foo] = 42 + r = h.except(:foo) + r.should == {bar: 12} + r.class.should == Hash + r.default.should == nil end end diff --git a/core/hash/index_spec.rb b/core/hash/index_spec.rb deleted file mode 100644 index be4e2cc6ab..0000000000 --- a/core/hash/index_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/index' - -ruby_version_is ''...'3.0' do - describe "Hash#index" do - it_behaves_like :hash_index, :index - end -end diff --git a/core/hash/shared/each.rb b/core/hash/shared/each.rb index b2483c8116..f9839ff58f 100644 --- a/core/hash/shared/each.rb +++ b/core/hash/shared/each.rb @@ -21,37 +21,18 @@ ary.sort.should == ["a", "b", "c"] end - ruby_version_is ""..."3.0" do - it "yields 2 values and not an Array of 2 elements when given a callable of arity 2" do - obj = Object.new - def obj.foo(key, value) - ScratchPad << key << value - end - - ScratchPad.record([]) - { "a" => 1 }.send(@method, &obj.method(:foo)) - ScratchPad.recorded.should == ["a", 1] - - ScratchPad.record([]) - { "a" => 1 }.send(@method, &-> key, value { ScratchPad << key << value }) - ScratchPad.recorded.should == ["a", 1] + it "always yields an Array of 2 elements, even when given a callable of arity 2" do + obj = Object.new + def obj.foo(key, value) end - end - - ruby_version_is "3.0" do - it "always yields an Array of 2 elements, even when given a callable of arity 2" do - obj = Object.new - def obj.foo(key, value) - end - -> { - { "a" => 1 }.send(@method, &obj.method(:foo)) - }.should raise_error(ArgumentError) + -> { + { "a" => 1 }.send(@method, &obj.method(:foo)) + }.should raise_error(ArgumentError) - -> { - { "a" => 1 }.send(@method, &-> key, value { }) - }.should raise_error(ArgumentError) - end + -> { + { "a" => 1 }.send(@method, &-> key, value { }) + }.should raise_error(ArgumentError) end it "yields an Array of 2 elements when given a callable of arity 1" do diff --git a/core/hash/to_a_spec.rb b/core/hash/to_a_spec.rb index 8b7894a2ba..5baf677929 100644 --- a/core/hash/to_a_spec.rb +++ b/core/hash/to_a_spec.rb @@ -26,14 +26,4 @@ ent.should be_kind_of(Array) ent.should == pairs end - - ruby_version_is ''...'3.0' do - it "returns a not tainted array if self is tainted" do - {}.taint.to_a.tainted?.should be_false - end - - it "returns a trusted array if self is untrusted" do - {}.untrust.to_a.untrusted?.should be_false - end - end end diff --git a/core/hash/to_proc_spec.rb b/core/hash/to_proc_spec.rb index 8f5d21beb5..9dbc79e5eb 100644 --- a/core/hash/to_proc_spec.rb +++ b/core/hash/to_proc_spec.rb @@ -19,20 +19,12 @@ @proc = @hash.to_proc end - ruby_version_is ""..."3.0" do - it "is not a lambda" do - @proc.should_not.lambda? - end + it "is a lambda" do + @proc.should.lambda? end - ruby_version_is "3.0" do - it "is a lambda" do - @proc.should.lambda? - end - - it "has an arity of 1" do - @proc.arity.should == 1 - end + it "has an arity of 1" do + @proc.arity.should == 1 end it "raises ArgumentError if not passed exactly one argument" do diff --git a/core/hash/transform_keys_spec.rb b/core/hash/transform_keys_spec.rb index 361089ca97..2fbb17a8e2 100644 --- a/core/hash/transform_keys_spec.rb +++ b/core/hash/transform_keys_spec.rb @@ -43,18 +43,16 @@ r.class.should == Hash end - ruby_version_is "3.0" do - it "allows a hash argument" do - @hash.transform_keys({ a: :A, b: :B, c: :C }).should == { A: 1, B: 2, C: 3 } - end + it "allows a hash argument" do + @hash.transform_keys({ a: :A, b: :B, c: :C }).should == { A: 1, B: 2, C: 3 } + end - it "allows a partial transformation of keys when using a hash argument" do - @hash.transform_keys({ a: :A, c: :C }).should == { A: 1, b: 2, C: 3 } - end + it "allows a partial transformation of keys when using a hash argument" do + @hash.transform_keys({ a: :A, c: :C }).should == { A: 1, b: 2, C: 3 } + end - it "allows a combination of hash and block argument" do - @hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 } - end + it "allows a combination of hash and block argument" do + @hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 } end end @@ -111,11 +109,9 @@ end end - ruby_version_is "3.0" do - it "allows a hash argument" do - @hash.transform_keys!({ a: :A, b: :B, c: :C, d: :D }) - @hash.should == { A: 1, B: 2, C: 3, D: 4 } - end + it "allows a hash argument" do + @hash.transform_keys!({ a: :A, b: :B, c: :C, d: :D }) + @hash.should == { A: 1, B: 2, C: 3, D: 4 } end describe "on frozen instance" do @@ -132,10 +128,8 @@ @hash.should == @initial_pairs end - ruby_version_is "3.0" do - it "raises a FrozenError on hash argument" do - ->{ @hash.transform_keys!({ a: :A, b: :B, c: :C }) }.should raise_error(FrozenError) - end + it "raises a FrozenError on hash argument" do + ->{ @hash.transform_keys!({ a: :A, b: :B, c: :C }) }.should raise_error(FrozenError) end context "when no block is given" do diff --git a/core/integer/zero_spec.rb b/core/integer/zero_spec.rb index 2dac50c406..bd362c4181 100644 --- a/core/integer/zero_spec.rb +++ b/core/integer/zero_spec.rb @@ -7,15 +7,7 @@ -1.should_not.zero? end - ruby_version_is "3.0" do - it "Integer#zero? overrides Numeric#zero?" do - 42.method(:zero?).owner.should == Integer - end - end - - ruby_version_is ""..."3.0" do - it "Integer#zero? uses Numeric#zero?" do - 42.method(:zero?).owner.should == Numeric - end + it "Integer#zero? overrides Numeric#zero?" do + 42.method(:zero?).owner.should == Integer end end diff --git a/core/io/bytes_spec.rb b/core/io/bytes_spec.rb deleted file mode 100644 index 6e328983f2..0000000000 --- a/core/io/bytes_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -*- encoding: utf-8 -*- -require_relative '../../spec_helper' -require_relative 'fixtures/classes' - -ruby_version_is ''...'3.0' do - describe "IO#bytes" do - before :each do - @io = IOSpecs.io_fixture "lines.txt" - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - @io.close unless @io.closed? - end - - it "returns an enumerator of the next bytes from the stream" do - enum = @io.bytes - enum.should be_an_instance_of(Enumerator) - @io.readline.should == "Voici la ligne une.\n" - enum.first(5).should == [81, 117, 105, 32, 195] - end - - it "yields each byte" do - count = 0 - ScratchPad.record [] - @io.each_byte do |byte| - ScratchPad << byte - break if 4 < count += 1 - end - - ScratchPad.recorded.should == [86, 111, 105, 99, 105] - end - - it "raises an IOError on closed stream" do - enum = IOSpecs.closed_io.bytes - -> { enum.first }.should raise_error(IOError) - end - - it "raises an IOError on an enumerator for a stream that has been closed" do - enum = @io.bytes - enum.first.should == 86 - @io.close - -> { enum.first }.should raise_error(IOError) - end - end -end diff --git a/core/io/chars_spec.rb b/core/io/chars_spec.rb deleted file mode 100644 index 15db595aed..0000000000 --- a/core/io/chars_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# -*- encoding: utf-8 -*- -require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/chars' - -ruby_version_is ''...'3.0' do - describe "IO#chars" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :io_chars, :chars - end - - describe "IO#chars" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :io_chars_empty, :chars - end -end diff --git a/core/io/codepoints_spec.rb b/core/io/codepoints_spec.rb deleted file mode 100644 index 04c115dd3f..0000000000 --- a/core/io/codepoints_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/codepoints' - -ruby_version_is ''...'3.0' do - - # See redmine #1667 - describe "IO#codepoints" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :io_codepoints, :codepoints - end - - describe "IO#codepoints" do - before :each do - @io = IOSpecs.io_fixture "lines.txt" - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - @io.close unless @io.closed? - end - - it "calls the given block" do - r = [] - @io.codepoints { |c| r << c } - r[24].should == 232 - r.last.should == 10 - end - end -end diff --git a/core/io/gets_spec.rb b/core/io/gets_spec.rb index f38e3d3974..73d76b3abd 100644 --- a/core/io/gets_spec.rb +++ b/core/io/gets_spec.rb @@ -149,14 +149,12 @@ @io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0] end - ruby_version_is "3.0" do - it "raises exception when options passed as Hash" do - -> { @io.gets({ chomp: true }) }.should raise_error(TypeError) + it "raises exception when options passed as Hash" do + -> { @io.gets({ chomp: true }) }.should raise_error(TypeError) - -> { - @io.gets("\n", 1, { chomp: true }) - }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") - end + -> { + @io.gets("\n", 1, { chomp: true }) + }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") end end end diff --git a/core/io/initialize_spec.rb b/core/io/initialize_spec.rb index 28fd7af7ab..026252a13d 100644 --- a/core/io/initialize_spec.rb +++ b/core/io/initialize_spec.rb @@ -27,17 +27,15 @@ @io.fileno.should == fd end - ruby_version_is "3.0" do - it "accepts options as keyword arguments" do - fd = new_fd @name, "w:utf-8" + it "accepts options as keyword arguments" do + fd = new_fd @name, "w:utf-8" - @io.send(:initialize, fd, "w", flags: File::CREAT) - @io.fileno.should == fd + @io.send(:initialize, fd, "w", flags: File::CREAT) + @io.fileno.should == fd - -> { - @io.send(:initialize, fd, "w", {flags: File::CREAT}) - }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)") - end + -> { + @io.send(:initialize, fd, "w", {flags: File::CREAT}) + }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)") end it "raises a TypeError when passed an IO" do diff --git a/core/io/lines_spec.rb b/core/io/lines_spec.rb deleted file mode 100644 index 5b29a1d07e..0000000000 --- a/core/io/lines_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# -*- encoding: utf-8 -*- -require_relative '../../spec_helper' -require_relative 'fixtures/classes' - -ruby_version_is ''...'3.0' do - describe "IO#lines" do - before :each do - @io = IOSpecs.io_fixture "lines.txt" - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - @io.close if @io - end - - it "returns an Enumerator" do - @io.lines.should be_an_instance_of(Enumerator) - end - - describe "when no block is given" do - it "returns an Enumerator" do - @io.lines.should be_an_instance_of(Enumerator) - end - - describe "returned Enumerator" do - describe "size" do - it "should return nil" do - @io.lines.size.should == nil - end - end - end - end - - it "returns a line when accessed" do - enum = @io.lines - enum.first.should == IOSpecs.lines[0] - end - - it "yields each line to the passed block" do - ScratchPad.record [] - @io.lines { |s| ScratchPad << s } - ScratchPad.recorded.should == IOSpecs.lines - end - end -end diff --git a/core/io/nonblock_spec.rb b/core/io/nonblock_spec.rb index e81ac10c58..99dc0cafd0 100644 --- a/core/io/nonblock_spec.rb +++ b/core/io/nonblock_spec.rb @@ -12,43 +12,21 @@ end end - ruby_version_is ""..."3.0" do - it "returns false for pipe by default" do - r, w = IO.pipe - begin - r.nonblock?.should == false - w.nonblock?.should == false - ensure - r.close - w.close - end - end - - it "returns false for socket by default" do - require 'socket' - TCPServer.open(0) do |socket| - socket.nonblock?.should == false - end + it "returns true for pipe by default" do + r, w = IO.pipe + begin + r.nonblock?.should == true + w.nonblock?.should == true + ensure + r.close + w.close end end - ruby_version_is "3.0" do - it "returns true for pipe by default" do - r, w = IO.pipe - begin - r.nonblock?.should == true - w.nonblock?.should == true - ensure - r.close - w.close - end - end - - it "returns true for socket by default" do - require 'socket' - TCPServer.open(0) do |socket| - socket.nonblock?.should == true - end + it "returns true for socket by default" do + require 'socket' + TCPServer.open(0) do |socket| + socket.nonblock?.should == true end end end diff --git a/core/io/read_spec.rb b/core/io/read_spec.rb index 8bffd50876..a829ffd18c 100644 --- a/core/io/read_spec.rb +++ b/core/io/read_spec.rb @@ -23,15 +23,13 @@ IO.read(p) end - ruby_version_is "3.0" do - # https://bugs.ruby-lang.org/issues/19354 - it "accepts options as keyword arguments" do - IO.read(@fname, 3, 0, mode: "r+").should == @contents[0, 3] + # https://bugs.ruby-lang.org/issues/19354 + it "accepts options as keyword arguments" do + IO.read(@fname, 3, 0, mode: "r+").should == @contents[0, 3] - -> { - IO.read(@fname, 3, 0, {mode: "r+"}) - }.should raise_error(ArgumentError, /wrong number of arguments/) - end + -> { + IO.read(@fname, 3, 0, {mode: "r+"}) + }.should raise_error(ArgumentError, /wrong number of arguments/) end it "accepts an empty options Hash" do diff --git a/core/io/readline_spec.rb b/core/io/readline_spec.rb index cf9f0dfc11..a814c1be90 100644 --- a/core/io/readline_spec.rb +++ b/core/io/readline_spec.rb @@ -73,14 +73,12 @@ @io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0] end - ruby_version_is "3.0" do - it "raises exception when options passed as Hash" do - -> { @io.readline({ chomp: true }) }.should raise_error(TypeError) + it "raises exception when options passed as Hash" do + -> { @io.readline({ chomp: true }) }.should raise_error(TypeError) - -> { - @io.readline("\n", 1, { chomp: true }) - }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") - end + -> { + @io.readline("\n", 1, { chomp: true }) + }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") end end end diff --git a/core/io/readlines_spec.rb b/core/io/readlines_spec.rb index 43d0750a72..d6c4d539cf 100644 --- a/core/io/readlines_spec.rb +++ b/core/io/readlines_spec.rb @@ -117,14 +117,12 @@ @io.readlines(chomp: true).should == IOSpecs.lines_without_newline_characters end - ruby_version_is "3.0" do - it "raises exception when options passed as Hash" do - -> { @io.readlines({ chomp: true }) }.should raise_error(TypeError) + it "raises exception when options passed as Hash" do + -> { @io.readlines({ chomp: true }) }.should raise_error(TypeError) - -> { - @io.readlines("\n", 1, { chomp: true }) - }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") - end + -> { + @io.readlines("\n", 1, { chomp: true }) + }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") end end diff --git a/core/io/shared/binwrite.rb b/core/io/shared/binwrite.rb index 950a6f51ab..e51093329b 100644 --- a/core/io/shared/binwrite.rb +++ b/core/io/shared/binwrite.rb @@ -21,14 +21,12 @@ IO.send(@method, @filename, "abcde").should == 5 end - ruby_version_is "3.0" do - it "accepts options as a keyword argument" do - IO.send(@method, @filename, "hi", 0, flags: File::CREAT).should == 2 + it "accepts options as a keyword argument" do + IO.send(@method, @filename, "hi", 0, flags: File::CREAT).should == 2 - -> { - IO.send(@method, @filename, "hi", 0, {flags: File::CREAT}) - }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 2..3)") - end + -> { + IO.send(@method, @filename, "hi", 0, {flags: File::CREAT}) + }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 2..3)") end it "creates a file if missing" do diff --git a/core/io/shared/each.rb b/core/io/shared/each.rb index 02bbe19c1a..dbc0178dd6 100644 --- a/core/io/shared/each.rb +++ b/core/io/shared/each.rb @@ -180,16 +180,14 @@ ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters end - ruby_version_is "3.0" do - it "raises exception when options passed as Hash" do - -> { - @io.send(@method, { chomp: true }) { |s| } - }.should raise_error(TypeError) - - -> { - @io.send(@method, "\n", 1, { chomp: true }) { |s| } - }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") - end + it "raises exception when options passed as Hash" do + -> { + @io.send(@method, { chomp: true }) { |s| } + }.should raise_error(TypeError) + + -> { + @io.send(@method, "\n", 1, { chomp: true }) { |s| } + }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 0..2)") end end diff --git a/core/io/shared/new.rb b/core/io/shared/new.rb index da4c0af7a9..99b19e6a1b 100644 --- a/core/io/shared/new.rb +++ b/core/io/shared/new.rb @@ -64,15 +64,13 @@ @io.should be_an_instance_of(IO) end - ruby_version_is "3.0" do - it "accepts options as keyword arguments" do - @io = IO.send(@method, @fd, "w", flags: File::CREAT) - @io.write("foo").should == 3 - - -> { - IO.send(@method, @fd, "w", {flags: File::CREAT}) - }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)") - end + it "accepts options as keyword arguments" do + @io = IO.send(@method, @fd, "w", flags: File::CREAT) + @io.write("foo").should == 3 + + -> { + IO.send(@method, @fd, "w", {flags: File::CREAT}) + }.should raise_error(ArgumentError, "wrong number of arguments (given 3, expected 1..2)") end it "accepts a :mode option" do @@ -210,21 +208,10 @@ @io.internal_encoding.to_s.should == 'IBM866' end - ruby_version_is ''...'3.0' do - it "accepts nil options" do - @io = suppress_keyword_warning do - IO.send(@method, @fd, 'w', nil) - end - @io.write("foo").should == 3 - end - end - - ruby_version_is '3.0' do - it "raises ArgumentError for nil options" do - -> { - IO.send(@method, @fd, 'w', nil) - }.should raise_error(ArgumentError) - end + it "raises ArgumentError for nil options" do + -> { + IO.send(@method, @fd, 'w', nil) + }.should raise_error(ArgumentError) end it "coerces mode with #to_str" do @@ -395,21 +382,9 @@ }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it "raises TypeError if passed a hash for mode and nil for options" do - -> { - suppress_keyword_warning do - @io = IO.send(@method, @fd, {mode: 'w'}, nil) - end - }.should raise_error(TypeError) - end - end - - ruby_version_is '3.0' do - it "raises ArgumentError if passed a hash for mode and nil for options" do - -> { - @io = IO.send(@method, @fd, {mode: 'w'}, nil) - }.should raise_error(ArgumentError) - end + it "raises ArgumentError if passed a hash for mode and nil for options" do + -> { + @io = IO.send(@method, @fd, {mode: 'w'}, nil) + }.should raise_error(ArgumentError) end end diff --git a/core/io/shared/readlines.rb b/core/io/shared/readlines.rb index 7681e1b5c1..d2b604bba3 100644 --- a/core/io/shared/readlines.rb +++ b/core/io/shared/readlines.rb @@ -105,12 +105,10 @@ end describe "when the object is an options Hash" do - ruby_version_is "3.0" do - it "raises TypeError exception" do - -> { - IO.send(@method, @name, { chomp: true }, &@object) - }.should raise_error(TypeError) - end + it "raises TypeError exception" do + -> { + IO.send(@method, @name, { chomp: true }, &@object) + }.should raise_error(TypeError) end end @@ -179,12 +177,10 @@ end describe "when the second object is an options Hash" do - ruby_version_is "3.0" do - it "raises TypeError exception" do - -> { - IO.send(@method, @name, "", { chomp: true }, &@object) - }.should raise_error(TypeError) - end + it "raises TypeError exception" do + -> { + IO.send(@method, @name, "", { chomp: true }, &@object) + }.should raise_error(TypeError) end end end diff --git a/core/io/ungetc_spec.rb b/core/io/ungetc_spec.rb index 41a455c836..47a4e99ebf 100644 --- a/core/io/ungetc_spec.rb +++ b/core/io/ungetc_spec.rb @@ -103,19 +103,9 @@ -> { @io.sysread(1) }.should raise_error(IOError) end - ruby_version_is ""..."3.0" do - it "does not affect the stream and returns nil when passed nil" do - @io.getc.should == ?V - @io.ungetc(nil) - @io.getc.should == ?o - end - end - - ruby_version_is "3.0" do - it "raises TypeError if passed nil" do - @io.getc.should == ?V - proc{@io.ungetc(nil)}.should raise_error(TypeError) - end + it "raises TypeError if passed nil" do + @io.getc.should == ?V + proc{@io.ungetc(nil)}.should raise_error(TypeError) end it "puts one or more characters back in the stream" do diff --git a/core/io/write_spec.rb b/core/io/write_spec.rb index bf23634372..3f04fb053f 100644 --- a/core/io/write_spec.rb +++ b/core/io/write_spec.rb @@ -259,25 +259,23 @@ end end -ruby_version_is "3.0" do - describe "IO#write on STDOUT" do - # https://bugs.ruby-lang.org/issues/14413 - platform_is_not :windows do - it "raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs" do - stderr_file = tmp("stderr") - begin - IO.popen([*ruby_exe, "-e", "loop { puts :ok }"], "r", err: stderr_file) do |io| - io.gets.should == "ok\n" - io.close - end - status = $? - status.should_not.success? - status.should.signaled? - Signal.signame(status.termsig).should == 'PIPE' - File.read(stderr_file).should.empty? - ensure - rm_r stderr_file +describe "IO#write on STDOUT" do + # https://bugs.ruby-lang.org/issues/14413 + platform_is_not :windows do + it "raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs" do + stderr_file = tmp("stderr") + begin + IO.popen([*ruby_exe, "-e", "loop { puts :ok }"], "r", err: stderr_file) do |io| + io.gets.should == "ok\n" + io.close end + status = $? + status.should_not.success? + status.should.signaled? + Signal.signame(status.termsig).should == 'PIPE' + File.read(stderr_file).should.empty? + ensure + rm_r stderr_file end end end diff --git a/core/kernel/__dir___spec.rb b/core/kernel/__dir___spec.rb index 324792a408..242adbf48b 100644 --- a/core/kernel/__dir___spec.rb +++ b/core/kernel/__dir___spec.rb @@ -19,19 +19,9 @@ end end - ruby_version_is ""..."3.0" do - context "when used in eval with top level binding" do - it "returns the real name of the directory containing the currently-executing file" do - eval("__dir__", binding).should == File.realpath(File.dirname(__FILE__)) - end - end - end - - ruby_version_is "3.0" do - context "when used in eval with top level binding" do - it "returns nil" do - eval("__dir__", binding).should == nil - end + context "when used in eval with top level binding" do + it "returns nil" do + eval("__dir__", binding).should == nil end end end diff --git a/core/kernel/clone_spec.rb b/core/kernel/clone_spec.rb index a87c7544fe..5adcbbe603 100644 --- a/core/kernel/clone_spec.rb +++ b/core/kernel/clone_spec.rb @@ -45,26 +45,18 @@ def klass.allocate end describe "with freeze: nil" do - ruby_version_is ""..."3.0" do - it "raises ArgumentError" do - -> { @obj.clone(freeze: nil) }.should raise_error(ArgumentError, /unexpected value for freeze: NilClass/) - end - end - - ruby_version_is "3.0" do - it "copies frozen state from the original, like #clone without arguments" do - o2 = @obj.clone(freeze: nil) - o2.should_not.frozen? + it "copies frozen state from the original, like #clone without arguments" do + o2 = @obj.clone(freeze: nil) + o2.should_not.frozen? - @obj.freeze - o3 = @obj.clone(freeze: nil) - o3.should.frozen? - end + @obj.freeze + o3 = @obj.clone(freeze: nil) + o3.should.frozen? + end - it "copies frozen?" do - o = "".freeze.clone(freeze: nil) - o.frozen?.should be_true - end + it "copies frozen?" do + o = "".freeze.clone(freeze: nil) + o.frozen?.should be_true end end @@ -74,33 +66,19 @@ def klass.allocate @obj.clone(freeze: true).should.frozen? end - ruby_version_is ''...'3.0' do - it 'does not freeze the copy even if the original is not frozen' do - @obj.clone(freeze: true).should_not.frozen? - end - - it "calls #initialize_clone with no kwargs" do - obj = KernelSpecs::CloneFreeze.new - obj.clone(freeze: true) - ScratchPad.recorded.should == [obj, {}] - end + it 'freezes the copy even if the original was not frozen' do + @obj.clone(freeze: true).should.frozen? end - ruby_version_is '3.0' do - it 'freezes the copy even if the original was not frozen' do - @obj.clone(freeze: true).should.frozen? - end - - it "calls #initialize_clone with kwargs freeze: true" do - obj = KernelSpecs::CloneFreeze.new - obj.clone(freeze: true) - ScratchPad.recorded.should == [obj, { freeze: true }] - end + it "calls #initialize_clone with kwargs freeze: true" do + obj = KernelSpecs::CloneFreeze.new + obj.clone(freeze: true) + ScratchPad.recorded.should == [obj, { freeze: true }] + end - it "calls #initialize_clone with kwargs freeze: true even if #initialize_clone only takes a single argument" do - obj = KernelSpecs::Clone.new - -> { obj.clone(freeze: true) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') - end + it "calls #initialize_clone with kwargs freeze: true even if #initialize_clone only takes a single argument" do + obj = KernelSpecs::Clone.new + -> { obj.clone(freeze: true) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') end end @@ -114,25 +92,15 @@ def klass.allocate @obj.clone(freeze: false).should_not.frozen? end - ruby_version_is ''...'3.0' do - it "calls #initialize_clone with no kwargs" do - obj = KernelSpecs::CloneFreeze.new - obj.clone(freeze: false) - ScratchPad.recorded.should == [obj, {}] - end + it "calls #initialize_clone with kwargs freeze: false" do + obj = KernelSpecs::CloneFreeze.new + obj.clone(freeze: false) + ScratchPad.recorded.should == [obj, { freeze: false }] end - ruby_version_is '3.0' do - it "calls #initialize_clone with kwargs freeze: false" do - obj = KernelSpecs::CloneFreeze.new - obj.clone(freeze: false) - ScratchPad.recorded.should == [obj, { freeze: false }] - end - - it "calls #initialize_clone with kwargs freeze: false even if #initialize_clone only takes a single argument" do - obj = KernelSpecs::Clone.new - -> { obj.clone(freeze: false) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') - end + it "calls #initialize_clone with kwargs freeze: false even if #initialize_clone only takes a single argument" do + obj = KernelSpecs::Clone.new + -> { obj.clone(freeze: false) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') end end diff --git a/core/kernel/eval_spec.rb b/core/kernel/eval_spec.rb index 9be0f2dfd3..e6761ab789 100644 --- a/core/kernel/eval_spec.rb +++ b/core/kernel/eval_spec.rb @@ -159,37 +159,18 @@ class Object end end - ruby_version_is ""..."3.0" do - it "uses the filename of the binding if none is provided" do - eval("__FILE__").should == "(eval)" - suppress_warning {eval("__FILE__", binding)}.should == __FILE__ - eval("__FILE__", binding, "success").should == "success" - suppress_warning {eval("eval '__FILE__', binding")}.should == "(eval)" - suppress_warning {eval("eval '__FILE__', binding", binding)}.should == __FILE__ - suppress_warning {eval("eval '__FILE__', binding", binding, 'success')}.should == 'success' - end - - it 'uses the given binding file and line for __FILE__ and __LINE__' do - suppress_warning { - eval("[__FILE__, __LINE__]", binding).should == [__FILE__, __LINE__] - } - end - end - - ruby_version_is "3.0" do - it "uses (eval) filename if none is provided" do - eval("__FILE__").should == "(eval)" - eval("__FILE__", binding).should == "(eval)" - eval("__FILE__", binding, "success").should == "success" - eval("eval '__FILE__', binding").should == "(eval)" - eval("eval '__FILE__', binding", binding).should == "(eval)" - eval("eval '__FILE__', binding", binding, 'success').should == '(eval)' - eval("eval '__FILE__', binding, 'success'", binding).should == 'success' - end - - it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do - eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1] - end + it "uses (eval) filename if none is provided" do + eval("__FILE__").should == "(eval)" + eval("__FILE__", binding).should == "(eval)" + eval("__FILE__", binding, "success").should == "success" + eval("eval '__FILE__', binding").should == "(eval)" + eval("eval '__FILE__', binding", binding).should == "(eval)" + eval("eval '__FILE__', binding", binding, 'success').should == '(eval)' + eval("eval '__FILE__', binding, 'success'", binding).should == 'success' + end + + it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do + eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1] end # Found via Rubinius bug github:#149 diff --git a/core/kernel/initialize_clone_spec.rb b/core/kernel/initialize_clone_spec.rb index 2d889f5aad..21a90c19f0 100644 --- a/core/kernel/initialize_clone_spec.rb +++ b/core/kernel/initialize_clone_spec.rb @@ -18,11 +18,9 @@ a.send(:initialize_clone, b) end - ruby_version_is "3.0" do - it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do - a = Object.new - b = Object.new - a.send(:initialize_clone, b, freeze: true).should == a - end + it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do + a = Object.new + b = Object.new + a.send(:initialize_clone, b, freeze: true).should == a end end diff --git a/core/kernel/iterator_spec.rb b/core/kernel/iterator_spec.rb deleted file mode 100644 index 3fe8317f26..0000000000 --- a/core/kernel/iterator_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/classes' - -ruby_version_is ""..."3.0" do - describe "Kernel#iterator?" do - it "is a private method" do - Kernel.should have_private_instance_method(:iterator?) - end - end - - describe "Kernel.iterator?" do - it "needs to be reviewed for spec completeness" - end -end diff --git a/core/kernel/lambda_spec.rb b/core/kernel/lambda_spec.rb index 2aa4d4f2fb..2f7abc749c 100644 --- a/core/kernel/lambda_spec.rb +++ b/core/kernel/lambda_spec.rb @@ -136,15 +136,13 @@ def ret klass.new.ret.should == 1 end - ruby_version_is "3.0" do - context "when called without a literal block" do - it "warns when proc isn't a lambda" do - -> { lambda(&proc{}) }.should complain("#{__FILE__}:#{__LINE__}: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n") - end + context "when called without a literal block" do + it "warns when proc isn't a lambda" do + -> { lambda(&proc{}) }.should complain("#{__FILE__}:#{__LINE__}: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n") + end - it "doesn't warn when proc is lambda" do - -> { lambda(&lambda{}) }.should_not complain(verbose: true) - end + it "doesn't warn when proc is lambda" do + -> { lambda(&lambda{}) }.should_not complain(verbose: true) end end end diff --git a/core/kernel/open_spec.rb b/core/kernel/open_spec.rb index bad2ae9d2c..99793294c5 100644 --- a/core/kernel/open_spec.rb +++ b/core/kernel/open_spec.rb @@ -72,15 +72,13 @@ -> { open }.should raise_error(ArgumentError) end - ruby_version_is "3.0" do - it "accepts options as keyword arguments" do - @file = open(@name, "r", 0666, flags: File::CREAT) - @file.should be_kind_of(File) + it "accepts options as keyword arguments" do + @file = open(@name, "r", 0666, flags: File::CREAT) + @file.should be_kind_of(File) - -> { - open(@name, "r", 0666, {flags: File::CREAT}) - }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") - end + -> { + open(@name, "r", 0666, {flags: File::CREAT}) + }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") end describe "when given an object that responds to to_open" do @@ -158,28 +156,14 @@ def obj.to_open(*args, **kw) open(@name, nil, nil) { |f| f.gets }.should == @content end - ruby_version_is ""..."3.0" do - it "works correctly when redefined by open-uri" do - code = <<~RUBY + it "is not redefined by open-uri" do + code = <<~RUBY + before = Kernel.instance_method(:open) require 'open-uri' - obj = Object.new - def obj.to_open; self; end - p open(obj) == obj - RUBY - ruby_exe(code, args: "2>&1").should == "true\n" - end - end - - ruby_version_is "3.0" do - it "is not redefined by open-uri" do - code = <<~RUBY - before = Kernel.instance_method(:open) - require 'open-uri' - after = Kernel.instance_method(:open) - p before == after - RUBY - ruby_exe(code, args: "2>&1").should == "true\n" - end + after = Kernel.instance_method(:open) + p before == after + RUBY + ruby_exe(code, args: "2>&1").should == "true\n" end end diff --git a/core/kernel/proc_spec.rb b/core/kernel/proc_spec.rb index 231c1f0dfb..6553b8fd04 100644 --- a/core/kernel/proc_spec.rb +++ b/core/kernel/proc_spec.rb @@ -40,19 +40,9 @@ def some_method proc end - ruby_version_is ""..."3.0" do - it "can be created when called with no block" do - -> { - some_method { "hello" } - }.should complain(/Capturing the given block using Kernel#proc is deprecated/) - end - end - - ruby_version_is "3.0" do - it "raises an ArgumentError when passed no block" do - -> { - some_method { "hello" } - }.should raise_error(ArgumentError, 'tried to create Proc object without a block') - end + it "raises an ArgumentError when passed no block" do + -> { + some_method { "hello" } + }.should raise_error(ArgumentError, 'tried to create Proc object without a block') end end diff --git a/core/kernel/shared/require.rb b/core/kernel/shared/require.rb index 5cbc11c9ec..61081b200c 100644 --- a/core/kernel/shared/require.rb +++ b/core/kernel/shared/require.rb @@ -262,13 +262,11 @@ ScratchPad.recorded.should == [:loaded] end - ruby_bug "#16926", ""..."3.0" do - it "does not load a feature twice when $LOAD_PATH has been modified" do - $LOAD_PATH.replace [CODE_LOADING_DIR] - @object.require("load_fixture").should be_true - $LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR] - @object.require("load_fixture").should be_false - end + it "does not load a feature twice when $LOAD_PATH has been modified" do + $LOAD_PATH.replace [CODE_LOADING_DIR] + @object.require("load_fixture").should be_true + $LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR] + @object.require("load_fixture").should be_false end end @@ -566,23 +564,21 @@ -> { @object.require("unicode_normalize") }.should raise_error(LoadError) end - ruby_version_is "3.0" do - it "does not load a file earlier on the $LOAD_PATH when other similar features were already loaded" do - Dir.chdir CODE_LOADING_DIR do - @object.send(@method, "../code/load_fixture").should be_true - end - ScratchPad.recorded.should == [:loaded] + it "does not load a file earlier on the $LOAD_PATH when other similar features were already loaded" do + Dir.chdir CODE_LOADING_DIR do + @object.send(@method, "../code/load_fixture").should be_true + end + ScratchPad.recorded.should == [:loaded] - $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/b" - # This loads because the above load was not on the $LOAD_PATH - @object.send(@method, "load_fixture").should be_true - ScratchPad.recorded.should == [:loaded, :loaded] + $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/b" + # This loads because the above load was not on the $LOAD_PATH + @object.send(@method, "load_fixture").should be_true + ScratchPad.recorded.should == [:loaded, :loaded] - $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/c" - # This does not load because the above load was on the $LOAD_PATH - @object.send(@method, "load_fixture").should be_false - ScratchPad.recorded.should == [:loaded, :loaded] - end + $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/c" + # This does not load because the above load was on the $LOAD_PATH + @object.send(@method, "load_fixture").should be_false + ScratchPad.recorded.should == [:loaded, :loaded] end end diff --git a/core/kernel/warn_spec.rb b/core/kernel/warn_spec.rb index 7df6fa72d1..00164ad90b 100644 --- a/core/kernel/warn_spec.rb +++ b/core/kernel/warn_spec.rb @@ -128,36 +128,34 @@ end end - ruby_version_is "3.0" do - it "accepts :category keyword with a symbol" do - -> { - $VERBOSE = true - warn("message", category: :deprecated) - }.should output(nil, "message\n") - end + it "accepts :category keyword with a symbol" do + -> { + $VERBOSE = true + warn("message", category: :deprecated) + }.should output(nil, "message\n") + end - it "accepts :category keyword with nil" do - -> { - $VERBOSE = true - warn("message", category: nil) - }.should output(nil, "message\n") - end + it "accepts :category keyword with nil" do + -> { + $VERBOSE = true + warn("message", category: nil) + }.should output(nil, "message\n") + end - it "accepts :category keyword with object convertible to symbol" do - o = Object.new - def o.to_sym; :deprecated; end - -> { - $VERBOSE = true - warn("message", category: o) - }.should output(nil, "message\n") - end + it "accepts :category keyword with object convertible to symbol" do + o = Object.new + def o.to_sym; :deprecated; end + -> { + $VERBOSE = true + warn("message", category: o) + }.should output(nil, "message\n") + end - it "raises if :category keyword is not nil and not convertible to symbol" do - -> { - $VERBOSE = true - warn("message", category: Object.new) - }.should raise_error(TypeError) - end + it "raises if :category keyword is not nil and not convertible to symbol" do + -> { + $VERBOSE = true + warn("message", category: Object.new) + }.should raise_error(TypeError) end it "converts first arg using to_s" do @@ -212,67 +210,52 @@ def o.to_sym; :deprecated; end -> { warn('foo', **h) }.should complain("foo\n") end - ruby_version_is '3.0' do - it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do - verbose = $VERBOSE - $VERBOSE = false - class << Warning - alias_method :_warn, :warn - def warn(message) - ScratchPad.record(message) - end - end - - begin - ScratchPad.clear - Kernel.warn("Chunky bacon!") - ScratchPad.recorded.should == "Chunky bacon!\n" - - Kernel.warn("Deprecated bacon!", category: :deprecated) - ScratchPad.recorded.should == "Deprecated bacon!\n" - ensure - class << Warning - remove_method :warn - alias_method :warn, :_warn - remove_method :_warn - end - $VERBOSE = verbose + it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do + verbose = $VERBOSE + $VERBOSE = false + class << Warning + alias_method :_warn, :warn + def warn(message) + ScratchPad.record(message) end end - it "calls Warning.warn with category: nil if Warning.warn accepts keyword arguments" do - Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil) - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!") - ensure - $VERBOSE = verbose + begin + ScratchPad.clear + Kernel.warn("Chunky bacon!") + ScratchPad.recorded.should == "Chunky bacon!\n" + + Kernel.warn("Deprecated bacon!", category: :deprecated) + ScratchPad.recorded.should == "Deprecated bacon!\n" + ensure + class << Warning + remove_method :warn + alias_method :warn, :_warn + remove_method :_warn end + $VERBOSE = verbose end + end - it "calls Warning.warn with given category keyword converted to a symbol" do - Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated) - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!", category: 'deprecated') - ensure - $VERBOSE = verbose - end + it "calls Warning.warn with category: nil if Warning.warn accepts keyword arguments" do + Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil) + verbose = $VERBOSE + $VERBOSE = false + begin + Kernel.warn("Chunky bacon!") + ensure + $VERBOSE = verbose end end - ruby_version_is ''...'3.0' do - it "calls Warning.warn with no keyword arguments" do - Warning.should_receive(:warn).with("Chunky bacon!\n") - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!") - ensure - $VERBOSE = verbose - end + it "calls Warning.warn with given category keyword converted to a symbol" do + Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated) + verbose = $VERBOSE + $VERBOSE = false + begin + Kernel.warn("Chunky bacon!", category: 'deprecated') + ensure + $VERBOSE = verbose end end diff --git a/core/main/private_spec.rb b/core/main/private_spec.rb index cac0645b40..e8c1f3f44c 100644 --- a/core/main/private_spec.rb +++ b/core/main/private_spec.rb @@ -22,13 +22,11 @@ end end - ruby_version_is "3.0" do - context "when single argument is passed and is an array" do - it "sets the visibility of the given methods to private" do - eval "private [:main_public_method, :main_public_method2]", TOPLEVEL_BINDING - Object.should have_private_method(:main_public_method) - Object.should have_private_method(:main_public_method2) - end + context "when single argument is passed and is an array" do + it "sets the visibility of the given methods to private" do + eval "private [:main_public_method, :main_public_method2]", TOPLEVEL_BINDING + Object.should have_private_method(:main_public_method) + Object.should have_private_method(:main_public_method2) end end diff --git a/core/main/public_spec.rb b/core/main/public_spec.rb index 91f045dbab..31baad4583 100644 --- a/core/main/public_spec.rb +++ b/core/main/public_spec.rb @@ -22,13 +22,11 @@ end end - ruby_version_is "3.0" do - context "when single argument is passed and is an array" do - it "sets the visibility of the given methods to public" do - eval "public [:main_private_method, :main_private_method2]", TOPLEVEL_BINDING - Object.should_not have_private_method(:main_private_method) - Object.should_not have_private_method(:main_private_method2) - end + context "when single argument is passed and is an array" do + it "sets the visibility of the given methods to public" do + eval "public [:main_private_method, :main_private_method2]", TOPLEVEL_BINDING + Object.should_not have_private_method(:main_private_method) + Object.should_not have_private_method(:main_private_method2) end end diff --git a/core/marshal/dump_spec.rb b/core/marshal/dump_spec.rb index f38250b513..c694b48bab 100644 --- a/core/marshal/dump_spec.rb +++ b/core/marshal/dump_spec.rb @@ -626,17 +626,6 @@ def finalizer.noop(_) load.should == (1...2) end - ruby_version_is ""..."3.0" do - it "dumps a Range with extra instance variables" do - range = (1...3) - range.instance_variable_set :@foo, 42 - dump = Marshal.dump(range) - load = Marshal.load(dump) - load.should == range - load.instance_variable_get(:@foo).should == 42 - end - end - it "raises TypeError with an anonymous Range subclass" do -> { Marshal.dump(Class.new(Range).new(1, 2)) }.should raise_error(TypeError, /can't dump anonymous class/) end diff --git a/core/matchdata/element_reference_spec.rb b/core/matchdata/element_reference_spec.rb index 0e0d3991cb..1be399cfe1 100644 --- a/core/matchdata/element_reference_spec.rb +++ b/core/matchdata/element_reference_spec.rb @@ -48,11 +48,9 @@ /(.)(.)(\d+)(\d)/.match("THX1138.")[nil..nil].should == %w|HX1138 H X 113 8| end - ruby_version_is "3.0" do - it "returns instances of String when given a String subclass" do - str = MatchDataSpecs::MyString.new("THX1138.") - /(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should be_an_instance_of(String) } - end + it "returns instances of String when given a String subclass" do + str = MatchDataSpecs::MyString.new("THX1138.") + /(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should be_an_instance_of(String) } end end diff --git a/core/matchdata/post_match_spec.rb b/core/matchdata/post_match_spec.rb index d3aa4c8900..b8d1e032eb 100644 --- a/core/matchdata/post_match_spec.rb +++ b/core/matchdata/post_match_spec.rb @@ -17,10 +17,8 @@ str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1) end - ruby_version_is "3.0" do - it "returns an instance of String when given a String subclass" do - str = MatchDataSpecs::MyString.new("THX1138: The Movie") - /(.)(.)(\d+)(\d)/.match(str).post_match.should be_an_instance_of(String) - end + it "returns an instance of String when given a String subclass" do + str = MatchDataSpecs::MyString.new("THX1138: The Movie") + /(.)(.)(\d+)(\d)/.match(str).post_match.should be_an_instance_of(String) end end diff --git a/core/matchdata/pre_match_spec.rb b/core/matchdata/pre_match_spec.rb index b43be5fb41..741cb6e923 100644 --- a/core/matchdata/pre_match_spec.rb +++ b/core/matchdata/pre_match_spec.rb @@ -17,10 +17,8 @@ str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1) end - ruby_version_is "3.0" do - it "returns an instance of String when given a String subclass" do - str = MatchDataSpecs::MyString.new("THX1138: The Movie") - /(.)(.)(\d+)(\d)/.match(str).pre_match.should be_an_instance_of(String) - end + it "returns an instance of String when given a String subclass" do + str = MatchDataSpecs::MyString.new("THX1138: The Movie") + /(.)(.)(\d+)(\d)/.match(str).pre_match.should be_an_instance_of(String) end end diff --git a/core/matchdata/shared/captures.rb b/core/matchdata/shared/captures.rb index d2c85ece5a..33f834561a 100644 --- a/core/matchdata/shared/captures.rb +++ b/core/matchdata/shared/captures.rb @@ -6,10 +6,8 @@ /(.)(.)(\d+)(\d)/.match("THX1138.").send(@method).should == ["H","X","113","8"] end - ruby_version_is "3.0" do - it "returns instances of String when given a String subclass" do - str = MatchDataSpecs::MyString.new("THX1138: The Movie") - /(.)(.)(\d+)(\d)/.match(str).send(@method).each { |c| c.should be_an_instance_of(String) } - end + it "returns instances of String when given a String subclass" do + str = MatchDataSpecs::MyString.new("THX1138: The Movie") + /(.)(.)(\d+)(\d)/.match(str).send(@method).each { |c| c.should be_an_instance_of(String) } end end diff --git a/core/matchdata/to_a_spec.rb b/core/matchdata/to_a_spec.rb index 50f5a161a5..4fa11ff604 100644 --- a/core/matchdata/to_a_spec.rb +++ b/core/matchdata/to_a_spec.rb @@ -6,10 +6,8 @@ /(.)(.)(\d+)(\d)/.match("THX1138.").to_a.should == ["HX1138", "H", "X", "113", "8"] end - ruby_version_is "3.0" do - it "returns instances of String when given a String subclass" do - str = MatchDataSpecs::MyString.new("THX1138.") - /(.)(.)(\d+)(\d)/.match(str)[0..-1].to_a.each { |m| m.should be_an_instance_of(String) } - end + it "returns instances of String when given a String subclass" do + str = MatchDataSpecs::MyString.new("THX1138.") + /(.)(.)(\d+)(\d)/.match(str)[0..-1].to_a.each { |m| m.should be_an_instance_of(String) } end end diff --git a/core/matchdata/to_s_spec.rb b/core/matchdata/to_s_spec.rb index aab0955ae1..cd1c4dbca2 100644 --- a/core/matchdata/to_s_spec.rb +++ b/core/matchdata/to_s_spec.rb @@ -6,10 +6,8 @@ /(.)(.)(\d+)(\d)/.match("THX1138.").to_s.should == "HX1138" end - ruby_version_is "3.0" do - it "returns an instance of String when given a String subclass" do - str = MatchDataSpecs::MyString.new("THX1138.") - /(.)(.)(\d+)(\d)/.match(str).to_s.should be_an_instance_of(String) - end + it "returns an instance of String when given a String subclass" do + str = MatchDataSpecs::MyString.new("THX1138.") + /(.)(.)(\d+)(\d)/.match(str).to_s.should be_an_instance_of(String) end end diff --git a/core/method/shared/to_s.rb b/core/method/shared/to_s.rb index 6fdeaaf99c..5f9b47872d 100644 --- a/core/method/shared/to_s.rb +++ b/core/method/shared/to_s.rb @@ -53,20 +53,18 @@ MethodSpecs::A.new.method(:baz).send(@method).should.start_with? "#(#{m.inspect})#bar" - end + c = MethodSpecs::MySub.dup + m = Module.new{def bar; end} + c.extend(m) + @string = c.method(:bar).send(@method) + @string.should.start_with? "#(#{m.inspect})#bar" end it "returns a String containing the singleton class if method is defined in the singleton class" do diff --git a/core/module/alias_method_spec.rb b/core/module/alias_method_spec.rb index 391efa227a..c36dedd2d8 100644 --- a/core/module/alias_method_spec.rb +++ b/core/module/alias_method_spec.rb @@ -92,17 +92,9 @@ def uno_refined_method end describe "returned value" do - ruby_version_is ""..."3.0" do - it "returns self" do - @class.send(:alias_method, :checking_return_value, :public_one).should equal(@class) - end - end - - ruby_version_is "3.0" do - it "returns symbol of the defined method name" do - @class.send(:alias_method, :checking_return_value, :public_one).should equal(:checking_return_value) - @class.send(:alias_method, 'checking_return_value', :public_one).should equal(:checking_return_value) - end + it "returns symbol of the defined method name" do + @class.send(:alias_method, :checking_return_value, :public_one).should equal(:checking_return_value) + @class.send(:alias_method, 'checking_return_value', :public_one).should equal(:checking_return_value) end end diff --git a/core/module/attr_accessor_spec.rb b/core/module/attr_accessor_spec.rb index ba5289cbea..eea5b4b64b 100644 --- a/core/module/attr_accessor_spec.rb +++ b/core/module/attr_accessor_spec.rb @@ -80,19 +80,9 @@ class TrueClass Module.should have_public_instance_method(:attr_accessor, false) end - ruby_version_is ""..."3.0" do - it "returns nil" do - Class.new do - (attr_accessor :foo, 'bar').should == nil - end - end - end - - ruby_version_is "3.0" do - it "returns an array of defined method names as symbols" do - Class.new do - (attr_accessor :foo, 'bar').should == [:foo, :foo=, :bar, :bar=] - end + it "returns an array of defined method names as symbols" do + Class.new do + (attr_accessor :foo, 'bar').should == [:foo, :foo=, :bar, :bar=] end end diff --git a/core/module/attr_reader_spec.rb b/core/module/attr_reader_spec.rb index b0ae906ab5..0b6d996719 100644 --- a/core/module/attr_reader_spec.rb +++ b/core/module/attr_reader_spec.rb @@ -62,19 +62,9 @@ class TrueClass Module.should have_public_instance_method(:attr_reader, false) end - ruby_version_is ""..."3.0" do - it "returns nil" do - Class.new do - (attr_reader :foo, 'bar').should == nil - end - end - end - - ruby_version_is "3.0" do - it "returns an array of defined method names as symbols" do - Class.new do - (attr_reader :foo, 'bar').should == [:foo, :bar] - end + it "returns an array of defined method names as symbols" do + Class.new do + (attr_reader :foo, 'bar').should == [:foo, :bar] end end end diff --git a/core/module/attr_spec.rb b/core/module/attr_spec.rb index 33e0eb8628..72a6646b1e 100644 --- a/core/module/attr_spec.rb +++ b/core/module/attr_spec.rb @@ -146,23 +146,11 @@ def initialize Module.should have_public_instance_method(:attr, false) end - ruby_version_is ""..."3.0" do - it "returns nil" do - Class.new do - (attr :foo, 'bar').should == nil - (attr :baz, false).should == nil - (attr :qux, true).should == nil - end - end - end - - ruby_version_is "3.0" do - it "returns an array of defined method names as symbols" do - Class.new do - (attr :foo, 'bar').should == [:foo, :bar] - (attr :baz, false).should == [:baz] - (attr :qux, true).should == [:qux, :qux=] - end + it "returns an array of defined method names as symbols" do + Class.new do + (attr :foo, 'bar').should == [:foo, :bar] + (attr :baz, false).should == [:baz] + (attr :qux, true).should == [:qux, :qux=] end end end diff --git a/core/module/attr_writer_spec.rb b/core/module/attr_writer_spec.rb index 0e9d201317..aaea0ce43f 100644 --- a/core/module/attr_writer_spec.rb +++ b/core/module/attr_writer_spec.rb @@ -72,19 +72,9 @@ class TrueClass Module.should have_public_instance_method(:attr_writer, false) end - ruby_version_is ""..."3.0" do - it "returns nil" do - Class.new do - (attr_writer :foo, 'bar').should == nil - end - end - end - - ruby_version_is "3.0" do - it "returns an array of defined method names as symbols" do - Class.new do - (attr_writer :foo, 'bar').should == [:foo=, :bar=] - end + it "returns an array of defined method names as symbols" do + Class.new do + (attr_writer :foo, 'bar').should == [:foo=, :bar=] end end end diff --git a/core/module/const_set_spec.rb b/core/module/const_set_spec.rb index ba7810d17b..5bdfd7b68f 100644 --- a/core/module/const_set_spec.rb +++ b/core/module/const_set_spec.rb @@ -20,20 +20,10 @@ m.name.should == "ConstantSpecs::CS_CONST1000" end - ruby_version_is ""..."3.0" do - it "does not set the name of a module scoped by an anonymous module" do - a, b = Module.new, Module.new - a.const_set :B, b - b.name.should be_nil - end - end - - ruby_version_is "3.0" do - it "sets the name of a module scoped by an anonymous module" do - a, b = Module.new, Module.new - a.const_set :B, b - b.name.should.end_with? '::B' - end + it "sets the name of a module scoped by an anonymous module" do + a, b = Module.new, Module.new + a.const_set :B, b + b.name.should.end_with? '::B' end it "sets the name of contained modules when assigning a toplevel anonymous module" do diff --git a/core/module/name_spec.rb b/core/module/name_spec.rb index b78bbfcc80..9d2e79e95c 100644 --- a/core/module/name_spec.rb +++ b/core/module/name_spec.rb @@ -6,20 +6,10 @@ Module.new.name.should be_nil end - ruby_version_is ""..."3.0" do - it "is nil when assigned to a constant in an anonymous module" do - m = Module.new - m::N = Module.new - m::N.name.should be_nil - end - end - - ruby_version_is "3.0" do - it "is not nil when assigned to a constant in an anonymous module" do - m = Module.new - m::N = Module.new - m::N.name.should.end_with? '::N' - end + it "is not nil when assigned to a constant in an anonymous module" do + m = Module.new + m::N = Module.new + m::N.name.should.end_with? '::N' end it "is not nil for a nested module created with the module keyword" do diff --git a/core/module/prepend_spec.rb b/core/module/prepend_spec.rb index 976b09b105..96598e7209 100644 --- a/core/module/prepend_spec.rb +++ b/core/module/prepend_spec.rb @@ -499,34 +499,17 @@ module M c.dup.new.should be_kind_of(m) end - ruby_version_is ''...'3.0' do - it "keeps the module in the chain when dupping an intermediate module" do - m1 = Module.new { def calc(x) x end } - m2 = Module.new { prepend(m1) } - c1 = Class.new { prepend(m2) } - m2dup = m2.dup - m2dup.ancestors.should == [m2dup,m1,m2] - c2 = Class.new { prepend(m2dup) } - c1.ancestors[0,3].should == [m1,m2,c1] - c1.new.should be_kind_of(m1) - c2.ancestors[0,4].should == [m2dup,m1,m2,c2] - c2.new.should be_kind_of(m1) - end - end - - ruby_version_is '3.0' do - it "uses only new module when dupping the module" do - m1 = Module.new { def calc(x) x end } - m2 = Module.new { prepend(m1) } - c1 = Class.new { prepend(m2) } - m2dup = m2.dup - m2dup.ancestors.should == [m1,m2dup] - c2 = Class.new { prepend(m2dup) } - c1.ancestors[0,3].should == [m1,m2,c1] - c1.new.should be_kind_of(m1) - c2.ancestors[0,3].should == [m1,m2dup,c2] - c2.new.should be_kind_of(m1) - end + it "uses only new module when dupping the module" do + m1 = Module.new { def calc(x) x end } + m2 = Module.new { prepend(m1) } + c1 = Class.new { prepend(m2) } + m2dup = m2.dup + m2dup.ancestors.should == [m1,m2dup] + c2 = Class.new { prepend(m2dup) } + c1.ancestors[0,3].should == [m1,m2,c1] + c1.new.should be_kind_of(m1) + c2.ancestors[0,3].should == [m1,m2dup,c2] + c2.new.should be_kind_of(m1) end it "depends on prepend_features to add the module" do diff --git a/core/module/private_class_method_spec.rb b/core/module/private_class_method_spec.rb index 407779cccc..f899c71a57 100644 --- a/core/module/private_class_method_spec.rb +++ b/core/module/private_class_method_spec.rb @@ -79,15 +79,13 @@ def foo() "foo" end end.should raise_error(NameError) end - ruby_version_is "3.0" do - context "when single argument is passed and is an array" do - it "sets the visibility of the given methods to private" do - c = Class.new do - def self.foo() "foo" end - private_class_method [:foo] - end - -> { c.foo }.should raise_error(NoMethodError) + context "when single argument is passed and is an array" do + it "sets the visibility of the given methods to private" do + c = Class.new do + def self.foo() "foo" end + private_class_method [:foo] end + -> { c.foo }.should raise_error(NoMethodError) end end end diff --git a/core/module/public_class_method_spec.rb b/core/module/public_class_method_spec.rb index b5d76e7b7a..71b20acda5 100644 --- a/core/module/public_class_method_spec.rb +++ b/core/module/public_class_method_spec.rb @@ -78,19 +78,17 @@ def foo() "foo" end end.should raise_error(NameError) end - ruby_version_is "3.0" do - context "when single argument is passed and is an array" do - it "makes a class method public" do - c = Class.new do - class << self - private - def foo() "foo" end - end - public_class_method [:foo] + context "when single argument is passed and is an array" do + it "makes a class method public" do + c = Class.new do + class << self + private + def foo() "foo" end end - - c.foo.should == "foo" + public_class_method [:foo] end + + c.foo.should == "foo" end end end diff --git a/core/module/ruby2_keywords_spec.rb b/core/module/ruby2_keywords_spec.rb index 80a99e2624..dc16d712c7 100644 --- a/core/module/ruby2_keywords_spec.rb +++ b/core/module/ruby2_keywords_spec.rb @@ -22,9 +22,7 @@ def regular(*args) end h = {a: 1} - ruby_version_is "3.0" do - obj.regular(**h).should.equal?(h) - end + obj.regular(**h).should.equal?(h) last = mark(**h).last Hash.ruby2_keywords_hash?(last).should == true @@ -223,25 +221,6 @@ def baz(*a) a.last end Hash.ruby2_keywords_hash?(last).should == true end - ruby_version_is ""..."3.0" do - it "fixes delegation warnings when calling a method accepting keywords" do - obj = Object.new - - obj.singleton_class.class_exec do - def foo(*a) bar(*a) end - def bar(*a, **b) end - end - - -> { obj.foo(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/) - - obj.singleton_class.class_exec do - ruby2_keywords :foo - end - - -> { obj.foo(1, 2, {a: "a"}) }.should_not complain - end - end - it "returns nil" do obj = Object.new diff --git a/core/module/shared/set_visibility.rb b/core/module/shared/set_visibility.rb index 9f31e230ca..a1586dd2bd 100644 --- a/core/module/shared/set_visibility.rb +++ b/core/module/shared/set_visibility.rb @@ -22,21 +22,19 @@ def test2() end end end - ruby_version_is "3.0" do - describe "array as a single argument" do - it "sets visibility of given method names" do - visibility = @method - old_visibility = [:protected, :private].find {|vis| vis != visibility } - - mod = Module.new { - send old_visibility - def test1() end - def test2() end - send visibility, [:test1, :test2] - } - mod.should send(:"have_#{visibility}_instance_method", :test1, false) - mod.should send(:"have_#{visibility}_instance_method", :test2, false) - end + describe "array as a single argument" do + it "sets visibility of given method names" do + visibility = @method + old_visibility = [:protected, :private].find {|vis| vis != visibility } + + mod = Module.new { + send old_visibility + def test1() end + def test2() end + send visibility, [:test1, :test2] + } + mod.should send(:"have_#{visibility}_instance_method", :test1, false) + mod.should send(:"have_#{visibility}_instance_method", :test2, false) end end diff --git a/core/mutex/owned_spec.rb b/core/mutex/owned_spec.rb index 1f843cd576..7bfc7d8f83 100644 --- a/core/mutex/owned_spec.rb +++ b/core/mutex/owned_spec.rb @@ -41,15 +41,13 @@ end end - ruby_version_is "3.0" do - it "is held per Fiber" do - m = Mutex.new - m.lock - - Fiber.new do - m.locked?.should == true - m.owned?.should == false - end.resume - end + it "is held per Fiber" do + m = Mutex.new + m.lock + + Fiber.new do + m.locked?.should == true + m.owned?.should == false + end.resume end end diff --git a/core/numeric/clone_spec.rb b/core/numeric/clone_spec.rb index c3b06ca0c9..5834b17089 100644 --- a/core/numeric/clone_spec.rb +++ b/core/numeric/clone_spec.rb @@ -23,10 +23,8 @@ -> { 1.clone(freeze: false) }.should raise_error(ArgumentError, /can't unfreeze/) end - ruby_version_is "3.0" do - it "does not change frozen status if passed freeze: nil" do - value = 1 - value.clone(freeze: nil).should equal(value) - end + it "does not change frozen status if passed freeze: nil" do + value = 1 + value.clone(freeze: nil).should equal(value) end end diff --git a/core/numeric/shared/step.rb b/core/numeric/shared/step.rb index 8b1a7bf307..b817a0a726 100644 --- a/core/numeric/shared/step.rb +++ b/core/numeric/shared/step.rb @@ -258,12 +258,6 @@ describe "when no block is given" do step_enum_class = Enumerator::ArithmeticSequence - ruby_version_is ""..."3.0" do - it "returns an #{step_enum_class} when step is 0" do - @step.call(1, 2, 0).should be_an_instance_of(step_enum_class) - end - end - it "returns an #{step_enum_class} when not passed a block and self > stop" do @step.call(1, 0, 2).should be_an_instance_of(step_enum_class) end diff --git a/core/numeric/step_spec.rb b/core/numeric/step_spec.rb index 095c474fec..1705fb1b4e 100644 --- a/core/numeric/step_spec.rb +++ b/core/numeric/step_spec.rb @@ -23,30 +23,8 @@ describe "when no block is given" do step_enum_class = Enumerator::ArithmeticSequence - ruby_version_is ""..."3.0" do - it "returns an #{step_enum_class} when step is 0" do - 1.step(5, 0).should be_an_instance_of(step_enum_class) - end - - it "returns an #{step_enum_class} when step is 0.0" do - 1.step(2, 0.0).should be_an_instance_of(step_enum_class) - end - end - describe "returned #{step_enum_class}" do describe "size" do - ruby_version_is ""..."3.0" do - it "is infinity when step is 0" do - enum = 1.step(5, 0) - enum.size.should == Float::INFINITY - end - - it "is infinity when step is 0.0" do - enum = 1.step(2, 0.0) - enum.size.should == Float::INFINITY - end - end - it "defaults to an infinite size" do enum = 1.step enum.size.should == Float::INFINITY @@ -63,22 +41,6 @@ end describe 'with keyword arguments' do - ruby_version_is ""..."3.0" do - it "doesn't raise an error when step is 0" do - -> { 1.step(to: 5, by: 0) { break } }.should_not raise_error - end - - it "doesn't raise an error when step is 0.0" do - -> { 1.step(to: 2, by: 0.0) { break } }.should_not raise_error - end - - it "should loop over self when step is 0 or 0.0" do - 1.step(to: 2, by: 0.0).take(5).should eql [1.0, 1.0, 1.0, 1.0, 1.0] - 1.step(to: 2, by: 0).take(5).should eql [1, 1, 1, 1, 1] - 1.1.step(to: 2, by: 0).take(5).should eql [1.1, 1.1, 1.1, 1.1, 1.1] - end - end - describe "when no block is given" do describe "returned Enumerator" do describe "size" do @@ -86,16 +48,6 @@ 1.step(by: 42).size.should == infinity_value end - ruby_version_is ""..."3.0" do - it "should return infinity_value when step is 0" do - 1.step(to: 5, by: 0).size.should == infinity_value - end - - it "should return infinity_value when step is 0.0" do - 1.step(to: 2, by: 0.0).size.should == infinity_value - end - end - it "should return infinity_value when ascending towards a limit of Float::INFINITY" do 1.step(to: Float::INFINITY, by: 42).size.should == infinity_value end @@ -128,24 +80,12 @@ end describe 'with mixed arguments' do - ruby_version_is ""..."3.0" do - it "doesn't raise an error when step is 0" do - -> { 1.step(5, by: 0) { break } }.should_not raise_error - end - - it "doesn't raise an error when step is 0.0" do - -> { 1.step(2, by: 0.0) { break } }.should_not raise_error - end + it " raises an ArgumentError when step is 0" do + -> { 1.step(5, by: 0) { break } }.should raise_error(ArgumentError) end - ruby_version_is "3.0" do - it " raises an ArgumentError when step is 0" do - -> { 1.step(5, by: 0) { break } }.should raise_error(ArgumentError) - end - - it "raises an ArgumentError when step is 0.0" do - -> { 1.step(2, by: 0.0) { break } }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when step is 0.0" do + -> { 1.step(2, by: 0.0) { break } }.should raise_error(ArgumentError) end it "raises a ArgumentError when limit and to are defined" do @@ -156,26 +96,9 @@ -> { 1.step(5, 1, by: 5) { break } }.should raise_error(ArgumentError) end - ruby_version_is ""..."3.0" do - it "should loop over self when step is 0 or 0.0" do - 1.step(2, by: 0.0).take(5).should eql [1.0, 1.0, 1.0, 1.0, 1.0] - 1.step(2, by: 0).take(5).should eql [1, 1, 1, 1, 1] - 1.1.step(2, by: 0).take(5).should eql [1.1, 1.1, 1.1, 1.1, 1.1] - end - end - describe "when no block is given" do describe "returned Enumerator" do describe "size" do - ruby_version_is ""..."3.0" do - it "should return infinity_value when step is 0" do - 1.step(5, by: 0).size.should == infinity_value - end - - it "should return infinity_value when step is 0.0" do - 1.step(2, by: 0.0).size.should == infinity_value - end - end end end end diff --git a/core/objectspace/define_finalizer_spec.rb b/core/objectspace/define_finalizer_spec.rb index d9db027e0b..6be83e518e 100644 --- a/core/objectspace/define_finalizer_spec.rb +++ b/core/objectspace/define_finalizer_spec.rb @@ -60,55 +60,53 @@ def scoped ruby_exe(code, :args => "2>&1").should include("finalizer run\n") end - ruby_version_is "3.0" do - it "warns if the finalizer has the object as the receiver" do - code = <<-RUBY - class CapturesSelf - def initialize - ObjectSpace.define_finalizer(self, proc { - puts "finalizer run" - }) - end + it "warns if the finalizer has the object as the receiver" do + code = <<-RUBY + class CapturesSelf + def initialize + ObjectSpace.define_finalizer(self, proc { + puts "finalizer run" + }) end - CapturesSelf.new - exit 0 - RUBY + end + CapturesSelf.new + exit 0 + RUBY - ruby_exe(code, :args => "2>&1").should include("warning: finalizer references object to be finalized\n") - end + ruby_exe(code, :args => "2>&1").should include("warning: finalizer references object to be finalized\n") + end - it "warns if the finalizer is a method bound to the receiver" do - code = <<-RUBY - class CapturesSelf - def initialize - ObjectSpace.define_finalizer(self, method(:finalize)) - end - def finalize(id) - puts "finalizer run" - end + it "warns if the finalizer is a method bound to the receiver" do + code = <<-RUBY + class CapturesSelf + def initialize + ObjectSpace.define_finalizer(self, method(:finalize)) end - CapturesSelf.new - exit 0 - RUBY + def finalize(id) + puts "finalizer run" + end + end + CapturesSelf.new + exit 0 + RUBY - ruby_exe(code, :args => "2>&1").should include("warning: finalizer references object to be finalized\n") - end + ruby_exe(code, :args => "2>&1").should include("warning: finalizer references object to be finalized\n") + end - it "warns if the finalizer was a block in the receiver" do - code = <<-RUBY - class CapturesSelf - def initialize - ObjectSpace.define_finalizer(self) do - puts "finalizer run" - end + it "warns if the finalizer was a block in the receiver" do + code = <<-RUBY + class CapturesSelf + def initialize + ObjectSpace.define_finalizer(self) do + puts "finalizer run" end end - CapturesSelf.new - exit 0 - RUBY + end + CapturesSelf.new + exit 0 + RUBY - ruby_exe(code, :args => "2>&1").should include("warning: finalizer references object to be finalized\n") - end + ruby_exe(code, :args => "2>&1").should include("warning: finalizer references object to be finalized\n") end it "calls a finalizer at exit even if it is self-referencing" do diff --git a/core/proc/eql_spec.rb b/core/proc/eql_spec.rb index 06aee272e5..ad8f6749fc 100644 --- a/core/proc/eql_spec.rb +++ b/core/proc/eql_spec.rb @@ -2,11 +2,5 @@ require_relative 'shared/equal' describe "Proc#eql?" do - ruby_version_is ""..."3.0" do - it_behaves_like :proc_equal_undefined, :eql? - end - - ruby_version_is "3.0" do - it_behaves_like :proc_equal, :eql? - end + it_behaves_like :proc_equal, :eql? end diff --git a/core/proc/equal_value_spec.rb b/core/proc/equal_value_spec.rb index ee88c0537d..ec7f274732 100644 --- a/core/proc/equal_value_spec.rb +++ b/core/proc/equal_value_spec.rb @@ -2,11 +2,5 @@ require_relative 'shared/equal' describe "Proc#==" do - ruby_version_is ""..."3.0" do - it_behaves_like :proc_equal_undefined, :== - end - - ruby_version_is "3.0" do - it_behaves_like :proc_equal, :== - end + it_behaves_like :proc_equal, :== end diff --git a/core/proc/new_spec.rb b/core/proc/new_spec.rb index cb52e94f44..b2b7387756 100644 --- a/core/proc/new_spec.rb +++ b/core/proc/new_spec.rb @@ -166,36 +166,13 @@ def some_method -> { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError) end - ruby_version_is ""..."3.0" do - it "can be created if invoked from within a method with a block" do - -> { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) - end - - it "can be created if invoked on a subclass from within a method with a block" do - -> { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) - end - - - it "can be create when called with no block" do - def some_method - Proc.new - end - - -> { - some_method { "hello" } - }.should complain(/Capturing the given block using Proc.new is deprecated/) + it "raises an ArgumentError when passed no block" do + def some_method + Proc.new end - end - ruby_version_is "3.0" do - it "raises an ArgumentError when passed no block" do - def some_method - Proc.new - end - - -> { ProcSpecs.new_proc_in_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') - -> { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') - -> { some_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') - end + -> { ProcSpecs.new_proc_in_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') + -> { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') + -> { some_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') end end diff --git a/core/proc/ruby2_keywords_spec.rb b/core/proc/ruby2_keywords_spec.rb index c6eb03e693..ab67302231 100644 --- a/core/proc/ruby2_keywords_spec.rb +++ b/core/proc/ruby2_keywords_spec.rb @@ -25,28 +25,6 @@ Hash.ruby2_keywords_hash?(f4.call(1, 2, a: "a")).should == true end - ruby_version_is ""..."3.0" do - it "fixes delegation warnings when calling a method accepting keywords" do - obj = Object.new - def obj.foo(*a, **b) end - - f = -> *a { obj.foo(*a) } - - -> { f.call(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/) - f.ruby2_keywords - -> { f.call(1, 2, {a: "a"}) }.should_not complain - end - - it "fixes delegation warnings when calling a proc accepting keywords" do - g = -> *a, **b { } - f = -> *a { g.call(*a) } - - -> { f.call(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/) - f.ruby2_keywords - -> { f.call(1, 2, {a: "a"}) }.should_not complain - end - end - it "returns self" do f = -> *a { } f.ruby2_keywords.should equal f diff --git a/core/process/status/wait_spec.rb b/core/process/status/wait_spec.rb index ee9ea80ebb..57d56209a9 100644 --- a/core/process/status/wait_spec.rb +++ b/core/process/status/wait_spec.rb @@ -1,102 +1,100 @@ require_relative '../../../spec_helper' require_relative '../fixtures/common' -ruby_version_is "3.0" do - describe "Process::Status.wait" do - ProcessSpecs.use_system_ruby(self) - - before :all do - begin - leaked = Process.waitall - # Ruby-space should not see PIDs used by rjit - raise "subprocesses leaked before wait specs: #{leaked}" unless leaked.empty? - rescue NotImplementedError - end +describe "Process::Status.wait" do + ProcessSpecs.use_system_ruby(self) + + before :all do + begin + leaked = Process.waitall + # Ruby-space should not see PIDs used by rjit + raise "subprocesses leaked before wait specs: #{leaked}" unless leaked.empty? + rescue NotImplementedError end + end + + it "returns a status with pid -1 if there are no child processes" do + Process::Status.wait.pid.should == -1 + end - it "returns a status with pid -1 if there are no child processes" do - Process::Status.wait.pid.should == -1 + platform_is_not :windows do + it "returns a status with its child pid" do + pid = Process.spawn(ruby_cmd('exit')) + status = Process::Status.wait + status.should be_an_instance_of(Process::Status) + status.pid.should == pid end - platform_is_not :windows do - it "returns a status with its child pid" do - pid = Process.spawn(ruby_cmd('exit')) - status = Process::Status.wait - status.should be_an_instance_of(Process::Status) - status.pid.should == pid - end + it "should not set $? to the Process::Status" do + pid = Process.spawn(ruby_cmd('exit')) + status = Process::Status.wait + $?.should_not equal(status) + end - it "should not set $? to the Process::Status" do - pid = Process.spawn(ruby_cmd('exit')) - status = Process::Status.wait - $?.should_not equal(status) - end + it "should not change the value of $?" do + pid = Process.spawn(ruby_cmd('exit')) + Process.wait + status = $? + Process::Status.wait + status.should equal($?) + end - it "should not change the value of $?" do - pid = Process.spawn(ruby_cmd('exit')) - Process.wait - status = $? - Process::Status.wait - status.should equal($?) - end + it "waits for any child process if no pid is given" do + pid = Process.spawn(ruby_cmd('exit')) + Process::Status.wait.pid.should == pid + -> { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) + end - it "waits for any child process if no pid is given" do - pid = Process.spawn(ruby_cmd('exit')) - Process::Status.wait.pid.should == pid - -> { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) - end + it "waits for a specific child if a pid is given" do + pid1 = Process.spawn(ruby_cmd('exit')) + pid2 = Process.spawn(ruby_cmd('exit')) + Process::Status.wait(pid2).pid.should == pid2 + Process::Status.wait(pid1).pid.should == pid1 + -> { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH) + -> { Process.kill(0, pid2) }.should raise_error(Errno::ESRCH) + end - it "waits for a specific child if a pid is given" do - pid1 = Process.spawn(ruby_cmd('exit')) - pid2 = Process.spawn(ruby_cmd('exit')) - Process::Status.wait(pid2).pid.should == pid2 - Process::Status.wait(pid1).pid.should == pid1 - -> { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH) - -> { Process.kill(0, pid2) }.should raise_error(Errno::ESRCH) - end + it "coerces the pid to an Integer" do + pid1 = Process.spawn(ruby_cmd('exit')) + Process::Status.wait(mock_int(pid1)).pid.should == pid1 + -> { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH) + end - it "coerces the pid to an Integer" do - pid1 = Process.spawn(ruby_cmd('exit')) - Process::Status.wait(mock_int(pid1)).pid.should == pid1 - -> { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH) - end + # This spec is probably system-dependent. + it "waits for a child whose process group ID is that of the calling process" do + pid1 = Process.spawn(ruby_cmd('exit'), pgroup: true) + pid2 = Process.spawn(ruby_cmd('exit')) - # This spec is probably system-dependent. - it "waits for a child whose process group ID is that of the calling process" do - pid1 = Process.spawn(ruby_cmd('exit'), pgroup: true) - pid2 = Process.spawn(ruby_cmd('exit')) + Process::Status.wait(0).pid.should == pid2 + Process::Status.wait.pid.should == pid1 + end - Process::Status.wait(0).pid.should == pid2 - Process::Status.wait.pid.should == pid1 + # This spec is probably system-dependent. + it "doesn't block if no child is available when WNOHANG is used" do + read, write = IO.pipe + pid = Process.fork do + read.close + Signal.trap("TERM") { Process.exit! } + write << 1 + write.close + sleep end - # This spec is probably system-dependent. - it "doesn't block if no child is available when WNOHANG is used" do - read, write = IO.pipe - pid = Process.fork do - read.close - Signal.trap("TERM") { Process.exit! } - write << 1 - write.close - sleep - end + Process::Status.wait(pid, Process::WNOHANG).should be_nil - Process::Status.wait(pid, Process::WNOHANG).should be_nil + # wait for the child to setup its TERM handler + write.close + read.read(1) + read.close - # wait for the child to setup its TERM handler - write.close - read.read(1) - read.close - - Process.kill("TERM", pid) - Process::Status.wait.pid.should == pid - end + Process.kill("TERM", pid) + Process::Status.wait.pid.should == pid + end - it "always accepts flags=0" do - pid = Process.spawn(ruby_cmd('exit')) - Process::Status.wait(-1, 0).pid.should == pid - -> { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) - end + it "always accepts flags=0" do + pid = Process.spawn(ruby_cmd('exit')) + Process::Status.wait(-1, 0).pid.should == pid + -> { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) end end end diff --git a/core/random/default_spec.rb b/core/random/default_spec.rb index b4ffcb81f4..01d7430df8 100644 --- a/core/random/default_spec.rb +++ b/core/random/default_spec.rb @@ -14,26 +14,16 @@ seed1.should != seed2 end - ruby_version_is ''...'3.0' do - it "returns a Random instance" do - suppress_warning do - Random::DEFAULT.should be_an_instance_of(Random) - end + it "refers to the Random class" do + suppress_warning do + Random::DEFAULT.should.equal?(Random) end end - ruby_version_is '3.0' do - it "refers to the Random class" do - suppress_warning do - Random::DEFAULT.should.equal?(Random) - end - end - - it "is deprecated" do - -> { - Random::DEFAULT.should.equal?(Random) - }.should complain(/constant Random::DEFAULT is deprecated/) - end + it "is deprecated" do + -> { + Random::DEFAULT.should.equal?(Random) + }.should complain(/constant Random::DEFAULT is deprecated/) end end diff --git a/core/range/frozen_spec.rb b/core/range/frozen_spec.rb index 298ffc87cb..8dab5e5339 100644 --- a/core/range/frozen_spec.rb +++ b/core/range/frozen_spec.rb @@ -2,26 +2,24 @@ # There is no Range#frozen? method but this feels like the best place for these specs describe "Range#frozen?" do - ruby_version_is "3.0" do - it "is true for literal ranges" do - (1..2).should.frozen? - (1..).should.frozen? - (..1).should.frozen? - end + it "is true for literal ranges" do + (1..2).should.frozen? + (1..).should.frozen? + (..1).should.frozen? + end - it "is true for Range.new" do - Range.new(1, 2).should.frozen? - Range.new(1, nil).should.frozen? - Range.new(nil, 1).should.frozen? - end + it "is true for Range.new" do + Range.new(1, 2).should.frozen? + Range.new(1, nil).should.frozen? + Range.new(nil, 1).should.frozen? + end - it "is false for instances of a subclass of Range" do - sub_range = Class.new(Range).new(1, 2) - sub_range.should_not.frozen? - end + it "is false for instances of a subclass of Range" do + sub_range = Class.new(Range).new(1, 2) + sub_range.should_not.frozen? + end - it "is false for Range.allocate" do - Range.allocate.should_not.frozen? - end + it "is false for Range.allocate" do + Range.allocate.should_not.frozen? end end diff --git a/core/range/initialize_spec.rb b/core/range/initialize_spec.rb index 8a6ca65daa..c653caf0c6 100644 --- a/core/range/initialize_spec.rb +++ b/core/range/initialize_spec.rb @@ -27,18 +27,9 @@ -> { @range.send(:initialize, 1, 3, 5, 7, 9) }.should raise_error(ArgumentError) end - ruby_version_is ""..."3.0" do - it "raises a NameError if called on an already initialized Range" do - -> { (0..1).send(:initialize, 1, 3) }.should raise_error(NameError) - -> { (0..1).send(:initialize, 1, 3, true) }.should raise_error(NameError) - end - end - - ruby_version_is "3.0" do - it "raises a FrozenError if called on an already initialized Range" do - -> { (0..1).send(:initialize, 1, 3) }.should raise_error(FrozenError) - -> { (0..1).send(:initialize, 1, 3, true) }.should raise_error(FrozenError) - end + it "raises a FrozenError if called on an already initialized Range" do + -> { (0..1).send(:initialize, 1, 3) }.should raise_error(FrozenError) + -> { (0..1).send(:initialize, 1, 3, true) }.should raise_error(FrozenError) end it "raises an ArgumentError if arguments don't respond to <=>" do diff --git a/core/range/max_spec.rb b/core/range/max_spec.rb index 6c9ada2a3c..a3bbc31e7d 100644 --- a/core/range/max_spec.rb +++ b/core/range/max_spec.rb @@ -50,17 +50,15 @@ -> { eval("(1..)").max }.should raise_error(RangeError) end - ruby_version_is "3.0" do - it "returns the end point for beginless ranges" do - (..1).max.should == 1 - (..1.0).max.should == 1.0 - end + it "returns the end point for beginless ranges" do + (..1).max.should == 1 + (..1.0).max.should == 1.0 + end - it "raises for an exclusive beginless range" do - -> { - (...1).max - }.should raise_error(TypeError, 'cannot exclude end value with non Integer begin value') - end + it "raises for an exclusive beginless range" do + -> { + (...1).max + }.should raise_error(TypeError, 'cannot exclude end value with non Integer begin value') end end diff --git a/core/range/minmax_spec.rb b/core/range/minmax_spec.rb index b2b4fd61a1..6651ae3726 100644 --- a/core/range/minmax_spec.rb +++ b/core/range/minmax_spec.rb @@ -86,24 +86,22 @@ /cannot get the maximum of beginless range with custom comparison method|cannot get the minimum of beginless range/) end - ruby_bug "#17014", ""..."3.0" do - it 'should return nil pair if beginning and end are equal without iterating the range' do - @x.should_not_receive(:succ) + it 'should return nil pair if beginning and end are equal without iterating the range' do + @x.should_not_receive(:succ) - (@x...@x).minmax.should == [nil, nil] - end + (@x...@x).minmax.should == [nil, nil] + end - it 'should return nil pair if beginning is greater than end without iterating the range' do - @y.should_not_receive(:succ) + it 'should return nil pair if beginning is greater than end without iterating the range' do + @y.should_not_receive(:succ) - (@y...@x).minmax.should == [nil, nil] - end + (@y...@x).minmax.should == [nil, nil] + end - it 'should return the minimum and maximum values for a non-numeric range by iterating the range' do - @x.should_receive(:succ).once.and_return(@y) + it 'should return the minimum and maximum values for a non-numeric range by iterating the range' do + @x.should_receive(:succ).once.and_return(@y) - (@x...@y).minmax.should == [@x, @x] - end + (@x...@y).minmax.should == [@x, @x] end it 'should return the minimum and maximum values for a numeric range' do diff --git a/core/range/new_spec.rb b/core/range/new_spec.rb index 40df914b83..3cab887799 100644 --- a/core/range/new_spec.rb +++ b/core/range/new_spec.rb @@ -66,14 +66,12 @@ range_exclude.should_not == range_include end - ruby_version_is "3.0" do - it "creates a frozen range if the class is Range.class" do - Range.new(1, 2).should.frozen? - end - - it "does not create a frozen range if the class is not Range.class" do - Class.new(Range).new(1, 2).should_not.frozen? - end + it "creates a frozen range if the class is Range.class" do + Range.new(1, 2).should.frozen? + end + + it "does not create a frozen range if the class is not Range.class" do + Class.new(Range).new(1, 2).should_not.frozen? end end end diff --git a/core/range/step_spec.rb b/core/range/step_spec.rb index 9024636d55..64ea3de4ed 100644 --- a/core/range/step_spec.rb +++ b/core/range/step_spec.rb @@ -377,48 +377,21 @@ end describe "when no block is given" do - ruby_version_is "3.0" do - it "raises an ArgumentError if step is 0" do - -> { (-1..1).step(0) }.should raise_error(ArgumentError) - end + it "raises an ArgumentError if step is 0" do + -> { (-1..1).step(0) }.should raise_error(ArgumentError) end describe "returned Enumerator" do describe "size" do - ruby_version_is ""..."3.0" do - it "raises a TypeError if step does not respond to #to_int" do - obj = mock("Range#step non-integer") - enum = (1..2).step(obj) - -> { enum.size }.should raise_error(TypeError) - end - - it "raises a TypeError if #to_int does not return an Integer" do - obj = mock("Range#step non-integer") - obj.should_receive(:to_int).and_return("1") - enum = (1..2).step(obj) - - -> { enum.size }.should raise_error(TypeError) - end + it "raises a TypeError if step does not respond to #to_int" do + obj = mock("Range#step non-integer") + -> { (1..2).step(obj) }.should raise_error(TypeError) end - ruby_version_is "3.0" do - it "raises a TypeError if step does not respond to #to_int" do - obj = mock("Range#step non-integer") - -> { (1..2).step(obj) }.should raise_error(TypeError) - end - - it "raises a TypeError if #to_int does not return an Integer" do - obj = mock("Range#step non-integer") - obj.should_receive(:to_int).and_return("1") - -> { (1..2).step(obj) }.should raise_error(TypeError) - end - end - - ruby_version_is ""..."3.0" do - it "returns Float::INFINITY for zero step" do - (-1..1).step(0).size.should == Float::INFINITY - (-1..1).step(0.0).size.should == Float::INFINITY - end + it "raises a TypeError if #to_int does not return an Integer" do + obj = mock("Range#step non-integer") + obj.should_receive(:to_int).and_return("1") + -> { (1..2).step(obj) }.should raise_error(TypeError) end it "returns the ceil of range size divided by the number of steps" do diff --git a/core/regexp/initialize_spec.rb b/core/regexp/initialize_spec.rb index a1583384af..dd57292242 100644 --- a/core/regexp/initialize_spec.rb +++ b/core/regexp/initialize_spec.rb @@ -5,16 +5,8 @@ Regexp.should have_private_instance_method(:initialize) end - ruby_version_is ""..."3.0" do - it "raises a SecurityError on a Regexp literal" do - -> { //.send(:initialize, "") }.should raise_error(SecurityError) - end - end - - ruby_version_is "3.0" do - it "raises a FrozenError on a Regexp literal" do - -> { //.send(:initialize, "") }.should raise_error(FrozenError) - end + it "raises a FrozenError on a Regexp literal" do + -> { //.send(:initialize, "") }.should raise_error(FrozenError) end it "raises a TypeError on an initialized non-literal Regexp" do diff --git a/core/string/capitalize_spec.rb b/core/string/capitalize_spec.rb index 3f85cf5ae4..b79e9cfdbd 100644 --- a/core/string/capitalize_spec.rb +++ b/core/string/capitalize_spec.rb @@ -78,18 +78,9 @@ -> { "abc".capitalize(:invalid_option) }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("hello").capitalize.should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("Hello").capitalize.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("hello").capitalize.should be_an_instance_of(String) - StringSpecs::MyString.new("Hello").capitalize.should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("hello").capitalize.should be_an_instance_of(String) + StringSpecs::MyString.new("Hello").capitalize.should be_an_instance_of(String) end it "returns a String in the same encoding as self" do diff --git a/core/string/center_spec.rb b/core/string/center_spec.rb index 76da6e1e09..a59dd2a91b 100644 --- a/core/string/center_spec.rb +++ b/core/string/center_spec.rb @@ -81,26 +81,13 @@ -> { "hello".center(0, "") }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on subclasses" do - StringSpecs::MyString.new("").center(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").center(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(StringSpecs::MyString) - - "".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end - end + it "returns String instances when called on subclasses" do + StringSpecs::MyString.new("").center(10).should be_an_instance_of(String) + StringSpecs::MyString.new("foo").center(10).should be_an_instance_of(String) + StringSpecs::MyString.new("foo").center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - ruby_version_is '3.0' do - it "returns String instances when called on subclasses" do - StringSpecs::MyString.new("").center(10).should be_an_instance_of(String) - StringSpecs::MyString.new("foo").center(10).should be_an_instance_of(String) - StringSpecs::MyString.new("foo").center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - - "".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end + "".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) + "foo".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) end describe "with width" do diff --git a/core/string/chomp_spec.rb b/core/string/chomp_spec.rb index d0508d938f..ec0490220b 100644 --- a/core/string/chomp_spec.rb +++ b/core/string/chomp_spec.rb @@ -44,18 +44,9 @@ "abc\n\n".encode("US-ASCII").chomp.encoding.should == Encoding::US_ASCII end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - str = StringSpecs::MyString.new("hello\n").chomp - str.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - str = StringSpecs::MyString.new("hello\n").chomp - str.should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + str = StringSpecs::MyString.new("hello\n").chomp + str.should be_an_instance_of(String) end it "removes trailing characters that match $/ when it has been assigned a value" do diff --git a/core/string/chop_spec.rb b/core/string/chop_spec.rb index f598d34bc8..75f25b39cd 100644 --- a/core/string/chop_spec.rb +++ b/core/string/chop_spec.rb @@ -49,16 +49,8 @@ s.chop.should_not equal(s) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("hello\n").chop.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("hello\n").chop.should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("hello\n").chop.should be_an_instance_of(String) end it "returns a String in the same encoding as self" do diff --git a/core/string/delete_prefix_spec.rb b/core/string/delete_prefix_spec.rb index 238de85f05..4214fdecce 100644 --- a/core/string/delete_prefix_spec.rb +++ b/core/string/delete_prefix_spec.rb @@ -38,18 +38,9 @@ 'hello'.delete_prefix(o).should == 'o' end - ruby_version_is ''...'3.0' do - it "returns a subclass instance when called on a subclass instance" do - s = StringSpecs::MyString.new('hello') - s.delete_prefix('hell').should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns a String instance when called on a subclass instance" do - s = StringSpecs::MyString.new('hello') - s.delete_prefix('hell').should be_an_instance_of(String) - end + it "returns a String instance when called on a subclass instance" do + s = StringSpecs::MyString.new('hello') + s.delete_prefix('hell').should be_an_instance_of(String) end it "returns a String in the same encoding as self" do diff --git a/core/string/delete_spec.rb b/core/string/delete_spec.rb index 87831a9d19..3b9aa4fb75 100644 --- a/core/string/delete_spec.rb +++ b/core/string/delete_spec.rb @@ -84,16 +84,8 @@ -> { "hello world".delete(mock('x')) }.should raise_error(TypeError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("oh no!!!").delete("!").should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("oh no!!!").delete("!").should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("oh no!!!").delete("!").should be_an_instance_of(String) end it "returns a String in the same encoding as self" do diff --git a/core/string/delete_suffix_spec.rb b/core/string/delete_suffix_spec.rb index 6883d6938c..9381f4cee7 100644 --- a/core/string/delete_suffix_spec.rb +++ b/core/string/delete_suffix_spec.rb @@ -38,18 +38,9 @@ 'hello'.delete_suffix(o).should == 'h' end - ruby_version_is ''...'3.0' do - it "returns a subclass instance when called on a subclass instance" do - s = StringSpecs::MyString.new('hello') - s.delete_suffix('ello').should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns a String instance when called on a subclass instance" do - s = StringSpecs::MyString.new('hello') - s.delete_suffix('ello').should be_an_instance_of(String) - end + it "returns a String instance when called on a subclass instance" do + s = StringSpecs::MyString.new('hello') + s.delete_suffix('ello').should be_an_instance_of(String) end it "returns a String in the same encoding as self" do diff --git a/core/string/downcase_spec.rb b/core/string/downcase_spec.rb index 153b4ce191..7ee9d6df1d 100644 --- a/core/string/downcase_spec.rb +++ b/core/string/downcase_spec.rb @@ -76,16 +76,8 @@ -> { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it "returns a subclass instance for subclasses" do - StringSpecs::MyString.new("FOObar").downcase.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns a String instance for subclasses" do - StringSpecs::MyString.new("FOObar").downcase.should be_an_instance_of(String) - end + it "returns a String instance for subclasses" do + StringSpecs::MyString.new("FOObar").downcase.should be_an_instance_of(String) end end diff --git a/core/string/dump_spec.rb b/core/string/dump_spec.rb index 81de0cfae4..cab8beff5a 100644 --- a/core/string/dump_spec.rb +++ b/core/string/dump_spec.rb @@ -7,16 +7,8 @@ "foo".freeze.dump.should_not.frozen? end - ruby_version_is ''...'3.0' do - it "returns a subclass instance" do - StringSpecs::MyString.new.dump.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns a String instance" do - StringSpecs::MyString.new.dump.should be_an_instance_of(String) - end + it "returns a String instance" do + StringSpecs::MyString.new.dump.should be_an_instance_of(String) end it "wraps string with \"" do diff --git a/core/string/each_grapheme_cluster_spec.rb b/core/string/each_grapheme_cluster_spec.rb index f28e24000e..e1fa4ae67b 100644 --- a/core/string/each_grapheme_cluster_spec.rb +++ b/core/string/each_grapheme_cluster_spec.rb @@ -8,11 +8,9 @@ it_behaves_like :string_grapheme_clusters, :each_grapheme_cluster it_behaves_like :string_each_char_without_block, :each_grapheme_cluster - ruby_version_is '3.0' do - it "yields String instances for subclasses" do - a = [] - StringSpecs::MyString.new("abc").each_grapheme_cluster { |s| a << s.class } - a.should == [String, String, String] - end + it "yields String instances for subclasses" do + a = [] + StringSpecs::MyString.new("abc").each_grapheme_cluster { |s| a << s.class } + a.should == [String, String, String] end end diff --git a/core/string/gsub_spec.rb b/core/string/gsub_spec.rb index c87a566591..9e3b50322c 100644 --- a/core/string/gsub_spec.rb +++ b/core/string/gsub_spec.rb @@ -192,22 +192,11 @@ def replacement.to_str() "hello_replacement" end -> { "hello".gsub(/[aeiou]/, nil) }.should raise_error(TypeError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("").gsub(//, "").should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("").gsub(/foo/, "").should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").gsub(/foo/, "").should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").gsub("foo", "").should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("").gsub(//, "").should be_an_instance_of(String) - StringSpecs::MyString.new("").gsub(/foo/, "").should be_an_instance_of(String) - StringSpecs::MyString.new("foo").gsub(/foo/, "").should be_an_instance_of(String) - StringSpecs::MyString.new("foo").gsub("foo", "").should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("").gsub(//, "").should be_an_instance_of(String) + StringSpecs::MyString.new("").gsub(/foo/, "").should be_an_instance_of(String) + StringSpecs::MyString.new("foo").gsub(/foo/, "").should be_an_instance_of(String) + StringSpecs::MyString.new("foo").gsub("foo", "").should be_an_instance_of(String) end it "sets $~ to MatchData of last match and nil when there's none" do diff --git a/core/string/ljust_spec.rb b/core/string/ljust_spec.rb index 9a25d3abd4..9208ec5897 100644 --- a/core/string/ljust_spec.rb +++ b/core/string/ljust_spec.rb @@ -64,26 +64,13 @@ -> { "hello".ljust(10, '') }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on subclasses" do - StringSpecs::MyString.new("").ljust(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").ljust(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(StringSpecs::MyString) - - "".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end - end + it "returns String instances when called on subclasses" do + StringSpecs::MyString.new("").ljust(10).should be_an_instance_of(String) + StringSpecs::MyString.new("foo").ljust(10).should be_an_instance_of(String) + StringSpecs::MyString.new("foo").ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - ruby_version_is '3.0' do - it "returns String instances when called on subclasses" do - StringSpecs::MyString.new("").ljust(10).should be_an_instance_of(String) - StringSpecs::MyString.new("foo").ljust(10).should be_an_instance_of(String) - StringSpecs::MyString.new("foo").ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - - "".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end + "".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) + "foo".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) end describe "with width" do diff --git a/core/string/lstrip_spec.rb b/core/string/lstrip_spec.rb index 75434613f1..85685deb0a 100644 --- a/core/string/lstrip_spec.rb +++ b/core/string/lstrip_spec.rb @@ -20,11 +20,9 @@ " こにちわ "[1...-1].lstrip.should == "こにちわ" end - ruby_version_is '3.0' do - it "strips leading \\0" do - "\x00hello".lstrip.should == "hello" - "\000 \000hello\000 \000".lstrip.should == "hello\000 \000" - end + it "strips leading \\0" do + "\x00hello".lstrip.should == "hello" + "\000 \000hello\000 \000".lstrip.should == "hello\000 \000" end end @@ -47,12 +45,10 @@ " ".lstrip.should == "" end - ruby_version_is '3.0' do - it "removes leading NULL bytes and whitespace" do - a = "\000 \000hello\000 \000" - a.lstrip! - a.should == "hello\000 \000" - end + it "removes leading NULL bytes and whitespace" do + a = "\000 \000hello\000 \000" + a.lstrip! + a.should == "hello\000 \000" end it "raises a FrozenError on a frozen instance that is modified" do diff --git a/core/string/reverse_spec.rb b/core/string/reverse_spec.rb index 73526256ef..e67122c05c 100644 --- a/core/string/reverse_spec.rb +++ b/core/string/reverse_spec.rb @@ -10,20 +10,10 @@ "".reverse.should == "" end - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("stressed").reverse.should be_an_instance_of(String) - StringSpecs::MyString.new("m").reverse.should be_an_instance_of(String) - StringSpecs::MyString.new("").reverse.should be_an_instance_of(String) - end - end - - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("stressed").reverse.should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("m").reverse.should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("").reverse.should be_an_instance_of(StringSpecs::MyString) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("stressed").reverse.should be_an_instance_of(String) + StringSpecs::MyString.new("m").reverse.should be_an_instance_of(String) + StringSpecs::MyString.new("").reverse.should be_an_instance_of(String) end it "reverses a string with multi byte characters" do diff --git a/core/string/rjust_spec.rb b/core/string/rjust_spec.rb index d067b7bdb3..fcbaf3b938 100644 --- a/core/string/rjust_spec.rb +++ b/core/string/rjust_spec.rb @@ -64,26 +64,13 @@ -> { "hello".rjust(10, '') }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on subclasses" do - StringSpecs::MyString.new("").rjust(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").rjust(10).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(StringSpecs::MyString) - - "".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end - end + it "returns String instances when called on subclasses" do + StringSpecs::MyString.new("").rjust(10).should be_an_instance_of(String) + StringSpecs::MyString.new("foo").rjust(10).should be_an_instance_of(String) + StringSpecs::MyString.new("foo").rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - ruby_version_is '3.0' do - it "returns String instances when called on subclasses" do - StringSpecs::MyString.new("").rjust(10).should be_an_instance_of(String) - StringSpecs::MyString.new("foo").rjust(10).should be_an_instance_of(String) - StringSpecs::MyString.new("foo").rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - - "".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - "foo".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) - end + "".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) + "foo".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String) end describe "with width" do diff --git a/core/string/rstrip_spec.rb b/core/string/rstrip_spec.rb index e96ce4120f..e4cf93315e 100644 --- a/core/string/rstrip_spec.rb +++ b/core/string/rstrip_spec.rb @@ -51,12 +51,10 @@ " ".rstrip.should == "" end - ruby_version_is '3.0' do - it "removes trailing NULL bytes and whitespace" do - a = "\000 goodbye \000" - a.rstrip! - a.should == "\000 goodbye" - end + it "removes trailing NULL bytes and whitespace" do + a = "\000 goodbye \000" + a.rstrip! + a.should == "\000 goodbye" end it "raises a FrozenError on a frozen instance that is modified" do diff --git a/core/string/scan_spec.rb b/core/string/scan_spec.rb index a2d1815132..70c3b7fb7b 100644 --- a/core/string/scan_spec.rb +++ b/core/string/scan_spec.rb @@ -165,11 +165,9 @@ end end - ruby_version_is '3.0' do - it "yields String instances for subclasses" do - a = [] - StringSpecs::MyString.new("abc").scan(/./) { |s| a << s.class } - a.should == [String, String, String] - end + it "yields String instances for subclasses" do + a = [] + StringSpecs::MyString.new("abc").scan(/./) { |s| a << s.class } + a.should == [String, String, String] end end diff --git a/core/string/scrub_spec.rb b/core/string/scrub_spec.rb index a51fbd020a..bcee4db463 100644 --- a/core/string/scrub_spec.rb +++ b/core/string/scrub_spec.rb @@ -36,18 +36,10 @@ "abc\u3042#{x81}".scrub.encoding.should == Encoding::UTF_8 end - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("foo").scrub.should be_an_instance_of(String) - input = [0x81].pack('C').force_encoding('utf-8') - StringSpecs::MyString.new(input).scrub.should be_an_instance_of(String) - end - end - - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("foo").scrub.should be_an_instance_of(StringSpecs::MyString) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("foo").scrub.should be_an_instance_of(String) + input = [0x81].pack('C').force_encoding('utf-8') + StringSpecs::MyString.new(input).scrub.should be_an_instance_of(String) end end @@ -97,12 +89,10 @@ block.should raise_error(TypeError) end - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("foo").scrub("*").should be_an_instance_of(String) - input = [0x81].pack('C').force_encoding('utf-8') - StringSpecs::MyString.new(input).scrub("*").should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("foo").scrub("*").should be_an_instance_of(String) + input = [0x81].pack('C').force_encoding('utf-8') + StringSpecs::MyString.new(input).scrub("*").should be_an_instance_of(String) end end @@ -129,12 +119,10 @@ replaced.should == "€€" end - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("foo").scrub { |b| "*" }.should be_an_instance_of(String) - input = [0x81].pack('C').force_encoding('utf-8') - StringSpecs::MyString.new(input).scrub { |b| "<#{b.unpack("H*")[0]}>" }.should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("foo").scrub { |b| "*" }.should be_an_instance_of(String) + input = [0x81].pack('C').force_encoding('utf-8') + StringSpecs::MyString.new(input).scrub { |b| "<#{b.unpack("H*")[0]}>" }.should be_an_instance_of(String) end end diff --git a/core/string/shared/dedup.rb b/core/string/shared/dedup.rb index 6ffcb9b045..893fd1e360 100644 --- a/core/string/shared/dedup.rb +++ b/core/string/shared/dedup.rb @@ -48,10 +48,8 @@ dynamic.send(@method).should equal(dynamic) end - ruby_version_is "3.0" do - it "interns the provided string if it is frozen" do - dynamic = "this string is unique and frozen #{rand}".freeze - dynamic.send(@method).should equal(dynamic) - end + it "interns the provided string if it is frozen" do + dynamic = "this string is unique and frozen #{rand}".freeze + dynamic.send(@method).should equal(dynamic) end end diff --git a/core/string/shared/each_line.rb b/core/string/shared/each_line.rb index df78bd2186..a14b4d7779 100644 --- a/core/string/shared/each_line.rb +++ b/core/string/shared/each_line.rb @@ -85,20 +85,10 @@ end end - ruby_version_is ''...'3.0' do - it "yields subclass instances for subclasses" do - a = [] - StringSpecs::MyString.new("hello\nworld").send(@method) { |s| a << s.class } - a.should == [StringSpecs::MyString, StringSpecs::MyString] - end - end - - ruby_version_is '3.0' do - it "yields String instances for subclasses" do - a = [] - StringSpecs::MyString.new("hello\nworld").send(@method) { |s| a << s.class } - a.should == [String, String] - end + it "yields String instances for subclasses" do + a = [] + StringSpecs::MyString.new("hello\nworld").send(@method) { |s| a << s.class } + a.should == [String, String] end it "returns self" do diff --git a/core/string/shared/partition.rb b/core/string/shared/partition.rb index 41b3c7e0c9..4cac149ce5 100644 --- a/core/string/shared/partition.rb +++ b/core/string/shared/partition.rb @@ -2,35 +2,17 @@ require_relative '../fixtures/classes' describe :string_partition, shared: true do - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("hello").send(@method, "l").each do |item| - item.should be_an_instance_of(String) - end - - StringSpecs::MyString.new("hello").send(@method, "x").each do |item| - item.should be_an_instance_of(String) - end - - StringSpecs::MyString.new("hello").send(@method, /l./).each do |item| - item.should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("hello").send(@method, "l").each do |item| + item.should be_an_instance_of(String) end - end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("hello").send(@method, StringSpecs::MyString.new("l")).each do |item| - item.should be_an_instance_of(StringSpecs::MyString) - end - - StringSpecs::MyString.new("hello").send(@method, "x").each do |item| - item.should be_an_instance_of(StringSpecs::MyString) - end + StringSpecs::MyString.new("hello").send(@method, "x").each do |item| + item.should be_an_instance_of(String) + end - StringSpecs::MyString.new("hello").send(@method, /l./).each do |item| - item.should be_an_instance_of(StringSpecs::MyString) - end + StringSpecs::MyString.new("hello").send(@method, /l./).each do |item| + item.should be_an_instance_of(String) end end diff --git a/core/string/shared/slice.rb b/core/string/shared/slice.rb index a7c1d05b56..3ef4bc50d7 100644 --- a/core/string/shared/slice.rb +++ b/core/string/shared/slice.rb @@ -152,22 +152,11 @@ -> { "hello".send(@method, 0, bignum_value) }.should raise_error(RangeError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, 0,0).should be_an_instance_of(StringSpecs::MyString) - s.send(@method, 0,4).should be_an_instance_of(StringSpecs::MyString) - s.send(@method, 1,4).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, 0,0).should be_an_instance_of(String) - s.send(@method, 0,4).should be_an_instance_of(String) - s.send(@method, 1,4).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.send(@method, 0,0).should be_an_instance_of(String) + s.send(@method, 0,4).should be_an_instance_of(String) + s.send(@method, 1,4).should be_an_instance_of(String) end it "handles repeated application" do @@ -242,22 +231,11 @@ "x".send(@method, 1...-1).should == "" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, 0...0).should be_an_instance_of(StringSpecs::MyString) - s.send(@method, 0..4).should be_an_instance_of(StringSpecs::MyString) - s.send(@method, 1..4).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, 0...0).should be_an_instance_of(String) - s.send(@method, 0..4).should be_an_instance_of(String) - s.send(@method, 1..4).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.send(@method, 0...0).should be_an_instance_of(String) + s.send(@method, 0..4).should be_an_instance_of(String) + s.send(@method, 1..4).should be_an_instance_of(String) end it "calls to_int on range arguments" do @@ -336,20 +314,10 @@ "hello there".encode("US-ASCII").send(@method, /[aeiou](.)\1/).encoding.should == Encoding::US_ASCII end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, //).should be_an_instance_of(StringSpecs::MyString) - s.send(@method, /../).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, //).should be_an_instance_of(String) - s.send(@method, /../).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.send(@method, //).should be_an_instance_of(String) + s.send(@method, /../).should be_an_instance_of(String) end it "sets $~ to MatchData when there is a match and nil when there's none" do @@ -418,20 +386,10 @@ -> { "hello".send(@method, /(.)(.)(.)/, nil) }.should raise_error(TypeError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, /(.)(.)/, 0).should be_an_instance_of(StringSpecs::MyString) - s.send(@method, /(.)(.)/, 1).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, /(.)(.)/, 0).should be_an_instance_of(String) - s.send(@method, /(.)(.)/, 1).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.send(@method, /(.)(.)/, 0).should be_an_instance_of(String) + s.send(@method, /(.)(.)/, 1).should be_an_instance_of(String) end it "sets $~ to MatchData when there is a match and nil when there's none" do @@ -470,22 +428,11 @@ -> { "hello".send(@method, o) }.should raise_error(TypeError) end - ruby_version_is ''...'3.0' do - it "returns a subclass instance when given a subclass instance" do - s = StringSpecs::MyString.new("el") - r = "hello".send(@method, s) - r.should == "el" - r.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns a String instance when given a subclass instance" do - s = StringSpecs::MyString.new("el") - r = "hello".send(@method, s) - r.should == "el" - r.should be_an_instance_of(String) - end + it "returns a String instance when given a subclass instance" do + s = StringSpecs::MyString.new("el") + r = "hello".send(@method, s) + r.should == "el" + r.should be_an_instance_of(String) end end @@ -531,18 +478,9 @@ -> { "hello".send(@method, /(?)/, '') }.should raise_error(IndexError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, /(?.)/, 'q').should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.send(@method, /(?.)/, 'q').should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.send(@method, /(?.)/, 'q').should be_an_instance_of(String) end it "sets $~ to MatchData when there is a match and nil when there's none" do diff --git a/core/string/shared/strip.rb b/core/string/shared/strip.rb index 0c0aae20f3..3af77b50fe 100644 --- a/core/string/shared/strip.rb +++ b/core/string/shared/strip.rb @@ -6,19 +6,9 @@ " hello ".encode("US-ASCII").send(@method).encoding.should == Encoding::US_ASCII end - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new(" hello ").send(@method).should be_an_instance_of(String) - StringSpecs::MyString.new(" ").send(@method).should be_an_instance_of(String) - StringSpecs::MyString.new("").send(@method).should be_an_instance_of(String) - end - end - - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new(" hello ").send(@method).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new(" ").send(@method).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("").send(@method).should be_an_instance_of(StringSpecs::MyString) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new(" hello ").send(@method).should be_an_instance_of(String) + StringSpecs::MyString.new(" ").send(@method).should be_an_instance_of(String) + StringSpecs::MyString.new("").send(@method).should be_an_instance_of(String) end end diff --git a/core/string/shared/succ.rb b/core/string/shared/succ.rb index 3605fa99a2..24a729ce26 100644 --- a/core/string/shared/succ.rb +++ b/core/string/shared/succ.rb @@ -59,20 +59,10 @@ "\xFF\xFF".send(@method).should == "\x01\x00\x00" end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("").send(@method).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("a").send(@method).should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("z").send(@method).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("").send(@method).should be_an_instance_of(String) - StringSpecs::MyString.new("a").send(@method).should be_an_instance_of(String) - StringSpecs::MyString.new("z").send(@method).should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("").send(@method).should be_an_instance_of(String) + StringSpecs::MyString.new("a").send(@method).should be_an_instance_of(String) + StringSpecs::MyString.new("z").send(@method).should be_an_instance_of(String) end it "returns a String in the same encoding as self" do diff --git a/core/string/slice_spec.rb b/core/string/slice_spec.rb index c9e13ed1bc..87c5a7ac37 100644 --- a/core/string/slice_spec.rb +++ b/core/string/slice_spec.rb @@ -132,20 +132,10 @@ def obj.method_missing(name, *) name == :to_int ? 2 : super; end "hello".slice!(obj, obj).should == "ll" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(0, 0).should be_an_instance_of(StringSpecs::MyString) - s.slice!(0, 4).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(0, 0).should be_an_instance_of(String) - s.slice!(0, 4).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.slice!(0, 0).should be_an_instance_of(String) + s.slice!(0, 4).should be_an_instance_of(String) end it "returns the substring given by the character offsets" do @@ -185,20 +175,10 @@ def obj.method_missing(name, *) name == :to_int ? 2 : super; end b.should == "hello" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(0...0).should be_an_instance_of(StringSpecs::MyString) - s.slice!(0..4).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(0...0).should be_an_instance_of(String) - s.slice!(0..4).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.slice!(0...0).should be_an_instance_of(String) + s.slice!(0..4).should be_an_instance_of(String) end it "calls to_int on range arguments" do @@ -274,20 +254,10 @@ def to.method_missing(name) name == :to_int ? -2 : super; end s.should == "this is a string" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(//).should be_an_instance_of(StringSpecs::MyString) - s.slice!(/../).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(//).should be_an_instance_of(String) - s.slice!(/../).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.slice!(//).should be_an_instance_of(String) + s.slice!(/../).should be_an_instance_of(String) end it "returns the matching portion of self with a multi byte character" do @@ -344,20 +314,10 @@ def to.method_missing(name) name == :to_int ? -2 : super; end "har".slice!(/(.)(.)(.)/, obj).should == "a" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(/(.)(.)/, 0).should be_an_instance_of(StringSpecs::MyString) - s.slice!(/(.)(.)/, 1).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(/(.)(.)/, 0).should be_an_instance_of(String) - s.slice!(/(.)(.)/, 1).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.slice!(/(.)(.)/, 0).should be_an_instance_of(String) + s.slice!(/(.)(.)/, 1).should be_an_instance_of(String) end it "returns the encoding aware capture for the given index" do @@ -415,22 +375,11 @@ def to.method_missing(name) name == :to_int ? -2 : super; end -> { "hello".slice!(o) }.should raise_error(TypeError) end - ruby_version_is ''...'3.0' do - it "returns a subclass instance when given a subclass instance" do - s = StringSpecs::MyString.new("el") - r = "hello".slice!(s) - r.should == "el" - r.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns a subclass instance when given a subclass instance" do - s = StringSpecs::MyString.new("el") - r = "hello".slice!(s) - r.should == "el" - r.should be_an_instance_of(String) - end + it "returns a subclass instance when given a subclass instance" do + s = StringSpecs::MyString.new("el") + r = "hello".slice!(s) + r.should == "el" + r.should be_an_instance_of(String) end it "raises a FrozenError if self is frozen" do diff --git a/core/string/split_spec.rb b/core/string/split_spec.rb index 519c5d845d..c5cca651c2 100644 --- a/core/string/split_spec.rb +++ b/core/string/split_spec.rb @@ -192,44 +192,16 @@ "foo".split("bar", 3).should == ["foo"] end - ruby_version_is ''...'3.0' do - it "returns subclass instances based on self" do - ["", "x.y.z.", " x y "].each do |str| - ["", ".", " "].each do |pat| - [-1, 0, 1, 2].each do |limit| - StringSpecs::MyString.new(str).split(pat, limit).each do |x| - x.should be_an_instance_of(StringSpecs::MyString) - end - - str.split(StringSpecs::MyString.new(pat), limit).each do |x| - x.should be_an_instance_of(String) - end + it "returns String instances based on self" do + ["", "x.y.z.", " x y "].each do |str| + ["", ".", " "].each do |pat| + [-1, 0, 1, 2].each do |limit| + StringSpecs::MyString.new(str).split(pat, limit).each do |x| + x.should be_an_instance_of(String) end - end - end - end - - it "does not call constructor on created subclass instances" do - # can't call should_not_receive on an object that doesn't yet exist - # so failure here is signalled by exception, not expectation failure - - s = StringSpecs::StringWithRaisingConstructor.new('silly:string') - s.split(':').first.should == 'silly' - end - end - - ruby_version_is '3.0' do - it "returns String instances based on self" do - ["", "x.y.z.", " x y "].each do |str| - ["", ".", " "].each do |pat| - [-1, 0, 1, 2].each do |limit| - StringSpecs::MyString.new(str).split(pat, limit).each do |x| - x.should be_an_instance_of(String) - end - str.split(StringSpecs::MyString.new(pat), limit).each do |x| - x.should be_an_instance_of(String) - end + str.split(StringSpecs::MyString.new(pat), limit).each do |x| + x.should be_an_instance_of(String) end end end @@ -414,36 +386,12 @@ "foo".split(/bar/, 3).should == ["foo"] end - ruby_version_is ''...'3.0' do - it "returns subclass instances based on self" do - ["", "x:y:z:", " x y "].each do |str| - [//, /:/, /\s+/].each do |pat| - [-1, 0, 1, 2].each do |limit| - StringSpecs::MyString.new(str).split(pat, limit).each do |x| - x.should be_an_instance_of(StringSpecs::MyString) - end - end - end - end - end - - it "does not call constructor on created subclass instances" do - # can't call should_not_receive on an object that doesn't yet exist - # so failure here is signalled by exception, not expectation failure - - s = StringSpecs::StringWithRaisingConstructor.new('silly:string') - s.split(/:/).first.should == 'silly' - end - end - - ruby_version_is '3.0' do - it "returns String instances based on self" do - ["", "x:y:z:", " x y "].each do |str| - [//, /:/, /\s+/].each do |pat| - [-1, 0, 1, 2].each do |limit| - StringSpecs::MyString.new(str).split(pat, limit).each do |x| - x.should be_an_instance_of(String) - end + it "returns String instances based on self" do + ["", "x:y:z:", " x y "].each do |str| + [//, /:/, /\s+/].each do |pat| + [-1, 0, 1, 2].each do |limit| + StringSpecs::MyString.new(str).split(pat, limit).each do |x| + x.should be_an_instance_of(String) end end end @@ -569,32 +517,16 @@ end describe "for a String subclass" do - ruby_version_is ''...'3.0' do - it "yields instances of the same subclass" do - a = [] - StringSpecs::MyString.new("a|b").split("|") { |str| a << str } - first, last = a - - first.should be_an_instance_of(StringSpecs::MyString) - first.should == "a" - - last.should be_an_instance_of(StringSpecs::MyString) - last.should == "b" - end - end - - ruby_version_is '3.0' do - it "yields instances of String" do - a = [] - StringSpecs::MyString.new("a|b").split("|") { |str| a << str } - first, last = a + it "yields instances of String" do + a = [] + StringSpecs::MyString.new("a|b").split("|") { |str| a << str } + first, last = a - first.should be_an_instance_of(String) - first.should == "a" + first.should be_an_instance_of(String) + first.should == "a" - last.should be_an_instance_of(String) - last.should == "b" - end + last.should be_an_instance_of(String) + last.should == "b" end end diff --git a/core/string/squeeze_spec.rb b/core/string/squeeze_spec.rb index 2f3fa65745..4796a170f2 100644 --- a/core/string/squeeze_spec.rb +++ b/core/string/squeeze_spec.rb @@ -75,16 +75,8 @@ -> { "hello world".squeeze(mock('x')) }.should raise_error(TypeError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("oh no!!!").squeeze("!").should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("oh no!!!").squeeze("!").should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("oh no!!!").squeeze("!").should be_an_instance_of(String) end end diff --git a/core/string/strip_spec.rb b/core/string/strip_spec.rb index 662f13b032..5e90fe35d0 100644 --- a/core/string/strip_spec.rb +++ b/core/string/strip_spec.rb @@ -11,10 +11,8 @@ "\tgoodbye\r\v\n".strip.should == "goodbye" end - ruby_version_is '3.0' do - it "returns a copy of self without leading and trailing NULL bytes and whitespace" do - " \x00 goodbye \x00 ".strip.should == "goodbye" - end + it "returns a copy of self without leading and trailing NULL bytes and whitespace" do + " \x00 goodbye \x00 ".strip.should == "goodbye" end end @@ -41,12 +39,10 @@ " ".strip.should == "" end - ruby_version_is '3.0' do - it "removes leading and trailing NULL bytes and whitespace" do - a = "\000 goodbye \000" - a.strip! - a.should == "goodbye" - end + it "removes leading and trailing NULL bytes and whitespace" do + a = "\000 goodbye \000" + a.strip! + a.should == "goodbye" end it "raises a FrozenError on a frozen instance that is modified" do diff --git a/core/string/sub_spec.rb b/core/string/sub_spec.rb index 99dd7b45a8..51920486f5 100644 --- a/core/string/sub_spec.rb +++ b/core/string/sub_spec.rb @@ -170,22 +170,11 @@ -> { "hello".sub(/[aeiou]/, 99) }.should raise_error(TypeError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("").sub(//, "").should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("").sub(/foo/, "").should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").sub(/foo/, "").should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("foo").sub("foo", "").should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("").sub(//, "").should be_an_instance_of(String) - StringSpecs::MyString.new("").sub(/foo/, "").should be_an_instance_of(String) - StringSpecs::MyString.new("foo").sub(/foo/, "").should be_an_instance_of(String) - StringSpecs::MyString.new("foo").sub("foo", "").should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("").sub(//, "").should be_an_instance_of(String) + StringSpecs::MyString.new("").sub(/foo/, "").should be_an_instance_of(String) + StringSpecs::MyString.new("foo").sub(/foo/, "").should be_an_instance_of(String) + StringSpecs::MyString.new("foo").sub("foo", "").should be_an_instance_of(String) end it "sets $~ to MatchData of match and nil when there's none" do diff --git a/core/string/swapcase_spec.rb b/core/string/swapcase_spec.rb index d369ab3e4e..d740fb86c6 100644 --- a/core/string/swapcase_spec.rb +++ b/core/string/swapcase_spec.rb @@ -74,18 +74,9 @@ -> { "abc".swapcase(:invalid_option) }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("").swapcase.should be_an_instance_of(StringSpecs::MyString) - StringSpecs::MyString.new("hello").swapcase.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("").swapcase.should be_an_instance_of(String) - StringSpecs::MyString.new("hello").swapcase.should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("").swapcase.should be_an_instance_of(String) + StringSpecs::MyString.new("hello").swapcase.should be_an_instance_of(String) end end diff --git a/core/string/tr_s_spec.rb b/core/string/tr_s_spec.rb index e1bb20ce35..b5c87d4e4e 100644 --- a/core/string/tr_s_spec.rb +++ b/core/string/tr_s_spec.rb @@ -45,16 +45,8 @@ "bla".tr_s(from_str, to_str).should == "BlA" end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("hello").tr_s("e", "a").should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances when called on a subclass" do - StringSpecs::MyString.new("hello").tr_s("e", "a").should be_an_instance_of(String) - end + it "returns String instances when called on a subclass" do + StringSpecs::MyString.new("hello").tr_s("e", "a").should be_an_instance_of(String) end # http://redmine.ruby-lang.org/issues/show/1839 diff --git a/core/string/tr_spec.rb b/core/string/tr_spec.rb index 72adb9f2eb..cf485d32a3 100644 --- a/core/string/tr_spec.rb +++ b/core/string/tr_spec.rb @@ -57,16 +57,8 @@ "bla".tr(from_str, to_str).should == "BlA" end - ruby_version_is ''...'3.0' do - it "returns subclass instances when called on a subclass" do - StringSpecs::MyString.new("hello").tr("e", "a").should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns Stringinstances when called on a subclass" do - StringSpecs::MyString.new("hello").tr("e", "a").should be_an_instance_of(String) - end + it "returns Stringinstances when called on a subclass" do + StringSpecs::MyString.new("hello").tr("e", "a").should be_an_instance_of(String) end # http://redmine.ruby-lang.org/issues/show/1839 diff --git a/core/string/upcase_spec.rb b/core/string/upcase_spec.rb index 5ce7b0b95f..a2e34f5f40 100644 --- a/core/string/upcase_spec.rb +++ b/core/string/upcase_spec.rb @@ -73,16 +73,8 @@ -> { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - it "returns a subclass instance for subclasses" do - StringSpecs::MyString.new("fooBAR").upcase.should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns a String instance for subclasses" do - StringSpecs::MyString.new("fooBAR").upcase.should be_an_instance_of(String) - end + it "returns a String instance for subclasses" do + StringSpecs::MyString.new("fooBAR").upcase.should be_an_instance_of(String) end end diff --git a/core/string/valid_encoding_spec.rb b/core/string/valid_encoding_spec.rb index be7cef7a8e..bb26062c0f 100644 --- a/core/string/valid_encoding_spec.rb +++ b/core/string/valid_encoding_spec.rb @@ -100,12 +100,10 @@ str.force_encoding('UTF8-MAC').valid_encoding?.should be_true end - ruby_version_is '3.0' do - it "returns true for IBM720 encoding self is valid in" do - str = "\xE6\x9D\x94" - str.force_encoding('IBM720').valid_encoding?.should be_true - str.force_encoding('CP720').valid_encoding?.should be_true - end + it "returns true for IBM720 encoding self is valid in" do + str = "\xE6\x9D\x94" + str.force_encoding('IBM720').valid_encoding?.should be_true + str.force_encoding('CP720').valid_encoding?.should be_true end it "returns false if self is valid in one encoding, but invalid in the one it's tagged with" do diff --git a/core/symbol/name_spec.rb b/core/symbol/name_spec.rb index 15b9aa75e9..f9b631266c 100644 --- a/core/symbol/name_spec.rb +++ b/core/symbol/name_spec.rb @@ -1,19 +1,17 @@ require_relative '../../spec_helper' -ruby_version_is "3.0" do - describe "Symbol#name" do - it "returns string" do - :ruby.name.should == "ruby" - :ルビー.name.should == "ルビー" - end +describe "Symbol#name" do + it "returns string" do + :ruby.name.should == "ruby" + :ルビー.name.should == "ルビー" + end - it "returns same string instance" do - :"ruby_3".name.should.equal?(:ruby_3.name) - :"ruby_#{1+2}".name.should.equal?(:ruby_3.name) - end + it "returns same string instance" do + :"ruby_3".name.should.equal?(:ruby_3.name) + :"ruby_#{1+2}".name.should.equal?(:ruby_3.name) + end - it "returns frozen string" do - :symbol.name.should.frozen? - end + it "returns frozen string" do + :symbol.name.should.frozen? end end diff --git a/core/symbol/to_proc_spec.rb b/core/symbol/to_proc_spec.rb index 6d9c4bc622..2cd013696a 100644 --- a/core/symbol/to_proc_spec.rb +++ b/core/symbol/to_proc_spec.rb @@ -12,38 +12,19 @@ :to_s.to_proc.call(obj).should == "Received #to_s" end - ruby_version_is ""..."3.0" do - it "returns a Proc with #lambda? false" do - pr = :to_s.to_proc - pr.should_not.lambda? - end - - it "produces a Proc with arity -1" do - pr = :to_s.to_proc - pr.arity.should == -1 - end - - it "produces a Proc that always returns [[:rest]] for #parameters" do - pr = :to_s.to_proc - pr.parameters.should == [[:rest]] - end + it "returns a Proc with #lambda? true" do + pr = :to_s.to_proc + pr.should.lambda? end - ruby_version_is "3.0" do - it "returns a Proc with #lambda? true" do - pr = :to_s.to_proc - pr.should.lambda? - end - - it "produces a Proc with arity -2" do - pr = :to_s.to_proc - pr.arity.should == -2 - end + it "produces a Proc with arity -2" do + pr = :to_s.to_proc + pr.arity.should == -2 + end - it "produces a Proc that always returns [[:req], [:rest]] for #parameters" do - pr = :to_s.to_proc - pr.parameters.should == [[:req], [:rest]] - end + it "produces a Proc that always returns [[:req], [:rest]] for #parameters" do + pr = :to_s.to_proc + pr.parameters.should == [[:req], [:rest]] end ruby_version_is "3.2" do diff --git a/core/thread/exclusive_spec.rb b/core/thread/exclusive_spec.rb deleted file mode 100644 index 37c4b19d1a..0000000000 --- a/core/thread/exclusive_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ''...'3.0' do - describe "Thread.exclusive" do - before :each do - ScratchPad.clear - $VERBOSE, @verbose = nil, $VERBOSE - end - - after :each do - $VERBOSE = @verbose - end - - it "yields to the block" do - Thread.exclusive { ScratchPad.record true } - ScratchPad.recorded.should == true - end - - it "returns the result of yielding" do - Thread.exclusive { :result }.should == :result - end - - it "blocks the caller if another thread is also in an exclusive block" do - m = Mutex.new - q1 = Queue.new - q2 = Queue.new - - t = Thread.new { - Thread.exclusive { - q1.push :ready - q2.pop - } - } - - q1.pop.should == :ready - - -> { Thread.exclusive { } }.should block_caller - - q2.push :done - t.join - end - - it "is not recursive" do - Thread.exclusive do - -> { Thread.exclusive { } }.should raise_error(ThreadError) - end - end - end -end diff --git a/core/thread/ignore_deadlock_spec.rb b/core/thread/ignore_deadlock_spec.rb index 53cc2a7f5b..b48bc9f9b0 100644 --- a/core/thread/ignore_deadlock_spec.rb +++ b/core/thread/ignore_deadlock_spec.rb @@ -1,21 +1,19 @@ require_relative '../../spec_helper' -ruby_version_is "3.0" do - describe "Thread.ignore_deadlock" do - it "returns false by default" do - Thread.ignore_deadlock.should == false - end +describe "Thread.ignore_deadlock" do + it "returns false by default" do + Thread.ignore_deadlock.should == false end +end - describe "Thread.ignore_deadlock=" do - it "changes the value of Thread.ignore_deadlock" do - ignore_deadlock = Thread.ignore_deadlock - Thread.ignore_deadlock = true - begin - Thread.ignore_deadlock.should == true - ensure - Thread.ignore_deadlock = ignore_deadlock - end +describe "Thread.ignore_deadlock=" do + it "changes the value of Thread.ignore_deadlock" do + ignore_deadlock = Thread.ignore_deadlock + Thread.ignore_deadlock = true + begin + Thread.ignore_deadlock.should == true + ensure + Thread.ignore_deadlock = ignore_deadlock end end end diff --git a/core/thread/report_on_exception_spec.rb b/core/thread/report_on_exception_spec.rb index 9279fa1da5..ab0af0972e 100644 --- a/core/thread/report_on_exception_spec.rb +++ b/core/thread/report_on_exception_spec.rb @@ -61,34 +61,32 @@ }.should raise_error(RuntimeError, "Thread#report_on_exception specs") end - ruby_version_is "3.0" do - it "prints a backtrace on $stderr in the regular backtrace order" do - line_raise = __LINE__ + 2 - def foo - raise RuntimeError, "Thread#report_on_exception specs backtrace order" - end - - line_call_foo = __LINE__ + 5 - go = false - t = Thread.new { - Thread.current.report_on_exception = true - Thread.pass until go - foo - } + it "prints a backtrace on $stderr in the regular backtrace order" do + line_raise = __LINE__ + 2 + def foo + raise RuntimeError, "Thread#report_on_exception specs backtrace order" + end - -> { - go = true - Thread.pass while t.alive? - }.should output("", < { + go = true + Thread.pass while t.alive? + }.should output("", <' +\tfrom #{__FILE__}:#{line_call_foo}:in `block (4 levels) in ' ERR - -> { - t.join - }.should raise_error(RuntimeError, "Thread#report_on_exception specs backtrace order") - end + -> { + t.join + }.should raise_error(RuntimeError, "Thread#report_on_exception specs backtrace order") end it "prints the backtrace even if the thread was killed just after Thread#raise" do diff --git a/core/time/new_spec.rb b/core/time/new_spec.rb index d95c82b20a..71b3c21593 100644 --- a/core/time/new_spec.rb +++ b/core/time/new_spec.rb @@ -200,10 +200,8 @@ time.zone.should == zone time.utc_offset.should == 5*3600+30*60 - ruby_version_is "3.0" do - time.wday.should == 6 - time.yday.should == 1 - end + time.wday.should == 6 + time.yday.should == 1 end it "accepts timezone argument that must have #local_to_utc and #utc_to_local methods" do diff --git a/core/time/succ_spec.rb b/core/time/succ_spec.rb deleted file mode 100644 index cbf7cf0951..0000000000 --- a/core/time/succ_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require_relative '../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'fixtures/classes' - - describe "Time#succ" do - it "returns a new time one second later than time" do - suppress_warning { - @result = Time.at(100).succ - } - - @result.should == Time.at(101) - end - - it "returns a new instance" do - time = Time.at(100) - - suppress_warning { - @result = time.succ - } - - @result.should_not equal time - end - - it "is obsolete" do - -> { - Time.at(100).succ - }.should complain(/Time#succ is obsolete/) - end - - context "zone is a timezone object" do - it "preserves time zone" do - zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60)) - time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 1 - - time.zone.should == zone - end - end - end -end diff --git a/core/tracepoint/enable_spec.rb b/core/tracepoint/enable_spec.rb index 24f6070b97..6cc8bb3897 100644 --- a/core/tracepoint/enable_spec.rb +++ b/core/tracepoint/enable_spec.rb @@ -149,13 +149,7 @@ describe "when nested" do before do - ruby_version_is ""..."3.0" do - @path_prefix = '@' - end - - ruby_version_is "3.0" do - @path_prefix = ' ' - end + @path_prefix = ' ' end it "enables both TracePoints but only calls the respective callbacks" do diff --git a/core/tracepoint/inspect_spec.rb b/core/tracepoint/inspect_spec.rb index 151a08e7b4..21d62e9e26 100644 --- a/core/tracepoint/inspect_spec.rb +++ b/core/tracepoint/inspect_spec.rb @@ -3,13 +3,7 @@ describe 'TracePoint#inspect' do before do - ruby_version_is ""..."3.0" do - @path_prefix = '@' - end - - ruby_version_is "3.0" do - @path_prefix = ' ' - end + @path_prefix = ' ' end it 'returns a string containing a human-readable TracePoint status' do diff --git a/core/warning/element_set_spec.rb b/core/warning/element_set_spec.rb index d20ee215ad..f439ffde0a 100644 --- a/core/warning/element_set_spec.rb +++ b/core/warning/element_set_spec.rb @@ -8,13 +8,7 @@ describe ":experimental" do before do - ruby_version_is ""..."3.0" do - @src = 'case [0, 1]; in [a, b]; end' - end - - ruby_version_is "3.0" do - @src = 'warn "This is experimental warning.", category: :experimental' - end + @src = 'warn "This is experimental warning.", category: :experimental' end it "emits and suppresses warnings for :experimental" do diff --git a/core/warning/warn_spec.rb b/core/warning/warn_spec.rb index e2fcfbf93f..8f96fe9287 100644 --- a/core/warning/warn_spec.rb +++ b/core/warning/warn_spec.rb @@ -51,100 +51,85 @@ def Warning.warn(msg) end end - ruby_version_is '3.0' do - it "is called by Kernel.warn with nil category keyword" do - Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil) - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!") - ensure - $VERBOSE = verbose - end - end - - it "is called by Kernel.warn with given category keyword converted to a symbol" do - Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated) - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!", category: "deprecated") - ensure - $VERBOSE = verbose - end + it "is called by Kernel.warn with nil category keyword" do + Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil) + verbose = $VERBOSE + $VERBOSE = false + begin + Kernel.warn("Chunky bacon!") + ensure + $VERBOSE = verbose end + end - it "warns when category is :deprecated and Warning[:deprecated] is true" do - warn_deprecated = Warning[:deprecated] - Warning[:deprecated] = true - begin - -> { - Warning.warn("foo", category: :deprecated) - }.should complain("foo") - ensure - Warning[:deprecated] = warn_deprecated - end + it "is called by Kernel.warn with given category keyword converted to a symbol" do + Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated) + verbose = $VERBOSE + $VERBOSE = false + begin + Kernel.warn("Chunky bacon!", category: "deprecated") + ensure + $VERBOSE = verbose end + end - it "warns when category is :experimental and Warning[:experimental] is true" do - warn_experimental = Warning[:experimental] - Warning[:experimental] = true - begin - -> { - Warning.warn("foo", category: :experimental) - }.should complain("foo") - ensure - Warning[:experimental] = warn_experimental - end + it "warns when category is :deprecated and Warning[:deprecated] is true" do + warn_deprecated = Warning[:deprecated] + Warning[:deprecated] = true + begin + -> { + Warning.warn("foo", category: :deprecated) + }.should complain("foo") + ensure + Warning[:deprecated] = warn_deprecated end + end - it "doesn't print message when category is :deprecated but Warning[:deprecated] is false" do - warn_deprecated = Warning[:deprecated] - Warning[:deprecated] = false - begin - -> { - Warning.warn("foo", category: :deprecated) - }.should_not complain - ensure - Warning[:deprecated] = warn_deprecated - end + it "warns when category is :experimental and Warning[:experimental] is true" do + warn_experimental = Warning[:experimental] + Warning[:experimental] = true + begin + -> { + Warning.warn("foo", category: :experimental) + }.should complain("foo") + ensure + Warning[:experimental] = warn_experimental end + end - it "doesn't print message when category is :experimental but Warning[:experimental] is false" do - warn_experimental = Warning[:experimental] - Warning[:experimental] = false - begin - -> { - Warning.warn("foo", category: :experimental) - }.should_not complain - ensure - Warning[:experimental] = warn_experimental - end + it "doesn't print message when category is :deprecated but Warning[:deprecated] is false" do + warn_deprecated = Warning[:deprecated] + Warning[:deprecated] = false + begin + -> { + Warning.warn("foo", category: :deprecated) + }.should_not complain + ensure + Warning[:deprecated] = warn_deprecated end + end - it "prints the message when VERBOSE is false" do - -> { Warning.warn("foo") }.should complain("foo") + it "doesn't print message when category is :experimental but Warning[:experimental] is false" do + warn_experimental = Warning[:experimental] + Warning[:experimental] = false + begin + -> { + Warning.warn("foo", category: :experimental) + }.should_not complain + ensure + Warning[:experimental] = warn_experimental end + end - it "prints the message when VERBOSE is nil" do - -> { Warning.warn("foo") }.should complain("foo", verbose: nil) - end + it "prints the message when VERBOSE is false" do + -> { Warning.warn("foo") }.should complain("foo") + end - it "prints the message when VERBOSE is true" do - -> { Warning.warn("foo") }.should complain("foo", verbose: true) - end + it "prints the message when VERBOSE is nil" do + -> { Warning.warn("foo") }.should complain("foo", verbose: nil) end - ruby_version_is ''...'3.0' do - it "is called by Kernel.warn" do - Warning.should_receive(:warn).with("Chunky bacon!\n") - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!") - ensure - $VERBOSE = verbose - end - end + it "prints the message when VERBOSE is true" do + -> { Warning.warn("foo") }.should complain("foo", verbose: true) end end diff --git a/language/block_spec.rb b/language/block_spec.rb index 8488b945d5..90329e2f6f 100644 --- a/language/block_spec.rb +++ b/language/block_spec.rb @@ -53,66 +53,18 @@ def m(a) yield a end end end - ruby_version_is ''..."3.0" do - it "assigns elements to mixed argument types" do - suppress_keyword_warning do - result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] } - result.should == [1, 2, [], 3, 2, {x: 9}] - end - end - - it "assigns symbol keys from a Hash to keyword arguments" do - suppress_keyword_warning do - result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 1}, a: 10] - end - end - - it "assigns symbol keys from a Hash returned by #to_hash to keyword arguments" do - suppress_keyword_warning do - obj = mock("coerce block keyword arguments") - obj.should_receive(:to_hash).and_return({"a" => 1, b: 2}) - - result = m([obj]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 1}, b: 2] - end - end + it "assigns elements to mixed argument types" do + result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] } + result.should == [1, 2, [3], {x: 9}, 2, {}] end - ruby_version_is "3.0" do - it "assigns elements to mixed argument types" do - result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] } - result.should == [1, 2, [3], {x: 9}, 2, {}] - end - - it "does not treat final Hash as keyword arguments and does not autosplat" do - result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] } - result.should == [[{"a" => 1, a: 10}], {}] - end - - it "does not call #to_hash on final argument to get keyword arguments and does not autosplat" do - suppress_keyword_warning do - obj = mock("coerce block keyword arguments") - obj.should_not_receive(:to_hash) - - result = m([obj]) { |a=nil, **b| [a, b] } - result.should == [[obj], {}] - end - end - end - - ruby_version_is ""...'3.0' do - it "calls #to_hash on the argument but ignores result when optional argument and keyword argument accepted" do - obj = mock("coerce block keyword arguments") - obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2}) - - result = m([obj]) { |a=nil, **b| [a, b] } - result.should == [obj, {}] - end + it "does not treat final Hash as keyword arguments and does not autosplat" do + result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] } + result.should == [[{"a" => 1, a: 10}], {}] end - ruby_version_is "3.0" do - it "does not call #to_hash on the argument when optional argument and keyword argument accepted and does not autosplat" do + it "does not call #to_hash on final argument to get keyword arguments and does not autosplat" do + suppress_keyword_warning do obj = mock("coerce block keyword arguments") obj.should_not_receive(:to_hash) @@ -121,102 +73,42 @@ def m(a) yield a end end end - describe "when non-symbol keys are in a keyword arguments Hash" do - ruby_version_is ""..."3.0" do - it "separates non-symbol keys and symbol keys" do - suppress_keyword_warning do - result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 10}, {b: 2}] - end - end - end - ruby_version_is "3.0" do - it "does not separate non-symbol keys and symbol keys and does not autosplat" do - suppress_keyword_warning do - result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] } - result.should == [[{"a" => 10, b: 2}], {}] - end - end - end - end - - ruby_version_is ""..."3.0" do - it "does not treat hashes with string keys as keyword arguments" do - result = m(["a" => 10]) { |a = nil, **b| [a, b] } - result.should == [{"a" => 10}, {}] - end - end + it "does not call #to_hash on the argument when optional argument and keyword argument accepted and does not autosplat" do + obj = mock("coerce block keyword arguments") + obj.should_not_receive(:to_hash) - ruby_version_is "3.0" do - it "does not treat hashes with string keys as keyword arguments and does not autosplat" do - result = m(["a" => 10]) { |a = nil, **b| [a, b] } - result.should == [[{"a" => 10}], {}] - end + result = m([obj]) { |a=nil, **b| [a, b] } + result.should == [[obj], {}] end - ruby_version_is ''...'3.0' do - it "calls #to_hash on the last element if keyword arguments are present" do - suppress_keyword_warning do - obj = mock("destructure block keyword arguments") - obj.should_receive(:to_hash).and_return({x: 9}) - - result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] } - result.should == [1, [2], 3, {x: 9}] - end - end - - it "assigns the last element to a non-keyword argument if #to_hash returns nil" do - suppress_keyword_warning do - obj = mock("destructure block keyword arguments") - obj.should_receive(:to_hash).and_return(nil) - - result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] } - result.should == [1, [2, 3], obj, {}] - end - end - - it "calls #to_hash on the last element when there are more arguments than parameters" do + describe "when non-symbol keys are in a keyword arguments Hash" do + it "does not separate non-symbol keys and symbol keys and does not autosplat" do suppress_keyword_warning do - x = mock("destructure matching block keyword argument") - x.should_receive(:to_hash).and_return({x: 9}) - - result = m([1, 2, 3, {y: 9}, 4, 5, x]) { |a, b=5, c, **k| [a, b, c, k] } - result.should == [1, 2, 3, {x: 9}] + result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] } + result.should == [[{"a" => 10, b: 2}], {}] end end + end - it "raises a TypeError if #to_hash does not return a Hash" do - obj = mock("destructure block keyword arguments") - obj.should_receive(:to_hash).and_return(1) - - -> { m([1, 2, 3, obj]) { |a, *b, c, **k| } }.should raise_error(TypeError) - end - - it "raises the error raised inside #to_hash" do - obj = mock("destructure block keyword arguments") - error = RuntimeError.new("error while converting to a hash") - obj.should_receive(:to_hash).and_raise(error) - - -> { m([1, 2, 3, obj]) { |a, *b, c, **k| } }.should raise_error(error) - end + it "does not treat hashes with string keys as keyword arguments and does not autosplat" do + result = m(["a" => 10]) { |a = nil, **b| [a, b] } + result.should == [[{"a" => 10}], {}] end - ruby_version_is '3.0' do - it "does not call #to_hash on the last element if keyword arguments are present" do - obj = mock("destructure block keyword arguments") - obj.should_not_receive(:to_hash) + it "does not call #to_hash on the last element if keyword arguments are present" do + obj = mock("destructure block keyword arguments") + obj.should_not_receive(:to_hash) - result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] } - result.should == [1, [2, 3], obj, {}] - end + result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] } + result.should == [1, [2, 3], obj, {}] + end - it "does not call #to_hash on the last element when there are more arguments than parameters" do - x = mock("destructure matching block keyword argument") - x.should_not_receive(:to_hash) + it "does not call #to_hash on the last element when there are more arguments than parameters" do + x = mock("destructure matching block keyword argument") + x.should_not_receive(:to_hash) - result = m([1, 2, 3, {y: 9}, 4, 5, x]) { |a, b=5, c, **k| [a, b, c, k] } - result.should == [1, 2, 3, {}] - end + result = m([1, 2, 3, {y: 9}, 4, 5, x]) { |a, b=5, c, **k| [a, b, c, k] } + result.should == [1, 2, 3, {}] end it "does not call #to_ary on the Array" do diff --git a/language/class_spec.rb b/language/class_spec.rb index 877895bf15..eab3cd0651 100644 --- a/language/class_spec.rb +++ b/language/class_spec.rb @@ -308,20 +308,10 @@ def xyz -> { class TestClass < BasicObject.new; end }.should raise_error(TypeError, error_msg) end - ruby_version_is ""..."3.0" do - it "allows accessing the block of the original scope" do - suppress_warning do - ClassSpecs.sclass_with_block { 123 }.should == 123 - end - end - end - - ruby_version_is "3.0" do - it "does not allow accessing the block of the original scope" do - -> { - ClassSpecs.sclass_with_block { 123 } - }.should raise_error(SyntaxError) - end + it "does not allow accessing the block of the original scope" do + -> { + ClassSpecs.sclass_with_block { 123 } + }.should raise_error(SyntaxError) end it "can use return to cause the enclosing method to return" do diff --git a/language/class_variable_spec.rb b/language/class_variable_spec.rb index f98deaa081..a26a3fb8de 100644 --- a/language/class_variable_spec.rb +++ b/language/class_variable_spec.rb @@ -83,34 +83,32 @@ end end -ruby_version_is "3.0" do - describe 'Accessing a class variable' do - it "raises a RuntimeError when accessed from the toplevel scope (not in some module or class)" do - -> { - eval "@@cvar_toplevel1" - }.should raise_error(RuntimeError, 'class variable access from toplevel') - -> { - eval "@@cvar_toplevel2 = 2" - }.should raise_error(RuntimeError, 'class variable access from toplevel') - end - - it "does not raise an error when checking if defined from the toplevel scope" do - -> { - eval "defined?(@@cvar_toplevel1)" - }.should_not raise_error - end - - it "raises a RuntimeError when a class variable is overtaken in an ancestor class" do - parent = Class.new() - subclass = Class.new(parent) - subclass.class_variable_set(:@@cvar_overtaken, :subclass) - parent.class_variable_set(:@@cvar_overtaken, :parent) - - -> { - subclass.class_variable_get(:@@cvar_overtaken) - }.should raise_error(RuntimeError, /class variable @@cvar_overtaken of .+ is overtaken by .+/) - - parent.class_variable_get(:@@cvar_overtaken).should == :parent - end +describe 'Accessing a class variable' do + it "raises a RuntimeError when accessed from the toplevel scope (not in some module or class)" do + -> { + eval "@@cvar_toplevel1" + }.should raise_error(RuntimeError, 'class variable access from toplevel') + -> { + eval "@@cvar_toplevel2 = 2" + }.should raise_error(RuntimeError, 'class variable access from toplevel') + end + + it "does not raise an error when checking if defined from the toplevel scope" do + -> { + eval "defined?(@@cvar_toplevel1)" + }.should_not raise_error + end + + it "raises a RuntimeError when a class variable is overtaken in an ancestor class" do + parent = Class.new() + subclass = Class.new(parent) + subclass.class_variable_set(:@@cvar_overtaken, :subclass) + parent.class_variable_set(:@@cvar_overtaken, :parent) + + -> { + subclass.class_variable_get(:@@cvar_overtaken) + }.should raise_error(RuntimeError, /class variable @@cvar_overtaken of .+ is overtaken by .+/) + + parent.class_variable_get(:@@cvar_overtaken).should == :parent end end diff --git a/language/constants_spec.rb b/language/constants_spec.rb index 8586e46158..08c534487e 100644 --- a/language/constants_spec.rb +++ b/language/constants_spec.rb @@ -170,34 +170,32 @@ module ConstantSpecsRHS; end -> { ConstantSpecs::ParentA::CS_CONSTX }.should raise_error(NameError) end - ruby_version_is "3.0" do - it "uses the module or class #name to craft the error message" do - mod = Module.new do - def self.name - "ModuleName" - end - - def self.inspect - "" - end + it "uses the module or class #name to craft the error message" do + mod = Module.new do + def self.name + "ModuleName" end - -> { mod::DOES_NOT_EXIST }.should raise_error(NameError, /uninitialized constant ModuleName::DOES_NOT_EXIST/) + def self.inspect + "" + end end - it "uses the module or class #inspect to craft the error message if they are anonymous" do - mod = Module.new do - def self.name - nil - end + -> { mod::DOES_NOT_EXIST }.should raise_error(NameError, /uninitialized constant ModuleName::DOES_NOT_EXIST/) + end - def self.inspect - "" - end + it "uses the module or class #inspect to craft the error message if they are anonymous" do + mod = Module.new do + def self.name + nil end - -> { mod::DOES_NOT_EXIST }.should raise_error(NameError, /uninitialized constant ::DOES_NOT_EXIST/) + def self.inspect + "" + end end + + -> { mod::DOES_NOT_EXIST }.should raise_error(NameError, /uninitialized constant ::DOES_NOT_EXIST/) end it "sends #const_missing to the original class or module scope" do diff --git a/language/hash_spec.rb b/language/hash_spec.rb index fa5c8723e9..9e2b9bd4c5 100644 --- a/language/hash_spec.rb +++ b/language/hash_spec.rb @@ -220,30 +220,15 @@ def m(**h) h.should == { one: 1, two: 2 } end - ruby_version_is ""..."3.0" do - it "makes a caller-side copy when calling a method taking a positional Hash" do - def m(h) - h.delete(:one); h - end - - h = { one: 1, two: 2 } - m(**h).should == { two: 2 } - m(**h).should_not.equal?(h) - h.should == { one: 1, two: 2 } + it "does not copy when calling a method taking a positional Hash" do + def m(h) + h.delete(:one); h end - end - ruby_version_is "3.0" do - it "does not copy when calling a method taking a positional Hash" do - def m(h) - h.delete(:one); h - end - - h = { one: 1, two: 2 } - m(**h).should == { two: 2 } - m(**h).should.equal?(h) - h.should == { two: 2 } - end + h = { one: 1, two: 2 } + m(**h).should == { two: 2 } + m(**h).should.equal?(h) + h.should == { two: 2 } end ruby_version_is "3.1" do diff --git a/language/keyword_arguments_spec.rb b/language/keyword_arguments_spec.rb index c47b7b0ae9..e2c816f622 100644 --- a/language/keyword_arguments_spec.rb +++ b/language/keyword_arguments_spec.rb @@ -1,286 +1,371 @@ require_relative '../spec_helper' -ruby_version_is "3.0" do - describe "Keyword arguments" do - def target(*args, **kwargs) +describe "Keyword arguments" do + def target(*args, **kwargs) + [args, kwargs] + end + + it "are separated from positional arguments" do + def m(*args, **kwargs) [args, kwargs] end - it "are separated from positional arguments" do - def m(*args, **kwargs) - [args, kwargs] - end + empty = {} + m(**empty).should == [[], {}] + m(empty).should == [[{}], {}] - empty = {} - m(**empty).should == [[], {}] - m(empty).should == [[{}], {}] + m(a: 1).should == [[], {a: 1}] + m({a: 1}).should == [[{a: 1}], {}] + end - m(a: 1).should == [[], {a: 1}] - m({a: 1}).should == [[{a: 1}], {}] + it "when the receiving method has not keyword parameters it treats kwargs as positional" do + def m(*a) + a end - it "when the receiving method has not keyword parameters it treats kwargs as positional" do + m(a: 1).should == [{a: 1}] + m({a: 1}).should == [{a: 1}] + end + + context "empty kwargs are treated as if they were not passed" do + it "when calling a method" do def m(*a) a end - m(a: 1).should == [{a: 1}] - m({a: 1}).should == [{a: 1}] + empty = {} + m(**empty).should == [] + m(empty).should == [{}] end - context "empty kwargs are treated as if they were not passed" do - it "when calling a method" do - def m(*a) - a - end - - empty = {} - m(**empty).should == [] - m(empty).should == [{}] + it "when yielding to a block" do + def y(*args, **kwargs) + yield(*args, **kwargs) end - it "when yielding to a block" do - def y(*args, **kwargs) - yield(*args, **kwargs) - end + empty = {} + y(**empty) { |*a| a }.should == [] + y(empty) { |*a| a }.should == [{}] + end + end - empty = {} - y(**empty) { |*a| a }.should == [] - y(empty) { |*a| a }.should == [{}] - end + it "extra keywords are not allowed without **kwrest" do + def m(*a, kw:) + a end - it "extra keywords are not allowed without **kwrest" do - def m(*a, kw:) - a - end + m(kw: 1).should == [] + -> { m(kw: 1, kw2: 2) }.should raise_error(ArgumentError, 'unknown keyword: :kw2') + -> { m(kw: 1, true => false) }.should raise_error(ArgumentError, 'unknown keyword: true') + -> { m(kw: 1, a: 1, b: 2, c: 3) }.should raise_error(ArgumentError, 'unknown keywords: :a, :b, :c') + end - m(kw: 1).should == [] - -> { m(kw: 1, kw2: 2) }.should raise_error(ArgumentError, 'unknown keyword: :kw2') - -> { m(kw: 1, true => false) }.should raise_error(ArgumentError, 'unknown keyword: true') - -> { m(kw: 1, a: 1, b: 2, c: 3) }.should raise_error(ArgumentError, 'unknown keywords: :a, :b, :c') + it "raises ArgumentError exception when required keyword argument is not passed" do + def m(a:, b:, c:) + [a, b, c] end - it "raises ArgumentError exception when required keyword argument is not passed" do - def m(a:, b:, c:) - [a, b, c] + -> { m(a: 1, b: 2) }.should raise_error(ArgumentError, /missing keyword: :c/) + -> { m() }.should raise_error(ArgumentError, /missing keywords: :a, :b, :c/) + end + + it "raises ArgumentError for missing keyword arguments even if there are extra ones" do + def m(a:) + a + end + + -> { m(b: 1) }.should raise_error(ArgumentError, /missing keyword: :a/) + end + + it "handle * and ** at the same call site" do + def m(*a) + a + end + + m(*[], **{}).should == [] + m(*[], 42, **{}).should == [42] + end + + context "**" do + it "does not copy a non-empty Hash for a method taking (*args)" do + def m(*args) + args[0] end - -> { m(a: 1, b: 2) }.should raise_error(ArgumentError, /missing keyword: :c/) - -> { m() }.should raise_error(ArgumentError, /missing keywords: :a, :b, :c/) + h = {a: 1} + m(**h).should.equal?(h) end - it "raises ArgumentError for missing keyword arguments even if there are extra ones" do - def m(a:) - a + it "copies the given Hash for a method taking (**kwargs)" do + def m(**kw) + kw end - -> { m(b: 1) }.should raise_error(ArgumentError, /missing keyword: :a/) + empty = {} + m(**empty).should == empty + m(**empty).should_not.equal?(empty) + + h = {a: 1} + m(**h).should == h + m(**h).should_not.equal?(h) end + end - it "handle * and ** at the same call site" do - def m(*a) - a + context "delegation" do + it "works with (*args, **kwargs)" do + def m(*args, **kwargs) + target(*args, **kwargs) end - m(*[], **{}).should == [] - m(*[], 42, **{}).should == [42] + empty = {} + m(**empty).should == [[], {}] + m(empty).should == [[{}], {}] + + m(a: 1).should == [[], {a: 1}] + m({a: 1}).should == [[{a: 1}], {}] end - context "**" do - it "does not copy a non-empty Hash for a method taking (*args)" do - def m(*args) - args[0] - end + it "works with proc { |*args, **kwargs| }" do + m = proc do |*args, **kwargs| + target(*args, **kwargs) + end + + empty = {} + m.(**empty).should == [[], {}] + m.(empty).should == [[{}], {}] - h = {a: 1} - m(**h).should.equal?(h) + m.(a: 1).should == [[], {a: 1}] + m.({a: 1}).should == [[{a: 1}], {}] + + # no autosplatting for |*args, **kwargs| + m.([1, 2]).should == [[[1, 2]], {}] + end + + it "works with -> (*args, **kwargs) {}" do + m = -> *args, **kwargs do + target(*args, **kwargs) end - it "copies the given Hash for a method taking (**kwargs)" do - def m(**kw) - kw - end + empty = {} + m.(**empty).should == [[], {}] + m.(empty).should == [[{}], {}] - empty = {} - m(**empty).should == empty - m(**empty).should_not.equal?(empty) + m.(a: 1).should == [[], {a: 1}] + m.({a: 1}).should == [[{a: 1}], {}] + end - h = {a: 1} - m(**h).should == h - m(**h).should_not.equal?(h) + it "works with (...)" do + instance_eval <<~DEF + def m(...) + target(...) end + DEF + + empty = {} + m(**empty).should == [[], {}] + m(empty).should == [[{}], {}] + + m(a: 1).should == [[], {a: 1}] + m({a: 1}).should == [[{a: 1}], {}] end - context "delegation" do - it "works with (*args, **kwargs)" do - def m(*args, **kwargs) - target(*args, **kwargs) + it "works with call(*ruby2_keyword_args)" do + class << self + ruby2_keywords def m(*args) + target(*args) end + end - empty = {} - m(**empty).should == [[], {}] - m(empty).should == [[{}], {}] + empty = {} + m(**empty).should == [[], {}] + Hash.ruby2_keywords_hash?(empty).should == false + m(empty).should == [[{}], {}] + Hash.ruby2_keywords_hash?(empty).should == false - m(a: 1).should == [[], {a: 1}] - m({a: 1}).should == [[{a: 1}], {}] - end + m(a: 1).should == [[], {a: 1}] + m({a: 1}).should == [[{a: 1}], {}] - it "works with proc { |*args, **kwargs| }" do - m = proc do |*args, **kwargs| - target(*args, **kwargs) - end + kw = {a: 1} - empty = {} - m.(**empty).should == [[], {}] - m.(empty).should == [[{}], {}] + m(**kw).should == [[], {a: 1}] + m(**kw)[1].should == kw + m(**kw)[1].should_not.equal?(kw) + Hash.ruby2_keywords_hash?(kw).should == false + Hash.ruby2_keywords_hash?(m(**kw)[1]).should == false - m.(a: 1).should == [[], {a: 1}] - m.({a: 1}).should == [[{a: 1}], {}] + m(kw).should == [[{a: 1}], {}] + m(kw)[0][0].should.equal?(kw) + Hash.ruby2_keywords_hash?(kw).should == false + end - # no autosplatting for |*args, **kwargs| - m.([1, 2]).should == [[[1, 2]], {}] + it "works with super(*ruby2_keyword_args)" do + parent = Class.new do + def m(*args, **kwargs) + [args, kwargs] + end end - it "works with -> (*args, **kwargs) {}" do - m = -> *args, **kwargs do - target(*args, **kwargs) + child = Class.new(parent) do + ruby2_keywords def m(*args) + super(*args) end + end - empty = {} - m.(**empty).should == [[], {}] - m.(empty).should == [[{}], {}] + obj = child.new - m.(a: 1).should == [[], {a: 1}] - m.({a: 1}).should == [[{a: 1}], {}] - end + empty = {} + obj.m(**empty).should == [[], {}] + Hash.ruby2_keywords_hash?(empty).should == false + obj.m(empty).should == [[{}], {}] + Hash.ruby2_keywords_hash?(empty).should == false - it "works with (...)" do - instance_eval <<~DEF - def m(...) - target(...) - end - DEF + obj.m(a: 1).should == [[], {a: 1}] + obj.m({a: 1}).should == [[{a: 1}], {}] - empty = {} - m(**empty).should == [[], {}] - m(empty).should == [[{}], {}] + kw = {a: 1} - m(a: 1).should == [[], {a: 1}] - m({a: 1}).should == [[{a: 1}], {}] + obj.m(**kw).should == [[], {a: 1}] + obj.m(**kw)[1].should == kw + obj.m(**kw)[1].should_not.equal?(kw) + Hash.ruby2_keywords_hash?(kw).should == false + Hash.ruby2_keywords_hash?(obj.m(**kw)[1]).should == false + + obj.m(kw).should == [[{a: 1}], {}] + obj.m(kw)[0][0].should.equal?(kw) + Hash.ruby2_keywords_hash?(kw).should == false + end + + it "works with zsuper" do + parent = Class.new do + def m(*args, **kwargs) + [args, kwargs] + end end - it "works with call(*ruby2_keyword_args)" do - class << self - ruby2_keywords def m(*args) - target(*args) - end + child = Class.new(parent) do + ruby2_keywords def m(*args) + super end + end - empty = {} - m(**empty).should == [[], {}] - Hash.ruby2_keywords_hash?(empty).should == false - m(empty).should == [[{}], {}] - Hash.ruby2_keywords_hash?(empty).should == false + obj = child.new - m(a: 1).should == [[], {a: 1}] - m({a: 1}).should == [[{a: 1}], {}] + empty = {} + obj.m(**empty).should == [[], {}] + Hash.ruby2_keywords_hash?(empty).should == false + obj.m(empty).should == [[{}], {}] + Hash.ruby2_keywords_hash?(empty).should == false - kw = {a: 1} + obj.m(a: 1).should == [[], {a: 1}] + obj.m({a: 1}).should == [[{a: 1}], {}] - m(**kw).should == [[], {a: 1}] - m(**kw)[1].should == kw - m(**kw)[1].should_not.equal?(kw) - Hash.ruby2_keywords_hash?(kw).should == false - Hash.ruby2_keywords_hash?(m(**kw)[1]).should == false + kw = {a: 1} - m(kw).should == [[{a: 1}], {}] - m(kw)[0][0].should.equal?(kw) - Hash.ruby2_keywords_hash?(kw).should == false - end + obj.m(**kw).should == [[], {a: 1}] + obj.m(**kw)[1].should == kw + obj.m(**kw)[1].should_not.equal?(kw) + Hash.ruby2_keywords_hash?(kw).should == false + Hash.ruby2_keywords_hash?(obj.m(**kw)[1]).should == false - it "works with super(*ruby2_keyword_args)" do - parent = Class.new do - def m(*args, **kwargs) - [args, kwargs] - end + obj.m(kw).should == [[{a: 1}], {}] + obj.m(kw)[0][0].should.equal?(kw) + Hash.ruby2_keywords_hash?(kw).should == false + end + + it "works with yield(*ruby2_keyword_args)" do + class << self + def y(args) + yield(*args) end - child = Class.new(parent) do - ruby2_keywords def m(*args) - super(*args) - end + ruby2_keywords def m(*outer_args) + y(outer_args, &-> *args, **kwargs { target(*args, **kwargs) }) end + end - obj = child.new + empty = {} + m(**empty).should == [[], {}] + Hash.ruby2_keywords_hash?(empty).should == false + m(empty).should == [[{}], {}] + Hash.ruby2_keywords_hash?(empty).should == false - empty = {} - obj.m(**empty).should == [[], {}] - Hash.ruby2_keywords_hash?(empty).should == false - obj.m(empty).should == [[{}], {}] - Hash.ruby2_keywords_hash?(empty).should == false + m(a: 1).should == [[], {a: 1}] + m({a: 1}).should == [[{a: 1}], {}] - obj.m(a: 1).should == [[], {a: 1}] - obj.m({a: 1}).should == [[{a: 1}], {}] + kw = {a: 1} - kw = {a: 1} + m(**kw).should == [[], {a: 1}] + m(**kw)[1].should == kw + m(**kw)[1].should_not.equal?(kw) + Hash.ruby2_keywords_hash?(kw).should == false + Hash.ruby2_keywords_hash?(m(**kw)[1]).should == false - obj.m(**kw).should == [[], {a: 1}] - obj.m(**kw)[1].should == kw - obj.m(**kw)[1].should_not.equal?(kw) - Hash.ruby2_keywords_hash?(kw).should == false - Hash.ruby2_keywords_hash?(obj.m(**kw)[1]).should == false + m(kw).should == [[{a: 1}], {}] + m(kw)[0][0].should.equal?(kw) + Hash.ruby2_keywords_hash?(kw).should == false + end - obj.m(kw).should == [[{a: 1}], {}] - obj.m(kw)[0][0].should.equal?(kw) - Hash.ruby2_keywords_hash?(kw).should == false + it "does not work with (*args)" do + class << self + def m(*args) + target(*args) + end end - it "works with zsuper" do - parent = Class.new do - def m(*args, **kwargs) - [args, kwargs] + empty = {} + m(**empty).should == [[], {}] + m(empty).should == [[{}], {}] + + m(a: 1).should == [[{a: 1}], {}] + m({a: 1}).should == [[{a: 1}], {}] + end + + ruby_version_is "3.1" do + describe "omitted values" do + it "accepts short notation 'key' for 'key: value' syntax" do + def m(a:, b:) + [a, b] end + + a = 1 + b = 2 + + eval('m(a:, b:).should == [1, 2]') end + end + end + + ruby_version_is "3.2" do + it "does not work with call(*ruby2_keyword_args) with missing ruby2_keywords in between" do + class << self + def n(*args) # Note the missing ruby2_keywords here + target(*args) + end - child = Class.new(parent) do ruby2_keywords def m(*args) - super + n(*args) end end - obj = child.new - empty = {} - obj.m(**empty).should == [[], {}] - Hash.ruby2_keywords_hash?(empty).should == false - obj.m(empty).should == [[{}], {}] - Hash.ruby2_keywords_hash?(empty).should == false - - obj.m(a: 1).should == [[], {a: 1}] - obj.m({a: 1}).should == [[{a: 1}], {}] - - kw = {a: 1} - - obj.m(**kw).should == [[], {a: 1}] - obj.m(**kw)[1].should == kw - obj.m(**kw)[1].should_not.equal?(kw) - Hash.ruby2_keywords_hash?(kw).should == false - Hash.ruby2_keywords_hash?(obj.m(**kw)[1]).should == false + m(**empty).should == [[], {}] + m(empty).should == [[{}], {}] - obj.m(kw).should == [[{a: 1}], {}] - obj.m(kw)[0][0].should.equal?(kw) - Hash.ruby2_keywords_hash?(kw).should == false + m(a: 1).should == [[{a: 1}], {}] + m({a: 1}).should == [[{a: 1}], {}] end + end - it "works with yield(*ruby2_keyword_args)" do + ruby_version_is ""..."3.2" do + # https://bugs.ruby-lang.org/issues/18625 + it "works with call(*ruby2_keyword_args) with missing ruby2_keywords in between due to CRuby bug #18625" do class << self - def y(args) - yield(*args) + def n(*args) # Note the missing ruby2_keywords here + target(*args) end - ruby2_keywords def m(*outer_args) - y(outer_args, &-> *args, **kwargs { target(*args, **kwargs) }) + ruby2_keywords def m(*args) + n(*args) end end @@ -305,93 +390,6 @@ def y(args) m(kw)[0][0].should.equal?(kw) Hash.ruby2_keywords_hash?(kw).should == false end - - it "does not work with (*args)" do - class << self - def m(*args) - target(*args) - end - end - - empty = {} - m(**empty).should == [[], {}] - m(empty).should == [[{}], {}] - - m(a: 1).should == [[{a: 1}], {}] - m({a: 1}).should == [[{a: 1}], {}] - end - - ruby_version_is "3.1" do - describe "omitted values" do - it "accepts short notation 'key' for 'key: value' syntax" do - def m(a:, b:) - [a, b] - end - - a = 1 - b = 2 - - eval('m(a:, b:).should == [1, 2]') - end - end - end - - ruby_version_is "3.2" do - it "does not work with call(*ruby2_keyword_args) with missing ruby2_keywords in between" do - class << self - def n(*args) # Note the missing ruby2_keywords here - target(*args) - end - - ruby2_keywords def m(*args) - n(*args) - end - end - - empty = {} - m(**empty).should == [[], {}] - m(empty).should == [[{}], {}] - - m(a: 1).should == [[{a: 1}], {}] - m({a: 1}).should == [[{a: 1}], {}] - end - end - - ruby_version_is ""..."3.2" do - # https://bugs.ruby-lang.org/issues/18625 - it "works with call(*ruby2_keyword_args) with missing ruby2_keywords in between due to CRuby bug #18625" do - class << self - def n(*args) # Note the missing ruby2_keywords here - target(*args) - end - - ruby2_keywords def m(*args) - n(*args) - end - end - - empty = {} - m(**empty).should == [[], {}] - Hash.ruby2_keywords_hash?(empty).should == false - m(empty).should == [[{}], {}] - Hash.ruby2_keywords_hash?(empty).should == false - - m(a: 1).should == [[], {a: 1}] - m({a: 1}).should == [[{a: 1}], {}] - - kw = {a: 1} - - m(**kw).should == [[], {a: 1}] - m(**kw)[1].should == kw - m(**kw)[1].should_not.equal?(kw) - Hash.ruby2_keywords_hash?(kw).should == false - Hash.ruby2_keywords_hash?(m(**kw)[1]).should == false - - m(kw).should == [[{a: 1}], {}] - m(kw)[0][0].should.equal?(kw) - Hash.ruby2_keywords_hash?(kw).should == false - end - end end end end diff --git a/language/lambda_spec.rb b/language/lambda_spec.rb index a3f01ec04b..3ab3569ebe 100644 --- a/language/lambda_spec.rb +++ b/language/lambda_spec.rb @@ -177,34 +177,16 @@ def create_lambda result.should == [1, 2, 3, [4, 5], 6, [7, 8], 9, 10, 11, 12] end - ruby_version_is ''...'3.0' do - evaluate <<-ruby do - @a = -> (*, **k) { k } - ruby - - @a.().should == {} - @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - - suppress_keyword_warning do - h = mock("keyword splat") - h.should_receive(:to_hash).and_return({a: 1}) - @a.(h).should == {a: 1} - end - end - end - - ruby_version_is '3.0' do - evaluate <<-ruby do - @a = -> (*, **k) { k } - ruby + evaluate <<-ruby do + @a = -> (*, **k) { k } + ruby - @a.().should == {} - @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} + @a.().should == {} + @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - h = mock("keyword splat") - h.should_not_receive(:to_hash) - @a.(h).should == {} - end + h = mock("keyword splat") + h.should_not_receive(:to_hash) + @a.(h).should == {} end evaluate <<-ruby do @@ -514,34 +496,16 @@ def m2() yield end result.should == [1, 2, 3, [4, 5], 6, [7, 8], 9, 10, 11, 12] end - ruby_version_is ''...'3.0' do - evaluate <<-ruby do - @a = lambda { |*, **k| k } - ruby - - @a.().should == {} - @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - - suppress_keyword_warning do - h = mock("keyword splat") - h.should_receive(:to_hash).and_return({a: 1}) - @a.(h).should == {a: 1} - end - end - end - - ruby_version_is '3.0' do - evaluate <<-ruby do - @a = lambda { |*, **k| k } - ruby + evaluate <<-ruby do + @a = lambda { |*, **k| k } + ruby - @a.().should == {} - @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} + @a.().should == {} + @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - h = mock("keyword splat") - h.should_not_receive(:to_hash) - @a.(h).should == {} - end + h = mock("keyword splat") + h.should_not_receive(:to_hash) + @a.(h).should == {} end evaluate <<-ruby do diff --git a/language/method_spec.rb b/language/method_spec.rb index b80b314f6f..b1d169aba8 100644 --- a/language/method_spec.rb +++ b/language/method_spec.rb @@ -749,68 +749,31 @@ def m(a, b:) [a, b] end end end - ruby_version_is ""..."3.0" do - evaluate <<-ruby do - def m(a, b: 1) [a, b] end - ruby - - m(2).should == [2, 1] - m(1, b: 2).should == [1, 2] - suppress_keyword_warning do - m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, 1] - end - end - - evaluate <<-ruby do - def m(a, **) a end - ruby - - m(1).should == 1 - m(1, a: 2, b: 3).should == 1 - suppress_keyword_warning do - m("a" => 1, b: 2).should == {"a" => 1, b: 2} - end - end - - evaluate <<-ruby do - def m(a, **k) [a, k] end - ruby + evaluate <<-ruby do + def m(a, b: 1) [a, b] end + ruby - m(1).should == [1, {}] - m(1, a: 2, b: 3).should == [1, {a: 2, b: 3}] - suppress_keyword_warning do - m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, {}] - end - end + m(2).should == [2, 1] + m(1, b: 2).should == [1, 2] + -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) end - ruby_version_is "3.0" do - evaluate <<-ruby do - def m(a, b: 1) [a, b] end - ruby - - m(2).should == [2, 1] - m(1, b: 2).should == [1, 2] - -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) - end - - evaluate <<-ruby do - def m(a, **) a end - ruby + evaluate <<-ruby do + def m(a, **) a end + ruby - m(1).should == 1 - m(1, a: 2, b: 3).should == 1 - -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) - end + m(1).should == 1 + m(1, a: 2, b: 3).should == 1 + -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) + end - evaluate <<-ruby do - def m(a, **k) [a, k] end - ruby + evaluate <<-ruby do + def m(a, **k) [a, k] end + ruby - m(1).should == [1, {}] - m(1, a: 2, b: 3).should == [1, {a: 2, b: 3}] - -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) - end + m(1).should == [1, {}] + m(1, a: 2, b: 3).should == [1, {a: 2, b: 3}] + -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) end evaluate <<-ruby do @@ -921,50 +884,23 @@ def m(a=1, (b, *c), (d, (*e, f))) result.should == [[1, 2, 3], 4, [5, 6], 7, [], 8] end - ruby_version_is ""..."3.0" do - evaluate <<-ruby do - def m(a=1, b:) [a, b] end - ruby - - m(b: 2).should == [1, 2] - m(2, b: 1).should == [2, 1] - suppress_keyword_warning do - m("a" => 1, b: 2).should == [{"a" => 1}, 2] - end - end - - evaluate <<-ruby do - def m(a=1, b: 2) [a, b] end - ruby + evaluate <<-ruby do + def m(a=1, b:) [a, b] end + ruby - m().should == [1, 2] - m(2).should == [2, 2] - m(b: 3).should == [1, 3] - suppress_keyword_warning do - m("a" => 1, b: 2).should == [{"a" => 1}, 2] - end - end + m(b: 2).should == [1, 2] + m(2, b: 1).should == [2, 1] + -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) end - ruby_version_is "3.0" do - evaluate <<-ruby do - def m(a=1, b:) [a, b] end - ruby - - m(b: 2).should == [1, 2] - m(2, b: 1).should == [2, 1] - -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) - end - - evaluate <<-ruby do - def m(a=1, b: 2) [a, b] end - ruby + evaluate <<-ruby do + def m(a=1, b: 2) [a, b] end + ruby - m().should == [1, 2] - m(2).should == [2, 2] - m(b: 3).should == [1, 3] - -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) - end + m().should == [1, 2] + m(2).should == [2, 2] + m(b: 3).should == [1, 3] + -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) end evaluate <<-ruby do @@ -1013,292 +949,6 @@ def m(*a, b) [a, b] end m(1, 2, 3).should == [[1, 2], 3] end - ruby_version_is ""...'3.0' do - evaluate <<-ruby do - def m(*, a:) a end - ruby - - m(a: 1).should == 1 - m(1, 2, a: 3).should == 3 - suppress_keyword_warning do - m("a" => 1, a: 2).should == 2 - end - end - - evaluate <<-ruby do - def m(*a, b:) [a, b] end - ruby - - m(b: 1).should == [[], 1] - m(1, 2, b: 3).should == [[1, 2], 3] - suppress_keyword_warning do - m("a" => 1, b: 2).should == [[{"a" => 1}], 2] - end - end - - evaluate <<-ruby do - def m(*, a: 1) a end - ruby - - m().should == 1 - m(1, 2).should == 1 - m(a: 2).should == 2 - m(1, a: 2).should == 2 - suppress_keyword_warning do - m("a" => 1, a: 2).should == 2 - end - end - - evaluate <<-ruby do - def m(*a, b: 1) [a, b] end - ruby - - m().should == [[], 1] - m(1, 2, 3, b: 4).should == [[1, 2, 3], 4] - suppress_keyword_warning do - m("a" => 1, b: 2).should == [[{"a" => 1}], 2] - end - - a = mock("splat") - a.should_not_receive(:to_ary) - m(*a).should == [[a], 1] - end - - evaluate <<-ruby do - def m(*a, **) a end - ruby - - m().should == [] - m(1, 2, 3, a: 4, b: 5).should == [1, 2, 3] - m("a" => 1, a: 1).should == [] - m(1, **{a: 2}).should == [1] - - h = mock("keyword splat") - h.should_receive(:to_hash) - -> { m(**h) }.should raise_error(TypeError) - end - - evaluate <<-ruby do - def m(*, **k) k end - ruby - - m().should == {} - m(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - m("a" => 1, a: 1).should == {"a" => 1, a: 1} - - h = mock("keyword splat") - h.should_receive(:to_hash).and_return({a: 1}) - suppress_warning do - m(h).should == {a: 1} - end - end - - evaluate <<-ruby do - def m(a = nil, **k) [a, k] end - ruby - - m().should == [nil, {}] - m("a" => 1).should == [nil, {"a" => 1}] - m(a: 1).should == [nil, {a: 1}] - m("a" => 1, a: 1).should == [nil, {"a" => 1, a: 1}] - m({ "a" => 1 }, a: 1).should == [{"a" => 1}, {a: 1}] - suppress_warning do - m({a: 1}, {}).should == [{a: 1}, {}] - - h = {"a" => 1, b: 2} - m(h).should == [{"a" => 1}, {b: 2}] - h.should == {"a" => 1, b: 2} - - h = {"a" => 1} - m(h).first.should == h - - h = {} - r = m(h) - r.first.should be_nil - r.last.should == {} - - hh = {} - h = mock("keyword splat empty hash") - h.should_receive(:to_hash).and_return(hh) - r = m(h) - r.first.should be_nil - r.last.should == {} - - h = mock("keyword splat") - h.should_receive(:to_hash).and_return({"a" => 1, a: 2}) - m(h).should == [{"a" => 1}, {a: 2}] - end - end - - evaluate <<-ruby do - def m(*a, **k) [a, k] end - ruby - - m().should == [[], {}] - m(1).should == [[1], {}] - m(a: 1, b: 2).should == [[], {a: 1, b: 2}] - m(1, 2, 3, a: 2).should == [[1, 2, 3], {a: 2}] - - m("a" => 1).should == [[], {"a" => 1}] - m(a: 1).should == [[], {a: 1}] - m("a" => 1, a: 1).should == [[], {"a" => 1, a: 1}] - m({ "a" => 1 }, a: 1).should == [[{"a" => 1}], {a: 1}] - suppress_warning do - m({a: 1}, {}).should == [[{a: 1}], {}] - end - m({a: 1}, {"a" => 1}).should == [[{a: 1}, {"a" => 1}], {}] - - bo = BasicObject.new - def bo.to_a; [1, 2, 3]; end - def bo.to_hash; {:b => 2, :c => 3}; end - - m(*bo, **bo).should == [[1, 2, 3], {:b => 2, :c => 3}] - end - - evaluate <<-ruby do - def m(*, a:) a end - ruby - - m(a: 1).should == 1 - m(1, 2, a: 3).should == 3 - suppress_keyword_warning do - m("a" => 1, a: 2).should == 2 - end - end - - evaluate <<-ruby do - def m(*a, b:) [a, b] end - ruby - - m(b: 1).should == [[], 1] - m(1, 2, b: 3).should == [[1, 2], 3] - suppress_keyword_warning do - m("a" => 1, b: 2).should == [[{"a" => 1}], 2] - end - end - - evaluate <<-ruby do - def m(*, a: 1) a end - ruby - - m().should == 1 - m(1, 2).should == 1 - m(a: 2).should == 2 - m(1, a: 2).should == 2 - suppress_keyword_warning do - m("a" => 1, a: 2).should == 2 - end - end - - evaluate <<-ruby do - def m(*a, b: 1) [a, b] end - ruby - - m().should == [[], 1] - m(1, 2, 3, b: 4).should == [[1, 2, 3], 4] - suppress_keyword_warning do - m("a" => 1, b: 2).should == [[{"a" => 1}], 2] - end - - a = mock("splat") - a.should_not_receive(:to_ary) - m(*a).should == [[a], 1] - end - - evaluate <<-ruby do - def m(*a, **) a end - ruby - - m().should == [] - m(1, 2, 3, a: 4, b: 5).should == [1, 2, 3] - m("a" => 1, a: 1).should == [] - m(1, **{a: 2}).should == [1] - - h = mock("keyword splat") - h.should_receive(:to_hash) - -> { m(**h) }.should raise_error(TypeError) - end - - evaluate <<-ruby do - def m(*, **k) k end - ruby - - m().should == {} - m(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - m("a" => 1, a: 1).should == {"a" => 1, a: 1} - - h = mock("keyword splat") - h.should_receive(:to_hash).and_return({a: 1}) - suppress_keyword_warning do - m(h).should == {a: 1} - end - end - - evaluate <<-ruby do - def m(a = nil, **k) [a, k] end - ruby - - m().should == [nil, {}] - m("a" => 1).should == [nil, {"a" => 1}] - m(a: 1).should == [nil, {a: 1}] - m("a" => 1, a: 1).should == [nil, {"a" => 1, a: 1}] - m({ "a" => 1 }, a: 1).should == [{"a" => 1}, {a: 1}] - suppress_keyword_warning do - m({a: 1}, {}).should == [{a: 1}, {}] - end - - h = {"a" => 1, b: 2} - suppress_keyword_warning do - m(h).should == [{"a" => 1}, {b: 2}] - end - h.should == {"a" => 1, b: 2} - - h = {"a" => 1} - m(h).first.should == h - - h = {} - suppress_keyword_warning do - m(h).should == [nil, {}] - end - - hh = {} - h = mock("keyword splat empty hash") - h.should_receive(:to_hash).and_return({a: 1}) - suppress_keyword_warning do - m(h).should == [nil, {a: 1}] - end - - h = mock("keyword splat") - h.should_receive(:to_hash).and_return({"a" => 1}) - m(h).should == [h, {}] - end - - evaluate <<-ruby do - def m(*a, **k) [a, k] end - ruby - - m().should == [[], {}] - m(1).should == [[1], {}] - m(a: 1, b: 2).should == [[], {a: 1, b: 2}] - m(1, 2, 3, a: 2).should == [[1, 2, 3], {a: 2}] - - m("a" => 1).should == [[], {"a" => 1}] - m(a: 1).should == [[], {a: 1}] - m("a" => 1, a: 1).should == [[], {"a" => 1, a: 1}] - m({ "a" => 1 }, a: 1).should == [[{"a" => 1}], {a: 1}] - suppress_keyword_warning do - m({a: 1}, {}).should == [[{a: 1}], {}] - end - m({a: 1}, {"a" => 1}).should == [[{a: 1}, {"a" => 1}], {}] - - bo = BasicObject.new - def bo.to_a; [1, 2, 3]; end - def bo.to_hash; {:b => 2, :c => 3}; end - - m(*bo, **bo).should == [[1, 2, 3], {:b => 2, :c => 3}] - end - end - evaluate <<-ruby do def m(*, &b) b end ruby @@ -1462,42 +1112,20 @@ def m(a, **nil); a end; -> { m("a" => 1) }.should raise_error(ArgumentError) end - ruby_version_is ''...'3.0' do - evaluate <<-ruby do - def m(a, b = nil, c = nil, d, e: nil, **f) - [a, b, c, d, e, f] - end - ruby - - result = m(1, 2) - result.should == [1, nil, nil, 2, nil, {}] - - suppress_warning do - result = m(1, 2, {foo: :bar}) - result.should == [1, nil, nil, 2, nil, {foo: :bar}] + evaluate <<-ruby do + def m(a, b = nil, c = nil, d, e: nil, **f) + [a, b, c, d, e, f] end + ruby - result = m(1, {foo: :bar}) - result.should == [1, nil, nil, {foo: :bar}, nil, {}] - end - end - - ruby_version_is '3.0' do - evaluate <<-ruby do - def m(a, b = nil, c = nil, d, e: nil, **f) - [a, b, c, d, e, f] - end - ruby - - result = m(1, 2) - result.should == [1, nil, nil, 2, nil, {}] + result = m(1, 2) + result.should == [1, nil, nil, 2, nil, {}] - result = m(1, 2, {foo: :bar}) - result.should == [1, 2, nil, {foo: :bar}, nil, {}] + result = m(1, 2, {foo: :bar}) + result.should == [1, 2, nil, {foo: :bar}, nil, {}] - result = m(1, {foo: :bar}) - result.should == [1, nil, nil, {foo: :bar}, nil, {}] - end + result = m(1, {foo: :bar}) + result.should == [1, nil, nil, {foo: :bar}, nil, {}] end end @@ -1511,60 +1139,27 @@ def m(*a); a; end end end - ruby_version_is ''...'3.0' do - context 'when passing an empty keyword splat to a method that does not accept keywords' do - evaluate <<-ruby do - def m(a); a; end - ruby - h = {} - - -> do - m(**h).should == {} - end.should complain(/warning: Passing the keyword argument as the last hash parameter is deprecated/) - end - end - end - - ruby_version_is ''...'3.0' do - context "assigns keyword arguments from a passed Hash without modifying it" do - evaluate <<-ruby do - def m(a: nil); a; end - ruby + context 'when passing an empty keyword splat to a method that does not accept keywords' do + evaluate <<-ruby do + def m(a); a; end + ruby + h = {} - options = {a: 1}.freeze - -> do - suppress_warning do - m(options).should == 1 - end - end.should_not raise_error - options.should == {a: 1} - end + -> do + m(**h).should == {} + end.should raise_error(ArgumentError) end end - ruby_version_is '3.0' do - context 'when passing an empty keyword splat to a method that does not accept keywords' do - evaluate <<-ruby do - def m(a); a; end - ruby - h = {} - - -> do - m(**h).should == {} - end.should raise_error(ArgumentError) - end - end - - context "raises ArgumentError if passing hash as keyword arguments" do - evaluate <<-ruby do - def m(a: nil); a; end - ruby + context "raises ArgumentError if passing hash as keyword arguments" do + evaluate <<-ruby do + def m(a: nil); a; end + ruby - options = {a: 1}.freeze - -> do - m(options) - end.should raise_error(ArgumentError) - end + options = {a: 1}.freeze + -> do + m(options) + end.should raise_error(ArgumentError) end end @@ -1670,105 +1265,107 @@ def [](*) end end -ruby_version_is "3.0" do - describe "An endless method definition" do - context "without arguments" do - evaluate <<-ruby do - def m() = 42 - ruby - - m.should == 42 - end - - context "without parenthesis" do - evaluate <<-ruby do - def m = 42 - ruby +describe "An endless method definition" do + context "without arguments" do + evaluate <<-ruby do + def m() = 42 + ruby - m.should == 42 - end - end + m.should == 42 end - context "with arguments" do + context "without parenthesis" do evaluate <<-ruby do - def m(a, b) = a + b - ruby + def m = 42 + ruby - m(1, 4).should == 5 + m.should == 42 end end + end - context "with multiline body" do - evaluate <<-ruby do - def m(n) = - if n > 2 - m(n - 2) + m(n - 1) - else - 1 - end - ruby + context "with arguments" do + evaluate <<-ruby do + def m(a, b) = a + b + ruby - m(6).should == 8 - end + m(1, 4).should == 5 end + end - context "with args forwarding" do - evaluate <<-ruby do - def mm(word, num:) - word * num + context "with multiline body" do + evaluate <<-ruby do + def m(n) = + if n > 2 + m(n - 2) + m(n - 1) + else + 1 end + ruby - def m(...) = mm(...) + mm(...) - ruby - - m("meow", num: 2).should == "meow" * 4 - end + m(6).should == 8 end + end - ruby_version_is ""..."3.0" do - context "inside 'endless' method definitions" do - it "does not allow method calls without parenthesis" do - -> { - eval("def greet(person) = 'Hi, '.concat person") - }.should raise_error(SyntaxError) + context "with args forwarding" do + evaluate <<-ruby do + def mm(word, num:) + word * num end - end + + def m(...) = mm(...) + mm(...) + ruby + + m("meow", num: 2).should == "meow" * 4 end end +end - describe "Keyword arguments are now separated from positional arguments" do - context "when the method has only positional parameters" do - it "treats incoming keyword arguments as positional for compatibility" do - def foo(a, b, c, hsh) - hsh[:key] - end - - foo(1, 2, 3, key: 42).should == 42 +describe "Keyword arguments are now separated from positional arguments" do + context "when the method has only positional parameters" do + it "treats incoming keyword arguments as positional for compatibility" do + def foo(a, b, c, hsh) + hsh[:key] end + + foo(1, 2, 3, key: 42).should == 42 end + end - context "when the method takes a ** parameter" do - it "captures the passed literal keyword arguments" do - def foo(a, b, c, **hsh) - hsh[:key] - end + context "when the method takes a ** parameter" do + it "captures the passed literal keyword arguments" do + def foo(a, b, c, **hsh) + hsh[:key] + end + + foo(1, 2, 3, key: 42).should == 42 + end - foo(1, 2, 3, key: 42).should == 42 + it "captures the passed ** keyword arguments" do + def foo(a, b, c, **hsh) + hsh[:key] end - it "captures the passed ** keyword arguments" do - def foo(a, b, c, **hsh) - hsh[:key] - end + h = { key: 42 } + foo(1, 2, 3, **h).should == 42 + end - h = { key: 42 } - foo(1, 2, 3, **h).should == 42 + it "does not convert a positional Hash to keyword arguments" do + def foo(a, b, c, **hsh) + hsh[:key] end - it "does not convert a positional Hash to keyword arguments" do - def foo(a, b, c, **hsh) - hsh[:key] + -> { + foo(1, 2, 3, { key: 42 }) + }.should raise_error(ArgumentError, 'wrong number of arguments (given 4, expected 3)') + end + end + + context "when the method takes a key: parameter" do + context "when it's called with a positional Hash and no **" do + it "raises ArgumentError" do + def foo(a, b, c, key: 1) + key end -> { @@ -1777,28 +1374,14 @@ def foo(a, b, c, **hsh) end end - context "when the method takes a key: parameter" do - context "when it's called with a positional Hash and no **" do - it "raises ArgumentError" do - def foo(a, b, c, key: 1) - key - end - - -> { - foo(1, 2, 3, { key: 42 }) - }.should raise_error(ArgumentError, 'wrong number of arguments (given 4, expected 3)') + context "when it's called with **" do + it "captures the passed keyword arguments" do + def foo(a, b, c, key: 1) + key end - end - - context "when it's called with **" do - it "captures the passed keyword arguments" do - def foo(a, b, c, key: 1) - key - end - h = { key: 42 } - foo(1, 2, 3, **h).should == 42 - end + h = { key: 42 } + foo(1, 2, 3, **h).should == 42 end end end diff --git a/language/module_spec.rb b/language/module_spec.rb index e361bf58f5..fffcf9c90d 100644 --- a/language/module_spec.rb +++ b/language/module_spec.rb @@ -78,20 +78,10 @@ module ModuleSpecs::Modules::Klass; end mod.name.should == "ModuleSpecs_CS1" end - ruby_version_is ""..."3.0" do - it "does not set the name of a module scoped by an anonymous module" do - a, b = Module.new, Module.new - a::B = b - b.name.should be_nil - end - end - - ruby_version_is "3.0" do - it "sets the name of a module scoped by an anonymous module" do - a, b = Module.new, Module.new - a::B = b - b.name.should.end_with? '::B' - end + it "sets the name of a module scoped by an anonymous module" do + a, b = Module.new, Module.new + a::B = b + b.name.should.end_with? '::B' end it "sets the name of contained modules when assigning a toplevel anonymous module" do diff --git a/language/numbered_parameters_spec.rb b/language/numbered_parameters_spec.rb index 424d7a06e3..9d2bd7ff92 100644 --- a/language/numbered_parameters_spec.rb +++ b/language/numbered_parameters_spec.rb @@ -31,38 +31,19 @@ }.should raise_error(SyntaxError, /numbered parameter is already used in/m) end - ruby_version_is ''...'3.0' do - it "can be overwritten with local variable" do - suppress_warning do - eval <<~CODE - _1 = 0 - proc { _1 }.call("a").should == 0 - CODE - end - end - - it "warns when numbered parameter is overwritten with local variable" do - -> { - eval("_1 = 0") - }.should complain(/warning: `_1' is reserved for numbered parameter; consider another name/) - end + it "cannot be overwritten with local variable" do + -> { + eval <<~CODE + _1 = 0 + proc { _1 }.call("a").should == 0 + CODE + }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/) end - ruby_version_is '3.0' do - it "cannot be overwritten with local variable" do - -> { - eval <<~CODE - _1 = 0 - proc { _1 }.call("a").should == 0 - CODE - }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/) - end - - it "errors when numbered parameter is overwritten with local variable" do - -> { - eval("_1 = 0") - }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/) - end + it "errors when numbered parameter is overwritten with local variable" do + -> { + eval("_1 = 0") + }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/) end it "raises SyntaxError when block parameters are specified explicitly" do @@ -80,16 +61,8 @@ end describe "assigning to a numbered parameter" do - ruby_version_is ''...'3.0' do - it "warns" do - -> { eval("proc { _1 = 0 }") }.should complain(/warning: `_1' is reserved for numbered parameter; consider another name/) - end - end - - ruby_version_is '3.0' do - it "raises SyntaxError" do - -> { eval("proc { _1 = 0 }") }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/) - end + it "raises SyntaxError" do + -> { eval("proc { _1 = 0 }") }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/) end end diff --git a/language/pattern_matching_spec.rb b/language/pattern_matching_spec.rb index e4b7a5105e..8a1103ef0f 100644 --- a/language/pattern_matching_spec.rb +++ b/language/pattern_matching_spec.rb @@ -8,115 +8,113 @@ ScratchPad.record [] end - ruby_version_is "3.0" do - it "can be standalone assoc operator that deconstructs value" do - suppress_warning do - eval(<<-RUBY).should == [0, 1] - [0, 1] => [a, b] - [a, b] - RUBY - end + it "can be standalone assoc operator that deconstructs value" do + suppress_warning do + eval(<<-RUBY).should == [0, 1] + [0, 1] => [a, b] + [a, b] + RUBY end + end - describe "find pattern" do - it "captures preceding elements to the pattern" do - eval(<<~RUBY).should == [0, 1] - case [0, 1, 2, 3] - in [*pre, 2, 3] - pre - else - false - end - RUBY - end + describe "find pattern" do + it "captures preceding elements to the pattern" do + eval(<<~RUBY).should == [0, 1] + case [0, 1, 2, 3] + in [*pre, 2, 3] + pre + else + false + end + RUBY + end - it "captures following elements to the pattern" do - eval(<<~RUBY).should == [2, 3] - case [0, 1, 2, 3] - in [0, 1, *post] - post - else - false - end - RUBY - end + it "captures following elements to the pattern" do + eval(<<~RUBY).should == [2, 3] + case [0, 1, 2, 3] + in [0, 1, *post] + post + else + false + end + RUBY + end - it "captures both preceding and following elements to the pattern" do - eval(<<~RUBY).should == [[0, 1], [3, 4]] - case [0, 1, 2, 3, 4] - in [*pre, 2, *post] - [pre, post] - else - false - end - RUBY - end + it "captures both preceding and following elements to the pattern" do + eval(<<~RUBY).should == [[0, 1], [3, 4]] + case [0, 1, 2, 3, 4] + in [*pre, 2, *post] + [pre, post] + else + false + end + RUBY + end - it "can capture the entirety of the pattern" do - eval(<<~RUBY).should == [0, 1, 2, 3, 4] - case [0, 1, 2, 3, 4] - in [*everything] - everything - else - false - end - RUBY - end + it "can capture the entirety of the pattern" do + eval(<<~RUBY).should == [0, 1, 2, 3, 4] + case [0, 1, 2, 3, 4] + in [*everything] + everything + else + false + end + RUBY + end - it "will match an empty Array-like structure" do - eval(<<~RUBY).should == [] - case [] - in [*everything] - everything - else - false - end - RUBY - end + it "will match an empty Array-like structure" do + eval(<<~RUBY).should == [] + case [] + in [*everything] + everything + else + false + end + RUBY + end - it "can be nested" do - eval(<<~RUBY).should == [[0, [2, 4, 6]], [[4, 16, 64]], 27] - case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]] - in [*pre, [*, 9, a], *post] - [pre, post, a] - else - false - end - RUBY - end + it "can be nested" do + eval(<<~RUBY).should == [[0, [2, 4, 6]], [[4, 16, 64]], 27] + case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]] + in [*pre, [*, 9, a], *post] + [pre, post, a] + else + false + end + RUBY + end - it "can be nested with an array pattern" do - eval(<<~RUBY).should == [[4, 16, 64]] - case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]] - in [_, _, [*, 9, *], *post] - post - else - false - end - RUBY - end + it "can be nested with an array pattern" do + eval(<<~RUBY).should == [[4, 16, 64]] + case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]] + in [_, _, [*, 9, *], *post] + post + else + false + end + RUBY + end - it "can be nested within a hash pattern" do - eval(<<~RUBY).should == [27] - case {a: [3, 9, 27]} - in {a: [*, 9, *post]} - post - else - false - end - RUBY - end + it "can be nested within a hash pattern" do + eval(<<~RUBY).should == [27] + case {a: [3, 9, 27]} + in {a: [*, 9, *post]} + post + else + false + end + RUBY + end - it "can nest hash and array patterns" do - eval(<<~RUBY).should == [42, 2] - case [0, {a: 42, b: [0, 1]}, {a: 42, b: [1, 2]}] - in [*, {a:, b: [1, c]}, *] - [a, c] - else - false - end - RUBY - end + it "can nest hash and array patterns" do + eval(<<~RUBY).should == [42, 2] + case [0, {a: 42, b: [0, 1]}, {a: 42, b: [1, 2]}] + in [*, {a:, b: [1, c]}, *] + [a, c] + else + false + end + RUBY end end @@ -154,35 +152,25 @@ @src = 'case [0, 1]; in [a, b]; end' end - ruby_version_is ""..."3.0" do - it "warns about pattern matching is experimental feature" do - -> { eval @src }.should complain(/pattern matching is experimental, and the behavior may change in future versions of Ruby!/i) - end - end - - ruby_version_is "3.0" do - it "does not warn about pattern matching is experimental feature" do - -> { eval @src }.should_not complain - end + it "does not warn about pattern matching is experimental feature" do + -> { eval @src }.should_not complain end end context 'when one-line form' do - ruby_version_is '3.0' do - before :each do - @src = '[0, 1] => [a, b]' - end + before :each do + @src = '[0, 1] => [a, b]' + end - ruby_version_is ""..."3.1" do - it "warns about pattern matching is experimental feature" do - -> { eval @src }.should complain(/pattern matching is experimental, and the behavior may change in future versions of Ruby!/i) - end + ruby_version_is ""..."3.1" do + it "warns about pattern matching is experimental feature" do + -> { eval @src }.should complain(/pattern matching is experimental, and the behavior may change in future versions of Ruby!/i) end + end - ruby_version_is "3.1" do - it "does not warn about pattern matching is experimental feature" do - -> { eval @src }.should_not complain - end + ruby_version_is "3.1" do + it "does not warn about pattern matching is experimental feature" do + -> { eval @src }.should_not complain end end end @@ -687,26 +675,24 @@ def obj.deconstruct; [0, 1] end RUBY end - ruby_version_is "3.0" do - it "calls #deconstruct once for multiple patterns, caching the result" do - obj = Object.new + it "calls #deconstruct once for multiple patterns, caching the result" do + obj = Object.new - def obj.deconstruct - ScratchPad << :deconstruct - [0, 1] - end + def obj.deconstruct + ScratchPad << :deconstruct + [0, 1] + end - eval(<<~RUBY).should == true - case obj - in [1, 2] - false - in [0, 1] - true - end - RUBY + eval(<<~RUBY).should == true + case obj + in [1, 2] + false + in [0, 1] + true + end + RUBY - ScratchPad.recorded.should == [:deconstruct] - end + ScratchPad.recorded.should == [:deconstruct] end it "calls #deconstruct even on objects that are already an array" do diff --git a/language/predefined_spec.rb b/language/predefined_spec.rb index f6cec5fa75..6f779b55f5 100644 --- a/language/predefined_spec.rb +++ b/language/predefined_spec.rb @@ -1161,47 +1161,20 @@ def obj.foo2; yield; end describe "The predefined global constants" do describe "TRUE" do - ruby_version_is "3.0" do - it "is no longer defined" do - Object.const_defined?(:TRUE).should == false - end - end - - ruby_version_is ""..."3.0" do - it "includes TRUE" do - Object.const_defined?(:TRUE).should == true - -> { TRUE }.should complain(/constant ::TRUE is deprecated/) - end + it "is no longer defined" do + Object.const_defined?(:TRUE).should == false end end describe "FALSE" do - ruby_version_is "3.0" do - it "is no longer defined" do - Object.const_defined?(:FALSE).should == false - end - end - - ruby_version_is ""..."3.0" do - it "includes FALSE" do - Object.const_defined?(:FALSE).should == true - -> { FALSE }.should complain(/constant ::FALSE is deprecated/) - end + it "is no longer defined" do + Object.const_defined?(:FALSE).should == false end end describe "NIL" do - ruby_version_is "3.0" do - it "is no longer defined" do - Object.const_defined?(:NIL).should == false - end - end - - ruby_version_is ""..."3.0" do - it "includes NIL" do - Object.const_defined?(:NIL).should == true - -> { NIL }.should complain(/constant ::NIL is deprecated/) - end + it "is no longer defined" do + Object.const_defined?(:NIL).should == false end end diff --git a/language/proc_spec.rb b/language/proc_spec.rb index c5876fb2ed..cc69b7799c 100644 --- a/language/proc_spec.rb +++ b/language/proc_spec.rb @@ -235,18 +235,8 @@ @p = proc { |*a, **kw| [a, kw] } end - ruby_version_is ""..."3.0" do - it 'autosplats keyword arguments and warns' do - -> { - @p.call([1, {a: 1}]).should == [[1], {a: 1}] - }.should complain(/warning: Using the last argument as keyword parameters is deprecated; maybe \*\* should be added to the call/) - end - end - - ruby_version_is "3.0" do - it 'does not autosplat keyword arguments' do - @p.call([1, {a: 1}]).should == [[[1, {a: 1}]], {}] - end + it 'does not autosplat keyword arguments' do + @p.call([1, {a: 1}]).should == [[[1, {a: 1}]], {}] end end diff --git a/language/regexp/character_classes_spec.rb b/language/regexp/character_classes_spec.rb index a86200ff34..98d431a817 100644 --- a/language/regexp/character_classes_spec.rb +++ b/language/regexp/character_classes_spec.rb @@ -614,10 +614,8 @@ "1".match(eval("/\P{N}/")).should be_nil end - ruby_bug "#17340", ''...'3.0' do - it "raises a RegexpError for an unterminated unicode property" do - -> { Regexp.new('\p{') }.should raise_error(RegexpError) - end + it "raises a RegexpError for an unterminated unicode property" do + -> { Regexp.new('\p{') }.should raise_error(RegexpError) end it "supports \\X (unicode 9.0 with UTR #51 workarounds)" do diff --git a/language/regexp_spec.rb b/language/regexp_spec.rb index 646fb89d41..cdafd29f49 100644 --- a/language/regexp_spec.rb +++ b/language/regexp_spec.rb @@ -18,10 +18,8 @@ /Hello/.should be_kind_of(Regexp) end - ruby_version_is "3.0" do - it "is frozen" do - /Hello/.should.frozen? - end + it "is frozen" do + /Hello/.should.frozen? end it "caches the Regexp object" do diff --git a/language/safe_spec.rb b/language/safe_spec.rb index ee5c1b3ccc..03ae96148e 100644 --- a/language/safe_spec.rb +++ b/language/safe_spec.rb @@ -1,27 +1,11 @@ require_relative '../spec_helper' describe "The $SAFE variable" do - ruby_version_is ""..."3.0" do - it "warn when access" do - -> { - $SAFE - }.should complain(/\$SAFE will become a normal global variable in Ruby 3.0/) - end - - it "warn when set" do - -> { - $SAFE = 1 - }.should complain(/\$SAFE will become a normal global variable in Ruby 3.0/) - end - end - - ruby_version_is "3.0" do - it "$SAFE is a regular global variable" do - $SAFE.should == nil - $SAFE = 42 - $SAFE.should == 42 - ensure - $SAFE = nil - end + it "$SAFE is a regular global variable" do + $SAFE.should == nil + $SAFE = 42 + $SAFE.should == 42 + ensure + $SAFE = nil end end diff --git a/language/send_spec.rb b/language/send_spec.rb index 5999079d58..a1656559fe 100644 --- a/language/send_spec.rb +++ b/language/send_spec.rb @@ -411,36 +411,18 @@ def []=(*) specs.rest_len(0,*a,4,*5,6,7,*c,-1).should == 11 end - ruby_version_is ""..."3.0" do - it "expands the Array elements from the splat after executing the arguments and block if no other arguments follow the splat" do - def self.m(*args, &block) - [args, block] - end - - args = [1, nil] - m(*args, &args.pop).should == [[1], nil] - - args = [1, nil] - order = [] - m(*(order << :args; args), &(order << :block; args.pop)).should == [[1], nil] - order.should == [:args, :block] + it "expands the Array elements from the splat before applying block argument operations" do + def self.m(*args, &block) + [args, block] end - end - ruby_version_is "3.0" do - it "expands the Array elements from the splat before applying block argument operations" do - def self.m(*args, &block) - [args, block] - end - - args = [1, nil] - m(*args, &args.pop).should == [[1, nil], nil] + args = [1, nil] + m(*args, &args.pop).should == [[1, nil], nil] - args = [1, nil] - order = [] - m(*(order << :args; args), &(order << :block; args.pop)).should == [[1, nil], nil] - order.should == [:args, :block] - end + args = [1, nil] + order = [] + m(*(order << :args; args), &(order << :block; args.pop)).should == [[1, nil], nil] + order.should == [:args, :block] end it "evaluates the splatted arguments before the block if there are other arguments after the splat" do diff --git a/language/string_spec.rb b/language/string_spec.rb index 02e3488a1f..418dc2ca7d 100644 --- a/language/string_spec.rb +++ b/language/string_spec.rb @@ -277,23 +277,11 @@ def long_string_literals eval(code).should_not.frozen? end - ruby_version_is "3.0" do - it "creates a non-frozen String when # frozen-string-literal: true is used" do - code = <<~'RUBY' - # frozen-string-literal: true - "a#{6*7}c" - RUBY - eval(code).should_not.frozen? - end - end - - ruby_version_is ""..."3.0" do - it "creates a frozen String when # frozen-string-literal: true is used" do - code = <<~'RUBY' - # frozen-string-literal: true - "a#{6*7}c" - RUBY - eval(code).should.frozen? - end + it "creates a non-frozen String when # frozen-string-literal: true is used" do + code = <<~'RUBY' + # frozen-string-literal: true + "a#{6*7}c" + RUBY + eval(code).should_not.frozen? end end diff --git a/language/variables_spec.rb b/language/variables_spec.rb index cd862727ac..23c2cdb557 100644 --- a/language/variables_spec.rb +++ b/language/variables_spec.rb @@ -904,22 +904,11 @@ def test describe "Instance variables" do context "when instance variable is uninitialized" do - ruby_version_is ""..."3.0" do - it "warns about accessing uninitialized instance variable" do - obj = Object.new - def obj.foobar; a = @a; end - - -> { obj.foobar }.should complain(/warning: instance variable @a not initialized/, verbose: true) - end - end - - ruby_version_is "3.0" do - it "doesn't warn about accessing uninitialized instance variable" do - obj = Object.new - def obj.foobar; a = @a; end + it "doesn't warn about accessing uninitialized instance variable" do + obj = Object.new + def obj.foobar; a = @a; end - -> { obj.foobar }.should_not complain(verbose: true) - end + -> { obj.foobar }.should_not complain(verbose: true) end it "doesn't warn at lazy initialization" do diff --git a/language/yield_spec.rb b/language/yield_spec.rb index 05d713af70..5283517636 100644 --- a/language/yield_spec.rb +++ b/language/yield_spec.rb @@ -186,31 +186,14 @@ end describe "Using yield in a singleton class literal" do - ruby_version_is ""..."3.0" do - it 'emits a deprecation warning' do - code = <<~RUBY - def m - class << Object.new - yield - end - end - m { :ok } - RUBY - - -> { eval(code) }.should complain(/warning: `yield' in class syntax will not be supported from Ruby 3.0/) - end - end - - ruby_version_is "3.0" do - it 'raises a SyntaxError' do - code = <<~RUBY - class << Object.new - yield - end - RUBY + it 'raises a SyntaxError' do + code = <<~RUBY + class << Object.new + yield + end + RUBY - -> { eval(code) }.should raise_error(SyntaxError, /Invalid yield/) - end + -> { eval(code) }.should raise_error(SyntaxError, /Invalid yield/) end end diff --git a/library/bigdecimal/to_s_spec.rb b/library/bigdecimal/to_s_spec.rb index 4f1054d38e..042c7779f4 100644 --- a/library/bigdecimal/to_s_spec.rb +++ b/library/bigdecimal/to_s_spec.rb @@ -83,15 +83,13 @@ end end - ruby_version_is "3.0" do - it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do - Encoding.default_internal = nil - BigDecimal('1.23').to_s.encoding.should equal(Encoding::US_ASCII) - end + it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do + Encoding.default_internal = nil + BigDecimal('1.23').to_s.encoding.should equal(Encoding::US_ASCII) + end - it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do - Encoding.default_internal = Encoding::IBM437 - BigDecimal('1.23').to_s.encoding.should equal(Encoding::US_ASCII) - end + it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do + Encoding.default_internal = Encoding::IBM437 + BigDecimal('1.23').to_s.encoding.should equal(Encoding::US_ASCII) end end diff --git a/library/fiber/current_spec.rb b/library/fiber/current_spec.rb index e18603f069..1467a88d0d 100644 --- a/library/fiber/current_spec.rb +++ b/library/fiber/current_spec.rb @@ -48,22 +48,11 @@ fiber3 = Fiber.new do states << :fiber3 fiber2.transfer - ruby_version_is '3.0' do - states << :fiber3_terminated - end - ruby_version_is '' ... '3.0' do - flunk - end + states << :fiber3_terminated end fiber3.resume - ruby_version_is "" ... "3.0" do - states.should == [:fiber3, :fiber2, :fiber] - end - - ruby_version_is "3.0" do - states.should == [:fiber3, :fiber2, :fiber, :fiber3_terminated] - end + states.should == [:fiber3, :fiber2, :fiber, :fiber3_terminated] end end diff --git a/library/fiber/resume_spec.rb b/library/fiber/resume_spec.rb index 8b7c104a6f..fd69d3ba99 100644 --- a/library/fiber/resume_spec.rb +++ b/library/fiber/resume_spec.rb @@ -3,33 +3,16 @@ require 'fiber' describe "Fiber#resume" do - ruby_version_is '' ... '3.0' do - it "raises a FiberError if the Fiber has transferred control to another Fiber" do - fiber1 = Fiber.new { true } - fiber2 = Fiber.new { fiber1.transfer; Fiber.yield } - fiber2.resume - -> { fiber2.resume }.should raise_error(FiberError) - end - - it "raises a FiberError if the Fiber attempts to resume a resuming fiber" do - root_fiber = Fiber.current - fiber1 = Fiber.new { root_fiber.resume } - -> { fiber1.resume }.should raise_error(FiberError, /double resume/) - end + it "can work with Fiber#transfer" do + fiber1 = Fiber.new { true } + fiber2 = Fiber.new { fiber1.transfer; Fiber.yield 10 ; Fiber.yield 20; raise } + fiber2.resume.should == 10 + fiber2.resume.should == 20 end - ruby_version_is '3.0' do - it "can work with Fiber#transfer" do - fiber1 = Fiber.new { true } - fiber2 = Fiber.new { fiber1.transfer; Fiber.yield 10 ; Fiber.yield 20; raise } - fiber2.resume.should == 10 - fiber2.resume.should == 20 - end - - it "raises a FiberError if the Fiber attempts to resume a resuming fiber" do - root_fiber = Fiber.current - fiber1 = Fiber.new { root_fiber.resume } - -> { fiber1.resume }.should raise_error(FiberError, /attempt to resume a resuming fiber/) - end + it "raises a FiberError if the Fiber attempts to resume a resuming fiber" do + root_fiber = Fiber.current + fiber1 = Fiber.new { root_fiber.resume } + -> { fiber1.resume }.should raise_error(FiberError, /attempt to resume a resuming fiber/) end end diff --git a/library/fiber/transfer_spec.rb b/library/fiber/transfer_spec.rb index 7af548da1a..e20d51352e 100644 --- a/library/fiber/transfer_spec.rb +++ b/library/fiber/transfer_spec.rb @@ -11,13 +11,7 @@ it "transfers control from one Fiber to another when called from a Fiber" do fiber1 = Fiber.new { :fiber1 } fiber2 = Fiber.new { fiber1.transfer; :fiber2 } - - ruby_version_is '' ... '3.0' do - fiber2.resume.should == :fiber1 - end - ruby_version_is '3.0' do - fiber2.resume.should == :fiber2 - end + fiber2.resume.should == :fiber2 end it "returns to the root Fiber when finished" do @@ -40,24 +34,12 @@ states.should == [:start, :end] end - ruby_version_is '' ... '3.0' do - it "can transfer control to a Fiber that has transferred to another Fiber" do - states = [] - fiber1 = Fiber.new { states << :fiber1 } - fiber2 = Fiber.new { states << :fiber2_start; fiber1.transfer; states << :fiber2_end} - fiber2.resume.should == [:fiber2_start, :fiber1] - fiber2.transfer.should == [:fiber2_start, :fiber1, :fiber2_end] - end - end - - ruby_version_is '3.0' do - it "can not transfer control to a Fiber that has suspended by Fiber.yield" do - states = [] - fiber1 = Fiber.new { states << :fiber1 } - fiber2 = Fiber.new { states << :fiber2_start; Fiber.yield fiber1.transfer; states << :fiber2_end} - fiber2.resume.should == [:fiber2_start, :fiber1] - -> { fiber2.transfer }.should raise_error(FiberError) - end + it "can not transfer control to a Fiber that has suspended by Fiber.yield" do + states = [] + fiber1 = Fiber.new { states << :fiber1 } + fiber2 = Fiber.new { states << :fiber2_start; Fiber.yield fiber1.transfer; states << :fiber2_end} + fiber2.resume.should == [:fiber2_start, :fiber1] + -> { fiber2.transfer }.should raise_error(FiberError) end it "raises a FiberError when transferring to a Fiber which resumes itself" do @@ -101,28 +83,4 @@ thread.join states.should == [0, 1, 2, 3] end - - ruby_version_is "" ... "3.0" do - it "runs until Fiber.yield" do - obj = mock('obj') - obj.should_not_receive(:do) - fiber = Fiber.new { 1 + 2; Fiber.yield; obj.do } - fiber.transfer - end - - it "resumes from the last call to Fiber.yield on subsequent invocations" do - fiber = Fiber.new { Fiber.yield :first; :second } - fiber.transfer.should == :first - fiber.transfer.should == :second - end - - it "sets the block parameters to its arguments on the first invocation" do - first = mock('first') - first.should_receive(:arg).with(:first).twice - - fiber = Fiber.new { |arg| first.arg arg; Fiber.yield; first.arg arg; } - fiber.transfer :first - fiber.transfer :second - end - end end diff --git a/library/io-wait/wait_spec.rb b/library/io-wait/wait_spec.rb index d968c38774..4c63a07a10 100644 --- a/library/io-wait/wait_spec.rb +++ b/library/io-wait/wait_spec.rb @@ -24,73 +24,69 @@ @w.close unless @w.closed? end - ruby_version_is "3.0" do - context "[events, timeout] passed" do - ruby_version_is "3.0"..."3.2" do - it "returns self when the READABLE event is ready during the timeout" do - @w.write('data to read') - @r.wait(IO::READABLE, 2).should.equal?(@r) - end - - it "returns self when the WRITABLE event is ready during the timeout" do - @w.wait(IO::WRITABLE, 0).should.equal?(@w) - end + context "[events, timeout] passed" do + ruby_version_is "3.0"..."3.2" do + it "returns self when the READABLE event is ready during the timeout" do + @w.write('data to read') + @r.wait(IO::READABLE, 2).should.equal?(@r) end - ruby_version_is "3.2" do - it "returns events mask when the READABLE event is ready during the timeout" do - @w.write('data to read') - @r.wait(IO::READABLE, 2).should == IO::READABLE - end + it "returns self when the WRITABLE event is ready during the timeout" do + @w.wait(IO::WRITABLE, 0).should.equal?(@w) + end + end + + ruby_version_is "3.2" do + it "returns events mask when the READABLE event is ready during the timeout" do + @w.write('data to read') + @r.wait(IO::READABLE, 2).should == IO::READABLE + end - it "returns events mask when the WRITABLE event is ready during the timeout" do - @w.wait(IO::WRITABLE, 0).should == IO::WRITABLE - end + it "returns events mask when the WRITABLE event is ready during the timeout" do + @w.wait(IO::WRITABLE, 0).should == IO::WRITABLE end + end - ruby_version_is "3.0" do - it "waits for the READABLE event to be ready" do - queue = Queue.new - thread = Thread.new { queue.pop; sleep 1; @w.write('data to read') }; + it "waits for the READABLE event to be ready" do + queue = Queue.new + thread = Thread.new { queue.pop; sleep 1; @w.write('data to read') }; - queue.push('signal'); - @r.wait(IO::READABLE, 2).should_not == nil + queue.push('signal'); + @r.wait(IO::READABLE, 2).should_not == nil - thread.join - end + thread.join + end - it "waits for the WRITABLE event to be ready" do - written_bytes = IOWaitSpec.exhaust_write_buffer(@w) + it "waits for the WRITABLE event to be ready" do + written_bytes = IOWaitSpec.exhaust_write_buffer(@w) - queue = Queue.new - thread = Thread.new { queue.pop; sleep 1; @r.read(written_bytes) }; + queue = Queue.new + thread = Thread.new { queue.pop; sleep 1; @r.read(written_bytes) }; - queue.push('signal'); - @w.wait(IO::WRITABLE, 2).should_not == nil + queue.push('signal'); + @w.wait(IO::WRITABLE, 2).should_not == nil - thread.join - end + thread.join + end - it "returns nil when the READABLE event is not ready during the timeout" do - @w.wait(IO::READABLE, 0).should == nil - end + it "returns nil when the READABLE event is not ready during the timeout" do + @w.wait(IO::READABLE, 0).should == nil + end - it "returns nil when the WRITABLE event is not ready during the timeout" do - IOWaitSpec.exhaust_write_buffer(@w) - @w.wait(IO::WRITABLE, 0).should == nil - end + it "returns nil when the WRITABLE event is not ready during the timeout" do + IOWaitSpec.exhaust_write_buffer(@w) + @w.wait(IO::WRITABLE, 0).should == nil + end - it "raises IOError when io is closed (closed stream (IOError))" do - @io.close - -> { @io.wait(IO::READABLE, 0) }.should raise_error(IOError, "closed stream") - end + it "raises IOError when io is closed (closed stream (IOError))" do + @io.close + -> { @io.wait(IO::READABLE, 0) }.should raise_error(IOError, "closed stream") + end - ruby_version_is "3.2" do - it "raises ArgumentError when events is not positive" do - -> { @w.wait(0, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") - -> { @w.wait(-1, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") - end - end + ruby_version_is "3.2" do + it "raises ArgumentError when events is not positive" do + -> { @w.wait(0, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") + -> { @w.wait(-1, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") end end end diff --git a/library/net/http/http/get_spec.rb b/library/net/http/http/get_spec.rb index 9f6c45f26b..a3b62e3754 100644 --- a/library/net/http/http/get_spec.rb +++ b/library/net/http/http/get_spec.rb @@ -80,15 +80,13 @@ def start_threads end end - ruby_version_is "3.0" do # https://bugs.ruby-lang.org/issues/13882#note-6 - it "lets the kill Thread exception goes through and does not replace it with Zlib::BufError" do - socket, client_thread = start_threads - begin - client_thread.kill - client_thread.value.should == nil - ensure - socket.close - end + it "lets the kill Thread exception goes through and does not replace it with Zlib::BufError" do + socket, client_thread = start_threads + begin + client_thread.kill + client_thread.value.should == nil + ensure + socket.close end end end diff --git a/library/objectspace/dump_all_spec.rb b/library/objectspace/dump_all_spec.rb index dbf5bf1f76..e9b449a905 100644 --- a/library/objectspace/dump_all_spec.rb +++ b/library/objectspace/dump_all_spec.rb @@ -55,27 +55,25 @@ stdout.should == "File\ntrue\n" end - ruby_version_is "3.0" do - it "dumps Ruby heap to a temporary file when passed output: :nil" do - stdout = ruby_exe(<<~RUBY, options: "-robjspace") - string = "abc" - file = ObjectSpace.dump_all(output: nil) - - begin - file.flush - file.rewind - content = file.read - - puts file.class - puts content.include?('"value":"abc"') - ensure - file.close - File.unlink file.path - end - RUBY - - stdout.should == "File\ntrue\n" + it "dumps Ruby heap to a temporary file when passed output: :nil" do + stdout = ruby_exe(<<~RUBY, options: "-robjspace") + string = "abc" + file = ObjectSpace.dump_all(output: nil) + + begin + file.flush + file.rewind + content = file.read + + puts file.class + puts content.include?('"value":"abc"') + ensure + file.close + File.unlink file.path end + RUBY + + stdout.should == "File\ntrue\n" end it "dumps Ruby heap to stdout when passed output: :stdout" do diff --git a/library/objectspace/dump_spec.rb b/library/objectspace/dump_spec.rb index eacce51ba5..e22ee3df1e 100644 --- a/library/objectspace/dump_spec.rb +++ b/library/objectspace/dump_spec.rb @@ -23,29 +23,27 @@ string.should include('"value":"abc"') end - ruby_version_is "3.0" do - it "dumps to a temporary file when passed output: :file" do - file = ObjectSpace.dump("abc", output: :file) - file.should be_kind_of(File) + it "dumps to a temporary file when passed output: :file" do + file = ObjectSpace.dump("abc", output: :file) + file.should be_kind_of(File) - file.rewind - content = file.read - content.should include('"value":"abc"') - ensure - file.close - File.unlink file.path - end + file.rewind + content = file.read + content.should include('"value":"abc"') + ensure + file.close + File.unlink file.path + end - it "dumps to a temporary file when passed output: :nil" do - file = ObjectSpace.dump("abc", output: nil) - file.should be_kind_of(File) + it "dumps to a temporary file when passed output: :nil" do + file = ObjectSpace.dump("abc", output: nil) + file.should be_kind_of(File) - file.rewind - file.read.should include('"value":"abc"') - ensure - file.close - File.unlink file.path - end + file.rewind + file.read.should include('"value":"abc"') + ensure + file.close + File.unlink file.path end it "dumps to stdout when passed output: :stdout" do @@ -53,19 +51,17 @@ stdout.should include('"value":"abc"') end - ruby_version_is "3.0" do - it "dumps to provided IO when passed output: IO" do - filename = tmp("io_read.txt") - io = File.open(filename, "w+") - result = ObjectSpace.dump("abc", output: io) - result.should.equal? io + it "dumps to provided IO when passed output: IO" do + filename = tmp("io_read.txt") + io = File.open(filename, "w+") + result = ObjectSpace.dump("abc", output: io) + result.should.equal? io - io.rewind - io.read.should include('"value":"abc"') - ensure - io.close - rm_r filename - end + io.rewind + io.read.should include('"value":"abc"') + ensure + io.close + rm_r filename end it "raises ArgumentError when passed not supported :output value" do diff --git a/library/rexml/attribute/clone_spec.rb b/library/rexml/attribute/clone_spec.rb deleted file mode 100644 index 5c86468d45..0000000000 --- a/library/rexml/attribute/clone_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#clone" do - it "returns a copy of this Attribute" do - orig = REXML::Attribute.new("name", "value&&") - orig.should == orig.clone - orig.clone.to_s.should == orig.to_s - orig.clone.to_string.should == orig.to_string - end - end -end diff --git a/library/rexml/attribute/element_spec.rb b/library/rexml/attribute/element_spec.rb deleted file mode 100644 index 0e4ce46a4f..0000000000 --- a/library/rexml/attribute/element_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#element" do - it "returns the parent element" do - e = REXML::Element.new "root" - - REXML::Attribute.new("name", "value", e).element.should == e - REXML::Attribute.new("name", "default_constructor").element.should == nil - end - end - - describe "REXML::Attribute#element=" do - it "sets the parent element" do - e = REXML::Element.new "root" - f = REXML::Element.new "temp" - a = REXML::Attribute.new("name", "value", e) - a.element.should == e - - a.element = f - a.element.should == f - end - end -end diff --git a/library/rexml/attribute/equal_value_spec.rb b/library/rexml/attribute/equal_value_spec.rb deleted file mode 100644 index 1498bae624..0000000000 --- a/library/rexml/attribute/equal_value_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#==" do - it "returns true if other has equal name and value" do - a1 = REXML::Attribute.new("foo", "bar") - a1.should == a1.clone - - a2 = REXML::Attribute.new("foo", "bar") - a1.should == a2 - - a3 = REXML::Attribute.new("foo", "bla") - a1.should_not == a3 - - a4 = REXML::Attribute.new("baz", "bar") - a1.should_not == a4 - end - end -end diff --git a/library/rexml/attribute/hash_spec.rb b/library/rexml/attribute/hash_spec.rb deleted file mode 100644 index 7e0cbcc1ea..0000000000 --- a/library/rexml/attribute/hash_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#hash" do - # These are not really complete, any idea on how to make them more - # "testable" will be appreciated. - it "returns a hashcode made of the name and value of self" do - a = REXML::Attribute.new("name", "value") - a.hash.should be_kind_of(Numeric) - b = REXML::Attribute.new(a) - a.hash.should == b.hash - end - end -end diff --git a/library/rexml/attribute/initialize_spec.rb b/library/rexml/attribute/initialize_spec.rb deleted file mode 100644 index 35b87b0733..0000000000 --- a/library/rexml/attribute/initialize_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#initialize" do - before :each do - @e = REXML::Element.new "root" - @name = REXML::Attribute.new("name", "Nicko") - @e.add_attribute @name - end - - it "receives two strings for name and value" do - @e.attributes["name"].should == "Nicko" - @e.add_attribute REXML::Attribute.new("last_name", nil) - @e.attributes["last_name"].should == "" - end - - it "receives an Attribute and clones it" do - copy = REXML::Attribute.new(@name) - copy.should == @name - end - - it "receives a parent node" do - last_name = REXML::Attribute.new("last_name", "McBrain", @e) - last_name.element.should == @e - - last_name = REXML::Attribute.new(@name, @e) - last_name.element.should == @e - end - end -end diff --git a/library/rexml/attribute/inspect_spec.rb b/library/rexml/attribute/inspect_spec.rb deleted file mode 100644 index ee5236b98e..0000000000 --- a/library/rexml/attribute/inspect_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#inspect" do - it "returns the name and value as a string" do - a = REXML::Attribute.new("my_name", "my_value") - a.inspect.should == "my_name='my_value'" - end - - it "accepts attributes with no value" do - a = REXML::Attribute.new("my_name") - a.inspect.should == "my_name=''" - end - - it "does not escape text" do - a = REXML::Attribute.new("name", "<>") - a.inspect.should == "name='<>'" - end - end -end diff --git a/library/rexml/attribute/namespace_spec.rb b/library/rexml/attribute/namespace_spec.rb deleted file mode 100644 index 645b3cd1b1..0000000000 --- a/library/rexml/attribute/namespace_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#namespace" do - it "returns the namespace url" do - e = REXML::Element.new("root") - e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri") - e.namespace("ns").should == "http://some_uri" - end - - it "returns nil if namespace is not defined" do - e = REXML::Element.new("root") - e.add_attribute REXML::Attribute.new("test", "value") - e.namespace("test").should == nil - e.namespace("ns").should == nil - end - - it "defaults arg to nil" do - e = REXML::Element.new("root") - e.add_attribute REXML::Attribute.new("xmlns:ns", "http://some_uri") - e.namespace.should == "" - e.namespace("ns").should == "http://some_uri" - end - end -end diff --git a/library/rexml/attribute/node_type_spec.rb b/library/rexml/attribute/node_type_spec.rb deleted file mode 100644 index da055ae8f0..0000000000 --- a/library/rexml/attribute/node_type_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#node_type" do - it "always returns :attribute" do - attr = REXML::Attribute.new("foo", "bar") - attr.node_type.should == :attribute - REXML::Attribute.new(attr).node_type.should == :attribute - end - end -end diff --git a/library/rexml/attribute/prefix_spec.rb b/library/rexml/attribute/prefix_spec.rb deleted file mode 100644 index 87bff4822b..0000000000 --- a/library/rexml/attribute/prefix_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#prefix" do - it "returns the namespace of the Attribute" do - ans = REXML::Attribute.new("ns:someattr", "some_value") - out = REXML::Attribute.new("out:something", "some_other_value") - - ans.prefix.should == "ns" - out.prefix.should == "out" - end - - it "returns an empty string for Attributes with no prefixes" do - attr = REXML::Attribute.new("foo", "bar") - - attr.prefix.should == "" - end - end -end diff --git a/library/rexml/attribute/remove_spec.rb b/library/rexml/attribute/remove_spec.rb deleted file mode 100644 index 5f928b1286..0000000000 --- a/library/rexml/attribute/remove_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#remove" do - before :each do - @e = REXML::Element.new "Root" - @attr = REXML::Attribute.new("foo", "bar") - end - - it "deletes this Attribute from parent" do - @e.add_attribute(@attr) - @e.attributes["foo"].should_not == nil - @attr.remove - @e.attributes["foo"].should == nil - end - - it "does not anything if element has no parent" do - -> {@attr.remove}.should_not raise_error(Exception) - end - end -end diff --git a/library/rexml/attribute/to_s_spec.rb b/library/rexml/attribute/to_s_spec.rb deleted file mode 100644 index e362cee8f1..0000000000 --- a/library/rexml/attribute/to_s_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#to_s" do - it "returns the value of the Attribute" do - REXML::Attribute.new("name", "some_value").to_s.should == "some_value" - end - - it "returns the escaped value if it was created from Attribute" do - orig = REXML::Attribute.new("name", "<&>") - copy = REXML::Attribute.new(orig) - copy.to_s.should == "<&>" - end - end -end diff --git a/library/rexml/attribute/to_string_spec.rb b/library/rexml/attribute/to_string_spec.rb deleted file mode 100644 index a9d249f5bb..0000000000 --- a/library/rexml/attribute/to_string_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#to_string" do - it "returns the attribute as XML" do - attr = REXML::Attribute.new("name", "value") - attr_empty = REXML::Attribute.new("name") - attr_ns = REXML::Attribute.new("xmlns:ns", "http://uri") - - attr.to_string.should == "name='value'" - attr_empty.to_string.should == "name=''" - attr_ns.to_string.should == "xmlns:ns='http://uri'" - end - end -end diff --git a/library/rexml/attribute/value_spec.rb b/library/rexml/attribute/value_spec.rb deleted file mode 100644 index 77071f6f70..0000000000 --- a/library/rexml/attribute/value_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#value" do - it "returns the value of the Attribute unnormalized" do - attr = REXML::Attribute.new("name", "value") - attr_ents = REXML::Attribute.new("name", "<&>") - attr_empty = REXML::Attribute.new("name") - - attr.value.should == "value" - attr_ents.value.should == "<&>" - attr_empty.value.should == "" - end - end -end diff --git a/library/rexml/attribute/write_spec.rb b/library/rexml/attribute/write_spec.rb deleted file mode 100644 index 0012b3cc77..0000000000 --- a/library/rexml/attribute/write_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#write" do - before :each do - @attr = REXML::Attribute.new("name", "Charlotte") - @s = "" - end - - it "writes the name and value to output" do - @attr.write(@s) - @s.should == "name='Charlotte'" - end - - it "currently ignores the second argument" do - @attr.write(@s, 3) - @s.should == "name='Charlotte'" - - @s = "" - @attr.write(@s, "foo") - @s.should == "name='Charlotte'" - end - end -end diff --git a/library/rexml/attribute/xpath_spec.rb b/library/rexml/attribute/xpath_spec.rb deleted file mode 100644 index 0a09046b01..0000000000 --- a/library/rexml/attribute/xpath_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attribute#xpath" do - - before :each do - @e = REXML::Element.new "root" - @attr = REXML::Attribute.new("year", "1989") - end - - it "returns the path for Attribute" do - @e.add_attribute @attr - @attr.xpath.should == "root/@year" - end - - it "raises an error if attribute has no parent" do - -> { @attr.xpath }.should raise_error(Exception) - end - end -end diff --git a/library/rexml/attributes/add_spec.rb b/library/rexml/attributes/add_spec.rb deleted file mode 100644 index e24e9fabbc..0000000000 --- a/library/rexml/attributes/add_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/add' - require 'rexml/document' - - describe "REXML::Attributes#add" do - it_behaves_like :rexml_attribute_add, :add - end -end diff --git a/library/rexml/attributes/append_spec.rb b/library/rexml/attributes/append_spec.rb deleted file mode 100644 index f96a727f47..0000000000 --- a/library/rexml/attributes/append_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/add' - require 'rexml/document' - - describe "REXML::Attributes#<<" do - it_behaves_like :rexml_attribute_add, :<< - end -end diff --git a/library/rexml/attributes/delete_all_spec.rb b/library/rexml/attributes/delete_all_spec.rb deleted file mode 100644 index 707baa235b..0000000000 --- a/library/rexml/attributes/delete_all_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#delete_all" do - before :each do - @e = REXML::Element.new("root") - end - - it "deletes all attributes that match name" do - uri = REXML::Attribute.new("uri", "http://something") - @e.attributes << uri - @e.attributes.delete_all("uri") - @e.attributes.should be_empty - @e.attributes["uri"].should == nil - end - - it "deletes all attributes that match name with a namespace" do - ns_uri = REXML::Attribute.new("xmlns:uri", "http://something_here_too") - @e.attributes << ns_uri - @e.attributes.delete_all("xmlns:uri") - @e.attributes.should be_empty - @e.attributes["xmlns:uri"].should == nil - end - - it "returns the removed attribute" do - uri = REXML::Attribute.new("uri", "http://something_here_too") - @e.attributes << uri - attrs = @e.attributes.delete_all("uri") - attrs.first.should == uri - end - end -end diff --git a/library/rexml/attributes/delete_spec.rb b/library/rexml/attributes/delete_spec.rb deleted file mode 100644 index 723fa70751..0000000000 --- a/library/rexml/attributes/delete_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#delete" do - before :each do - @e = REXML::Element.new("root") - @name = REXML::Attribute.new("name", "Pepe") - end - - it "takes an attribute name and deletes the attribute" do - @e.attributes.delete("name") - @e.attributes["name"].should be_nil - @e.attributes.should be_empty - end - - it "takes an Attribute and deletes it" do - @e.attributes.delete(@name) - @e.attributes["name"].should be_nil - @e.attributes.should be_empty - end - - it "returns the element with the attribute removed" do - ret_val = @e.attributes.delete(@name) - ret_val.should == @e - ret_val.attributes.should be_empty - end - end -end diff --git a/library/rexml/attributes/each_attribute_spec.rb b/library/rexml/attributes/each_attribute_spec.rb deleted file mode 100644 index 692cf4f943..0000000000 --- a/library/rexml/attributes/each_attribute_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#each_attribute" do - it "iterates over the attributes yielding actual Attribute objects" do - e = REXML::Element.new("root") - name = REXML::Attribute.new("name", "Joe") - ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri") - e.add_attribute name - e.add_attribute ns_uri - - attributes = [] - - e.attributes.each_attribute do |attr| - attributes << attr - end - - attributes = attributes.sort_by {|a| a.name } - attributes.first.should == name - attributes.last.should == ns_uri - end - end -end diff --git a/library/rexml/attributes/each_spec.rb b/library/rexml/attributes/each_spec.rb deleted file mode 100644 index 49add3b77b..0000000000 --- a/library/rexml/attributes/each_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#each" do - before :each do - @e = REXML::Element.new("root") - @name = REXML::Attribute.new("name", "Joe") - @ns_uri = REXML::Attribute.new("xmlns:ns", "http://some_uri") - @e.add_attribute @name - @e.add_attribute @ns_uri - end - - it "iterates over the attributes yielding expanded-name/value" do - attributes = [] - @e.attributes.each do |attr| - attr.should be_kind_of(Array) - attributes << attr - end - attributes = attributes.sort_by {|a| a.first } - attributes.first.should == ["name", "Joe"] - attributes.last.should == ["xmlns:ns", "http://some_uri"] - end - end -end diff --git a/library/rexml/attributes/element_reference_spec.rb b/library/rexml/attributes/element_reference_spec.rb deleted file mode 100644 index 0d089eaab2..0000000000 --- a/library/rexml/attributes/element_reference_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#[]" do - before :each do - @e = REXML::Element.new("root") - @lang = REXML::Attribute.new("language", "english") - @e.attributes << @lang - end - - it "returns the value of an attribute" do - @e.attributes["language"].should == "english" - end - - it "returns nil if the attribute does not exist" do - @e.attributes["chunky bacon"].should == nil - end - end -end diff --git a/library/rexml/attributes/element_set_spec.rb b/library/rexml/attributes/element_set_spec.rb deleted file mode 100644 index 834ad682a6..0000000000 --- a/library/rexml/attributes/element_set_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#[]=" do - before :each do - @e = REXML::Element.new("song") - @name = REXML::Attribute.new("name", "Holy Smoke!") - @e.attributes << @name - end - - it "sets an attribute" do - @e.attributes["author"] = "_why's foxes" - @e.attributes["author"].should == "_why's foxes" - end - - it "overwrites an existing attribute" do - @e.attributes["name"] = "Chunky Bacon" - @e.attributes["name"].should == "Chunky Bacon" - end - - it "deletes an attribute is value is nil" do - @e.attributes["name"] = nil - @e.attributes.length.should == 0 - end - end -end diff --git a/library/rexml/attributes/get_attribute_ns_spec.rb b/library/rexml/attributes/get_attribute_ns_spec.rb deleted file mode 100644 index 1109ff519c..0000000000 --- a/library/rexml/attributes/get_attribute_ns_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#get_attribute_ns" do - it "returns an attribute by name and namespace" do - e = REXML::Element.new("root") - attr = REXML::Attribute.new("xmlns:ns", "http://some_url") - e.attributes << attr - attr.prefix.should == "xmlns" - # This might be a bug in Attribute, commenting until those specs - # are ready - # e.attributes.get_attribute_ns(attr.prefix, "name").should == "http://some_url" - end - end -end diff --git a/library/rexml/attributes/get_attribute_spec.rb b/library/rexml/attributes/get_attribute_spec.rb deleted file mode 100644 index cc94191729..0000000000 --- a/library/rexml/attributes/get_attribute_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#get_attribute" do - before :each do - @e = REXML::Element.new("root") - @name = REXML::Attribute.new("name", "Dave") - @e.attributes << @name - end - - it "fetches an attributes" do - @e.attributes.get_attribute("name").should == @name - end - - it "fetches an namespaced attribute" do - ns_name = REXML::Attribute.new("im:name", "Murray") - @e.attributes << ns_name - @e.attributes.get_attribute("name").should == @name - @e.attributes.get_attribute("im:name").should == ns_name - end - - it "returns an Attribute" do - @e.attributes.get_attribute("name").should be_kind_of(REXML::Attribute) - end - - it "returns nil if it attribute does not exist" do - @e.attributes.get_attribute("fake").should be_nil - end - end -end diff --git a/library/rexml/attributes/initialize_spec.rb b/library/rexml/attributes/initialize_spec.rb deleted file mode 100644 index 42ec742e60..0000000000 --- a/library/rexml/attributes/initialize_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#initialize" do - it "is auto initialized by Element" do - e = REXML::Element.new "root" - e.attributes.should be_kind_of(REXML::Attributes) - - e.attributes << REXML::Attribute.new("name", "Paul") - e.attributes["name"].should == "Paul" - end - - it "receives a parent node" do - e = REXML::Element.new "root" - e.attributes << REXML::Attribute.new("name", "Vic") - e.attributes["name"].should == "Vic" - end - end -end diff --git a/library/rexml/attributes/length_spec.rb b/library/rexml/attributes/length_spec.rb deleted file mode 100644 index 81733b4a96..0000000000 --- a/library/rexml/attributes/length_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/length' - require 'rexml/document' - - describe "REXML::Attributes#length" do - it_behaves_like :rexml_attribute_length, :length - end -end diff --git a/library/rexml/attributes/namespaces_spec.rb b/library/rexml/attributes/namespaces_spec.rb deleted file mode 100644 index b88346854f..0000000000 --- a/library/rexml/attributes/namespaces_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#namespaces" do - it "needs to be reviewed for spec completeness" - end -end diff --git a/library/rexml/attributes/prefixes_spec.rb b/library/rexml/attributes/prefixes_spec.rb deleted file mode 100644 index 574b7ffbaf..0000000000 --- a/library/rexml/attributes/prefixes_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#prefixes" do - before :each do - @e = REXML::Element.new("root") - a1 = REXML::Attribute.new("xmlns:a", "bar") - a2 = REXML::Attribute.new("xmlns:b", "bla") - a3 = REXML::Attribute.new("xmlns:c", "baz") - @e.attributes << a1 - @e.attributes << a2 - @e.attributes << a3 - - @e.attributes << REXML::Attribute.new("xmlns", "foo") - end - - it "returns an array with the prefixes of each attribute" do - @e.attributes.prefixes.sort.should == ["a", "b", "c"] - end - - it "does not include the default namespace" do - @e.attributes.prefixes.include?("xmlns").should == false - end - end -end diff --git a/library/rexml/attributes/size_spec.rb b/library/rexml/attributes/size_spec.rb deleted file mode 100644 index 13ef08f644..0000000000 --- a/library/rexml/attributes/size_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/length' - require 'rexml/document' - - describe "REXML::Attributes#size" do - it_behaves_like :rexml_attribute_length, :size - end -end diff --git a/library/rexml/attributes/to_a_spec.rb b/library/rexml/attributes/to_a_spec.rb deleted file mode 100644 index 902cd86a29..0000000000 --- a/library/rexml/attributes/to_a_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Attributes#to_a" do - it "returns an array with the attributes" do - e = REXML::Element.new("root") - name = REXML::Attribute.new("name", "Dave") - last = REXML::Attribute.new("last_name", "Murray") - - e.attributes << name - e.attributes << last - - e.attributes.to_a.sort{|a,b|a.to_s<=>b.to_s}.should == [name, last] - end - - it "returns an empty array if it has no attributes" do - REXML::Element.new("root").attributes.to_a.should == [] - end - end -end diff --git a/library/rexml/cdata/clone_spec.rb b/library/rexml/cdata/clone_spec.rb deleted file mode 100644 index abe1a0b062..0000000000 --- a/library/rexml/cdata/clone_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::CData#clone" do - it "makes a copy of itself" do - c = REXML::CData.new("some text") - c.clone.to_s.should == c.to_s - c.clone.should == c - end - end -end diff --git a/library/rexml/cdata/initialize_spec.rb b/library/rexml/cdata/initialize_spec.rb deleted file mode 100644 index 1393d97f4a..0000000000 --- a/library/rexml/cdata/initialize_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::CData#initialize" do - it "creates a new CData object" do - c = REXML::CData.new("some text") - c.should be_kind_of(REXML::CData) - c.should be_kind_of(REXML::Text) - end - - it "respects whitespace if whitespace is true" do - c = REXML::CData.new("whitespace test", true) - c1 = REXML::CData.new("whitespace test", false) - - c.to_s.should == "whitespace test" - c1.to_s.should == "whitespace test" - end - - it "receives parent as third argument" do - e = REXML::Element.new("root") - REXML::CData.new("test", true, e) - e.to_s.should == "" - end - end -end diff --git a/library/rexml/cdata/to_s_spec.rb b/library/rexml/cdata/to_s_spec.rb deleted file mode 100644 index a5c061f116..0000000000 --- a/library/rexml/cdata/to_s_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/to_s' - require 'rexml/document' - - describe "REXML::CData#to_s" do - it_behaves_like :rexml_cdata_to_s, :to_s - end -end diff --git a/library/rexml/cdata/value_spec.rb b/library/rexml/cdata/value_spec.rb deleted file mode 100644 index 9f36226976..0000000000 --- a/library/rexml/cdata/value_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require_relative 'shared/to_s' - require 'rexml/document' - - describe "REXML::CData#value" do - it_behaves_like :rexml_cdata_to_s, :value - end -end diff --git a/library/rexml/document/add_element_spec.rb b/library/rexml/document/add_element_spec.rb deleted file mode 100644 index 29dec0b24e..0000000000 --- a/library/rexml/document/add_element_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#add_element" do - it "adds arg1 with attributes arg2 as root node" do - d = REXML::Document.new - e = REXML::Element.new("root") - d.add_element e - d.root.should == e - end - - it "sets arg2 as arg1's attributes" do - d = REXML::Document.new - e = REXML::Element.new("root") - attr = {"foo" => "bar"} - d.add_element(e,attr) - d.root.attributes["foo"].should == attr["foo"] - end - - it "accepts a node name as arg1 and adds it as root" do - d = REXML::Document.new - d.add_element "foo" - d.root.name.should == "foo" - end - - it "sets arg1's context to the root's context" do - d = REXML::Document.new("", {"foo" => "bar"}) - d.add_element "foo" - d.root.context.should == d.context - end - end -end diff --git a/library/rexml/document/add_spec.rb b/library/rexml/document/add_spec.rb deleted file mode 100644 index 8666d3dbf9..0000000000 --- a/library/rexml/document/add_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - # This spec defines Document#add and Document#<< - - describe :rexml_document_add, shared: true do - before :each do - @doc = REXML::Document.new("") - @decl = REXML::XMLDecl.new("1.0") - end - - it "sets document's XML declaration" do - @doc.send(@method, @decl) - @doc.xml_decl.should == @decl - end - - it "inserts XML declaration as first node" do - @doc.send(@method, @decl) - @doc.children[0].version.should == "1.0" - end - - it "overwrites existing XML declaration" do - @doc.send(@method, @decl) - @doc.send(@method, REXML::XMLDecl.new("2.0")) - @doc.xml_decl.version.should == "2.0" - end - - it "sets document DocType" do - @doc.send(@method, REXML::DocType.new("transitional")) - @doc.doctype.name.should == "transitional" - end - - it "overwrites existing DocType" do - @doc.send(@method, REXML::DocType.new("transitional")) - @doc.send(@method, REXML::DocType.new("strict")) - @doc.doctype.name.should == "strict" - end - - it "adds root node unless it exists" do - d = REXML::Document.new("") - elem = REXML::Element.new "root" - d.send(@method, elem) - d.root.should == elem - end - - it "refuses to add second root" do - -> { @doc.send(@method, REXML::Element.new("foo")) }.should raise_error(RuntimeError) - end - end - - describe "REXML::Document#add" do - it_behaves_like :rexml_document_add, :add - end - - describe "REXML::Document#<<" do - it_behaves_like :rexml_document_add, :<< - end -end diff --git a/library/rexml/document/clone_spec.rb b/library/rexml/document/clone_spec.rb deleted file mode 100644 index 137fe8a073..0000000000 --- a/library/rexml/document/clone_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - # According to the MRI documentation (http://www.ruby-doc.org/stdlib/libdoc/rexml/rdoc/index.html), - # clone's behavior "should be obvious". Apparently "obvious" means cloning - # only the attributes and the context of the document, not its children. - describe "REXML::Document#clone" do - it "clones document attributes" do - d = REXML::Document.new("foo") - d.attributes["foo"] = "bar" - e = d.clone - e.attributes.should == d.attributes - end - - it "clones document context" do - d = REXML::Document.new("foo", {"foo" => "bar"}) - e = d.clone - e.context.should == d.context - end - end -end diff --git a/library/rexml/document/doctype_spec.rb b/library/rexml/document/doctype_spec.rb deleted file mode 100644 index e1b7ba4916..0000000000 --- a/library/rexml/document/doctype_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#doctype" do - it "returns the doctype" do - d = REXML::Document.new - dt = REXML::DocType.new("foo") - d.add dt - d.doctype.should == dt - end - - it "returns nil if there's no doctype" do - REXML::Document.new.doctype.should == nil - end - end -end diff --git a/library/rexml/document/encoding_spec.rb b/library/rexml/document/encoding_spec.rb deleted file mode 100644 index 2cc947f06a..0000000000 --- a/library/rexml/document/encoding_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#encoding" do - before :each do - @doc = REXML::Document.new - end - - it "returns encoding from XML declaration" do - @doc.add REXML::XMLDecl.new(nil, "UTF-16", nil) - @doc.encoding.should == "UTF-16" - end - - it "returns encoding from XML declaration (for UTF-16 as well)" do - @doc.add REXML::XMLDecl.new("1.0", "UTF-8", nil) - @doc.encoding.should == "UTF-8" - end - - it "uses UTF-8 as default encoding" do - @doc.encoding.should == "UTF-8" - end - end -end diff --git a/library/rexml/document/expanded_name_spec.rb b/library/rexml/document/expanded_name_spec.rb deleted file mode 100644 index 9d1025b5e0..0000000000 --- a/library/rexml/document/expanded_name_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe :document_expanded_name, shared: true do - it "returns an empty string for root" do # root nodes have no expanded name - REXML::Document.new.send(@method).should == "" - end - end - - describe "REXML::Document#expanded_name" do - it_behaves_like :document_expanded_name, :expanded_name - end - - describe "REXML::Document#name" do - it_behaves_like :document_expanded_name, :name - end -end diff --git a/library/rexml/document/new_spec.rb b/library/rexml/document/new_spec.rb deleted file mode 100644 index 4e24b6f5a1..0000000000 --- a/library/rexml/document/new_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#new" do - - it "initializes context of {} unless specified" do - d = REXML::Document.new("") - d.context.should == {} - end - - it "has empty attributes if source is nil" do - d = REXML::Document.new(nil) - d.elements.should be_empty - end - - it "can use other document context" do - s = REXML::Document.new("") - d = REXML::Document.new(s) - d.context.should == s.context - end - - it "clones source attributes" do - s = REXML::Document.new("") - s.attributes["some_attr"] = "some_val" - d = REXML::Document.new(s) - d.attributes.should == s.attributes - end - - it "raises an error if source is not a Document, String or IO" do - -> {REXML::Document.new(3)}.should raise_error(RuntimeError) - end - - it "does not perform XML validation" do - REXML::Document.new("Invalid document").should be_kind_of(REXML::Document) - end - end -end diff --git a/library/rexml/document/node_type_spec.rb b/library/rexml/document/node_type_spec.rb deleted file mode 100644 index b6d7e7a7da..0000000000 --- a/library/rexml/document/node_type_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#node_type" do - it "returns :document" do - REXML::Document.new.node_type.should == :document - end - end -end diff --git a/library/rexml/document/root_spec.rb b/library/rexml/document/root_spec.rb deleted file mode 100644 index 1a584a720b..0000000000 --- a/library/rexml/document/root_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#root" do - it "returns document root tag name" do - REXML::Document.new("").root.name.should == "foo" - end - - it "returns nil if there is not root" do - REXML::Document.new.root.should == nil - end - end -end diff --git a/library/rexml/document/stand_alone_spec.rb b/library/rexml/document/stand_alone_spec.rb deleted file mode 100644 index e1c721e782..0000000000 --- a/library/rexml/document/stand_alone_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#stand_alone?" do - it "returns the XMLDecl standalone value" do - d = REXML::Document.new - decl = REXML::XMLDecl.new("1.0", "UTF-8", "yes") - d.add decl - d.stand_alone?.should == "yes" - end - - # According to the docs this should return the default XMLDecl but that - # will carry some more problems when printing the document. Currently, it - # returns nil. See http://www.ruby-forum.com/topic/146812#650061 - it "returns the default value when no XML declaration present" do - REXML::Document.new.stand_alone?.should == nil - end - - end -end diff --git a/library/rexml/document/version_spec.rb b/library/rexml/document/version_spec.rb deleted file mode 100644 index 4f6b40551b..0000000000 --- a/library/rexml/document/version_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#version" do - it "returns XML version from declaration" do - d = REXML::Document.new - d.add REXML::XMLDecl.new("1.1") - d.version.should == "1.1" - end - - it "returns the default version when declaration is not present" do - REXML::Document.new.version.should == REXML::XMLDecl::DEFAULT_VERSION - end - end -end diff --git a/library/rexml/document/write_spec.rb b/library/rexml/document/write_spec.rb deleted file mode 100644 index 00c22141b3..0000000000 --- a/library/rexml/document/write_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - require 'rexml/formatters/transitive' - - # Maybe this can be cleaned - describe "REXML::Document#write" do - before :each do - @d = REXML::Document.new - city = REXML::Element.new "Springfield" - street = REXML::Element.new "EvergreenTerrace" - address = REXML::Element.new "House742" - @d << city << street << address - @str = "" - end - - it "returns document source as string" do - @d.write(@str) - @str.should == "" - end - - it "returns document indented" do - @d.write(@str, 2) - @str.should =~ /\s*\s*\s*\s*<\/EvergreenTerrace>\s*<\/Springfield>/ - end - - it "returns document with transitive support" do - @d.write(@str, 2, true) - @str.should =~ /\s*<\/EvergreenTerrace\s*><\/Springfield\s*>/ - end - - it "returns document with support for IE" do - @d.write(@str, -1, false, true) - @str.should == "" - end - end -end diff --git a/library/rexml/document/xml_decl_spec.rb b/library/rexml/document/xml_decl_spec.rb deleted file mode 100644 index 8ac47510b0..0000000000 --- a/library/rexml/document/xml_decl_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document#xml_decl" do - it "returns XML declaration of the document" do - d = REXML::Document.new - decl = REXML::XMLDecl.new("1.0", "UTF-16", "yes") - d.add decl - d.xml_decl.should == decl - end - - it "returns default XML declaration unless present" do - REXML::Document.new.xml_decl.should == REXML::XMLDecl.new - end - end -end diff --git a/library/rexml/element/add_attribute_spec.rb b/library/rexml/element/add_attribute_spec.rb deleted file mode 100644 index 64f2ec84a3..0000000000 --- a/library/rexml/element/add_attribute_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_attribute" do - before :each do - @person = REXML::Element.new "person" - @person.attributes["name"] = "Bill" - end - - it "adds a new attribute" do - @person.add_attribute("age", "17") - @person.attributes["age"].should == "17" - end - - it "overwrites an existing attribute" do - @person.add_attribute("name", "Bill") - @person.attributes["name"].should == "Bill" - end - - it "accepts a pair of strings" do - @person.add_attribute("male", "true") - @person.attributes["male"].should == "true" - end - - it "accepts an Attribute for key" do - attr = REXML::Attribute.new("male", "true") - @person.add_attribute attr - @person.attributes["male"].should == "true" - end - - it "ignores value if key is an Attribute" do - attr = REXML::Attribute.new("male", "true") - @person.add_attribute(attr, "false") - @person.attributes["male"].should == "true" - end - - it "returns the attribute added" do - attr = REXML::Attribute.new("name", "Tony") - @person.add_attribute(attr).should == attr - end - end -end diff --git a/library/rexml/element/add_attributes_spec.rb b/library/rexml/element/add_attributes_spec.rb deleted file mode 100644 index f331803dd8..0000000000 --- a/library/rexml/element/add_attributes_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_attributes" do - before :each do - @person = REXML::Element.new "person" - @person.attributes["name"] = "Bill" - end - - it "adds multiple attributes from a hash" do - @person.add_attributes({"name" => "Joe", "age" => "27"}) - @person.attributes["name"].should == "Joe" - @person.attributes["age"].should == "27" - end - - it "adds multiple attributes from an array" do - attrs = { "name" => "Joe", "age" => "27"} - @person.add_attributes attrs.to_a - @person.attributes["name"].should == "Joe" - @person.attributes["age"].should == "27" - end - end -end diff --git a/library/rexml/element/add_element_spec.rb b/library/rexml/element/add_element_spec.rb deleted file mode 100644 index 8ba023f2c7..0000000000 --- a/library/rexml/element/add_element_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_element" do - before :each do - @root = REXML::Element.new("root") - end - - it "adds a child without attributes" do - name = REXML::Element.new("name") - @root.add_element name - @root.elements["name"].name.should == name.name - @root.elements["name"].attributes.should == name.attributes - @root.elements["name"].context.should == name.context - end - - it "adds a child with attributes" do - person = REXML::Element.new("person") - @root.add_element(person, {"name" => "Madonna"}) - @root.elements["person"].name.should == person.name - @root.elements["person"].attributes.should == person.attributes - @root.elements["person"].context.should == person.context - end - - it "adds a child with name" do - @root.add_element "name" - @root.elements["name"].name.should == "name" - @root.elements["name"].attributes.should == {} - @root.elements["name"].context.should == nil - end - - it "returns the added child" do - name = @root.add_element "name" - @root.elements["name"].name.should == name.name - @root.elements["name"].attributes.should == name.attributes - @root.elements["name"].context.should == name.context - end - end -end diff --git a/library/rexml/element/add_namespace_spec.rb b/library/rexml/element/add_namespace_spec.rb deleted file mode 100644 index 44b074bac7..0000000000 --- a/library/rexml/element/add_namespace_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_namespace" do - before :each do - @elem = REXML::Element.new("person") - end - - it "adds a namespace to element" do - @elem.add_namespace("foo", "bar") - @elem.namespace("foo").should == "bar" - end - - it "accepts a prefix string as prefix" do - @elem.add_namespace("xmlns:foo", "bar") - @elem.namespace("foo").should == "bar" - end - - it "uses prefix as URI if uri is nil" do - @elem.add_namespace("some_uri", nil) - @elem.namespace.should == "some_uri" - end - end -end diff --git a/library/rexml/element/add_text_spec.rb b/library/rexml/element/add_text_spec.rb deleted file mode 100644 index 3a0531ad42..0000000000 --- a/library/rexml/element/add_text_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#add_text" do - before :each do - @name = REXML::Element.new "Name" - end - - it "adds text to an element" do - @name.add_text "Ringo" - @name.to_s.should == "Ringo" - end - - it "accepts a Text" do - @name.add_text(REXML::Text.new("Ringo")) - @name.to_s.should == "Ringo" - end - - it "joins the new text with the old one" do - @name.add_text "Ringo" - @name.add_text " Starr" - @name.to_s.should == "Ringo Starr" - end - end -end diff --git a/library/rexml/element/attribute_spec.rb b/library/rexml/element/attribute_spec.rb deleted file mode 100644 index b223d3440c..0000000000 --- a/library/rexml/element/attribute_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#attribute" do - it "returns an attribute by name" do - person = REXML::Element.new "Person" - attribute = REXML::Attribute.new("drink", "coffee") - person.add_attribute(attribute) - person.attribute("drink").should == attribute - end - - it "supports attributes inside namespaces" do - e = REXML::Element.new("element") - e.add_attributes({"xmlns:ns" => "http://some_uri"}) - e.attribute("ns", "ns").to_s.should == "http://some_uri" - end - end -end diff --git a/library/rexml/element/attributes_spec.rb b/library/rexml/element/attributes_spec.rb deleted file mode 100644 index 92bcecc40a..0000000000 --- a/library/rexml/element/attributes_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#attributes" do - it "returns element's Attributes" do - p = REXML::Element.new "Person" - - name = REXML::Attribute.new("name", "John") - attrs = REXML::Attributes.new(p) - attrs.add name - - p.add_attribute name - p.attributes.should == attrs - end - - it "returns an empty hash if element has no attributes" do - REXML::Element.new("Person").attributes.should == {} - end - end -end diff --git a/library/rexml/element/cdatas_spec.rb b/library/rexml/element/cdatas_spec.rb deleted file mode 100644 index 988b2cb422..0000000000 --- a/library/rexml/element/cdatas_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#cdatas" do - before :each do - @e = REXML::Element.new("Root") - end - - it "returns the array of children cdatas" do - c = REXML::CData.new("Primary") - d = REXML::CData.new("Secondary") - @e << c - @e << d - @e.cdatas.should == [c, d] - end - - it "freezes the returned array" do - @e.cdatas.should.frozen? - end - - it "returns an empty array if element has no cdata" do - @e.cdatas.should == [] - end - end -end diff --git a/library/rexml/element/clone_spec.rb b/library/rexml/element/clone_spec.rb deleted file mode 100644 index 490e43181f..0000000000 --- a/library/rexml/element/clone_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#clone" do - before :each do - @e = REXML::Element.new "a" - end - it "creates a copy of element" do - @e.clone.to_s.should == @e.to_s - end - - it "copies the attributes" do - @e.add_attribute("foo", "bar") - @e.clone.to_s.should == @e.to_s - end - - it "does not copy the text" do - @e.add_text "some text..." - @e.clone.to_s.should_not == @e - @e.clone.to_s.should == "" - end - - it "does not copy the child elements" do - b = REXML::Element.new "b" - @e << b - @e.clone.should_not == @e - @e.clone.to_s.should == "" - end - end -end diff --git a/library/rexml/element/comments_spec.rb b/library/rexml/element/comments_spec.rb deleted file mode 100644 index 84ab9a7469..0000000000 --- a/library/rexml/element/comments_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#comments" do - before :each do - @e = REXML::Element.new "root" - @c1 = REXML::Comment.new "this is a comment" - @c2 = REXML::Comment.new "this is another comment" - @e << @c1 - @e << @c2 - end - - it "returns the array of comments" do - @e.comments.should == [@c1, @c2] - end - - it "returns a frozen object" do - @e.comments.should.frozen? - end - end -end diff --git a/library/rexml/element/delete_attribute_spec.rb b/library/rexml/element/delete_attribute_spec.rb deleted file mode 100644 index e2ba81eb0d..0000000000 --- a/library/rexml/element/delete_attribute_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#delete_attribute" do - before :each do - @e = REXML::Element.new("Person") - @attr = REXML::Attribute.new("name", "Sean") - @e.add_attribute(@attr) - end - - it "deletes an attribute from the element" do - @e.delete_attribute("name") - @e.attributes["name"].should be_nil - end - - # Bug was filled with a patch in Ruby's tracker #20298 - quarantine! do - it "receives an Attribute" do - @e.add_attribute(@attr) - @e.delete_attribute(@attr) - @e.attributes["name"].should be_nil - end - end - - # Docs say that it returns the removed attribute but then examples - # show it returns the element with the attribute removed. - # Also fixed in #20298 - it "returns the element with the attribute removed" do - elem = @e.delete_attribute("name") - elem.attributes.should be_empty - elem.to_s.should eql("") - end - - it "returns nil if the attribute does not exist" do - @e.delete_attribute("name") - at = @e.delete_attribute("name") - at.should be_nil - end - end -end diff --git a/library/rexml/element/delete_element_spec.rb b/library/rexml/element/delete_element_spec.rb deleted file mode 100644 index c0b486a6f7..0000000000 --- a/library/rexml/element/delete_element_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#delete_element" do - before :each do - @root = REXML::Element.new("root") - end - - it "deletes the child element" do - node = REXML::Element.new("some_node") - @root.add_element node - @root.delete_element node - @root.elements.size.should == 0 - end - - it "deletes a child via XPath" do - @root.add_element "some_node" - @root.delete_element "some_node" - @root.elements.size.should == 0 - end - - it "deletes the child at index" do - @root.add_element "some_node" - @root.delete_element 1 - @root.elements.size.should == 0 - end - - # According to the docs this should return the deleted element - # but it won't if it's an Element. - it "deletes Element and returns it" do - node = REXML::Element.new("some_node") - @root.add_element node - del_node = @root.delete_element node - del_node.should == node - end - - # Note how passing the string will return the removed element - # but passing the Element as above won't. - it "deletes an element and returns it" do - node = REXML::Element.new("some_node") - @root.add_element node - del_node = @root.delete_element "some_node" - del_node.should == node - end - - it "returns nil unless element exists" do - @root.delete_element("something").should == nil - end - end -end diff --git a/library/rexml/element/delete_namespace_spec.rb b/library/rexml/element/delete_namespace_spec.rb deleted file mode 100644 index a7763d51e8..0000000000 --- a/library/rexml/element/delete_namespace_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#delete_namespace" do - - before :each do - @doc = REXML::Document.new "" - end - - it "deletes a namespace from the element" do - @doc.root.delete_namespace 'foo' - @doc.root.namespace("foo").should be_nil - @doc.root.to_s.should == "" - end - - it "deletes default namespace when called with no args" do - @doc.root.delete_namespace - @doc.root.namespace.should be_empty - @doc.root.to_s.should == "" - end - - it "returns the element" do - @doc.root.delete_namespace.should == @doc.root - end - end -end diff --git a/library/rexml/element/document_spec.rb b/library/rexml/element/document_spec.rb deleted file mode 100644 index 754f27d8a0..0000000000 --- a/library/rexml/element/document_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#document" do - - it "returns the element's document" do - d = REXML::Document.new("") - d << REXML::XMLDecl.new - d.root.document.should == d - d.root.document.to_s.should == d.to_s - end - - it "returns nil if it belongs to no document" do - REXML::Element.new("standalone").document.should be_nil - end - end -end diff --git a/library/rexml/element/each_element_with_attribute_spec.rb b/library/rexml/element/each_element_with_attribute_spec.rb deleted file mode 100644 index dcc6dbbf17..0000000000 --- a/library/rexml/element/each_element_with_attribute_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#each_element_with_attributes" do - before :each do - @document = REXML::Element.new("people") - @father = REXML::Element.new("Person") - @father.attributes["name"] = "Joe" - @son = REXML::Element.new("Child") - @son.attributes["name"] = "Fred" - @document.root << @father - @document.root << @son - @children = [] - end - - it "returns children with attribute" do - @document.each_element_with_attribute("name") { |elem| @children << elem } - @children[0].should == @father - @children[1].should == @son - end - - it "takes attribute value as second argument" do - @document.each_element_with_attribute("name", "Fred"){ |elem| elem.should == @son } - end - - it "takes max number of children as third argument" do - @document.each_element_with_attribute("name", nil, 1) { |elem| @children << elem } - @children.size.should == 1 - @children[0].should == @father - end - - it "takes XPath filter as fourth argument" do - @document.each_element_with_attribute("name", nil, 0, "Child"){ |elem| elem.should == @son} - end - end -end diff --git a/library/rexml/element/each_element_with_text_spec.rb b/library/rexml/element/each_element_with_text_spec.rb deleted file mode 100644 index a4a200d237..0000000000 --- a/library/rexml/element/each_element_with_text_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#each_element_with_text" do - before :each do - @document = REXML::Element.new("people") - - @joe = REXML::Element.new("Person") - @joe.text = "Joe" - @fred = REXML::Element.new("Person") - @fred.text = "Fred" - @another = REXML::Element.new("AnotherPerson") - @another.text = "Fred" - @document.root << @joe - @document.root << @fred - @document.root << @another - @children = [] - end - - it "returns children with text" do - @document.each_element_with_text("Joe"){|c| c.should == @joe} - end - - it "takes max as second argument" do - @document.each_element_with_text("Fred", 1){ |c| c.should == @fred} - end - - it "takes XPath filter as third argument" do - @document.each_element_with_text("Fred", 0, "Person"){ |c| c.should == @fred} - end - end -end diff --git a/library/rexml/element/element_reference_spec.rb b/library/rexml/element/element_reference_spec.rb deleted file mode 100644 index 9e5d371ce4..0000000000 --- a/library/rexml/element/element_reference_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#[]" do - - before :each do - @doc = REXML::Document.new("") - @child = REXML::Element.new("child") - @doc.root.add_element @child - end - - it "return attribute value if argument is string or symbol" do - @doc.root[:foo].should == 'bar' - @doc.root['foo'].should == 'bar' - end - - it "return nth element if argument is int" do - @doc.root[0].should == @child - end - end -end diff --git a/library/rexml/element/get_text_spec.rb b/library/rexml/element/get_text_spec.rb deleted file mode 100644 index 0fa8d7cb3f..0000000000 --- a/library/rexml/element/get_text_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#get_text" do - before :each do - @doc = REXML::Document.new "

some textthis is bold! more text

" - end - - it "returns the first text child node" do - @doc.root.get_text.value.should == "some text" - @doc.root.get_text.should be_kind_of(REXML::Text) - end - - it "returns text from an element matching path" do - @doc.root.get_text("b").value.should == "this is bold!" - @doc.root.get_text("b").should be_kind_of(REXML::Text) - end - end -end diff --git a/library/rexml/element/has_attributes_spec.rb b/library/rexml/element/has_attributes_spec.rb deleted file mode 100644 index af3ce8ce1b..0000000000 --- a/library/rexml/element/has_attributes_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#has_attributes?" do - before :each do - @e = REXML::Element.new("test_elem") - end - - it "returns true when element has any attributes" do - @e.add_attribute("name", "Joe") - @e.has_attributes?.should be_true - end - - it "returns false if element has no attributes" do - @e.has_attributes?.should be_false - end - end -end diff --git a/library/rexml/element/has_elements_spec.rb b/library/rexml/element/has_elements_spec.rb deleted file mode 100644 index 04c7fe01a5..0000000000 --- a/library/rexml/element/has_elements_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#has_elements?" do - before :each do - @e = REXML::Element.new("root") - end - - it "returns true if element has child elements" do - child = REXML::Element.new("child") - @e << child - @e.has_elements?.should be_true - end - - it "returns false if element doesn't have child elements" do - @e.has_elements?.should be_false - end - end -end diff --git a/library/rexml/element/has_text_spec.rb b/library/rexml/element/has_text_spec.rb deleted file mode 100644 index 206c167ae6..0000000000 --- a/library/rexml/element/has_text_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#has_text?" do - - it "returns true if element has a Text child" do - e = REXML::Element.new("Person") - e.text = "My text" - e.has_text?.should be_true - end - - it "returns false if it has no Text children" do - e = REXML::Element.new("Person") - e.has_text?.should be_false - end - end -end diff --git a/library/rexml/element/inspect_spec.rb b/library/rexml/element/inspect_spec.rb deleted file mode 100644 index ec16c136ee..0000000000 --- a/library/rexml/element/inspect_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#inspect" do - - before :each do - @name = REXML::Element.new "name" - end - - it "returns the node as a string" do - @name.inspect.should == "" - end - - it "inserts '...' if the node has children" do - e = REXML::Element.new "last_name" - @name << e - @name.inspect.should == " ... " - # This might make more sense but differs from MRI's default behavior - # @name.inspect.should == " ... " - end - - it "inserts the attributes in the string" do - @name.add_attribute "language" - @name.attributes["language"] = "english" - @name.inspect.should == "" - end - end -end diff --git a/library/rexml/element/instructions_spec.rb b/library/rexml/element/instructions_spec.rb deleted file mode 100644 index 11f1396df0..0000000000 --- a/library/rexml/element/instructions_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#instructions" do - before :each do - @elem = REXML::Element.new("root") - end - it "returns the Instruction children nodes" do - inst = REXML::Instruction.new("xml-stylesheet", "href='headlines.css'") - @elem << inst - @elem.instructions.first.should == inst - end - - it "returns an empty array if it has no Instruction children" do - @elem.instructions.should be_empty - end - - it "freezes the returned array" do - @elem.instructions.frozen?.should be_true - end - end -end diff --git a/library/rexml/element/namespace_spec.rb b/library/rexml/element/namespace_spec.rb deleted file mode 100644 index 28966289c5..0000000000 --- a/library/rexml/element/namespace_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#namespace" do - before :each do - @doc = REXML::Document.new("
") - @elem = @doc.elements["//b"] - end - - it "returns the default namespace" do - @elem.namespace.should == "1" - end - - it "accepts a namespace prefix" do - @elem.namespace("y").should == "2" - @doc.elements["//c"].namespace("z").should == "3" - end - - it "returns an empty String if default namespace is not defined" do - e = REXML::Document.new("") - e.root.namespace.should be_empty - end - - it "returns nil if namespace is not defined" do - @elem.namespace("z").should be_nil - end - end -end diff --git a/library/rexml/element/namespaces_spec.rb b/library/rexml/element/namespaces_spec.rb deleted file mode 100644 index 4544540173..0000000000 --- a/library/rexml/element/namespaces_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#namespaces" do - before :each do - doc = REXML::Document.new("") - @elem = doc.elements["//c"] - end - - it "returns a hash of the namespaces" do - ns = {"y"=>"2", "z"=>"3", "xmlns"=>"1"} - @elem.namespaces.keys.sort.should == ns.keys.sort - @elem.namespaces.values.sort.should == ns.values.sort - end - - it "returns an empty hash if no namespaces exist" do - e = REXML::Element.new "element" - e.namespaces.kind_of?(Hash).should == true - e.namespaces.should be_empty - end - - it "uses namespace prefixes as keys" do - prefixes = ["y", "z", "xmlns"] - @elem.namespaces.keys.sort.should == prefixes.sort - end - - it "uses namespace values as the hash values" do - values = ["2", "3", "1"] - @elem.namespaces.values.sort.should == values.sort - end - - end -end diff --git a/library/rexml/element/new_spec.rb b/library/rexml/element/new_spec.rb deleted file mode 100644 index c6ab289476..0000000000 --- a/library/rexml/element/new_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#new" do - - it "creates element from tag name" do - REXML::Element.new("foo").name.should == "foo" - end - - it "creates element with default attributes" do - e = REXML::Element.new - e.name.should == REXML::Element::UNDEFINED - e.context.should == nil - e.parent.should == nil - end - - it "creates element from another element" do - e = REXML::Element.new "foo" - f = REXML::Element.new e - e.name.should == f.name - e.context.should == f.context - e.parent.should == f.parent - end - - it "takes parent as second argument" do - parent = REXML::Element.new "foo" - child = REXML::Element.new "bar", parent - child.parent.should == parent - end - - it "takes context as third argument" do - context = {"some_key" => "some_value"} - REXML::Element.new("foo", nil, context).context.should == context - end - end -end diff --git a/library/rexml/element/next_element_spec.rb b/library/rexml/element/next_element_spec.rb deleted file mode 100644 index 46d8f74760..0000000000 --- a/library/rexml/element/next_element_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#next_element" do - before :each do - @a = REXML::Element.new "a" - @b = REXML::Element.new "b" - @c = REXML::Element.new "c" - @a.root << @b - @a.root << @c - end - it "returns next existing element" do - @a.elements["b"].next_element.should == @c - end - - it "returns nil on last element" do - @a.elements["c"].next_element.should == nil - end - end -end diff --git a/library/rexml/element/node_type_spec.rb b/library/rexml/element/node_type_spec.rb deleted file mode 100644 index a39c2deca5..0000000000 --- a/library/rexml/element/node_type_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#node_type" do - it "returns :element" do - REXML::Element.new("MyElem").node_type.should == :element - end - end -end diff --git a/library/rexml/element/prefixes_spec.rb b/library/rexml/element/prefixes_spec.rb deleted file mode 100644 index ea4caab4bc..0000000000 --- a/library/rexml/element/prefixes_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#prefixes" do - before :each do - doc = REXML::Document.new("") - @elem = doc.elements["//c"] - end - - it "returns an array of the prefixes of the namespaces" do - @elem.prefixes.should == ["y", "z"] - end - - it "does not include the default namespace" do - @elem.prefixes.include?("xmlns").should == false - end - - it "returns an empty array if no namespace was defined" do - doc = REXML::Document.new "" - root = doc.elements["//root"] - root.prefixes.should == [] - end - end -end diff --git a/library/rexml/element/previous_element_spec.rb b/library/rexml/element/previous_element_spec.rb deleted file mode 100644 index a43b1ddd10..0000000000 --- a/library/rexml/element/previous_element_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#previous_element" do - before :each do - @a = REXML::Element.new "a" - @b = REXML::Element.new "b" - @c = REXML::Element.new "c" - @a.root << @b - @a.root << @c - end - - it "returns previous element" do - @a.elements["c"].previous_element.should == @b - end - - it "returns nil on first element" do - @a.elements["b"].previous_element.should == nil - end - end -end diff --git a/library/rexml/element/raw_spec.rb b/library/rexml/element/raw_spec.rb deleted file mode 100644 index 200a99d194..0000000000 --- a/library/rexml/element/raw_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#raw" do - it "returns true if raw mode is set to all" do - REXML::Element.new("MyElem", nil, {raw: :all}).raw.should == true - end - - it "returns true if raw mode is set to expanded_name" do - REXML::Element.new("MyElem", nil, {raw: "MyElem"}).raw.should == true - end - - it "returns false if raw mode is not set" do - REXML::Element.new("MyElem", nil, {raw: ""}).raw.should == false - end - - it "returns false if raw is not :all or expanded_name" do - REXML::Element.new("MyElem", nil, {raw: "Something"}).raw.should == false - end - - it "returns nil if context is not set" do - REXML::Element.new("MyElem").raw.should == nil - end - end -end diff --git a/library/rexml/element/root_spec.rb b/library/rexml/element/root_spec.rb deleted file mode 100644 index 52aa4571b9..0000000000 --- a/library/rexml/element/root_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#root" do - before :each do - @doc = REXML::Document.new - @root = REXML::Element.new "root" - @node = REXML::Element.new "node" - @doc << @root << @node - end - - it "returns first child on documents" do - @doc.root.should == @root - end - - it "returns self on root nodes" do - @root.root.should == @root - end - - it "returns parent's root on child nodes" do - @node.root.should == @root - end - - it "returns self on standalone nodes" do - e = REXML::Element.new "Elem" # Note that it doesn't have a parent node - e.root.should == e - end - end -end diff --git a/library/rexml/element/text_spec.rb b/library/rexml/element/text_spec.rb deleted file mode 100644 index 3234bba153..0000000000 --- a/library/rexml/element/text_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#text" do - before :each do - @e = REXML::Element.new "name" - @e.text = "John" - end - - it "returns the text node of element" do - @e.text.should == "John" - end - - it "returns the text node value" do - t = REXML::Text.new "Joe" - @e.text = t - @e.text.should == "Joe" - @e.text.should_not == t - end - - it "returns nil if no text is attached" do - elem = REXML::Element.new "name" - elem.text.should == nil - end - end - - describe "REXML::Element#text=" do - before :each do - @e = REXML::Element.new "name" - @e.text = "John" - end - - it "sets the text node" do - @e.to_s.should == "John" - end - - it "replaces existing text" do - @e.text = "Joe" - @e.to_s.should == "Joe" - end - - it "receives nil as an argument" do - @e.text = nil - @e.to_s.should == "" - end - end -end diff --git a/library/rexml/element/texts_spec.rb b/library/rexml/element/texts_spec.rb deleted file mode 100644 index 2d374d5e66..0000000000 --- a/library/rexml/element/texts_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#texts" do - - it "returns an array of the Text children" do - e = REXML::Element.new("root") - e.add_text "First" - e.add_text "Second" - e.texts.should == ["FirstSecond"] - end - - it "returns an empty array if it has no Text children" do - REXML::Element.new("root").texts.should == [] - end - end -end diff --git a/library/rexml/element/whitespace_spec.rb b/library/rexml/element/whitespace_spec.rb deleted file mode 100644 index f455067922..0000000000 --- a/library/rexml/element/whitespace_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Element#whitespace" do - it "returns true if whitespace is respected in the element" do - e = REXML::Element.new("root") - e.whitespace.should be_true - - e = REXML::Element.new("root", nil, respect_whitespace: :all) - e.whitespace.should be_true - - e = REXML::Element.new("root", nil, respect_whitespace: ["root"]) - e.whitespace.should be_true - end - - it "returns false if whitespace is ignored inside element" do - e = REXML::Element.new("root", nil, compress_whitespace: :all) - e.whitespace.should be_false - - e = REXML::Element.new("root", nil, compress_whitespace: ["root"]) - e.whitespace.should be_false - end - end -end diff --git a/library/rexml/node/each_recursive_spec.rb b/library/rexml/node/each_recursive_spec.rb deleted file mode 100644 index da347b1389..0000000000 --- a/library/rexml/node/each_recursive_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#each_recursive" do - before :each do - @doc = REXML::Document.new - @doc << REXML::XMLDecl.new - @root = REXML::Element.new "root" - @child1 = REXML::Element.new "child1" - @child2 = REXML::Element.new "child2" - @root << @child1 - @root << @child2 - @doc << @root - end - - it "visits all subnodes of self" do - nodes = [] - @doc.each_recursive { |node| nodes << node} - nodes.should == [@root, @child1, @child2] - end - end -end diff --git a/library/rexml/node/find_first_recursive_spec.rb b/library/rexml/node/find_first_recursive_spec.rb deleted file mode 100644 index 2a4f1097ae..0000000000 --- a/library/rexml/node/find_first_recursive_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#find_first_recursive" do - before :each do - @e = REXML::Element.new("root") - @node1 = REXML::Element.new("node") - @node2 = REXML::Element.new("another node") - @subnode = REXML::Element.new("another node") - @node1 << @subnode - @e << @node1 - @e << @node2 - end - - it "finds the first element that matches block" do - found = @e.find_first_recursive { |n| n.to_s == ""} - found.should == @node1 - end - - it "visits the nodes in preorder" do - found = @e.find_first_recursive { |n| n.to_s == ""} - found.should == @subnode - found.should_not == @node2 - end - end -end diff --git a/library/rexml/node/index_in_parent_spec.rb b/library/rexml/node/index_in_parent_spec.rb deleted file mode 100644 index 55909f86d6..0000000000 --- a/library/rexml/node/index_in_parent_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#index_in_parent" do - it "returns the index (starting from 1) of self in parent" do - e = REXML::Element.new("root") - node1 = REXML::Element.new("node") - node2 = REXML::Element.new("another node") - e << node1 - e << node2 - - node1.index_in_parent.should == 1 - node2.index_in_parent.should == 2 - end - end -end diff --git a/library/rexml/node/next_sibling_node_spec.rb b/library/rexml/node/next_sibling_node_spec.rb deleted file mode 100644 index 7aae861d75..0000000000 --- a/library/rexml/node/next_sibling_node_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#next_sibling_node" do - before :each do - @e = REXML::Element.new("root") - @node1 = REXML::Element.new("node") - @node2 = REXML::Element.new("another node") - @e << @node1 - @e << @node2 - end - - it "returns the next child node in parent" do - @node1.next_sibling_node.should == @node2 - end - - it "returns nil if there are no more child nodes next" do - @node2.next_sibling_node.should == nil - @e.next_sibling_node.should == nil - end - end -end diff --git a/library/rexml/node/parent_spec.rb b/library/rexml/node/parent_spec.rb deleted file mode 100644 index 43c3a747e0..0000000000 --- a/library/rexml/node/parent_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#parent?" do - it "returns true for Elements" do - e = REXML::Element.new("foo") - e.should.parent? - end - - it "returns true for Documents" do - e = REXML::Document.new - e.should.parent? - end - - # This includes attributes, CData and declarations. - it "returns false for Texts" do - e = REXML::Text.new("foo") - e.should_not.parent? - end - end -end diff --git a/library/rexml/node/previous_sibling_node_spec.rb b/library/rexml/node/previous_sibling_node_spec.rb deleted file mode 100644 index 11263968a7..0000000000 --- a/library/rexml/node/previous_sibling_node_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Node#previous_sibling_node" do - before :each do - @e = REXML::Element.new("root") - @node1 = REXML::Element.new("node") - @node2 = REXML::Element.new("another node") - @e << @node1 - @e << @node2 - end - - it "returns the previous child node in parent" do - @node2.previous_sibling_node.should == @node1 - end - - it "returns nil if there are no more child nodes before" do - @node1.previous_sibling_node.should == nil - @e.previous_sibling_node.should == nil - end - end -end diff --git a/library/rexml/text/append_spec.rb b/library/rexml/text/append_spec.rb deleted file mode 100644 index 5e7a5bae7c..0000000000 --- a/library/rexml/text/append_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#<<" do - it "appends a string to this text node" do - text = REXML::Text.new("foo") - text << "bar" - text.should == "foobar" - end - end -end diff --git a/library/rexml/text/clone_spec.rb b/library/rexml/text/clone_spec.rb deleted file mode 100644 index 7801782ff5..0000000000 --- a/library/rexml/text/clone_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#clone" do - it "creates a copy of this node" do - text = REXML::Text.new("foo") - text.clone.should == "foo" - text.clone.should == text - end - end -end diff --git a/library/rexml/text/comparison_spec.rb b/library/rexml/text/comparison_spec.rb deleted file mode 100644 index 119dd050a6..0000000000 --- a/library/rexml/text/comparison_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#<=>" do - before :each do - @first = REXML::Text.new("abc") - @last = REXML::Text.new("def") - end - - it "returns -1 if lvalue is less than rvalue" do - val = @first <=> @last - val.should == -1 - end - - it "returns -1 if lvalue is greater than rvalue" do - val = @last <=> @first - val.should == 1 - end - - it "returns 0 if both values are equal" do - tmp = REXML::Text.new("tmp") - val = tmp <=> tmp - val.should == 0 - end - end -end diff --git a/library/rexml/text/empty_spec.rb b/library/rexml/text/empty_spec.rb deleted file mode 100644 index 4c9c899bcb..0000000000 --- a/library/rexml/text/empty_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#empty?" do - it "returns true if the text is empty" do - REXML::Text.new("").should.empty? - end - - it "returns false if the text is not empty" do - REXML::Text.new("some_text").should_not.empty? - end - end -end diff --git a/library/rexml/text/indent_text_spec.rb b/library/rexml/text/indent_text_spec.rb deleted file mode 100644 index 73065c37da..0000000000 --- a/library/rexml/text/indent_text_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#indent_text" do - before :each do - @t = REXML::Text.new("") - end - it "indents a string with default parameters" do - @t.indent_text("foo").should == "\tfoo" - end - - it "accepts a custom indentation level as second argument" do - @t.indent_text("foo", 2, "\t", true).should == "\t\tfoo" - end - - it "accepts a custom separator as third argument" do - @t.indent_text("foo", 1, "\n", true).should == "\nfoo" - end - - it "accepts a fourth parameter to skip the first line" do - @t.indent_text("foo", 1, "\t", false).should == "foo" - end - end -end diff --git a/library/rexml/text/inspect_spec.rb b/library/rexml/text/inspect_spec.rb deleted file mode 100644 index af389890ee..0000000000 --- a/library/rexml/text/inspect_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#inspect" do - it "inspects the string attribute as a string" do - REXML::Text.new("a text").inspect.should == "a text".inspect - end - end -end diff --git a/library/rexml/text/new_spec.rb b/library/rexml/text/new_spec.rb deleted file mode 100644 index 8b33da9294..0000000000 --- a/library/rexml/text/new_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text.new" do - - it "creates a Text child node with no parent" do - t = REXML::Text.new("test") - t.should be_kind_of(REXML::Child) - t.should == "test" - t.parent.should == nil - end - - it "respects whitespace if second argument is true" do - t = REXML::Text.new("testing whitespace", true) - t.should == "testing whitespace" - t = REXML::Text.new(" ", true) - t.should == " " - end - - it "receives a parent as third argument" do - e = REXML::Element.new("root") - t = REXML::Text.new("test", false, e) - t.parent.should == e - e.to_s.should == "test" - end - - it "expects escaped text if raw is true" do - t = REXML::Text.new("<&>", false, nil, true) - t.should == "<&>" - - ->{ REXML::Text.new("<&>", false, nil, true)}.should raise_error(Exception) - end - - it "uses raw value of the parent if raw is nil" do - e1 = REXML::Element.new("root", nil, { raw: :all}) - -> {REXML::Text.new("<&>", false, e1)}.should raise_error(Exception) - - e2 = REXML::Element.new("root", nil, { raw: []}) - e2.raw.should be_false - t1 = REXML::Text.new("<&>", false, e2) - t1.should == "<&>" - end - - it "escapes the values if raw is false" do - t = REXML::Text.new("<&>", false, nil, false) - t.should == "<&>" - end - end -end diff --git a/library/rexml/text/node_type_spec.rb b/library/rexml/text/node_type_spec.rb deleted file mode 100644 index f44a1ede3e..0000000000 --- a/library/rexml/text/node_type_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#node_type" do - it "returns :text" do - REXML::Text.new("test").node_type.should == :text - end - end -end diff --git a/library/rexml/text/normalize_spec.rb b/library/rexml/text/normalize_spec.rb deleted file mode 100644 index cde11ec3c9..0000000000 --- a/library/rexml/text/normalize_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text.normalize" do - it "escapes a string with <, >, &, ' and \" " do - REXML::Text.normalize("< > & \" '").should == "< > & " '" - end - end -end diff --git a/library/rexml/text/read_with_substitution_spec.rb b/library/rexml/text/read_with_substitution_spec.rb deleted file mode 100644 index 7ff26f4d53..0000000000 --- a/library/rexml/text/read_with_substitution_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text.read_with_substitution" do - it "reads a text and escapes entities" do - REXML::Text.read_with_substitution("< > & " '").should == "< > & \" '" - end - - it "accepts an regex for invalid expressions and raises an error if text matches" do - -> {REXML::Text.read_with_substitution("this is illegal", /illegal/)}.should raise_error(Exception) - end - end -end diff --git a/library/rexml/text/to_s_spec.rb b/library/rexml/text/to_s_spec.rb deleted file mode 100644 index e67632c9a1..0000000000 --- a/library/rexml/text/to_s_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#to_s" do - it "returns the string of this Text node" do - u = REXML::Text.new("sean russell", false, nil, true) - u.to_s.should == "sean russell" - - t = REXML::Text.new("some test text") - t.to_s.should == "some test text" - end - - it "escapes the text" do - t = REXML::Text.new("& < >") - t.to_s.should == "& < >" - end - end -end diff --git a/library/rexml/text/unnormalize_spec.rb b/library/rexml/text/unnormalize_spec.rb deleted file mode 100644 index 7b507194d0..0000000000 --- a/library/rexml/text/unnormalize_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text.unnormalize" do - it "unescapes a string with the values defined in SETUTITSBUS" do - REXML::Text.unnormalize("< > & " '").should == "< > & \" '" - end - end -end diff --git a/library/rexml/text/value_spec.rb b/library/rexml/text/value_spec.rb deleted file mode 100644 index 53d40c765f..0000000000 --- a/library/rexml/text/value_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#value" do - it "returns the text value of this node" do - REXML::Text.new("test").value.should == "test" - end - - it "does not escape entities" do - REXML::Text.new("& \"").value.should == "& \"" - end - - it "follows the respect_whitespace attribute" do - REXML::Text.new("test bar", false).value.should == "test bar" - REXML::Text.new("test bar", true).value.should == "test bar" - end - - it "ignores the raw attribute" do - REXML::Text.new("sean russell", false, nil, true).value.should == "sean russell" - end - end - - describe "REXML::Text#value=" do - before :each do - @t = REXML::Text.new("new") - end - - it "sets the text of the node" do - @t.value = "another text" - @t.to_s.should == "another text" - end - - it "escapes entities" do - @t.value = "" - @t.to_s.should == "<a>" - end - end -end diff --git a/library/rexml/text/wrap_spec.rb b/library/rexml/text/wrap_spec.rb deleted file mode 100644 index 331a8439e2..0000000000 --- a/library/rexml/text/wrap_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#wrap" do - before :each do - @t = REXML::Text.new("abc def") - end - - it "wraps the text at width" do - @t.wrap("abc def", 3, false).should == "abc\ndef" - end - - it "returns the string if width is greater than the size of the string" do - @t.wrap("abc def", 10, false).should == "abc def" - end - - it "takes a newline at the beginning option as the third parameter" do - @t.wrap("abc def", 3, true).should == "\nabc\ndef" - end - end -end diff --git a/library/rexml/text/write_with_substitution_spec.rb b/library/rexml/text/write_with_substitution_spec.rb deleted file mode 100644 index 840f141e3d..0000000000 --- a/library/rexml/text/write_with_substitution_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Text#write_with_substitution" do - before :each do - @t = REXML::Text.new("test") - @f = tmp("rexml_spec") - @file = File.open(@f, "w+") - end - - after :each do - @file.close - rm_r @f - end - - it "writes out the input to a String" do - s = "" - @t.write_with_substitution(s, "some text") - s.should == "some text" - end - - it "writes out the input to an IO" do - @t.write_with_substitution(@file, "some text") - @file.rewind - @file.gets.should == "some text" - end - - it "escapes characters" do - @t.write_with_substitution(@file, "& < >") - @file.rewind - @file.gets.should == "& < >" - end - end -end diff --git a/library/set/comparison_spec.rb b/library/set/comparison_spec.rb index 6b7a71e659..ddcfbae0af 100644 --- a/library/set/comparison_spec.rb +++ b/library/set/comparison_spec.rb @@ -1,29 +1,27 @@ require_relative '../../spec_helper' require 'set' -ruby_version_is "3.0" do - describe "Set#<=>" do - it "returns 0 if the sets are equal" do - (Set[] <=> Set[]).should == 0 - (Set[:a, :b, :c] <=> Set[:a, :b, :c]).should == 0 - end +describe "Set#<=>" do + it "returns 0 if the sets are equal" do + (Set[] <=> Set[]).should == 0 + (Set[:a, :b, :c] <=> Set[:a, :b, :c]).should == 0 + end - it "returns -1 if the set is a proper subset of the other set" do - (Set[] <=> Set[1]).should == -1 - (Set[1, 2] <=> Set[1, 2, 3]).should == -1 - end + it "returns -1 if the set is a proper subset of the other set" do + (Set[] <=> Set[1]).should == -1 + (Set[1, 2] <=> Set[1, 2, 3]).should == -1 + end - it "returns +1 if the set is a proper superset of other set" do - (Set[1] <=> Set[]).should == +1 - (Set[1, 2, 3] <=> Set[1, 2]).should == +1 - end + it "returns +1 if the set is a proper superset of other set" do + (Set[1] <=> Set[]).should == +1 + (Set[1, 2, 3] <=> Set[1, 2]).should == +1 + end - it "returns nil if the set has unique elements" do - (Set[1, 2, 3] <=> Set[:a, :b, :c]).should be_nil - end + it "returns nil if the set has unique elements" do + (Set[1, 2, 3] <=> Set[:a, :b, :c]).should be_nil + end - it "returns nil when the argument is not set-like" do - (Set[] <=> false).should be_nil - end + it "returns nil when the argument is not set-like" do + (Set[] <=> false).should be_nil end end diff --git a/library/set/enumerable/to_set_spec.rb b/library/set/enumerable/to_set_spec.rb index 3790d8deee..b2d850515b 100644 --- a/library/set/enumerable/to_set_spec.rb +++ b/library/set/enumerable/to_set_spec.rb @@ -7,14 +7,6 @@ {a: 1, b: 2}.to_set.should == Set[[:b, 2], [:a, 1]] end - ruby_version_is ''...'3.0' do - it "allows passing an alternate class for Set" do - sorted_set = [1, 2, 3].to_set(SortedSet) - sorted_set.should == SortedSet[1, 2, 3] - sorted_set.instance_of?(SortedSet).should == true - end - end - it "passes down passed blocks" do [1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9] end diff --git a/library/set/initialize_clone_spec.rb b/library/set/initialize_clone_spec.rb index 62985987fa..bda42cd6e8 100644 --- a/library/set/initialize_clone_spec.rb +++ b/library/set/initialize_clone_spec.rb @@ -2,17 +2,15 @@ require 'set' describe "Set#initialize_clone" do - ruby_version_is "3.0" do - # See https://bugs.ruby-lang.org/issues/14266 - it "does not freeze the new Set when called from clone(freeze: false)" do - set1 = Set[1, 2] - set1.freeze - set2 = set1.clone(freeze: false) - set1.frozen?.should == true - set2.frozen?.should == false - set2.add 3 - set1.should == Set[1, 2] - set2.should == Set[1, 2, 3] - end + # See https://bugs.ruby-lang.org/issues/14266 + it "does not freeze the new Set when called from clone(freeze: false)" do + set1 = Set[1, 2] + set1.freeze + set2 = set1.clone(freeze: false) + set1.frozen?.should == true + set2.frozen?.should == false + set2.add 3 + set1.should == Set[1, 2] + set2.should == Set[1, 2, 3] end end diff --git a/library/set/join_spec.rb b/library/set/join_spec.rb index 7498a91d98..3f511a84e4 100644 --- a/library/set/join_spec.rb +++ b/library/set/join_spec.rb @@ -1,31 +1,29 @@ require_relative '../../spec_helper' require 'set' -ruby_version_is "3.0" do - describe "Set#join" do - it "returns an empty string if the Set is empty" do - Set[].join.should == '' - end +describe "Set#join" do + it "returns an empty string if the Set is empty" do + Set[].join.should == '' + end - it "returns a new string formed by joining elements after conversion" do - set = Set[:a, :b, :c] - set.join.should == "abc" - end + it "returns a new string formed by joining elements after conversion" do + set = Set[:a, :b, :c] + set.join.should == "abc" + end - it "does not separate elements when the passed separator is nil" do - set = Set[:a, :b, :c] - set.join(nil).should == "abc" - end + it "does not separate elements when the passed separator is nil" do + set = Set[:a, :b, :c] + set.join(nil).should == "abc" + end - it "returns a string formed by concatenating each element separated by the separator" do - set = Set[:a, :b, :c] - set.join(' | ').should == "a | b | c" - end + it "returns a string formed by concatenating each element separated by the separator" do + set = Set[:a, :b, :c] + set.join(' | ').should == "a | b | c" + end - it "calls #to_a to convert the Set in to an Array" do - set = Set[:a, :b, :c] - set.should_receive(:to_a).and_return([:a, :b, :c]) - set.join.should == "abc" - end + it "calls #to_a to convert the Set in to an Array" do + set = Set[:a, :b, :c] + set.should_receive(:to_a).and_return([:a, :b, :c]) + set.join.should == "abc" end end diff --git a/library/set/sortedset/add_spec.rb b/library/set/sortedset/add_spec.rb deleted file mode 100644 index 4f3bb252e1..0000000000 --- a/library/set/sortedset/add_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/add' - - describe "SortedSet#add" do - it_behaves_like :sorted_set_add, :add - - it "takes only values which responds <=>" do - obj = mock('no_comparison_operator') - obj.stub!(:respond_to?).with(:<=>).and_return(false) - -> { SortedSet["hello"].add(obj) }.should raise_error(ArgumentError) - end - - it "raises on incompatible <=> comparison" do - # Use #to_a here as elements are sorted only when needed. - # Therefore the <=> incompatibility is only noticed on sorting. - -> { SortedSet['1', '2'].add(3).to_a }.should raise_error(ArgumentError) - end - end - - describe "SortedSet#add?" do - before :each do - @set = SortedSet.new - end - - it "adds the passed Object to self" do - @set.add?("cat") - @set.should include("cat") - end - - it "returns self when the Object has not yet been added to self" do - @set.add?("cat").should equal(@set) - end - - it "returns nil when the Object has already been added to self" do - @set.add?("cat") - @set.add?("cat").should be_nil - end - end -end diff --git a/library/set/sortedset/append_spec.rb b/library/set/sortedset/append_spec.rb deleted file mode 100644 index d72d70b21f..0000000000 --- a/library/set/sortedset/append_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/add' - - describe "SortedSet#<<" do - it_behaves_like :sorted_set_add, :<< - end -end diff --git a/library/set/sortedset/case_equality_spec.rb b/library/set/sortedset/case_equality_spec.rb deleted file mode 100644 index d7c296b626..0000000000 --- a/library/set/sortedset/case_equality_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/include' - require 'set' - - describe "SortedSet#===" do - it_behaves_like :sorted_set_include, :=== - end -end diff --git a/library/set/sortedset/classify_spec.rb b/library/set/sortedset/classify_spec.rb deleted file mode 100644 index 4011e58b82..0000000000 --- a/library/set/sortedset/classify_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#classify" do - before :each do - @set = SortedSet["one", "two", "three", "four"] - end - - it "yields each Object in self in sorted order" do - res = [] - @set.classify { |x| res << x } - res.should == ["one", "two", "three", "four"].sort - end - - it "returns an Enumerator when passed no block" do - enum = @set.classify - enum.should be_an_instance_of(Enumerator) - - classified = enum.each { |x| x.length } - classified.should == { 3 => SortedSet["one", "two"], 4 => SortedSet["four"], 5 => SortedSet["three"] } - end - - it "classifies the Objects in self based on the block's return value" do - classified = @set.classify { |x| x.length } - classified.should == { 3 => SortedSet["one", "two"], 4 => SortedSet["four"], 5 => SortedSet["three"] } - end - end -end diff --git a/library/set/sortedset/clear_spec.rb b/library/set/sortedset/clear_spec.rb deleted file mode 100644 index 879aa824d8..0000000000 --- a/library/set/sortedset/clear_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#clear" do - before :each do - @set = SortedSet["one", "two", "three", "four"] - end - - it "removes all elements from self" do - @set.clear - @set.should be_empty - end - - it "returns self" do - @set.clear.should equal(@set) - end - end -end diff --git a/library/set/sortedset/collect_spec.rb b/library/set/sortedset/collect_spec.rb deleted file mode 100644 index 0674f0d130..0000000000 --- a/library/set/sortedset/collect_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/collect' - - describe "SortedSet#collect!" do - it_behaves_like :sorted_set_collect_bang, :collect! - end -end diff --git a/library/set/sortedset/constructor_spec.rb b/library/set/sortedset/constructor_spec.rb deleted file mode 100644 index 31f30fd892..0000000000 --- a/library/set/sortedset/constructor_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet[]" do - it "returns a new SortedSet populated with the passed Objects" do - set = SortedSet[1, 2, 3] - - set.instance_of?(SortedSet).should be_true - set.size.should eql(3) - - set.should include(1) - set.should include(2) - set.should include(3) - end - end -end diff --git a/library/set/sortedset/delete_if_spec.rb b/library/set/sortedset/delete_if_spec.rb deleted file mode 100644 index 787639ae12..0000000000 --- a/library/set/sortedset/delete_if_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#delete_if" do - before :each do - @set = SortedSet["one", "two", "three"] - end - - it "yields each Object in self in sorted order" do - ret = [] - @set.delete_if { |x| ret << x } - ret.should == ["one", "two", "three"].sort - end - - it "deletes every element from self for which the passed block returns true" do - @set.delete_if { |x| x.size == 3 } - @set.size.should eql(1) - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - - it "returns self" do - @set.delete_if { |x| x }.should equal(@set) - end - - it "returns an Enumerator when passed no block" do - enum = @set.delete_if - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size == 3 } - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - end -end diff --git a/library/set/sortedset/delete_spec.rb b/library/set/sortedset/delete_spec.rb deleted file mode 100644 index 0e2a6accf3..0000000000 --- a/library/set/sortedset/delete_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#delete" do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "deletes the passed Object from self" do - @set.delete("a") - @set.should_not include("a") - end - - it "returns self" do - @set.delete("a").should equal(@set) - @set.delete("x").should equal(@set) - end - end - - describe "SortedSet#delete?" do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "deletes the passed Object from self" do - @set.delete?("a") - @set.should_not include("a") - end - - it "returns self when the passed Object is in self" do - @set.delete?("a").should equal(@set) - end - - it "returns nil when the passed Object is not in self" do - @set.delete?("x").should be_nil - end - end -end diff --git a/library/set/sortedset/difference_spec.rb b/library/set/sortedset/difference_spec.rb deleted file mode 100644 index fb064bdff9..0000000000 --- a/library/set/sortedset/difference_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/difference' - - describe "SortedSet#difference" do - it_behaves_like :sorted_set_difference, :difference - end -end diff --git a/library/set/sortedset/divide_spec.rb b/library/set/sortedset/divide_spec.rb deleted file mode 100644 index 31ab6037e4..0000000000 --- a/library/set/sortedset/divide_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#divide" do - it "divides self into a set of subsets based on the blocks return values" do - set = SortedSet["one", "two", "three", "four", "five"].divide { |x| x.length } - set.map { |x| x.to_a }.to_a.sort.should == [["five", "four"], ["one", "two"], ["three"]] - end - - it "yields each Object in self in sorted order" do - ret = [] - SortedSet["one", "two", "three", "four", "five"].divide { |x| ret << x } - ret.should == ["one", "two", "three", "four", "five"].sort - end - - # BUG: Does not raise a LocalJumpError, but a NoMethodError - # - # it "raises a LocalJumpError when not passed a block" do - # lambda { SortedSet[1].divide }.should raise_error(LocalJumpError) - # end - end - - describe "SortedSet#divide when passed a block with an arity of 2" do - it "divides self into a set of subsets based on the blocks return values" do - set = SortedSet[1, 3, 4, 6, 9, 10, 11].divide { |x, y| (x - y).abs == 1 } - set.map { |x| x.to_a }.to_a.sort.should == [[1], [3, 4], [6], [9, 10, 11]] - end - - it "yields each two Objects to the block" do - ret = [] - SortedSet[1, 2].divide { |x, y| ret << [x, y] } - ret.should == [[1, 1], [1, 2], [2, 1], [2, 2]] - end - end -end diff --git a/library/set/sortedset/each_spec.rb b/library/set/sortedset/each_spec.rb deleted file mode 100644 index 79d8aee223..0000000000 --- a/library/set/sortedset/each_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#each" do - before :each do - @set = SortedSet[1, 2, 3] - end - - it "yields each Object in self in sorted order" do - ret = [] - SortedSet["one", "two", "three"].each { |x| ret << x } - ret.should == ["one", "two", "three"].sort - end - - it "returns self" do - @set.each { |x| x }.should equal(@set) - end - - it "returns an Enumerator when not passed a block" do - enum = @set.each - - ret = [] - enum.each { |x| ret << x } - ret.sort.should == [1, 2, 3] - end - end -end diff --git a/library/set/sortedset/empty_spec.rb b/library/set/sortedset/empty_spec.rb deleted file mode 100644 index 2e52c3e81a..0000000000 --- a/library/set/sortedset/empty_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#empty?" do - it "returns true if self is empty" do - SortedSet[].empty?.should be_true - SortedSet[1].empty?.should be_false - SortedSet[1,2,3].empty?.should be_false - end - end -end diff --git a/library/set/sortedset/eql_spec.rb b/library/set/sortedset/eql_spec.rb deleted file mode 100644 index 050464994b..0000000000 --- a/library/set/sortedset/eql_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#eql?" do - it "returns true when the passed argument is a SortedSet and contains the same elements" do - SortedSet[].should eql(SortedSet[]) - SortedSet[1, 2, 3].should eql(SortedSet[1, 2, 3]) - SortedSet[1, 2, 3].should eql(SortedSet[3, 2, 1]) - - # SortedSet["a", :b, ?c].should eql(SortedSet[?c, :b, "a"]) - - SortedSet[1, 2, 3].should_not eql(SortedSet[1.0, 2, 3]) - SortedSet[1, 2, 3].should_not eql(SortedSet[2, 3]) - SortedSet[1, 2, 3].should_not eql(SortedSet[]) - end - end -end diff --git a/library/set/sortedset/equal_value_spec.rb b/library/set/sortedset/equal_value_spec.rb deleted file mode 100644 index 30422f5b95..0000000000 --- a/library/set/sortedset/equal_value_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#==" do - it "returns true when the passed Object is a SortedSet and self and the Object contain the same elements" do - SortedSet[].should == SortedSet[] - SortedSet[1, 2, 3].should == SortedSet[1, 2, 3] - SortedSet["1", "2", "3"].should == SortedSet["1", "2", "3"] - - SortedSet[1, 2, 3].should_not == SortedSet[1.0, 2, 3] - SortedSet[1, 2, 3].should_not == [1, 2, 3] - end - end -end diff --git a/library/set/sortedset/exclusion_spec.rb b/library/set/sortedset/exclusion_spec.rb deleted file mode 100644 index 1967dfbfa6..0000000000 --- a/library/set/sortedset/exclusion_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#^" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns a new SortedSet containing elements that are not in both self and the passed Enumerable" do - (@set ^ SortedSet[3, 4, 5]).should == SortedSet[1, 2, 5] - (@set ^ [3, 4, 5]).should == SortedSet[1, 2, 5] - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { @set ^ 3 }.should raise_error(ArgumentError) - -> { @set ^ Object.new }.should raise_error(ArgumentError) - end - end -end diff --git a/library/set/sortedset/filter_spec.rb b/library/set/sortedset/filter_spec.rb deleted file mode 100644 index 3b9dcb63c9..0000000000 --- a/library/set/sortedset/filter_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/select' - require 'set' - - describe "SortedSet#filter!" do - it_behaves_like :sorted_set_select_bang, :filter! - end -end diff --git a/library/set/sortedset/flatten_merge_spec.rb b/library/set/sortedset/flatten_merge_spec.rb deleted file mode 100644 index 0d67cb331e..0000000000 --- a/library/set/sortedset/flatten_merge_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#flatten_merge" do - it "is protected" do - SortedSet.should have_protected_instance_method("flatten_merge") - end - end -end diff --git a/library/set/sortedset/flatten_spec.rb b/library/set/sortedset/flatten_spec.rb deleted file mode 100644 index e83ad1044a..0000000000 --- a/library/set/sortedset/flatten_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - # Note: Flatten make little sens on sorted sets, because SortedSets are not (by default) - # comparable. For a SortedSet to be both valid and nested, we need to define a comparison operator: - module SortedSet_FlattenSpecs - class ComparableSortedSet < SortedSet - def <=>(other) - return puts "#{other} vs #{self}" unless other.is_a?(ComparableSortedSet) - to_a <=> other.to_a - end - end - end - - describe "SortedSet#flatten" do - it "returns a copy of self with each included SortedSet flattened" do - klass = SortedSet_FlattenSpecs::ComparableSortedSet - set = klass[klass[1,2], klass[3,4], klass[5,6,7], klass[8]] - flattened_set = set.flatten - - flattened_set.should_not equal(set) - flattened_set.should == klass[1, 2, 3, 4, 5, 6, 7, 8] - end - end - - describe "SortedSet#flatten!" do - it "flattens self" do - klass = SortedSet_FlattenSpecs::ComparableSortedSet - set = klass[klass[1,2], klass[3,4], klass[5,6,7], klass[8]] - set.flatten! - set.should == klass[1, 2, 3, 4, 5, 6, 7, 8] - end - - it "returns self when self was modified" do - klass = SortedSet_FlattenSpecs::ComparableSortedSet - set = klass[klass[1,2], klass[3,4]] - set.flatten!.should equal(set) - end - - it "returns nil when self was not modified" do - set = SortedSet[1, 2, 3, 4] - set.flatten!.should be_nil - end - end -end diff --git a/library/set/sortedset/hash_spec.rb b/library/set/sortedset/hash_spec.rb deleted file mode 100644 index 40676de7fc..0000000000 --- a/library/set/sortedset/hash_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#hash" do - it "is static" do - SortedSet[].hash.should == SortedSet[].hash - SortedSet[1, 2, 3].hash.should == SortedSet[1, 2, 3].hash - SortedSet["a", "b", "c"].hash.should == SortedSet["c", "b", "a"].hash - - SortedSet[].hash.should_not == SortedSet[1, 2, 3].hash - SortedSet[1, 2, 3].hash.should_not == SortedSet["a", "b", "c"].hash - end - end -end diff --git a/library/set/sortedset/include_spec.rb b/library/set/sortedset/include_spec.rb deleted file mode 100644 index ec2ad987d5..0000000000 --- a/library/set/sortedset/include_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/include' - require 'set' - - describe "SortedSet#include?" do - it_behaves_like :sorted_set_include, :include? - end -end diff --git a/library/set/sortedset/initialize_spec.rb b/library/set/sortedset/initialize_spec.rb deleted file mode 100644 index 4d1707b72a..0000000000 --- a/library/set/sortedset/initialize_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#initialize" do - it "is private" do - SortedSet.should have_private_instance_method("initialize") - end - - it "adds all elements of the passed Enumerable to self" do - s = SortedSet.new([1, 2, 3]) - s.size.should eql(3) - s.should include(1) - s.should include(2) - s.should include(3) - end - - it "preprocesses all elements by a passed block before adding to self" do - s = SortedSet.new([1, 2, 3]) { |x| x * x } - s.size.should eql(3) - s.should include(1) - s.should include(4) - s.should include(9) - end - - it "raises on incompatible <=> comparison" do - # Use #to_a here as elements are sorted only when needed. - # Therefore the <=> incompatibility is only noticed on sorting. - -> { SortedSet.new(['00', nil]).to_a }.should raise_error(ArgumentError) - end - end -end diff --git a/library/set/sortedset/inspect_spec.rb b/library/set/sortedset/inspect_spec.rb deleted file mode 100644 index 1c4dd9e6e2..0000000000 --- a/library/set/sortedset/inspect_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#inspect" do - it "returns a String representation of self" do - SortedSet[].inspect.should be_kind_of(String) - SortedSet[1, 2, 3].inspect.should be_kind_of(String) - SortedSet["1", "2", "3"].inspect.should be_kind_of(String) - end - end -end diff --git a/library/set/sortedset/intersection_spec.rb b/library/set/sortedset/intersection_spec.rb deleted file mode 100644 index 6daa271b73..0000000000 --- a/library/set/sortedset/intersection_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/intersection' - require 'set' - - describe "SortedSet#intersection" do - it_behaves_like :sorted_set_intersection, :intersection - end - - describe "SortedSet#&" do - it_behaves_like :sorted_set_intersection, :& - end -end diff --git a/library/set/sortedset/keep_if_spec.rb b/library/set/sortedset/keep_if_spec.rb deleted file mode 100644 index 3e5f3bbc47..0000000000 --- a/library/set/sortedset/keep_if_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#keep_if" do - before :each do - @set = SortedSet["one", "two", "three"] - end - - it "yields each Object in self in sorted order" do - ret = [] - @set.keep_if { |x| ret << x } - ret.should == ["one", "two", "three"].sort - end - - it "keeps every element from self for which the passed block returns true" do - @set.keep_if { |x| x.size != 3 } - @set.to_a.should == ["three"] - end - - it "returns self" do - @set.keep_if {}.should equal(@set) - end - - it "returns an Enumerator when passed no block" do - enum = @set.keep_if - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size != 3 } - @set.to_a.should == ["three"] - end - end -end diff --git a/library/set/sortedset/length_spec.rb b/library/set/sortedset/length_spec.rb deleted file mode 100644 index de6791f6bb..0000000000 --- a/library/set/sortedset/length_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/length' - require 'set' - - describe "SortedSet#length" do - it_behaves_like :sorted_set_length, :length - end -end diff --git a/library/set/sortedset/map_spec.rb b/library/set/sortedset/map_spec.rb deleted file mode 100644 index 4971b9529b..0000000000 --- a/library/set/sortedset/map_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/collect' - - describe "SortedSet#map!" do - it_behaves_like :sorted_set_collect_bang, :map! - end -end diff --git a/library/set/sortedset/member_spec.rb b/library/set/sortedset/member_spec.rb deleted file mode 100644 index 142b09b651..0000000000 --- a/library/set/sortedset/member_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/include' - require 'set' - - describe "SortedSet#member?" do - it_behaves_like :sorted_set_include, :member? - end -end diff --git a/library/set/sortedset/merge_spec.rb b/library/set/sortedset/merge_spec.rb deleted file mode 100644 index c4cbc6d2b4..0000000000 --- a/library/set/sortedset/merge_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#merge" do - it "adds the elements of the passed Enumerable to self" do - SortedSet["a", "b"].merge(SortedSet["b", "c", "d"]).should == SortedSet["a", "b", "c", "d"] - SortedSet[1, 2].merge([3, 4]).should == SortedSet[1, 2, 3, 4] - end - - it "returns self" do - set = SortedSet[1, 2] - set.merge([3, 4]).should equal(set) - end - - it "raises an ArgumentError when passed a non-Enumerable" do - -> { SortedSet[1, 2].merge(1) }.should raise_error(ArgumentError) - -> { SortedSet[1, 2].merge(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/library/set/sortedset/minus_spec.rb b/library/set/sortedset/minus_spec.rb deleted file mode 100644 index d6abc5e204..0000000000 --- a/library/set/sortedset/minus_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - require_relative 'shared/difference' - - describe "SortedSet#-" do - it_behaves_like :sorted_set_difference, :- - end -end diff --git a/library/set/sortedset/plus_spec.rb b/library/set/sortedset/plus_spec.rb deleted file mode 100644 index 13fc873ad1..0000000000 --- a/library/set/sortedset/plus_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/union' - require 'set' - - describe "SortedSet#+" do - it_behaves_like :sorted_set_union, :+ - end -end diff --git a/library/set/sortedset/pretty_print_cycle_spec.rb b/library/set/sortedset/pretty_print_cycle_spec.rb deleted file mode 100644 index e97f509406..0000000000 --- a/library/set/sortedset/pretty_print_cycle_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#pretty_print_cycle" do - it "passes the 'pretty print' representation of a self-referencing SortedSet to the pretty print writer" do - pp = mock("PrettyPrint") - pp.should_receive(:text).with("#") - SortedSet[1, 2, 3].pretty_print_cycle(pp) - end - end -end diff --git a/library/set/sortedset/pretty_print_spec.rb b/library/set/sortedset/pretty_print_spec.rb deleted file mode 100644 index a8088bf797..0000000000 --- a/library/set/sortedset/pretty_print_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#pretty_print" do - it "passes the 'pretty print' representation of self to the pretty print writer" do - pp = mock("PrettyPrint") - set = SortedSet[1, 2, 3] - - pp.should_receive(:text).with("#") - - pp.should_receive(:nest).with(1).and_yield - pp.should_receive(:seplist).with(set) - - set.pretty_print(pp) - end - end -end diff --git a/library/set/sortedset/proper_subset_spec.rb b/library/set/sortedset/proper_subset_spec.rb deleted file mode 100644 index 34fb89d13d..0000000000 --- a/library/set/sortedset/proper_subset_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#proper_subset?" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns true if passed a SortedSet that self is a proper subset of" do - SortedSet[].proper_subset?(@set).should be_true - SortedSet[].proper_subset?(SortedSet[1, 2, 3]).should be_true - SortedSet[].proper_subset?(SortedSet["a", "b", "c"]).should be_true - - SortedSet[1, 2, 3].proper_subset?(@set).should be_true - SortedSet[1, 3].proper_subset?(@set).should be_true - SortedSet[1, 2].proper_subset?(@set).should be_true - SortedSet[1].proper_subset?(@set).should be_true - - SortedSet[5].proper_subset?(@set).should be_false - SortedSet[1, 5].proper_subset?(@set).should be_false - SortedSet["test"].proper_subset?(@set).should be_false - - @set.proper_subset?(@set).should be_false - SortedSet[].proper_subset?(SortedSet[]).should be_false - end - - it "raises an ArgumentError when passed a non-SortedSet" do - -> { SortedSet[].proper_subset?([]) }.should raise_error(ArgumentError) - -> { SortedSet[].proper_subset?(1) }.should raise_error(ArgumentError) - -> { SortedSet[].proper_subset?("test") }.should raise_error(ArgumentError) - -> { SortedSet[].proper_subset?(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/library/set/sortedset/proper_superset_spec.rb b/library/set/sortedset/proper_superset_spec.rb deleted file mode 100644 index 8b92444f72..0000000000 --- a/library/set/sortedset/proper_superset_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#proper_superset?" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns true if passed a SortedSet that self is a proper superset of" do - @set.proper_superset?(SortedSet[]).should be_true - SortedSet[1, 2, 3].proper_superset?(SortedSet[]).should be_true - SortedSet["a", "b", "c"].proper_superset?(SortedSet[]).should be_true - - @set.proper_superset?(SortedSet[1, 2, 3]).should be_true - @set.proper_superset?(SortedSet[1, 3]).should be_true - @set.proper_superset?(SortedSet[1, 2]).should be_true - @set.proper_superset?(SortedSet[1]).should be_true - - @set.proper_superset?(SortedSet[5]).should be_false - @set.proper_superset?(SortedSet[1, 5]).should be_false - @set.proper_superset?(SortedSet["test"]).should be_false - - @set.proper_superset?(@set).should be_false - SortedSet[].proper_superset?(SortedSet[]).should be_false - end - - it "raises an ArgumentError when passed a non-SortedSet" do - -> { SortedSet[].proper_superset?([]) }.should raise_error(ArgumentError) - -> { SortedSet[].proper_superset?(1) }.should raise_error(ArgumentError) - -> { SortedSet[].proper_superset?("test") }.should raise_error(ArgumentError) - -> { SortedSet[].proper_superset?(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/library/set/sortedset/reject_spec.rb b/library/set/sortedset/reject_spec.rb deleted file mode 100644 index 396b864cc5..0000000000 --- a/library/set/sortedset/reject_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#reject!" do - before :each do - @set = SortedSet["one", "two", "three"] - end - - it "yields each Object in self in sorted order" do - res = [] - @set.reject! { |x| res << x } - res.should == ["one", "two", "three"].sort - end - - it "deletes every element from self for which the passed block returns true" do - @set.reject! { |x| x.size == 3 } - @set.size.should eql(1) - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - - it "returns self when self was modified" do - @set.reject! { |x| true }.should equal(@set) - end - - it "returns nil when self was not modified" do - @set.reject! { |x| false }.should be_nil - end - - it "returns an Enumerator when passed no block" do - enum = @set.reject! - enum.should be_an_instance_of(Enumerator) - - enum.each { |x| x.size == 3 } - - @set.should_not include("one") - @set.should_not include("two") - @set.should include("three") - end - end -end diff --git a/library/set/sortedset/replace_spec.rb b/library/set/sortedset/replace_spec.rb deleted file mode 100644 index 2900221c01..0000000000 --- a/library/set/sortedset/replace_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#replace" do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "replaces the contents with other and returns self" do - @set.replace(SortedSet[1, 2, 3]).should == @set - @set.should == SortedSet[1, 2, 3] - end - - it "accepts any enumerable as other" do - @set.replace([1, 2, 3]).should == SortedSet[1, 2, 3] - end - end -end diff --git a/library/set/sortedset/select_spec.rb b/library/set/sortedset/select_spec.rb deleted file mode 100644 index fc4c15ee4d..0000000000 --- a/library/set/sortedset/select_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/select' - require 'set' - - describe "SortedSet#select!" do - it_behaves_like :sorted_set_select_bang, :select! - end -end diff --git a/library/set/sortedset/size_spec.rb b/library/set/sortedset/size_spec.rb deleted file mode 100644 index d908b33b53..0000000000 --- a/library/set/sortedset/size_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/length' - require 'set' - - describe "SortedSet#size" do - it_behaves_like :sorted_set_length, :size - end -end diff --git a/library/set/sortedset/sortedset_spec.rb b/library/set/sortedset/sortedset_spec.rb index 3ead5495fc..67993dee29 100644 --- a/library/set/sortedset/sortedset_spec.rb +++ b/library/set/sortedset/sortedset_spec.rb @@ -1,22 +1,12 @@ require_relative '../../../spec_helper' require 'set' -ruby_version_is "3.0" do - describe "SortedSet" do - it "raises error including message that it has been extracted from the set stdlib" do - -> { - SortedSet - }.should raise_error(RuntimeError) { |e| - e.message.should.include?("The `SortedSet` class has been extracted from the `set` library") - } - end - end -end - -ruby_version_is ""..."3.0" do - describe "SortedSet" do - it "is part of the set stdlib" do - SortedSet.superclass.should == Set - end +describe "SortedSet" do + it "raises error including message that it has been extracted from the set stdlib" do + -> { + SortedSet + }.should raise_error(RuntimeError) { |e| + e.message.should.include?("The `SortedSet` class has been extracted from the `set` library") + } end end diff --git a/library/set/sortedset/subset_spec.rb b/library/set/sortedset/subset_spec.rb deleted file mode 100644 index 272e3f985e..0000000000 --- a/library/set/sortedset/subset_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#subset?" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns true if passed a SortedSet that is equal to self or self is a subset of" do - @set.subset?(@set).should be_true - SortedSet[].subset?(SortedSet[]).should be_true - - SortedSet[].subset?(@set).should be_true - SortedSet[].subset?(SortedSet[1, 2, 3]).should be_true - SortedSet[].subset?(SortedSet["a", "b", "c"]).should be_true - - SortedSet[1, 2, 3].subset?(@set).should be_true - SortedSet[1, 3].subset?(@set).should be_true - SortedSet[1, 2].subset?(@set).should be_true - SortedSet[1].subset?(@set).should be_true - - SortedSet[5].subset?(@set).should be_false - SortedSet[1, 5].subset?(@set).should be_false - SortedSet["test"].subset?(@set).should be_false - end - - it "raises an ArgumentError when passed a non-SortedSet" do - -> { SortedSet[].subset?([]) }.should raise_error(ArgumentError) - -> { SortedSet[].subset?(1) }.should raise_error(ArgumentError) - -> { SortedSet[].subset?("test") }.should raise_error(ArgumentError) - -> { SortedSet[].subset?(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/library/set/sortedset/subtract_spec.rb b/library/set/sortedset/subtract_spec.rb deleted file mode 100644 index b2af127f89..0000000000 --- a/library/set/sortedset/subtract_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#subtract" do - before :each do - @set = SortedSet["a", "b", "c"] - end - - it "deletes any elements contained in other and returns self" do - @set.subtract(SortedSet["b", "c"]).should == @set - @set.should == SortedSet["a"] - end - - it "accepts any enumerable as other" do - @set.subtract(["c"]).should == SortedSet["a", "b"] - end - end -end diff --git a/library/set/sortedset/superset_spec.rb b/library/set/sortedset/superset_spec.rb deleted file mode 100644 index a1bbacb966..0000000000 --- a/library/set/sortedset/superset_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#superset?" do - before :each do - @set = SortedSet[1, 2, 3, 4] - end - - it "returns true if passed a SortedSet that equals self or self is a proper superset of" do - @set.superset?(@set).should be_true - SortedSet[].superset?(SortedSet[]).should be_true - - @set.superset?(SortedSet[]).should be_true - SortedSet[1, 2, 3].superset?(SortedSet[]).should be_true - SortedSet["a", "b", "c"].superset?(SortedSet[]).should be_true - - @set.superset?(SortedSet[1, 2, 3]).should be_true - @set.superset?(SortedSet[1, 3]).should be_true - @set.superset?(SortedSet[1, 2]).should be_true - @set.superset?(SortedSet[1]).should be_true - - @set.superset?(SortedSet[5]).should be_false - @set.superset?(SortedSet[1, 5]).should be_false - @set.superset?(SortedSet["test"]).should be_false - end - - it "raises an ArgumentError when passed a non-SortedSet" do - -> { SortedSet[].superset?([]) }.should raise_error(ArgumentError) - -> { SortedSet[].superset?(1) }.should raise_error(ArgumentError) - -> { SortedSet[].superset?("test") }.should raise_error(ArgumentError) - -> { SortedSet[].superset?(Object.new) }.should raise_error(ArgumentError) - end - end -end diff --git a/library/set/sortedset/to_a_spec.rb b/library/set/sortedset/to_a_spec.rb deleted file mode 100644 index bb54cd7cdb..0000000000 --- a/library/set/sortedset/to_a_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require 'set' - - describe "SortedSet#to_a" do - it "returns an array containing elements" do - set = SortedSet.new [1, 2, 3] - set.to_a.should == [1, 2, 3] - end - - it "returns a sorted array containing elements" do - set = SortedSet[2, 3, 1] - set.to_a.should == [1, 2, 3] - - set = SortedSet.new [5, 6, 4, 4] - set.to_a.should == [4, 5, 6] - end - end -end diff --git a/library/set/sortedset/union_spec.rb b/library/set/sortedset/union_spec.rb deleted file mode 100644 index c942f20d3e..0000000000 --- a/library/set/sortedset/union_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../../spec_helper' - -ruby_version_is ""..."3.0" do - require_relative 'shared/union' - require 'set' - - describe "SortedSet#union" do - it_behaves_like :sorted_set_union, :union - end - - describe "SortedSet#|" do - it_behaves_like :sorted_set_union, :| - end -end diff --git a/library/socket/socket/new_spec.rb b/library/socket/socket/new_spec.rb deleted file mode 100644 index b2ec607f6a..0000000000 --- a/library/socket/socket/new_spec.rb +++ /dev/null @@ -1,2 +0,0 @@ -require_relative '../spec_helper' -require_relative '../fixtures/classes' diff --git a/library/socket/tcpsocket/shared/new.rb b/library/socket/tcpsocket/shared/new.rb index 5d91435a2a..11e43fd0f4 100644 --- a/library/socket/tcpsocket/shared/new.rb +++ b/library/socket/tcpsocket/shared/new.rb @@ -92,11 +92,9 @@ @socket.addr[2].should =~ /^#{@hostname}/ end - ruby_version_is "3.0" do - it "connects to a server when passed connect_timeout argument" do - @socket = TCPSocket.send(@method, @hostname, @server.port, connect_timeout: 1) - @socket.should be_an_instance_of(TCPSocket) - end + it "connects to a server when passed connect_timeout argument" do + @socket = TCPSocket.send(@method, @hostname, @server.port, connect_timeout: 1) + @socket.should be_an_instance_of(TCPSocket) end end end diff --git a/library/stringio/append_spec.rb b/library/stringio/append_spec.rb index 981229fc10..5383e3e795 100644 --- a/library/stringio/append_spec.rb +++ b/library/stringio/append_spec.rb @@ -29,13 +29,6 @@ @io.string.should == "example\000\000\000\000\000\000\000\000just testing" end - ruby_version_is ""..."3.0" do - it "does not taint self when the passed argument is tainted" do - (@io << "test".taint) - @io.tainted?.should be_false - end - end - it "updates self's position" do @io << "test" @io.pos.should eql(4) diff --git a/library/stringio/bytes_spec.rb b/library/stringio/bytes_spec.rb deleted file mode 100644 index 4ef7a490a5..0000000000 --- a/library/stringio/bytes_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../../spec_helper' -require 'stringio' -require_relative 'shared/each_byte' - -ruby_version_is ''...'3.0' do - describe "StringIO#bytes" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_byte, :bytes - end - - describe "StringIO#bytes when self is not readable" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_byte_not_readable, :bytes - end -end diff --git a/library/stringio/chars_spec.rb b/library/stringio/chars_spec.rb deleted file mode 100644 index 58cba77634..0000000000 --- a/library/stringio/chars_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../../spec_helper' -require 'stringio' -require_relative 'shared/each_char' - -ruby_version_is ''...'3.0' do - describe "StringIO#chars" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_char, :chars - end - - describe "StringIO#chars when self is not readable" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_char_not_readable, :chars - end -end diff --git a/library/stringio/codepoints_spec.rb b/library/stringio/codepoints_spec.rb deleted file mode 100644 index ceaadefc32..0000000000 --- a/library/stringio/codepoints_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# -*- encoding: utf-8 -*- -require_relative '../../spec_helper' -require_relative 'fixtures/classes' -require_relative 'shared/codepoints' - -ruby_version_is ''...'3.0' do - # See redmine #1667 - describe "StringIO#codepoints" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_codepoints, :codepoints - end -end diff --git a/library/stringio/lines_spec.rb b/library/stringio/lines_spec.rb deleted file mode 100644 index 42d11772ae..0000000000 --- a/library/stringio/lines_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require_relative '../../spec_helper' -require 'stringio' -require_relative 'shared/each' - -ruby_version_is ''...'3.0' do - describe "StringIO#lines when passed a separator" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_separator, :lines - end - - describe "StringIO#lines when passed no arguments" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_no_arguments, :lines - end - - describe "StringIO#lines when self is not readable" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_not_readable, :lines - end - - describe "StringIO#lines when passed chomp" do - before :each do - @verbose, $VERBOSE = $VERBOSE, nil - end - - after :each do - $VERBOSE = @verbose - end - - it_behaves_like :stringio_each_chomp, :lines - end -end diff --git a/library/stringio/reopen_spec.rb b/library/stringio/reopen_spec.rb index 4863a5332b..9851c5b706 100644 --- a/library/stringio/reopen_spec.rb +++ b/library/stringio/reopen_spec.rb @@ -23,17 +23,6 @@ @io.string.should == "reopened, another time" end - ruby_version_is ""..."3.0" do - # NOTE: WEIRD! - it "does not taint self when the passed Object was tainted" do - @io.reopen("reopened".taint, IO::RDONLY) - @io.tainted?.should be_false - - @io.reopen("reopened".taint, IO::WRONLY) - @io.tainted?.should be_false - end - end - it "tries to convert the passed Object to a String using #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_return("to_str") @@ -92,17 +81,6 @@ str.should == "" end - ruby_version_is ""..."3.0" do - # NOTE: WEIRD! - it "does not taint self when the passed Object was tainted" do - @io.reopen("reopened".taint, "r") - @io.tainted?.should be_false - - @io.reopen("reopened".taint, "w") - @io.tainted?.should be_false - end - end - it "tries to convert the passed Object to a String using #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_return("to_str") @@ -164,14 +142,6 @@ @io.string.should == "reopened" end - ruby_version_is ""..."3.0" do - # NOTE: WEIRD! - it "does not taint self when the passed Object was tainted" do - @io.reopen("reopened".taint) - @io.tainted?.should be_false - end - end - it "resets self's position to 0" do @io.read(5) @io.reopen("reopened") diff --git a/library/stringio/shared/write.rb b/library/stringio/shared/write.rb index b91e6ecec1..aa67bb73c7 100644 --- a/library/stringio/shared/write.rb +++ b/library/stringio/shared/write.rb @@ -60,13 +60,6 @@ @io.string.size.should == n.times.map(&:to_s).join.size end - ruby_version_is ""..."3.0" do - it "does not taint self when the passed argument is tainted" do - @io.send(@method, "test".taint) - @io.tainted?.should be_false - end - end - it "handles writing non-ASCII UTF-8 after seek" do @io.binmode @io << "\x80" diff --git a/library/zlib/deflate/new_spec.rb b/library/zlib/deflate/new_spec.rb deleted file mode 100644 index e15f14f95f..0000000000 --- a/library/zlib/deflate/new_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' diff --git a/library/zlib/gzipreader/new_spec.rb b/library/zlib/gzipreader/new_spec.rb deleted file mode 100644 index e15f14f95f..0000000000 --- a/library/zlib/gzipreader/new_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' diff --git a/library/zlib/inflate/new_spec.rb b/library/zlib/inflate/new_spec.rb deleted file mode 100644 index e15f14f95f..0000000000 --- a/library/zlib/inflate/new_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' diff --git a/optional/capi/class_spec.rb b/optional/capi/class_spec.rb index 66af381243..d0a9913570 100644 --- a/optional/capi/class_spec.rb +++ b/optional/capi/class_spec.rb @@ -119,23 +119,21 @@ end end - ruby_version_is "3.0" do - describe "rb_class_new_instance_kw" do - it "passes arguments and keywords to the #initialize method" do - obj = @s.rb_class_new_instance_kw([{pos: 1}, {kw: 2}], CApiClassSpecs::KeywordAlloc) - obj.args.should == [{pos: 1}] - obj.kwargs.should == {kw: 2} - - obj = @s.rb_class_new_instance_kw([{}], CApiClassSpecs::KeywordAlloc) - obj.args.should == [] - obj.kwargs.should == {} - end - - it "raises TypeError if the last argument is not a Hash" do - -> { - @s.rb_class_new_instance_kw([42], CApiClassSpecs::KeywordAlloc) - }.should raise_error(TypeError, 'no implicit conversion of Integer into Hash') - end + describe "rb_class_new_instance_kw" do + it "passes arguments and keywords to the #initialize method" do + obj = @s.rb_class_new_instance_kw([{pos: 1}, {kw: 2}], CApiClassSpecs::KeywordAlloc) + obj.args.should == [{pos: 1}] + obj.kwargs.should == {kw: 2} + + obj = @s.rb_class_new_instance_kw([{}], CApiClassSpecs::KeywordAlloc) + obj.args.should == [] + obj.kwargs.should == {} + end + + it "raises TypeError if the last argument is not a Hash" do + -> { + @s.rb_class_new_instance_kw([42], CApiClassSpecs::KeywordAlloc) + }.should raise_error(TypeError, 'no implicit conversion of Integer into Hash') end end diff --git a/optional/capi/kernel_spec.rb b/optional/capi/kernel_spec.rb index 54d8d8a8d3..68e3ffa95a 100644 --- a/optional/capi/kernel_spec.rb +++ b/optional/capi/kernel_spec.rb @@ -599,45 +599,43 @@ def sum(a, b) end end - ruby_version_is "3.0" do - describe "rb_funcallv_kw" do - it "passes keyword arguments to the callee" do - def m(*args, **kwargs) - [args, kwargs] - end - - @s.rb_funcallv_kw(self, :m, [{}]).should == [[], {}] - @s.rb_funcallv_kw(self, :m, [{a: 1}]).should == [[], {a: 1}] - @s.rb_funcallv_kw(self, :m, [{b: 2}, {a: 1}]).should == [[{b: 2}], {a: 1}] - @s.rb_funcallv_kw(self, :m, [{b: 2}, {}]).should == [[{b: 2}], {}] + describe "rb_funcallv_kw" do + it "passes keyword arguments to the callee" do + def m(*args, **kwargs) + [args, kwargs] end - it "raises TypeError if the last argument is not a Hash" do - def m(*args, **kwargs) - [args, kwargs] - end + @s.rb_funcallv_kw(self, :m, [{}]).should == [[], {}] + @s.rb_funcallv_kw(self, :m, [{a: 1}]).should == [[], {a: 1}] + @s.rb_funcallv_kw(self, :m, [{b: 2}, {a: 1}]).should == [[{b: 2}], {a: 1}] + @s.rb_funcallv_kw(self, :m, [{b: 2}, {}]).should == [[{b: 2}], {}] + end - -> { - @s.rb_funcallv_kw(self, :m, [42]) - }.should raise_error(TypeError, 'no implicit conversion of Integer into Hash') + it "raises TypeError if the last argument is not a Hash" do + def m(*args, **kwargs) + [args, kwargs] end + + -> { + @s.rb_funcallv_kw(self, :m, [42]) + }.should raise_error(TypeError, 'no implicit conversion of Integer into Hash') end + end - describe "rb_keyword_given_p" do - it "returns whether keywords were given to the C extension method" do - h = {a: 1} - empty = {} - @s.rb_keyword_given_p(a: 1).should == true - @s.rb_keyword_given_p("foo" => "bar").should == true - @s.rb_keyword_given_p(**h).should == true + describe "rb_keyword_given_p" do + it "returns whether keywords were given to the C extension method" do + h = {a: 1} + empty = {} + @s.rb_keyword_given_p(a: 1).should == true + @s.rb_keyword_given_p("foo" => "bar").should == true + @s.rb_keyword_given_p(**h).should == true - @s.rb_keyword_given_p(h).should == false - @s.rb_keyword_given_p().should == false - @s.rb_keyword_given_p(**empty).should == false + @s.rb_keyword_given_p(h).should == false + @s.rb_keyword_given_p().should == false + @s.rb_keyword_given_p(**empty).should == false - @s.rb_funcallv_kw(@s, :rb_keyword_given_p, [{a: 1}]).should == true - @s.rb_funcallv_kw(@s, :rb_keyword_given_p, [{}]).should == false - end + @s.rb_funcallv_kw(@s, :rb_keyword_given_p, [{a: 1}]).should == true + @s.rb_funcallv_kw(@s, :rb_keyword_given_p, [{}]).should == false end end diff --git a/optional/capi/util_spec.rb b/optional/capi/util_spec.rb index 38f6f47b1a..320527521b 100644 --- a/optional/capi/util_spec.rb +++ b/optional/capi/util_spec.rb @@ -115,22 +115,11 @@ ScratchPad.recorded.should == [1, nil] end - ruby_version_is ''...'3.0' do - it "assigns required and Hash arguments with nil Hash" do - suppress_warning do - @o.rb_scan_args([1, nil], "1:", 2, @acc).should == 1 - end - ScratchPad.recorded.should == [1, nil] - end - end - - ruby_version_is '3.0' do - it "rejects the use of nil as a hash" do - -> { - @o.rb_scan_args([1, nil], "1:", 2, @acc).should == 1 - }.should raise_error(ArgumentError) - ScratchPad.recorded.should == [] - end + it "rejects the use of nil as a hash" do + -> { + @o.rb_scan_args([1, nil], "1:", 2, @acc).should == 1 + }.should raise_error(ArgumentError) + ScratchPad.recorded.should == [] end it "assigns required and optional arguments with no hash argument given" do @@ -144,55 +133,22 @@ ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc] end - ruby_version_is ''...'3.0' do - # r43934 - it "rejects non-keyword arguments" do - h = {1 => 2, 3 => 4} - -> { - suppress_warning do - @o.rb_scan_args([h], "k0:", 1, @acc) - end - }.should raise_error(ArgumentError) - ScratchPad.recorded.should == [] - end - - it "rejects required and non-keyword arguments" do - h = {1 => 2, 3 => 4} - -> { - suppress_warning do - @o.rb_scan_args([1, h], "k1:", 2, @acc) - end - }.should raise_error(ArgumentError) - ScratchPad.recorded.should == [] - end - - it "considers the hash as a post argument when there is a splat" do - h = {1 => 2, 3 => 4} - suppress_warning do - @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 6 - end - ScratchPad.recorded.should == [1, 2, [3, 4, 5], h, nil, @prc] - end + it "does not reject non-symbol keys in keyword arguments" do + h = {1 => 2, 3 => 4} + @o.rb_scan_args([h], "k0:", 1, @acc).should == 0 + ScratchPad.recorded.should == [h] end - ruby_version_is '3.0' do - it "does not reject non-symbol keys in keyword arguments" do - h = {1 => 2, 3 => 4} - @o.rb_scan_args([h], "k0:", 1, @acc).should == 0 - ScratchPad.recorded.should == [h] - end - - it "does not reject non-symbol keys in keyword arguments with required argument" do - h = {1 => 2, 3 => 4} - @o.rb_scan_args([1, h], "k1:", 2, @acc).should == 1 - ScratchPad.recorded.should == [1, h] - end + it "does not reject non-symbol keys in keyword arguments with required argument" do + h = {1 => 2, 3 => 4} + @o.rb_scan_args([1, h], "k1:", 2, @acc).should == 1 + ScratchPad.recorded.should == [1, h] + end - it "considers keyword arguments with non-symbol keys as keywords when using splat and post arguments" do - h = {1 => 2, 3 => 4} - @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 5 - ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc] - end + it "considers keyword arguments with non-symbol keys as keywords when using splat and post arguments" do + h = {1 => 2, 3 => 4} + @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 5 + ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc] end end diff --git a/security/cve_2014_8080_spec.rb b/security/cve_2014_8080_spec.rb deleted file mode 100644 index 23770f94b1..0000000000 --- a/security/cve_2014_8080_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../spec_helper' - -ruby_version_is ''...'3.0' do - require 'rexml/document' - - describe "REXML::Document.new" do - - it "resists CVE-2014-8080 by raising an exception when entity expansion has grown too large" do - xml = < - - - - - - - - - - - ]> - - %x9;%x9;%x9;%x9;%x9;%x9;%x9;%x9;%x9;%x9; - -XML - - -> { - REXML::Document.new(xml).doctype.entities['x9'].value - }.should raise_error(REXML::ParseException, /entity expansion has grown too large/) - end - - end -end diff --git a/security/cve_2017_17742_spec.rb b/security/cve_2017_17742_spec.rb deleted file mode 100644 index b0d93e42b8..0000000000 --- a/security/cve_2017_17742_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require_relative '../spec_helper' - -# webrick is no longer in stdlib in Ruby 3+ -ruby_version_is ""..."3.0" do - require "webrick" - require "stringio" - require "net/http" - - describe "WEBrick" do - describe "resists CVE-2017-17742" do - it "for a response splitting headers" do - config = WEBrick::Config::HTTP - res = WEBrick::HTTPResponse.new config - res['X-header'] = "malicious\r\nCookie: hack" - io = StringIO.new - res.send_response io - io.rewind - res = Net::HTTPResponse.read_new(Net::BufferedIO.new(io)) - res.code.should == '500' - io.string.should_not =~ /hack/ - end - - it "for a response splitting cookie headers" do - user_input = "malicious\r\nCookie: hack" - config = WEBrick::Config::HTTP - res = WEBrick::HTTPResponse.new config - res.cookies << WEBrick::Cookie.new('author', user_input) - io = StringIO.new - res.send_response io - io.rewind - res = Net::HTTPResponse.read_new(Net::BufferedIO.new(io)) - res.code.should == '500' - io.string.should_not =~ /hack/ - end - end - end -end diff --git a/shared/string/times.rb b/shared/string/times.rb index 8ca9507570..be3b622f73 100644 --- a/shared/string/times.rb +++ b/shared/string/times.rb @@ -32,20 +32,10 @@ class MyString < String; end @object.call("", max_long).should == "" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - @object.call(MyString.new("cool"), 0).should be_an_instance_of(MyString) - @object.call(MyString.new("cool"), 1).should be_an_instance_of(MyString) - @object.call(MyString.new("cool"), 2).should be_an_instance_of(MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - @object.call(MyString.new("cool"), 0).should be_an_instance_of(String) - @object.call(MyString.new("cool"), 1).should be_an_instance_of(String) - @object.call(MyString.new("cool"), 2).should be_an_instance_of(String) - end + it "returns String instances" do + @object.call(MyString.new("cool"), 0).should be_an_instance_of(String) + @object.call(MyString.new("cool"), 1).should be_an_instance_of(String) + @object.call(MyString.new("cool"), 2).should be_an_instance_of(String) end it "returns a String in the same encoding as self" do