diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e95f3e5599..1a2eccefcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,12 @@ jobs: matrix: os: [ ubuntu, macos, windows ] ruby: [ 3.0.6, 3.1.4, 3.2.2, 3.3.0 ] + rubyopt: [""] + include: + - os: ubuntu + ruby: 3.3.0 + rubyopt: "--enable-frozen-string-literal" + runs-on: ${{ matrix.os }}-latest steps: - name: git config autocrlf @@ -28,6 +34,7 @@ jobs: if: matrix.os == 'ubuntu' env: CHECK_LEAKS: true + RUBYOPT: "${{ matrix.rubyopt }}" run: ../mspec/bin/mspec -j --timeout 30 - name: Run specs (macOS) diff --git a/core/argf/readpartial_spec.rb b/core/argf/readpartial_spec.rb index bbc8831131..ea4301f25c 100644 --- a/core/argf/readpartial_spec.rb +++ b/core/argf/readpartial_spec.rb @@ -29,7 +29,7 @@ it "clears output buffer even if EOFError is raised because @argf is at end" do begin - output = "to be cleared" + output = +"to be cleared" argf [@file1_name] do @argf.read diff --git a/core/argf/shared/getc.rb b/core/argf/shared/getc.rb index 8be39c60b6..d63372d9d7 100644 --- a/core/argf/shared/getc.rb +++ b/core/argf/shared/getc.rb @@ -9,7 +9,7 @@ it "reads each char of files" do argf [@file1, @file2] do - chars = "" + chars = +"" @chars.size.times { chars << @argf.send(@method) } chars.should == @chars end diff --git a/core/argf/shared/read.rb b/core/argf/shared/read.rb index fe903983c0..e76d022139 100644 --- a/core/argf/shared/read.rb +++ b/core/argf/shared/read.rb @@ -15,7 +15,7 @@ it "treats second argument as an output buffer" do argf [@file1_name] do - buffer = "" + buffer = +"" @argf.send(@method, @file1.size, buffer) buffer.should == @file1 end @@ -23,7 +23,7 @@ it "clears output buffer before appending to it" do argf [@file1_name] do - buffer = "to be cleared" + buffer = +"to be cleared" @argf.send(@method, @file1.size, buffer) buffer.should == @file1 end diff --git a/core/array/fill_spec.rb b/core/array/fill_spec.rb index 02360e550d..2c3b5d9e84 100644 --- a/core/array/fill_spec.rb +++ b/core/array/fill_spec.rb @@ -21,7 +21,7 @@ it "does not replicate the filler" do ary = [1, 2, 3, 4] - str = "x" + str = +"x" ary.fill(str).should == [str, str, str, str] str << "y" ary.should == [str, str, str, str] diff --git a/core/array/pack/buffer_spec.rb b/core/array/pack/buffer_spec.rb index ecb40bfd06..f1206efb3e 100644 --- a/core/array/pack/buffer_spec.rb +++ b/core/array/pack/buffer_spec.rb @@ -13,13 +13,13 @@ it "adds result at the end of buffer content" do n = [ 65, 66, 67 ] # result without buffer is "ABC" - buffer = "" + buffer = +"" n.pack("ccc", buffer: buffer).should == "ABC" - buffer = "123" + buffer = +"123" n.pack("ccc", buffer: buffer).should == "123ABC" - buffer = "12345" + buffer = +"12345" n.pack("ccc", buffer: buffer).should == "12345ABC" end @@ -31,19 +31,19 @@ context "offset (@) is specified" do it 'keeps buffer content if it is longer than offset' do n = [ 65, 66, 67 ] - buffer = "123456" + buffer = +"123456" n.pack("@3ccc", buffer: buffer).should == "123ABC" end it "fills the gap with \\0 if buffer content is shorter than offset" do n = [ 65, 66, 67 ] - buffer = "123" + buffer = +"123" n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC" end it 'does not keep buffer content if it is longer than offset + result' do n = [ 65, 66, 67 ] - buffer = "1234567890" + buffer = +"1234567890" n.pack("@3ccc", buffer: buffer).should == "123ABC" end end diff --git a/core/array/shared/inspect.rb b/core/array/shared/inspect.rb index a2b43d4959..af5128c645 100644 --- a/core/array/shared/inspect.rb +++ b/core/array/shared/inspect.rb @@ -19,7 +19,7 @@ end it "does not call #to_s on a String returned from #inspect" do - str = "abc" + str = +"abc" str.should_not_receive(:to_s) [str].send(@method).should == '["abc"]' @@ -98,8 +98,8 @@ end it "does not raise if inspected result is not default external encoding" do - utf_16be = mock("utf_16be") - utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) + utf_16be = mock(+"utf_16be") + utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE)) [utf_16be].send(@method).should == '["utf_16be \u3042"]' end diff --git a/core/complex/inspect_spec.rb b/core/complex/inspect_spec.rb index 7a89ec6854..045be94b22 100644 --- a/core/complex/inspect_spec.rb +++ b/core/complex/inspect_spec.rb @@ -17,7 +17,8 @@ it "calls #inspect on real and imaginary" do real = NumericSpecs::Subclass.new - real.should_receive(:inspect).and_return("1") + # + because of https://bugs.ruby-lang.org/issues/20337 + real.should_receive(:inspect).and_return(+"1") imaginary = NumericSpecs::Subclass.new imaginary.should_receive(:inspect).and_return("2") imaginary.should_receive(:<).any_number_of_times.and_return(false) @@ -26,7 +27,8 @@ it "adds an `*' before the `i' if the last character of the imaginary part is not numeric" do real = NumericSpecs::Subclass.new - real.should_receive(:inspect).and_return("(1)") + # + because of https://bugs.ruby-lang.org/issues/20337 + real.should_receive(:inspect).and_return(+"(1)") imaginary = NumericSpecs::Subclass.new imaginary.should_receive(:inspect).and_return("(2)") imaginary.should_receive(:<).any_number_of_times.and_return(false) diff --git a/core/complex/to_s_spec.rb b/core/complex/to_s_spec.rb index 7677dcd0b5..ceccffe470 100644 --- a/core/complex/to_s_spec.rb +++ b/core/complex/to_s_spec.rb @@ -45,7 +45,8 @@ it "treats real and imaginary parts as strings" do real = NumericSpecs::Subclass.new - real.should_receive(:to_s).and_return("1") + # + because of https://bugs.ruby-lang.org/issues/20337 + real.should_receive(:to_s).and_return(+"1") imaginary = NumericSpecs::Subclass.new imaginary.should_receive(:to_s).and_return("2") imaginary.should_receive(:<).any_number_of_times.and_return(false) diff --git a/core/encoding/converter/convert_spec.rb b/core/encoding/converter/convert_spec.rb index 95a9e0b758..ad2ac4efff 100644 --- a/core/encoding/converter/convert_spec.rb +++ b/core/encoding/converter/convert_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: true require_relative '../../../spec_helper' describe "Encoding::Converter#convert" do diff --git a/core/encoding/converter/last_error_spec.rb b/core/encoding/converter/last_error_spec.rb index 68567737b7..0cca3c1873 100644 --- a/core/encoding/converter/last_error_spec.rb +++ b/core/encoding/converter/last_error_spec.rb @@ -15,39 +15,39 @@ it "returns nil when #primitive_convert last returned :destination_buffer_full" do ec = Encoding::Converter.new("utf-8", "iso-2022-jp") - ec.primitive_convert("\u{9999}", "", 0, 0, partial_input: false) \ + ec.primitive_convert(+"\u{9999}", +"", 0, 0, partial_input: false) \ .should == :destination_buffer_full ec.last_error.should be_nil end it "returns nil when #primitive_convert last returned :finished" do ec = Encoding::Converter.new("utf-8", "iso-8859-1") - ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished + ec.primitive_convert("glark".force_encoding('utf-8'), +"").should == :finished ec.last_error.should be_nil end it "returns nil if the last conversion succeeded but the penultimate failed" do ec = Encoding::Converter.new("utf-8", "iso-8859-1") - ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence - ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished + ec.primitive_convert(+"\xf1abcd", +"").should == :invalid_byte_sequence + ec.primitive_convert("glark".force_encoding('utf-8'), +"").should == :finished ec.last_error.should be_nil end it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :invalid_byte_sequence" do ec = Encoding::Converter.new("utf-8", "iso-8859-1") - ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence + ec.primitive_convert(+"\xf1abcd", +"").should == :invalid_byte_sequence ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError) end it "returns an Encoding::UndefinedConversionError when #primitive_convert last returned :undefined_conversion" do ec = Encoding::Converter.new("utf-8", "iso-8859-1") - ec.primitive_convert("\u{9876}","").should == :undefined_conversion + ec.primitive_convert(+"\u{9876}", +"").should == :undefined_conversion ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError) end it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :incomplete_input" do ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") - ec.primitive_convert("\xa4", "", nil, 10).should == :incomplete_input + ec.primitive_convert(+"\xa4", +"", nil, 10).should == :incomplete_input ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError) end diff --git a/core/encoding/converter/primitive_convert_spec.rb b/core/encoding/converter/primitive_convert_spec.rb index ab34ebf33f..63f25eddef 100644 --- a/core/encoding/converter/primitive_convert_spec.rb +++ b/core/encoding/converter/primitive_convert_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter#primitive_convert" do diff --git a/core/encoding/converter/primitive_errinfo_spec.rb b/core/encoding/converter/primitive_errinfo_spec.rb index 1f836b259f..668eb9a924 100644 --- a/core/encoding/converter/primitive_errinfo_spec.rb +++ b/core/encoding/converter/primitive_errinfo_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter#primitive_errinfo" do diff --git a/core/encoding/converter/putback_spec.rb b/core/encoding/converter/putback_spec.rb index c4e0a5da21..7f4afe0379 100644 --- a/core/encoding/converter/putback_spec.rb +++ b/core/encoding/converter/putback_spec.rb @@ -4,7 +4,7 @@ describe "Encoding::Converter#putback" do before :each do @ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") - @ret = @ec.primitive_convert(@src="abc\xa1def", @dst="", nil, 10) + @ret = @ec.primitive_convert(@src=+"abc\xa1def", @dst=+"", nil, 10) end it "returns a String" do @@ -36,8 +36,8 @@ it "returns the problematic bytes for UTF-16LE" do ec = Encoding::Converter.new("utf-16le", "iso-8859-1") - src = "\x00\xd8\x61\x00" - dst = "" + src = +"\x00\xd8\x61\x00" + dst = +"" ec.primitive_convert(src, dst).should == :invalid_byte_sequence ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"] ec.putback.should == "a\x00".force_encoding("utf-16le") @@ -46,8 +46,8 @@ it "accepts an integer argument corresponding to the number of bytes to be put back" do ec = Encoding::Converter.new("utf-16le", "iso-8859-1") - src = "\x00\xd8\x61\x00" - dst = "" + src = +"\x00\xd8\x61\x00" + dst = +"" ec.primitive_convert(src, dst).should == :invalid_byte_sequence ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"] ec.putback(2).should == "a\x00".force_encoding("utf-16le") diff --git a/core/encoding/converter/replacement_spec.rb b/core/encoding/converter/replacement_spec.rb index 5ca42e7e5a..ba7a9d22e8 100644 --- a/core/encoding/converter/replacement_spec.rb +++ b/core/encoding/converter/replacement_spec.rb @@ -46,7 +46,7 @@ it "raises an UndefinedConversionError is the argument cannot be converted into the destination encoding" do ec = Encoding::Converter.new("sjis", "ascii") utf8_q = "\u{986}".force_encoding('utf-8') - ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion + ec.primitive_convert(utf8_q.dup, +"").should == :undefined_conversion -> { ec.replacement = utf8_q }.should \ raise_error(Encoding::UndefinedConversionError) end @@ -54,7 +54,7 @@ it "does not change the replacement character if the argument cannot be converted into the destination encoding" do ec = Encoding::Converter.new("sjis", "ascii") utf8_q = "\u{986}".force_encoding('utf-8') - ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion + ec.primitive_convert(utf8_q.dup, +"").should == :undefined_conversion -> { ec.replacement = utf8_q }.should \ raise_error(Encoding::UndefinedConversionError) ec.replacement.should == "?".force_encoding('us-ascii') @@ -63,8 +63,8 @@ it "uses the replacement character" do ec = Encoding::Converter.new("utf-8", "us-ascii", :invalid => :replace, :undef => :replace) ec.replacement = "!" - dest = "" - status = ec.primitive_convert "中文123", dest + dest = +"" + status = ec.primitive_convert(+"中文123", dest) status.should == :finished dest.should == "!!123" diff --git a/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb b/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb index 94201a9b15..8a3f3de69a 100644 --- a/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb +++ b/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb @@ -8,7 +8,7 @@ it "returns true if #primitive_convert returned :incomplete_input for the same data" do ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") - ec.primitive_convert("\xA1",'').should == :incomplete_input + ec.primitive_convert(+"\xA1", +'').should == :incomplete_input begin ec.convert("\xA1") rescue Encoding::InvalidByteSequenceError => e @@ -18,7 +18,7 @@ it "returns false if #primitive_convert returned :invalid_byte_sequence for the same data" do ec = Encoding::Converter.new("ascii", "utf-8") - ec.primitive_convert("\xfffffffff",'').should == :invalid_byte_sequence + ec.primitive_convert(+"\xfffffffff", +'').should == :invalid_byte_sequence begin ec.convert("\xfffffffff") rescue Encoding::InvalidByteSequenceError => e diff --git a/core/file/shared/path.rb b/core/file/shared/path.rb index ee8109ba05..aa2a64cf25 100644 --- a/core/file/shared/path.rb +++ b/core/file/shared/path.rb @@ -1,7 +1,7 @@ describe :file_path, shared: true do before :each do - @name = "file_to_path" - @path = tmp(@name) + @path = tmp("file_to_path") + @name = File.basename(@path) touch @path end diff --git a/core/hash/assoc_spec.rb b/core/hash/assoc_spec.rb index 64442918d1..62b2a11b30 100644 --- a/core/hash/assoc_spec.rb +++ b/core/hash/assoc_spec.rb @@ -22,11 +22,11 @@ end it "only returns the first matching key-value pair for identity hashes" do - # Avoid literal String keys in Hash#[]= due to https://bugs.ruby-lang.org/issues/12855 + # Avoid literal String keys since string literals can be frozen and interned e.g. with --enable-frozen-string-literal h = {}.compare_by_identity - k1 = 'pear' + k1 = 'pear'.dup h[k1] = :red - k2 = 'pear' + k2 = 'pear'.dup h[k2] = :green h.size.should == 2 h.keys.grep(/pear/).size.should == 2 diff --git a/core/hash/compare_by_identity_spec.rb b/core/hash/compare_by_identity_spec.rb index 874cd46eb7..3804f04bf6 100644 --- a/core/hash/compare_by_identity_spec.rb +++ b/core/hash/compare_by_identity_spec.rb @@ -85,19 +85,21 @@ def o.hash; 123; end -> { @h.compare_by_identity }.should raise_error(FrozenError) end - # Behaviour confirmed in bug #1871 + # Behaviour confirmed in https://bugs.ruby-lang.org/issues/1871 it "persists over #dups" do - @idh['foo'] = :bar - @idh['foo'] = :glark + @idh['foo'.dup] = :bar + @idh['foo'.dup] = :glark @idh.dup.should == @idh @idh.dup.size.should == @idh.size + @idh.dup.should.compare_by_identity? end it "persists over #clones" do - @idh['foo'] = :bar - @idh['foo'] = :glark + @idh['foo'.dup] = :bar + @idh['foo'.dup] = :glark @idh.clone.should == @idh @idh.clone.size.should == @idh.size + @idh.dup.should.compare_by_identity? end it "does not copy string keys" do @@ -109,8 +111,11 @@ def o.hash; 123; end end it "gives different identity for string literals" do + eval <<~RUBY + # frozen_string_literal: false @idh['foo'] = 1 @idh['foo'] = 2 + RUBY @idh.values.should == [1, 2] @idh.size.should == 2 end diff --git a/core/hash/element_reference_spec.rb b/core/hash/element_reference_spec.rb index e271f37ea6..94e8237839 100644 --- a/core/hash/element_reference_spec.rb +++ b/core/hash/element_reference_spec.rb @@ -30,7 +30,7 @@ end it "does not create copies of the immediate default value" do - str = "foo" + str = +"foo" h = Hash.new(str) a = h[:a] b = h[:b] diff --git a/core/hash/shared/store.rb b/core/hash/shared/store.rb index b823ea45ca..dd1bb52bac 100644 --- a/core/hash/shared/store.rb +++ b/core/hash/shared/store.rb @@ -9,7 +9,7 @@ it "duplicates string keys using dup semantics" do # dup doesn't copy singleton methods - key = "foo" + key = +"foo" def key.reverse() "bar" end h = {} h.send(@method, key, 0) @@ -44,7 +44,7 @@ def key.reverse() "bar" end end it "duplicates and freezes string keys" do - key = "foo" + key = +"foo" h = {} h.send(@method, key, 0) key << "bar" @@ -75,8 +75,8 @@ def key.reverse() "bar" end it "keeps the existing String key in the hash if there is a matching one" do h = { "a" => 1, "b" => 2, "c" => 3, "d" => 4 } - key1 = "foo" - key2 = "foo" + key1 = "foo".dup + key2 = "foo".dup key1.should_not equal(key2) h[key1] = 41 frozen_key = h.keys.last diff --git a/core/hash/shared/to_s.rb b/core/hash/shared/to_s.rb index 2db3a96583..7864d7cd4c 100644 --- a/core/hash/shared/to_s.rb +++ b/core/hash/shared/to_s.rb @@ -24,7 +24,7 @@ end it "does not call #to_s on a String returned from #inspect" do - str = "abc" + str = +"abc" str.should_not_receive(:to_s) { a: str }.send(@method).should == '{:a=>"abc"}' @@ -78,7 +78,7 @@ it "does not raise if inspected result is not default external encoding" do utf_16be = mock("utf_16be") - utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE)) + utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE)) {a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}' end diff --git a/core/io/ioctl_spec.rb b/core/io/ioctl_spec.rb index 8dcd9eb2c6..3f7b5ad5d7 100644 --- a/core/io/ioctl_spec.rb +++ b/core/io/ioctl_spec.rb @@ -12,7 +12,7 @@ guard -> { RUBY_PLATFORM.include?("86") } do # x86 / x86_64 it "resizes an empty String to match the output size" do File.open(__FILE__, 'r') do |f| - buffer = '' + buffer = +'' # FIONREAD in /usr/include/asm-generic/ioctls.h f.ioctl 0x541B, buffer buffer.unpack('I').first.should be_kind_of(Integer) diff --git a/core/io/pread_spec.rb b/core/io/pread_spec.rb index aa496ee803..28afc80e5c 100644 --- a/core/io/pread_spec.rb +++ b/core/io/pread_spec.rb @@ -21,19 +21,19 @@ end it "accepts a length, an offset, and an output buffer" do - buffer = "foo" + buffer = +"foo" @file.pread(3, 4, buffer) buffer.should == "567" end it "shrinks the buffer in case of less bytes read" do - buffer = "foo" + buffer = +"foo" @file.pread(1, 0, buffer) buffer.should == "1" end it "grows the buffer in case of more bytes read" do - buffer = "foo" + buffer = +"foo" @file.pread(5, 0, buffer) buffer.should == "12345" end @@ -57,7 +57,7 @@ end it "does not reset the buffer when reading with maxlen = 0" do - buffer = "foo" + buffer = +"foo" @file.pread(0, 4, buffer) buffer.should == "foo" @@ -79,7 +79,7 @@ it "converts a buffer to String using to_str" do buffer = mock('buffer') - buffer.should_receive(:to_str).at_least(1).and_return("foo") + buffer.should_receive(:to_str).at_least(1).and_return(+"foo") @file.pread(4, 0, buffer) buffer.should_not.is_a?(String) buffer.to_str.should == "1234" diff --git a/core/io/puts_spec.rb b/core/io/puts_spec.rb index 9a708fffef..9ed343c94c 100644 --- a/core/io/puts_spec.rb +++ b/core/io/puts_spec.rb @@ -6,7 +6,7 @@ @before_separator = $/ @name = tmp("io_puts.txt") @io = new_io @name - ScratchPad.record "" + ScratchPad.record(+"") def @io.write(str) ScratchPad << str end diff --git a/core/io/read_nonblock_spec.rb b/core/io/read_nonblock_spec.rb index a62b75274c..51e7cd6bd2 100644 --- a/core/io/read_nonblock_spec.rb +++ b/core/io/read_nonblock_spec.rb @@ -96,21 +96,21 @@ end it "reads into the passed buffer" do - buffer = "" + buffer = +"" @write.write("1") @read.read_nonblock(1, buffer) buffer.should == "1" end it "returns the passed buffer" do - buffer = "" + buffer = +"" @write.write("1") output = @read.read_nonblock(1, buffer) output.should equal(buffer) end it "discards the existing buffer content upon successful read" do - buffer = "existing content" + buffer = +"existing content" @write.write("hello world") @write.close @read.read_nonblock(11, buffer) @@ -118,7 +118,7 @@ end it "discards the existing buffer content upon error" do - buffer = "existing content" + buffer = +"existing content" @write.close -> { @read.read_nonblock(1, buffer) }.should raise_error(EOFError) buffer.should be_empty diff --git a/core/io/read_spec.rb b/core/io/read_spec.rb index b37c6c7121..40cbc52dcf 100644 --- a/core/io/read_spec.rb +++ b/core/io/read_spec.rb @@ -294,19 +294,19 @@ it "clears the output buffer if there is nothing to read" do @io.pos = 10 - buf = 'non-empty string' + buf = +'non-empty string' @io.read(10, buf).should == nil buf.should == '' - buf = 'non-empty string' + buf = +'non-empty string' @io.read(nil, buf).should == "" buf.should == '' - buf = 'non-empty string' + buf = +'non-empty string' @io.read(0, buf).should == "" @@ -344,53 +344,53 @@ end it "places the specified number of bytes in the buffer" do - buf = "" + buf = +"" @io.read 5, buf buf.should == "12345" end it "expands the buffer when too small" do - buf = "ABCDE" + buf = +"ABCDE" @io.read nil, buf buf.should == @contents end it "overwrites the buffer" do - buf = "ABCDEFGHIJ" + buf = +"ABCDEFGHIJ" @io.read nil, buf buf.should == @contents end it "truncates the buffer when too big" do - buf = "ABCDEFGHIJKLMNO" + buf = +"ABCDEFGHIJKLMNO" @io.read nil, buf buf.should == @contents @io.rewind - buf = "ABCDEFGHIJKLMNO" + buf = +"ABCDEFGHIJKLMNO" @io.read 5, buf buf.should == @contents[0..4] end it "returns the given buffer" do - buf = "" + buf = +"" @io.read(nil, buf).should equal buf end it "returns the given buffer when there is nothing to read" do - buf = "" + buf = +"" @io.read @io.read(nil, buf).should equal buf end it "coerces the second argument to string and uses it as a buffer" do - buf = "ABCDE" + buf = +"ABCDE" obj = mock("buff") obj.should_receive(:to_str).any_number_of_times.and_return(buf) @@ -588,7 +588,7 @@ describe "when passed nil for limit" do it "sets the buffer to a transcoded String" do - result = @io.read(nil, buf = "") + result = @io.read(nil, buf = +"") buf.should equal(result) buf.should == "ありがとう\n" end diff --git a/core/io/readpartial_spec.rb b/core/io/readpartial_spec.rb index 2901b429c2..0060beb545 100644 --- a/core/io/readpartial_spec.rb +++ b/core/io/readpartial_spec.rb @@ -59,7 +59,7 @@ end it "discards the existing buffer content upon successful read" do - buffer = "existing content" + buffer = +"existing content" @wr.write("hello world") @wr.close @rd.readpartial(11, buffer) @@ -74,7 +74,7 @@ end it "discards the existing buffer content upon error" do - buffer = 'hello' + buffer = +'hello' @wr.close -> { @rd.readpartial(1, buffer) }.should raise_error(EOFError) buffer.should be_empty @@ -95,7 +95,7 @@ ruby_bug "#18421", ""..."3.0.4" do it "clears and returns the given buffer if the length argument is 0" do - buffer = "existing content" + buffer = +"existing content" @rd.readpartial(0, buffer).should == buffer buffer.should == "" end diff --git a/core/io/sysread_spec.rb b/core/io/sysread_spec.rb index e7f63cefec..003bb9eb94 100644 --- a/core/io/sysread_spec.rb +++ b/core/io/sysread_spec.rb @@ -21,25 +21,25 @@ end it "reads the specified number of bytes from the file to the buffer" do - buf = "" # empty buffer + buf = +"" # empty buffer @file.sysread(15, buf).should == buf buf.should == "012345678901234" @file.rewind - buf = "ABCDE" # small buffer + buf = +"ABCDE" # small buffer @file.sysread(15, buf).should == buf buf.should == "012345678901234" @file.rewind - buf = "ABCDE" * 5 # large buffer + buf = +"ABCDE" * 5 # large buffer @file.sysread(15, buf).should == buf buf.should == "012345678901234" end it "coerces the second argument to string and uses it as a buffer" do - buf = "ABCDE" + buf = +"ABCDE" (obj = mock("buff")).should_receive(:to_str).any_number_of_times.and_return(buf) @file.sysread(15, obj).should == buf buf.should == "012345678901234" @@ -90,19 +90,19 @@ end it "immediately returns the given buffer if the length argument is 0" do - buffer = "existing content" + buffer = +"existing content" @file.sysread(0, buffer).should == buffer buffer.should == "existing content" end it "discards the existing buffer content upon successful read" do - buffer = "existing content" + buffer = +"existing content" @file.sysread(11, buffer) buffer.should == "01234567890" end it "discards the existing buffer content upon error" do - buffer = "existing content" + buffer = +"existing content" @file.seek(0, :END) -> { @file.sysread(1, buffer) }.should raise_error(EOFError) buffer.should be_empty diff --git a/core/kernel/Float_spec.rb b/core/kernel/Float_spec.rb index 015bcb33d6..0f83cb5824 100644 --- a/core/kernel/Float_spec.rb +++ b/core/kernel/Float_spec.rb @@ -41,7 +41,7 @@ end it "converts Strings to floats without calling #to_f" do - string = "10" + string = +"10" string.should_not_receive(:to_f) @object.send(:Float, string).should == 10.0 end diff --git a/core/kernel/String_spec.rb b/core/kernel/String_spec.rb index 47ee797be5..7caec6eda5 100644 --- a/core/kernel/String_spec.rb +++ b/core/kernel/String_spec.rb @@ -78,7 +78,7 @@ def method_missing(meth, *args) end it "returns the same object if it is already a String" do - string = "Hello" + string = +"Hello" string.should_not_receive(:to_s) string2 = @object.send(@method, string) string.should equal(string2) diff --git a/core/kernel/catch_spec.rb b/core/kernel/catch_spec.rb index 4060172429..9f59d3b384 100644 --- a/core/kernel/catch_spec.rb +++ b/core/kernel/catch_spec.rb @@ -35,7 +35,7 @@ end it "raises an ArgumentError if a String with different identity is thrown" do - -> { catch("exit") { throw "exit" } }.should raise_error(ArgumentError) + -> { catch("exit".dup) { throw "exit".dup } }.should raise_error(ArgumentError) end it "catches a Symbol when thrown a matching Symbol" do diff --git a/core/kernel/class_spec.rb b/core/kernel/class_spec.rb index 2725bde19b..b1d9df1671 100644 --- a/core/kernel/class_spec.rb +++ b/core/kernel/class_spec.rb @@ -19,7 +19,7 @@ end it "returns the first non-singleton class" do - a = "hello" + a = +"hello" def a.my_singleton_method; end a.class.should equal(String) end diff --git a/core/kernel/eval_spec.rb b/core/kernel/eval_spec.rb index cf3cd47a43..15c9d511fc 100644 --- a/core/kernel/eval_spec.rb +++ b/core/kernel/eval_spec.rb @@ -350,9 +350,6 @@ class EvalSpecs end it "allows a magic encoding comment and a subsequent frozen_string_literal magic comment" do - # Make sure frozen_string_literal is not default true - eval("'foo'".b).frozen?.should be_false - code = < { eval(code) }.should complain(/warning: [`']frozen_string_literal' is ignored after any tokens/, verbose: true) - EvalSpecs::Vπstring_not_frozen.frozen?.should be_false + EvalSpecs::Vπstring_not_frozen.frozen?.should == default_frozen_string_literal EvalSpecs.send :remove_const, :Vπstring_not_frozen -> { eval(code) }.should_not complain(verbose: false) - EvalSpecs::Vπstring_not_frozen.frozen?.should be_false + EvalSpecs::Vπstring_not_frozen.frozen?.should == default_frozen_string_literal EvalSpecs.send :remove_const, :Vπstring_not_frozen end end diff --git a/core/marshal/dump_spec.rb b/core/marshal/dump_spec.rb index 34db6fef83..1e606e0c19 100644 --- a/core/marshal/dump_spec.rb +++ b/core/marshal/dump_spec.rb @@ -150,7 +150,7 @@ it "indexes instance variables of a String returned by #_dump at first and then indexes the object itself" do class MarshalSpec::M1::A def _dump(level) - s = "" + s = +"" s.instance_variable_set(:@foo, "bar") s end @@ -297,7 +297,7 @@ def _dump(level) end it "dumps a String extended with a Module" do - Marshal.dump("".extend(Meths).force_encoding("binary")).should == "\004\be:\nMeths\"\000" + Marshal.dump("".dup.extend(Meths).force_encoding("binary")).should == "\004\be:\nMeths\"\000" end it "dumps a String subclass" do @@ -314,7 +314,7 @@ def _dump(level) end it "dumps a String with instance variables" do - str = "" + str = +"" str.instance_variable_set("@foo", "bar") Marshal.dump(str.force_encoding("binary")).should == "\x04\bI\"\x00\x06:\t@foo\"\bbar" end diff --git a/core/marshal/fixtures/marshal_data.rb b/core/marshal/fixtures/marshal_data.rb index 680cb08ac7..a508b6bea1 100644 --- a/core/marshal/fixtures/marshal_data.rb +++ b/core/marshal/fixtures/marshal_data.rb @@ -38,7 +38,7 @@ class UserDefinedWithIvar attr_reader :a, :b, :c def initialize - @a = 'stuff' + @a = +'stuff' @a.instance_variable_set :@foo, :UserDefinedWithIvar @b = 'more' @c = @b @@ -267,7 +267,7 @@ def self.name end end - module_eval(<<~ruby.force_encoding(Encoding::UTF_8)) + module_eval(<<~ruby.dup.force_encoding(Encoding::UTF_8)) class MultibyteぁあぃいClass end @@ -313,7 +313,7 @@ class ObjectWithoutFreeze < Object "\004\b\"\012small"], "String big" => ['big' * 100, "\004\b\"\002,\001#{'big' * 100}"], - "String extended" => [''.extend(Meths), # TODO: check for module on load + "String extended" => [''.dup.extend(Meths), # TODO: check for module on load "\004\be:\nMeths\"\000"], "String subclass" => [UserString.new, "\004\bC:\017UserString\"\000"], @@ -420,7 +420,7 @@ class ObjectWithoutFreeze < Object "\x04\bI\"\nsmall\x06:\x06EF"], "String big" => ['big' * 100, "\x04\bI\"\x02,\x01bigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbig\x06:\x06EF"], - "String extended" => [''.extend(Meths), # TODO: check for module on load + "String extended" => [''.dup.extend(Meths), # TODO: check for module on load "\x04\bIe:\nMeths\"\x00\x06:\x06EF"], "String subclass" => [UserString.new, "\004\bC:\017UserString\"\000"], diff --git a/core/marshal/shared/load.rb b/core/marshal/shared/load.rb index b70fb7a974..963e8a7ec2 100644 --- a/core/marshal/shared/load.rb +++ b/core/marshal/shared/load.rb @@ -183,7 +183,7 @@ describe "when called with a proc" do it "call the proc with frozen objects" do arr = [] - s = 'hi' + s = +'hi' s.instance_variable_set(:@foo, 5) st = Struct.new("Brittle", :a).new st.instance_variable_set(:@clue, 'none') @@ -268,7 +268,7 @@ it "loads an Array with proc" do arr = [] - s = 'hi' + s = +'hi' s.instance_variable_set(:@foo, 5) st = Struct.new("Brittle", :a).new st.instance_variable_set(:@clue, 'none') @@ -413,13 +413,13 @@ end it "raises a TypeError with bad Marshal version" do - marshal_data = '\xff\xff' + marshal_data = +'\xff\xff' marshal_data[0] = (Marshal::MAJOR_VERSION).chr marshal_data[1] = (Marshal::MINOR_VERSION + 1).chr -> { Marshal.send(@method, marshal_data) }.should raise_error(TypeError) - marshal_data = '\xff\xff' + marshal_data = +'\xff\xff' marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr marshal_data[1] = (Marshal::MINOR_VERSION).chr @@ -470,7 +470,7 @@ end it "loads an array having ivar" do - s = 'well' + s = +'well' s.instance_variable_set(:@foo, 10) obj = ['5', s, 'hi'].extend(Meths, MethsMore) obj.instance_variable_set(:@mix, s) @@ -516,7 +516,7 @@ end it "preserves hash ivars when hash contains a string having ivar" do - s = 'string' + s = +'string' s.instance_variable_set :@string_ivar, 'string ivar' h = { key: s } h.instance_variable_set :@hash_ivar, 'hash ivar' @@ -635,7 +635,7 @@ describe "for a String" do it "loads a string having ivar with ref to self" do - obj = 'hi' + obj = +'hi' obj.instance_variable_set(:@self, obj) Marshal.send(@method, "\004\bI\"\ahi\006:\n@self@\000").should == obj end @@ -647,7 +647,7 @@ end it "sets binmode if it is loading through StringIO stream" do - io = StringIO.new("\004\b:\vsymbol") + io = StringIO.new(+"\004\b:\vsymbol") def io.binmode; raise "binmode"; end -> { Marshal.load(io) }.should raise_error(RuntimeError, "binmode") end diff --git a/core/matchdata/string_spec.rb b/core/matchdata/string_spec.rb index 420233e1f3..952e953318 100644 --- a/core/matchdata/string_spec.rb +++ b/core/matchdata/string_spec.rb @@ -17,8 +17,9 @@ md.string.should equal(md.string) end - it "returns a frozen copy of the matched string for gsub(String)" do - 'he[[o'.gsub!('[', ']') + it "returns a frozen copy of the matched string for gsub!(String)" do + s = +'he[[o' + s.gsub!('[', ']') $~.string.should == 'he[[o' $~.string.should.frozen? end diff --git a/core/method/to_proc_spec.rb b/core/method/to_proc_spec.rb index 29b7bec2b3..4993cce239 100644 --- a/core/method/to_proc_spec.rb +++ b/core/method/to_proc_spec.rb @@ -35,7 +35,7 @@ end it "returns a proc that can be used by define_method" do - x = 'test' + x = +'test' to_s = class << x define_method :foo, method(:to_s).to_proc to_s diff --git a/core/module/using_spec.rb b/core/module/using_spec.rb index 4781b99bb7..a908363c96 100644 --- a/core/module/using_spec.rb +++ b/core/module/using_spec.rb @@ -316,7 +316,7 @@ def foo; "foo from refinement"; end using refinement def initialize - @a = "1703" + @a = +"1703" @a.instance_eval do def abc diff --git a/core/objectspace/define_finalizer_spec.rb b/core/objectspace/define_finalizer_spec.rb index 6be83e518e..effecc41d0 100644 --- a/core/objectspace/define_finalizer_spec.rb +++ b/core/objectspace/define_finalizer_spec.rb @@ -52,7 +52,7 @@ def scoped Proc.new { puts "finalizer run" } end handler = scoped - obj = "Test" + obj = +"Test" ObjectSpace.define_finalizer(obj, handler) exit 0 RUBY @@ -111,7 +111,7 @@ def initialize it "calls a finalizer at exit even if it is self-referencing" do code = <<-RUBY - obj = "Test" + obj = +"Test" handler = Proc.new { puts "finalizer run" } ObjectSpace.define_finalizer(obj, handler) exit 0 @@ -141,9 +141,9 @@ def finalizer(zelf) it "calls a finalizer defined in a finalizer running at exit" do code = <<-RUBY - obj = "Test" + obj = +"Test" handler = Proc.new do - obj2 = "Test" + obj2 = +"Test" handler2 = Proc.new { puts "finalizer 2 run" } ObjectSpace.define_finalizer(obj2, handler2) exit 0 diff --git a/core/proc/fixtures/proc_aref.rb b/core/proc/fixtures/proc_aref.rb index a305667797..8ee355b14c 100644 --- a/core/proc/fixtures/proc_aref.rb +++ b/core/proc/fixtures/proc_aref.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false module ProcArefSpecs def self.aref proc {|a| a }["sometext"] diff --git a/core/string/ascii_only_spec.rb b/core/string/ascii_only_spec.rb index c7e02fd874..d5d24d533e 100644 --- a/core/string/ascii_only_spec.rb +++ b/core/string/ascii_only_spec.rb @@ -60,8 +60,7 @@ end it "returns false when interpolating non ascii strings" do - base = "EU currency is" - base.force_encoding(Encoding::US_ASCII) + base = "EU currency is".force_encoding(Encoding::US_ASCII) euro = "\u20AC" interp = "#{base} #{euro}" euro.ascii_only?.should be_false @@ -70,14 +69,14 @@ end it "returns false after appending non ASCII characters to an empty String" do - ("" << "λ").ascii_only?.should be_false + ("".dup << "λ").ascii_only?.should be_false end it "returns false when concatenating an ASCII and non-ASCII String" do - "".concat("λ").ascii_only?.should be_false + "".dup.concat("λ").ascii_only?.should be_false end it "returns false when replacing an ASCII String with a non-ASCII String" do - "".replace("λ").ascii_only?.should be_false + "".dup.replace("λ").ascii_only?.should be_false end end diff --git a/core/string/b_spec.rb b/core/string/b_spec.rb index 37c7994700..4b1fafff11 100644 --- a/core/string/b_spec.rb +++ b/core/string/b_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#b" do diff --git a/core/string/bytes_spec.rb b/core/string/bytes_spec.rb index 859b346550..02151eebbc 100644 --- a/core/string/bytes_spec.rb +++ b/core/string/bytes_spec.rb @@ -50,6 +50,6 @@ end it "is unaffected by #force_encoding" do - @utf8.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a + @utf8.dup.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a end end diff --git a/core/string/bytesplice_spec.rb b/core/string/bytesplice_spec.rb index f13024a79b..967edcba29 100644 --- a/core/string/bytesplice_spec.rb +++ b/core/string/bytesplice_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#bytesplice" do diff --git a/core/string/capitalize_spec.rb b/core/string/capitalize_spec.rb index b79e9cfdbd..5e59b656c5 100644 --- a/core/string/capitalize_spec.rb +++ b/core/string/capitalize_spec.rb @@ -90,7 +90,7 @@ describe "String#capitalize!" do it "capitalizes self in place" do - a = "hello" + a = +"hello" a.capitalize!.should equal(a) a.should == "Hello" end @@ -103,13 +103,13 @@ describe "full Unicode case mapping" do it "modifies self in place for all of Unicode with no option" do - a = "äöÜ" + a = +"äöÜ" a.capitalize! a.should == "Äöü" end it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do - a = "ß" + a = +"ß" a.capitalize! a.should == "Ss" end @@ -121,7 +121,7 @@ end it "updates string metadata" do - capitalized = "ßeT" + capitalized = +"ßeT" capitalized.capitalize! capitalized.should == "Sset" @@ -133,7 +133,7 @@ describe "modifies self in place for ASCII-only case mapping" do it "does not capitalize non-ASCII characters" do - a = "ßet" + a = +"ßet" a.capitalize!(:ascii) a.should == "ßet" end @@ -147,13 +147,13 @@ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do it "capitalizes ASCII characters according to Turkic semantics" do - a = "iSa" + a = +"iSa" a.capitalize!(:turkic) a.should == "İsa" end it "allows Lithuanian as an extra option" do - a = "iSa" + a = +"iSa" a.capitalize!(:turkic, :lithuanian) a.should == "İsa" end @@ -165,13 +165,13 @@ describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do it "currently works the same as full Unicode case mapping" do - a = "iß" + a = +"iß" a.capitalize!(:lithuanian) a.should == "Iß" end it "allows Turkic as an extra option (and applies Turkic semantics)" do - a = "iß" + a = +"iß" a.capitalize!(:lithuanian, :turkic) a.should == "İß" end @@ -190,12 +190,12 @@ end it "returns nil when no changes are made" do - a = "Hello" + a = +"Hello" a.capitalize!.should == nil a.should == "Hello" - "".capitalize!.should == nil - "H".capitalize!.should == nil + (+"").capitalize!.should == nil + (+"H").capitalize!.should == nil end it "raises a FrozenError when self is frozen" do diff --git a/core/string/chomp_spec.rb b/core/string/chomp_spec.rb index ec0490220b..d27c84c6f6 100644 --- a/core/string/chomp_spec.rb +++ b/core/string/chomp_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/chop_spec.rb b/core/string/chop_spec.rb index 75f25b39cd..99c2c82190 100644 --- a/core/string/chop_spec.rb +++ b/core/string/chop_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/clear_spec.rb b/core/string/clear_spec.rb index e1d68e03bd..152986fd0f 100644 --- a/core/string/clear_spec.rb +++ b/core/string/clear_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#clear" do diff --git a/core/string/concat_spec.rb b/core/string/concat_spec.rb index 6f487eaa3a..cbd7df54e2 100644 --- a/core/string/concat_spec.rb +++ b/core/string/concat_spec.rb @@ -8,19 +8,19 @@ it_behaves_like :string_concat_type_coercion, :concat it "takes multiple arguments" do - str = "hello " + str = +"hello " str.concat "wo", "", "rld" str.should == "hello world" end it "concatenates the initial value when given arguments contain 2 self" do - str = "hello" + str = +"hello" str.concat str, str str.should == "hellohellohello" end it "returns self when given no arguments" do - str = "hello" + str = +"hello" str.concat.should equal(str) str.should == "hello" end diff --git a/core/string/delete_prefix_spec.rb b/core/string/delete_prefix_spec.rb index 4214fdecce..ee7f044905 100644 --- a/core/string/delete_prefix_spec.rb +++ b/core/string/delete_prefix_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/delete_spec.rb b/core/string/delete_spec.rb index 3b9aa4fb75..6d359776e4 100644 --- a/core/string/delete_spec.rb +++ b/core/string/delete_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/delete_suffix_spec.rb b/core/string/delete_suffix_spec.rb index 9381f4cee7..1842d75aa5 100644 --- a/core/string/delete_suffix_spec.rb +++ b/core/string/delete_suffix_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/downcase_spec.rb b/core/string/downcase_spec.rb index 7ee9d6df1d..2d260f23f1 100644 --- a/core/string/downcase_spec.rb +++ b/core/string/downcase_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/dup_spec.rb b/core/string/dup_spec.rb index 73f71b8ffc..073802d84b 100644 --- a/core/string/dup_spec.rb +++ b/core/string/dup_spec.rb @@ -51,7 +51,7 @@ class << @obj end it "does not modify the original setbyte-mutated string when changing dupped string" do - orig = "a" + orig = +"a" orig.setbyte 0, "b".ord copy = orig.dup orig.setbyte 0, "c".ord diff --git a/core/string/each_byte_spec.rb b/core/string/each_byte_spec.rb index e04dca807f..7b3db265ac 100644 --- a/core/string/each_byte_spec.rb +++ b/core/string/each_byte_spec.rb @@ -9,26 +9,26 @@ end it "keeps iterating from the old position (to new string end) when self changes" do - r = "" - s = "hello world" + r = +"" + s = +"hello world" s.each_byte do |c| r << c s.insert(0, "<>") if r.size < 3 end r.should == "h><>hello world" - r = "" - s = "hello world" + r = +"" + s = +"hello world" s.each_byte { |c| s.slice!(-1); r << c } r.should == "hello " - r = "" - s = "hello world" + r = +"" + s = +"hello world" s.each_byte { |c| s.slice!(0); r << c } r.should == "hlowrd" - r = "" - s = "hello world" + r = +"" + s = +"hello world" s.each_byte { |c| s.slice!(0..-1); r << c } r.should == "h" end diff --git a/core/string/element_set_spec.rb b/core/string/element_set_spec.rb index fa041fa31d..e7599f832c 100644 --- a/core/string/element_set_spec.rb +++ b/core/string/element_set_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/encode_spec.rb b/core/string/encode_spec.rb index 35ed27bb40..1a4b3f0689 100644 --- a/core/string/encode_spec.rb +++ b/core/string/encode_spec.rb @@ -122,8 +122,7 @@ describe "when passed to, from" do it "returns a copy in the destination encoding when both encodings are the same" do - str = "あ" - str.force_encoding("binary") + str = "あ".force_encoding("binary") encoded = str.encode("utf-8", "utf-8") encoded.should_not equal(str) @@ -155,8 +154,7 @@ end it "returns a copy in the destination encoding when both encodings are the same" do - str = "あ" - str.force_encoding("binary") + str = "あ".force_encoding("binary") encoded = str.encode("utf-8", "utf-8", invalid: :replace) encoded.should_not equal(str) @@ -191,13 +189,13 @@ describe "when passed no options" do it "returns self when Encoding.default_internal is nil" do Encoding.default_internal = nil - str = "あ" + str = +"あ" str.encode!.should equal(str) end it "returns self for a ASCII-only String when Encoding.default_internal is nil" do Encoding.default_internal = nil - str = "abc" + str = +"abc" str.encode!.should equal(str) end end @@ -205,14 +203,14 @@ describe "when passed options" do it "returns self for ASCII-only String when Encoding.default_internal is nil" do Encoding.default_internal = nil - str = "abc" + str = +"abc" str.encode!(invalid: :replace).should equal(str) end end describe "when passed to encoding" do it "returns self" do - str = "abc" + str = +"abc" result = str.encode!(Encoding::BINARY) result.encoding.should equal(Encoding::BINARY) result.should equal(str) @@ -221,7 +219,7 @@ describe "when passed to, from" do it "returns self" do - str = "ああ" + str = +"ああ" result = str.encode!("euc-jp", "utf-8") result.encoding.should equal(Encoding::EUC_JP) result.should equal(str) diff --git a/core/string/encoding_spec.rb b/core/string/encoding_spec.rb index 574a1e2f92..ea431212aa 100644 --- a/core/string/encoding_spec.rb +++ b/core/string/encoding_spec.rb @@ -18,7 +18,7 @@ end it "returns the given encoding if #encode!has been called" do - "a".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS + "a".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS end end @@ -113,8 +113,8 @@ end it "returns the given encoding if #encode!has been called" do - "\u{20}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS - "\u{2020}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS + "\u{20}".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS + "\u{2020}".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS end end @@ -173,16 +173,12 @@ end it "returns the given encoding if #force_encoding has been called" do - x50 = "\x50" - x50.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS - xD4 = [212].pack('C') - xD4.force_encoding(Encoding::ISO_8859_9).encoding.should == Encoding::ISO_8859_9 + "\x50".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS + [212].pack('C').force_encoding(Encoding::ISO_8859_9).encoding.should == Encoding::ISO_8859_9 end it "returns the given encoding if #encode!has been called" do - x50 = "\x50" - x50.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS - x00 = "x\00" - x00.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8 + "\x50".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS + "x\00".dup.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8 end end diff --git a/core/string/force_encoding_spec.rb b/core/string/force_encoding_spec.rb index f37aaf9eb4..2259dcf3cf 100644 --- a/core/string/force_encoding_spec.rb +++ b/core/string/force_encoding_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#force_encoding" do diff --git a/core/string/freeze_spec.rb b/core/string/freeze_spec.rb index 04d1e9513c..2e8e70386d 100644 --- a/core/string/freeze_spec.rb +++ b/core/string/freeze_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#freeze" do diff --git a/core/string/gsub_spec.rb b/core/string/gsub_spec.rb index 9e3b50322c..0d9f32eca2 100644 --- a/core/string/gsub_spec.rb +++ b/core/string/gsub_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/insert_spec.rb b/core/string/insert_spec.rb index 0c87df3a95..483f3c9367 100644 --- a/core/string/insert_spec.rb +++ b/core/string/insert_spec.rb @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- - +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/lstrip_spec.rb b/core/string/lstrip_spec.rb index 85685deb0a..99bab6f349 100644 --- a/core/string/lstrip_spec.rb +++ b/core/string/lstrip_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/strip' diff --git a/core/string/prepend_spec.rb b/core/string/prepend_spec.rb index a0393d4760..5248ea8056 100644 --- a/core/string/prepend_spec.rb +++ b/core/string/prepend_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/reverse_spec.rb b/core/string/reverse_spec.rb index e67122c05c..aa6abe6036 100644 --- a/core/string/reverse_spec.rb +++ b/core/string/reverse_spec.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/rstrip_spec.rb b/core/string/rstrip_spec.rb index e4cf93315e..6d46eb590e 100644 --- a/core/string/rstrip_spec.rb +++ b/core/string/rstrip_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/strip' diff --git a/core/string/scrub_spec.rb b/core/string/scrub_spec.rb index bcee4db463..b9ef0f1a16 100644 --- a/core/string/scrub_spec.rb +++ b/core/string/scrub_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/setbyte_spec.rb b/core/string/setbyte_spec.rb index 77bff64038..85403ca62c 100644 --- a/core/string/setbyte_spec.rb +++ b/core/string/setbyte_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#setbyte" do diff --git a/core/string/shared/chars.rb b/core/string/shared/chars.rb index e9fdf89fd6..4ccd230d75 100644 --- a/core/string/shared/chars.rb +++ b/core/string/shared/chars.rb @@ -46,7 +46,7 @@ end it "uses the String's encoding to determine what characters it contains" do - s = "\u{24B62}" + s = +"\u{24B62}" s.force_encoding('UTF-8').send(@method).to_a.should == [ s.force_encoding('UTF-8') diff --git a/core/string/shared/codepoints.rb b/core/string/shared/codepoints.rb index 0b2e078e0a..9a1df3d6fc 100644 --- a/core/string/shared/codepoints.rb +++ b/core/string/shared/codepoints.rb @@ -49,7 +49,7 @@ it "round-trips to the original String using Integer#chr" do s = "\u{13}\u{7711}\u{1010}" - s2 = "" + s2 = +"" s.send(@method) {|n| s2 << n.chr(Encoding::UTF_8)} s.should == s2 end diff --git a/core/string/shared/concat.rb b/core/string/shared/concat.rb index ee5ef2a98f..dded9a69e7 100644 --- a/core/string/shared/concat.rb +++ b/core/string/shared/concat.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false describe :string_concat, shared: true do it "concatenates the given argument to self and returns self" do str = 'hello ' diff --git a/core/string/shared/dedup.rb b/core/string/shared/dedup.rb index 893fd1e360..97b5df6ed1 100644 --- a/core/string/shared/dedup.rb +++ b/core/string/shared/dedup.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false describe :string_dedup, shared: true do it 'returns self if the String is frozen' do input = 'foo'.freeze diff --git a/core/string/shared/each_line.rb b/core/string/shared/each_line.rb index a14b4d7779..231a6d9d4f 100644 --- a/core/string/shared/each_line.rb +++ b/core/string/shared/each_line.rb @@ -106,7 +106,7 @@ end it "does not care if the string is modified while substituting" do - str = "hello\nworld." + str = +"hello\nworld." out = [] str.send(@method){|x| out << x; str[-1] = '!' }.should == "hello\nworld!" out.should == ["hello\n", "world."] diff --git a/core/string/shared/encode.rb b/core/string/shared/encode.rb index a73de5b943..3776e0d709 100644 --- a/core/string/shared/encode.rb +++ b/core/string/shared/encode.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false describe :string_encode, shared: true do describe "when passed no options" do it "transcodes to Encoding.default_internal when set" do diff --git a/core/string/shared/length.rb b/core/string/shared/length.rb index 94e5ec135b..4e3d69a974 100644 --- a/core/string/shared/length.rb +++ b/core/string/shared/length.rb @@ -18,7 +18,7 @@ end it "returns the length of the new self after encoding is changed" do - str = 'こにちわ' + str = +'こにちわ' str.send(@method) str.force_encoding('BINARY').send(@method).should == 12 diff --git a/core/string/shared/replace.rb b/core/string/shared/replace.rb index a5108d9e7c..24dac0eb27 100644 --- a/core/string/shared/replace.rb +++ b/core/string/shared/replace.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false describe :string_replace, shared: true do it "returns self" do a = "a" diff --git a/core/string/shared/succ.rb b/core/string/shared/succ.rb index 24a729ce26..b69a394875 100644 --- a/core/string/shared/succ.rb +++ b/core/string/shared/succ.rb @@ -73,6 +73,7 @@ describe :string_succ_bang, shared: true do it "is equivalent to succ, but modifies self in place (still returns self)" do ["", "abcd", "THX1138"].each do |s| + s = +s r = s.dup.send(@method) s.send(@method).should equal(s) s.should == r diff --git a/core/string/shared/to_sym.rb b/core/string/shared/to_sym.rb index 52d8314211..833eae100e 100644 --- a/core/string/shared/to_sym.rb +++ b/core/string/shared/to_sym.rb @@ -56,9 +56,9 @@ it "ignores existing symbols with different encoding" do source = "fée" - iso_symbol = source.force_encoding(Encoding::ISO_8859_1).send(@method) + iso_symbol = source.dup.force_encoding(Encoding::ISO_8859_1).send(@method) iso_symbol.encoding.should == Encoding::ISO_8859_1 - binary_symbol = source.force_encoding(Encoding::BINARY).send(@method) + binary_symbol = source.dup.force_encoding(Encoding::BINARY).send(@method) binary_symbol.encoding.should == Encoding::BINARY end diff --git a/core/string/slice_spec.rb b/core/string/slice_spec.rb index 87c5a7ac37..5aba2d3be0 100644 --- a/core/string/slice_spec.rb +++ b/core/string/slice_spec.rb @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- - +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/slice' diff --git a/core/string/split_spec.rb b/core/string/split_spec.rb index c5cca651c2..b1183611b3 100644 --- a/core/string/split_spec.rb +++ b/core/string/split_spec.rb @@ -409,7 +409,7 @@ end it "returns an ArgumentError if an invalid UTF-8 string is supplied" do - broken_str = 'проверка' # in russian, means "test" + broken_str = +'проверка' # in russian, means "test" broken_str.force_encoding('binary') broken_str.chop! broken_str.force_encoding('utf-8') diff --git a/core/string/squeeze_spec.rb b/core/string/squeeze_spec.rb index 4796a170f2..4ea238e6b5 100644 --- a/core/string/squeeze_spec.rb +++ b/core/string/squeeze_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/strip_spec.rb b/core/string/strip_spec.rb index 5e90fe35d0..edb6ea3b44 100644 --- a/core/string/strip_spec.rb +++ b/core/string/strip_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/strip' diff --git a/core/string/sub_spec.rb b/core/string/sub_spec.rb index 51920486f5..4f9f87a433 100644 --- a/core/string/sub_spec.rb +++ b/core/string/sub_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/swapcase_spec.rb b/core/string/swapcase_spec.rb index d740fb86c6..7f4c68366d 100644 --- a/core/string/swapcase_spec.rb +++ b/core/string/swapcase_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/tr_s_spec.rb b/core/string/tr_s_spec.rb index 3c31473044..dd72da440c 100644 --- a/core/string/tr_s_spec.rb +++ b/core/string/tr_s_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/tr_spec.rb b/core/string/tr_spec.rb index d60480dc7e..75841a974f 100644 --- a/core/string/tr_spec.rb +++ b/core/string/tr_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/unicode_normalize_spec.rb b/core/string/unicode_normalize_spec.rb index 6de7533fc7..2e7d22394a 100644 --- a/core/string/unicode_normalize_spec.rb +++ b/core/string/unicode_normalize_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' # Examples taken from http://www.unicode.org/reports/tr15/#Norm_Forms diff --git a/core/string/unicode_normalized_spec.rb b/core/string/unicode_normalized_spec.rb index 87f3740459..91cf2086b2 100644 --- a/core/string/unicode_normalized_spec.rb +++ b/core/string/unicode_normalized_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#unicode_normalized?" do diff --git a/core/string/upcase_spec.rb b/core/string/upcase_spec.rb index a2e34f5f40..652de5c2ef 100644 --- a/core/string/upcase_spec.rb +++ b/core/string/upcase_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/uplus_spec.rb b/core/string/uplus_spec.rb index 65b66260dd..c0b0c49ede 100644 --- a/core/string/uplus_spec.rb +++ b/core/string/uplus_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' describe 'String#+@' do diff --git a/core/string/valid_encoding_spec.rb b/core/string/valid_encoding_spec.rb index bb26062c0f..4bf87cbd2b 100644 --- a/core/string/valid_encoding_spec.rb +++ b/core/string/valid_encoding_spec.rb @@ -7,13 +7,13 @@ end it "returns true if self is valid in the current encoding and other encodings" do - str = "\x77" + str = +"\x77" str.force_encoding('utf-8').valid_encoding?.should be_true str.force_encoding('binary').valid_encoding?.should be_true end it "returns true for all encodings self is valid in" do - str = "\xE6\x9D\x94" + str = +"\xE6\x9D\x94" str.force_encoding('BINARY').valid_encoding?.should be_true str.force_encoding('UTF-8').valid_encoding?.should be_true str.force_encoding('US-ASCII').valid_encoding?.should be_false @@ -101,15 +101,15 @@ end it "returns true for IBM720 encoding self is valid in" do - str = "\xE6\x9D\x94" + 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 - str = "\u{8765}" + str = +"\u{8765}" str.valid_encoding?.should be_true - str = str.force_encoding('ascii') + str.force_encoding('ascii') str.valid_encoding?.should be_false end @@ -118,7 +118,7 @@ end it "returns false if a valid String had an invalid character appended to it" do - str = "a" + str = +"a" str.valid_encoding?.should be_true str << [0xDD].pack('C').force_encoding('utf-8') str.valid_encoding?.should be_false diff --git a/core/time/_load_spec.rb b/core/time/_load_spec.rb index 152934370f..f11b57b8e3 100644 --- a/core/time/_load_spec.rb +++ b/core/time/_load_spec.rb @@ -44,8 +44,7 @@ end it "treats the data as binary data" do - data = "\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE" - data.force_encoding Encoding::UTF_8 + data = "\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE".force_encoding Encoding::UTF_8 t = Marshal.load(data) t.to_s.should == "2013-04-08 12:47:45 UTC" end diff --git a/core/time/at_spec.rb b/core/time/at_spec.rb index 7fec8ad548..48fb3c6f52 100644 --- a/core/time/at_spec.rb +++ b/core/time/at_spec.rb @@ -196,7 +196,7 @@ end it "does not try to convert format to Symbol with #to_sym" do - format = "usec" + format = +"usec" format.should_not_receive(:to_sym) -> { Time.at(0, 123456, format) }.should raise_error(ArgumentError) end diff --git a/language/def_spec.rb b/language/def_spec.rb index c8531343c0..42e721c68c 100644 --- a/language/def_spec.rb +++ b/language/def_spec.rb @@ -238,7 +238,7 @@ def @a.foo end it "can be declared for a global variable" do - $__a__ = "hi" + $__a__ = +"hi" def $__a__.foo 7 end diff --git a/language/hash_spec.rb b/language/hash_spec.rb index 60e357fe61..a7631fb0d6 100644 --- a/language/hash_spec.rb +++ b/language/hash_spec.rb @@ -33,7 +33,7 @@ end it "freezes string keys on initialization" do - key = "foo" + key = +"foo" h = {key => "bar"} key.reverse! h["foo"].should == "bar" diff --git a/language/method_spec.rb b/language/method_spec.rb index e34ff7e1a6..9abe4cde20 100644 --- a/language/method_spec.rb +++ b/language/method_spec.rb @@ -1459,7 +1459,7 @@ def foo(val) describe "Inside 'endless' method definitions" do it "allows method calls without parenthesis" do eval <<-ruby - def greet(person) = "Hi, ".concat person + def greet(person) = "Hi, ".dup.concat person ruby greet("Homer").should == "Hi, Homer" diff --git a/language/send_spec.rb b/language/send_spec.rb index a1656559fe..aaccdf0998 100644 --- a/language/send_spec.rb +++ b/language/send_spec.rb @@ -43,7 +43,7 @@ end describe "with optional arguments" do - it "uses the optional argument if none is is passed" do + it "uses the optional argument if none is passed" do specs.fooM0O1.should == [1] end diff --git a/language/singleton_class_spec.rb b/language/singleton_class_spec.rb index 9d037717b2..45e1f7f3ad 100644 --- a/language/singleton_class_spec.rb +++ b/language/singleton_class_spec.rb @@ -70,7 +70,7 @@ end it "has class String as the superclass of a String instance" do - "blah".singleton_class.superclass.should == String + "blah".dup.singleton_class.superclass.should == String end it "doesn't have singleton class" do diff --git a/language/string_spec.rb b/language/string_spec.rb index 418dc2ca7d..403df15f67 100644 --- a/language/string_spec.rb +++ b/language/string_spec.rb @@ -232,7 +232,8 @@ def long_string_literals end it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do - ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "true" + frozen_literals_by_default = eval("'test'").frozen? + ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == (!frozen_literals_by_default).to_s end it "produce different objects for literals with the same content in different files if they have different encodings" do diff --git a/library/csv/generate_spec.rb b/library/csv/generate_spec.rb index 0a1e3d9604..b45e2eb95b 100644 --- a/library/csv/generate_spec.rb +++ b/library/csv/generate_spec.rb @@ -21,7 +21,7 @@ end it "appends and returns the argument itself" do - str = "" + str = +"" csv_str = CSV.generate(str) do |csv| csv.add_row [1, 2, 3] csv << [4, 5, 6] diff --git a/library/erb/run_spec.rb b/library/erb/run_spec.rb index 8c07442d8f..602e53ab38 100644 --- a/library/erb/run_spec.rb +++ b/library/erb/run_spec.rb @@ -6,7 +6,7 @@ # lambda { ... }.should output def _steal_stdout orig = $stdout - s = '' + s = +'' def s.write(arg); self << arg.to_s; end $stdout = s begin diff --git a/library/net-http/http/post_spec.rb b/library/net-http/http/post_spec.rb index 9e7574015c..d7d94fec4a 100644 --- a/library/net-http/http/post_spec.rb +++ b/library/net-http/http/post_spec.rb @@ -60,7 +60,7 @@ describe "when passed a block" do it "yields fragments of the response body to the passed block" do - str = "" + str = +"" @http.post("/request", "test=test") do |res| str << res end diff --git a/library/net-http/httpgenericrequest/exec_spec.rb b/library/net-http/httpgenericrequest/exec_spec.rb index cf13e9dfd6..7de03d7da0 100644 --- a/library/net-http/httpgenericrequest/exec_spec.rb +++ b/library/net-http/httpgenericrequest/exec_spec.rb @@ -4,7 +4,7 @@ describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do before :each do - @socket = StringIO.new("") + @socket = StringIO.new(+"") @buffered_socket = Net::BufferedIO.new(@socket) end diff --git a/library/net-http/httpresponse/inspect_spec.rb b/library/net-http/httpresponse/inspect_spec.rb index 43071ec8cd..23b6bff581 100644 --- a/library/net-http/httpresponse/inspect_spec.rb +++ b/library/net-http/httpresponse/inspect_spec.rb @@ -8,7 +8,7 @@ res.inspect.should == "#" res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - socket = Net::BufferedIO.new(StringIO.new("test body")) + socket = Net::BufferedIO.new(StringIO.new(+"test body")) res.reading_body(socket, true) {} res.inspect.should == "#" end diff --git a/library/net-http/httpresponse/read_body_spec.rb b/library/net-http/httpresponse/read_body_spec.rb index 380d17d3b9..61a576d812 100644 --- a/library/net-http/httpresponse/read_body_spec.rb +++ b/library/net-http/httpresponse/read_body_spec.rb @@ -5,7 +5,7 @@ describe "Net::HTTPResponse#read_body" do before :each do @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - @socket = Net::BufferedIO.new(StringIO.new("test body")) + @socket = Net::BufferedIO.new(StringIO.new(+"test body")) end describe "when passed no arguments" do @@ -25,7 +25,7 @@ describe "when passed a buffer" do it "reads the body to the passed buffer" do @res.reading_body(@socket, true) do - buffer = "" + buffer = +"" @res.read_body(buffer) buffer.should == "test body" end @@ -33,15 +33,15 @@ it "returns the passed buffer" do @res.reading_body(@socket, true) do - buffer = "" + buffer = +"" @res.read_body(buffer).should equal(buffer) end end it "raises an IOError if called a second time" do @res.reading_body(@socket, true) do - @res.read_body("") - -> { @res.read_body("") }.should raise_error(IOError) + @res.read_body(+"") + -> { @res.read_body(+"") }.should raise_error(IOError) end end end @@ -51,7 +51,7 @@ @res.reading_body(@socket, true) do yielded = false - buffer = "" + buffer = +"" @res.read_body do |body| yielded = true buffer << body @@ -79,7 +79,7 @@ describe "when passed buffer and block" do it "raises an ArgumentError" do @res.reading_body(@socket, true) do - -> { @res.read_body("") {} }.should raise_error(ArgumentError) + -> { @res.read_body(+"") {} }.should raise_error(ArgumentError) end end end diff --git a/library/net-http/httpresponse/reading_body_spec.rb b/library/net-http/httpresponse/reading_body_spec.rb index 637a2806f8..b9ab112c96 100644 --- a/library/net-http/httpresponse/reading_body_spec.rb +++ b/library/net-http/httpresponse/reading_body_spec.rb @@ -5,7 +5,7 @@ describe "Net::HTTPResponse#reading_body" do before :each do @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - @socket = Net::BufferedIO.new(StringIO.new("test body")) + @socket = Net::BufferedIO.new(StringIO.new(+"test body")) end describe "when body_allowed is true" do diff --git a/library/net-http/httpresponse/shared/body.rb b/library/net-http/httpresponse/shared/body.rb index 618e3936fb..f35ca3200c 100644 --- a/library/net-http/httpresponse/shared/body.rb +++ b/library/net-http/httpresponse/shared/body.rb @@ -3,7 +3,7 @@ describe :net_httpresponse_body, shared: true do before :each do @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response") - @socket = Net::BufferedIO.new(StringIO.new("test body")) + @socket = Net::BufferedIO.new(StringIO.new(+"test body")) end it "returns the read body" do diff --git a/library/objectspace/fixtures/trace.rb b/library/objectspace/fixtures/trace.rb index fd4524b0ba..e53a7a0cac 100644 --- a/library/objectspace/fixtures/trace.rb +++ b/library/objectspace/fixtures/trace.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require "objspace/trace" a = "foo" b = "b" + "a" + "r" diff --git a/library/objectspace/trace_spec.rb b/library/objectspace/trace_spec.rb index 59952a006c..532c282ce4 100644 --- a/library/objectspace/trace_spec.rb +++ b/library/objectspace/trace_spec.rb @@ -6,8 +6,8 @@ file = fixture(__FILE__ , "trace.rb") ruby_exe(file, args: "2>&1").lines(chomp: true).should == [ "objspace/trace is enabled", - "\"foo\" @ #{file}:2", - "\"bar\" @ #{file}:3", + "\"foo\" @ #{file}:3", + "\"bar\" @ #{file}:4", "42" ] end diff --git a/library/set/compare_by_identity_spec.rb b/library/set/compare_by_identity_spec.rb index 9ed1602189..602d1e758e 100644 --- a/library/set/compare_by_identity_spec.rb +++ b/library/set/compare_by_identity_spec.rb @@ -5,7 +5,7 @@ it "compares its members by identity" do a = "a" b1 = "b" - b2 = "b" + b2 = b1.dup set = Set.new set.compare_by_identity diff --git a/library/socket/basicsocket/recv_nonblock_spec.rb b/library/socket/basicsocket/recv_nonblock_spec.rb index b6ab8a9cea..17c846054d 100644 --- a/library/socket/basicsocket/recv_nonblock_spec.rb +++ b/library/socket/basicsocket/recv_nonblock_spec.rb @@ -52,7 +52,7 @@ @s2.send("data", 0, @s1.getsockname) IO.select([@s1], nil, nil, 2) - buf = "foo" + buf = +"foo" @s1.recv_nonblock(5, 0, buf) buf.should == "data" end diff --git a/library/socket/basicsocket/recv_spec.rb b/library/socket/basicsocket/recv_spec.rb index a56114f4ab..9fe8c52f9a 100644 --- a/library/socket/basicsocket/recv_spec.rb +++ b/library/socket/basicsocket/recv_spec.rb @@ -100,7 +100,7 @@ socket.write("data") client = @server.accept - buf = "foo" + buf = +"foo" begin client.recv(4, 0, buf) ensure diff --git a/library/socket/basicsocket/send_spec.rb b/library/socket/basicsocket/send_spec.rb index 041ce03d72..86b5567026 100644 --- a/library/socket/basicsocket/send_spec.rb +++ b/library/socket/basicsocket/send_spec.rb @@ -17,7 +17,7 @@ end it "sends a message to another socket and returns the number of bytes sent" do - data = "" + data = +"" t = Thread.new do client = @server.accept loop do @@ -62,7 +62,7 @@ end it "accepts a sockaddr as recipient address" do - data = "" + data = +"" t = Thread.new do client = @server.accept loop do diff --git a/library/socket/udpsocket/send_spec.rb b/library/socket/udpsocket/send_spec.rb index 5d5de684af..6dd5f67bea 100644 --- a/library/socket/udpsocket/send_spec.rb +++ b/library/socket/udpsocket/send_spec.rb @@ -63,7 +63,7 @@ @msg[1][3].should == "127.0.0.1" end - it "raises EMSGSIZE if data is too too big" do + it "raises EMSGSIZE if data is too big" do @socket = UDPSocket.open begin -> do diff --git a/library/stringio/append_spec.rb b/library/stringio/append_spec.rb index 5383e3e795..cb50d73d1b 100644 --- a/library/stringio/append_spec.rb +++ b/library/stringio/append_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#<< when passed [Object]" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns self" do @@ -44,10 +44,10 @@ describe "StringIO#<< when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io << "test" }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io << "test" }.should raise_error(IOError) end @@ -55,7 +55,7 @@ describe "StringIO#<< when in append mode" do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self, ignoring current position" do diff --git a/library/stringio/close_read_spec.rb b/library/stringio/close_read_spec.rb index 80bd547e85..0f08e1ff2e 100644 --- a/library/stringio/close_read_spec.rb +++ b/library/stringio/close_read_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#close_read" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns nil" do @@ -21,7 +21,7 @@ end it "raises an IOError when in write-only mode" do - io = StringIO.new("example", "w") + io = StringIO.new(+"example", "w") -> { io.close_read }.should raise_error(IOError) io = StringIO.new("example") diff --git a/library/stringio/close_write_spec.rb b/library/stringio/close_write_spec.rb index 1a4cfa113e..c86c3f9826 100644 --- a/library/stringio/close_write_spec.rb +++ b/library/stringio/close_write_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#close_write" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns nil" do @@ -21,10 +21,10 @@ end it "raises an IOError when in read-only mode" do - io = StringIO.new("example", "r") + io = StringIO.new(+"example", "r") -> { io.close_write }.should raise_error(IOError) - io = StringIO.new("example") + io = StringIO.new(+"example") io.close_write io.close_write.should == nil end diff --git a/library/stringio/closed_read_spec.rb b/library/stringio/closed_read_spec.rb index cb4267ac98..b4dcadc3a4 100644 --- a/library/stringio/closed_read_spec.rb +++ b/library/stringio/closed_read_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#closed_read?" do it "returns true if self is not readable" do - io = StringIO.new("example", "r+") + io = StringIO.new(+"example", "r+") io.close_write io.closed_read?.should be_false io.close_read diff --git a/library/stringio/closed_spec.rb b/library/stringio/closed_spec.rb index ca8a2232a8..bf7ba63184 100644 --- a/library/stringio/closed_spec.rb +++ b/library/stringio/closed_spec.rb @@ -3,13 +3,13 @@ describe "StringIO#closed?" do it "returns true if self is completely closed" do - io = StringIO.new("example", "r+") + io = StringIO.new(+"example", "r+") io.close_read io.closed?.should be_false io.close_write io.closed?.should be_true - io = StringIO.new("example", "r+") + io = StringIO.new(+"example", "r+") io.close io.closed?.should be_true end diff --git a/library/stringio/closed_write_spec.rb b/library/stringio/closed_write_spec.rb index 5c111affd8..2bd3e6fa8b 100644 --- a/library/stringio/closed_write_spec.rb +++ b/library/stringio/closed_write_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#closed_write?" do it "returns true if self is not writable" do - io = StringIO.new("example", "r+") + io = StringIO.new(+"example", "r+") io.close_read io.closed_write?.should be_false io.close_write diff --git a/library/stringio/fcntl_spec.rb b/library/stringio/fcntl_spec.rb index a78004d868..f252d5e738 100644 --- a/library/stringio/fcntl_spec.rb +++ b/library/stringio/fcntl_spec.rb @@ -3,6 +3,6 @@ describe "StringIO#fcntl" do it "raises a NotImplementedError" do - -> { StringIO.new("boom").fcntl }.should raise_error(NotImplementedError) + -> { StringIO.new(+"boom").fcntl }.should raise_error(NotImplementedError) end end diff --git a/library/stringio/flush_spec.rb b/library/stringio/flush_spec.rb index 17a16dfdd5..4dc58b1d48 100644 --- a/library/stringio/flush_spec.rb +++ b/library/stringio/flush_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#flush" do it "returns self" do - io = StringIO.new("flush") + io = StringIO.new(+"flush") io.flush.should equal(io) end end diff --git a/library/stringio/fsync_spec.rb b/library/stringio/fsync_spec.rb index 8fb2b59a24..85053cb2e5 100644 --- a/library/stringio/fsync_spec.rb +++ b/library/stringio/fsync_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#fsync" do it "returns zero" do - io = StringIO.new("fsync") + io = StringIO.new(+"fsync") io.fsync.should eql(0) end end diff --git a/library/stringio/gets_spec.rb b/library/stringio/gets_spec.rb index d597ec0e45..4af7704a41 100644 --- a/library/stringio/gets_spec.rb +++ b/library/stringio/gets_spec.rb @@ -233,7 +233,7 @@ describe "StringIO#gets when in write-only mode" do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.gets }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/library/stringio/initialize_spec.rb b/library/stringio/initialize_spec.rb index 158c08488b..ba4644d102 100644 --- a/library/stringio/initialize_spec.rb +++ b/library/stringio/initialize_spec.rb @@ -13,99 +13,99 @@ it "sets the mode based on the passed mode" do io = StringIO.allocate - io.send(:initialize, "example", "r") + io.send(:initialize, +"example", "r") io.closed_read?.should be_false io.closed_write?.should be_true io = StringIO.allocate - io.send(:initialize, "example", "rb") + io.send(:initialize, +"example", "rb") io.closed_read?.should be_false io.closed_write?.should be_true io = StringIO.allocate - io.send(:initialize, "example", "r+") + io.send(:initialize, +"example", "r+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "rb+") + io.send(:initialize, +"example", "rb+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "w") + io.send(:initialize, +"example", "w") io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "wb") + io.send(:initialize, +"example", "wb") io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "w+") + io.send(:initialize, +"example", "w+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "wb+") + io.send(:initialize, +"example", "wb+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "a") + io.send(:initialize, +"example", "a") io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "ab") + io.send(:initialize, +"example", "ab") io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "a+") + io.send(:initialize, +"example", "a+") io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", "ab+") + io.send(:initialize, +"example", "ab+") io.closed_read?.should be_false io.closed_write?.should be_false end it "allows passing the mode as an Integer" do io = StringIO.allocate - io.send(:initialize, "example", IO::RDONLY) + io.send(:initialize, +"example", IO::RDONLY) io.closed_read?.should be_false io.closed_write?.should be_true io = StringIO.allocate - io.send(:initialize, "example", IO::RDWR) + io.send(:initialize, +"example", IO::RDWR) io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::WRONLY) + io.send(:initialize, +"example", IO::WRONLY) io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::WRONLY | IO::TRUNC) + io.send(:initialize, +"example", IO::WRONLY | IO::TRUNC) io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::RDWR | IO::TRUNC) + io.send(:initialize, +"example", IO::RDWR | IO::TRUNC) io.closed_read?.should be_false io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::WRONLY | IO::APPEND) + io.send(:initialize, +"example", IO::WRONLY | IO::APPEND) io.closed_read?.should be_true io.closed_write?.should be_false io = StringIO.allocate - io.send(:initialize, "example", IO::RDWR | IO::APPEND) + io.send(:initialize, +"example", IO::RDWR | IO::APPEND) io.closed_read?.should be_false io.closed_write?.should be_false end @@ -118,7 +118,7 @@ it "tries to convert the passed mode to a String using #to_str" do obj = mock('to_str') obj.should_receive(:to_str).and_return("r") - @io.send(:initialize, "example", obj) + @io.send(:initialize, +"example", obj) @io.closed_read?.should be_false @io.closed_write?.should be_true @@ -142,12 +142,18 @@ @io.string.should equal(str) end - it "sets the mode to read-write" do - @io.send(:initialize, "example") + it "sets the mode to read-write if the string is mutable" do + @io.send(:initialize, +"example") @io.closed_read?.should be_false @io.closed_write?.should be_false end + it "sets the mode to read if the string is frozen" do + @io.send(:initialize, -"example") + @io.closed_read?.should be_false + @io.closed_write?.should be_true + 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("example") @@ -166,28 +172,28 @@ # NOTE: Synchronise with core/io/new_spec.rb (core/io/shared/new.rb) describe "StringIO#initialize when passed keyword arguments" do it "sets the mode based on the passed :mode option" do - io = StringIO.new("example", "r") + io = StringIO.new(+"example", "r") io.closed_read?.should be_false io.closed_write?.should be_true end it "accepts a mode argument set to nil with a valid :mode option" do - @io = StringIO.new('', nil, mode: "w") + @io = StringIO.new(+'', nil, mode: "w") @io.write("foo").should == 3 end it "accepts a mode argument with a :mode option set to nil" do - @io = StringIO.new('', "w", mode: nil) + @io = StringIO.new(+'', "w", mode: nil) @io.write("foo").should == 3 end it "sets binmode from :binmode option" do - @io = StringIO.new('', 'w', binmode: true) + @io = StringIO.new(+'', 'w', binmode: true) @io.external_encoding.to_s.should == "ASCII-8BIT" # #binmode? isn't implemented in StringIO end it "does not set binmode from false :binmode" do - @io = StringIO.new('', 'w', binmode: false) + @io = StringIO.new(+'', 'w', binmode: false) @io.external_encoding.to_s.should == "UTF-8" # #binmode? isn't implemented in StringIO end end @@ -196,54 +202,54 @@ describe "StringIO#initialize when passed keyword arguments and error happens" do it "raises an error if passed encodings two ways" do -> { - @io = StringIO.new('', 'w:ISO-8859-1', encoding: 'ISO-8859-1') + @io = StringIO.new(+'', 'w:ISO-8859-1', encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1') + @io = StringIO.new(+'', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1') + @io = StringIO.new(+'', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) end it "raises an error if passed matching binary/text mode two ways" do -> { - @io = StringIO.new('', "wb", binmode: true) + @io = StringIO.new(+'', "wb", binmode: true) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wt", textmode: true) + @io = StringIO.new(+'', "wt", textmode: true) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wb", textmode: false) + @io = StringIO.new(+'', "wb", textmode: false) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wt", binmode: false) + @io = StringIO.new(+'', "wt", binmode: false) }.should raise_error(ArgumentError) end it "raises an error if passed conflicting binary/text mode two ways" do -> { - @io = StringIO.new('', "wb", binmode: false) + @io = StringIO.new(+'', "wb", binmode: false) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wt", textmode: false) + @io = StringIO.new(+'', "wt", textmode: false) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wb", textmode: true) + @io = StringIO.new(+'', "wb", textmode: true) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', "wt", binmode: true) + @io = StringIO.new(+'', "wt", binmode: true) }.should raise_error(ArgumentError) end it "raises an error when trying to set both binmode and textmode" do -> { - @io = StringIO.new('', "w", textmode: true, binmode: true) + @io = StringIO.new(+'', "w", textmode: true, binmode: true) }.should raise_error(ArgumentError) -> { - @io = StringIO.new('', File::Constants::WRONLY, textmode: true, binmode: true) + @io = StringIO.new(+'', File::Constants::WRONLY, textmode: true, binmode: true) }.should raise_error(ArgumentError) end end @@ -258,7 +264,7 @@ end it "sets the mode to read-write" do - @io.send(:initialize, "example") + @io.send(:initialize) @io.closed_read?.should be_false @io.closed_write?.should be_false end diff --git a/library/stringio/open_spec.rb b/library/stringio/open_spec.rb index 3068e19435..b7c90661f9 100644 --- a/library/stringio/open_spec.rb +++ b/library/stringio/open_spec.rb @@ -8,26 +8,26 @@ end it "returns the blocks return value when yielding" do - ret = StringIO.open("example", "r") { :test } + ret = StringIO.open(+"example", "r") { :test } ret.should equal(:test) end it "yields self to the passed block" do io = nil - StringIO.open("example", "r") { |strio| io = strio } + StringIO.open(+"example", "r") { |strio| io = strio } io.should be_kind_of(StringIO) end it "closes self after yielding" do io = nil - StringIO.open("example", "r") { |strio| io = strio } + StringIO.open(+"example", "r") { |strio| io = strio } io.closed?.should be_true end it "even closes self when an exception is raised while yielding" do io = nil begin - StringIO.open("example", "r") do |strio| + StringIO.open(+"example", "r") do |strio| io = strio raise "Error" end @@ -38,14 +38,14 @@ it "sets self's string to nil after yielding" do io = nil - StringIO.open("example", "r") { |strio| io = strio } + StringIO.open(+"example", "r") { |strio| io = strio } io.string.should be_nil end it "even sets self's string to nil when an exception is raised while yielding" do io = nil begin - StringIO.open("example", "r") do |strio| + StringIO.open(+"example", "r") do |strio| io = strio raise "Error" end @@ -55,81 +55,81 @@ end it "sets the mode based on the passed mode" do - io = StringIO.open("example", "r") + io = StringIO.open(+"example", "r") io.closed_read?.should be_false io.closed_write?.should be_true - io = StringIO.open("example", "rb") + io = StringIO.open(+"example", "rb") io.closed_read?.should be_false io.closed_write?.should be_true - io = StringIO.open("example", "r+") + io = StringIO.open(+"example", "r+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "rb+") + io = StringIO.open(+"example", "rb+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "w") + io = StringIO.open(+"example", "w") io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", "wb") + io = StringIO.open(+"example", "wb") io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", "w+") + io = StringIO.open(+"example", "w+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "wb+") + io = StringIO.open(+"example", "wb+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "a") + io = StringIO.open(+"example", "a") io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", "ab") + io = StringIO.open(+"example", "ab") io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", "a+") + io = StringIO.open(+"example", "a+") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", "ab+") + io = StringIO.open(+"example", "ab+") io.closed_read?.should be_false io.closed_write?.should be_false end it "allows passing the mode as an Integer" do - io = StringIO.open("example", IO::RDONLY) + io = StringIO.open(+"example", IO::RDONLY) io.closed_read?.should be_false io.closed_write?.should be_true - io = StringIO.open("example", IO::RDWR) + io = StringIO.open(+"example", IO::RDWR) io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", IO::WRONLY) + io = StringIO.open(+"example", IO::WRONLY) io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", IO::WRONLY | IO::TRUNC) + io = StringIO.open(+"example", IO::WRONLY | IO::TRUNC) io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", IO::RDWR | IO::TRUNC) + io = StringIO.open(+"example", IO::RDWR | IO::TRUNC) io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.open("example", IO::WRONLY | IO::APPEND) + io = StringIO.open(+"example", IO::WRONLY | IO::APPEND) io.closed_read?.should be_true io.closed_write?.should be_false - io = StringIO.open("example", IO::RDWR | IO::APPEND) + io = StringIO.open(+"example", IO::RDWR | IO::APPEND) io.closed_read?.should be_false io.closed_write?.should be_false end @@ -141,7 +141,7 @@ it "tries to convert the passed mode to a String using #to_str" do obj = mock('to_str') obj.should_receive(:to_str).and_return("r") - io = StringIO.open("example", obj) + io = StringIO.open(+"example", obj) io.closed_read?.should be_false io.closed_write?.should be_true @@ -163,16 +163,16 @@ it "yields self to the passed block" do io = nil - ret = StringIO.open("example") { |strio| io = strio } + ret = StringIO.open(+"example") { |strio| io = strio } io.should equal(ret) end it "sets the mode to read-write (r+)" do - io = StringIO.open("example") + io = StringIO.open(+"example") io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.new("example") + io = StringIO.new(+"example") io.printf("%d", 123) io.string.should == "123mple" end @@ -204,7 +204,7 @@ io.closed_read?.should be_false io.closed_write?.should be_false - io = StringIO.new("example") + io = StringIO.new(+"example") io.printf("%d", 123) io.string.should == "123mple" end diff --git a/library/stringio/print_spec.rb b/library/stringio/print_spec.rb index 6ac6430900..00c33367dc 100644 --- a/library/stringio/print_spec.rb +++ b/library/stringio/print_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#print" do before :each do - @io = StringIO.new('example') + @io = StringIO.new(+'example') end it "prints $_ when passed no arguments" do @@ -73,7 +73,7 @@ describe "StringIO#print when in append mode" do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self" do @@ -92,10 +92,10 @@ describe "StringIO#print when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.print("test") }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.print("test") }.should raise_error(IOError) end diff --git a/library/stringio/printf_spec.rb b/library/stringio/printf_spec.rb index f3f669a185..ca82e84757 100644 --- a/library/stringio/printf_spec.rb +++ b/library/stringio/printf_spec.rb @@ -41,7 +41,7 @@ describe "StringIO#printf when in read-write mode" do before :each do - @io = StringIO.new("example", "r+") + @io = StringIO.new(+"example", "r+") end it "starts from the beginning" do @@ -62,7 +62,7 @@ describe "StringIO#printf when in append mode" do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self" do @@ -81,10 +81,10 @@ describe "StringIO#printf when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.printf("test") }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.printf("test") }.should raise_error(IOError) end diff --git a/library/stringio/putc_spec.rb b/library/stringio/putc_spec.rb index 1ce53b7ef2..9f1ac8ffb2 100644 --- a/library/stringio/putc_spec.rb +++ b/library/stringio/putc_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#putc when passed [String]" do before :each do - @io = StringIO.new('example') + @io = StringIO.new(+'example') end it "overwrites the character at the current position" do @@ -54,7 +54,7 @@ describe "StringIO#putc when passed [Object]" do before :each do - @io = StringIO.new('example') + @io = StringIO.new(+'example') end it "it writes the passed Integer % 256 to self" do @@ -85,7 +85,7 @@ describe "StringIO#putc when in append mode" do it "appends to the end of self" do - io = StringIO.new("test", "a") + io = StringIO.new(+"test", "a") io.putc(?t) io.string.should == "testt" end @@ -93,10 +93,10 @@ describe "StringIO#putc when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.putc(?a) }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.putc("t") }.should raise_error(IOError) end diff --git a/library/stringio/puts_spec.rb b/library/stringio/puts_spec.rb index 9c890262dd..054ec8227f 100644 --- a/library/stringio/puts_spec.rb +++ b/library/stringio/puts_spec.rb @@ -145,7 +145,7 @@ describe "StringIO#puts when in append mode" do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self" do @@ -164,10 +164,10 @@ describe "StringIO#puts when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.puts }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.puts }.should raise_error(IOError) end @@ -175,7 +175,7 @@ describe "StringIO#puts when passed an encoded string" do it "stores the bytes unmodified" do - io = StringIO.new("") + io = StringIO.new(+"") io.puts "\x00\x01\x02" io.puts "æåø" diff --git a/library/stringio/read_nonblock_spec.rb b/library/stringio/read_nonblock_spec.rb index d4ec56d9aa..8b78b1b0e4 100644 --- a/library/stringio/read_nonblock_spec.rb +++ b/library/stringio/read_nonblock_spec.rb @@ -8,7 +8,7 @@ it "accepts :exception option" do io = StringIO.new("example") - io.read_nonblock(3, buffer = "", exception: true) + io.read_nonblock(3, buffer = +"", exception: true) buffer.should == "exa" end end @@ -33,14 +33,14 @@ describe "StringIO#read_nonblock" do it "accepts an exception option" do - stringio = StringIO.new('foo') + stringio = StringIO.new(+'foo') stringio.read_nonblock(3, exception: false).should == 'foo' end context "when exception option is set to false" do context "when the end is reached" do it "returns nil" do - stringio = StringIO.new('') + stringio = StringIO.new(+'') stringio << "hello" stringio.rewind diff --git a/library/stringio/read_spec.rb b/library/stringio/read_spec.rb index 52ab3dcf47..e49f262127 100644 --- a/library/stringio/read_spec.rb +++ b/library/stringio/read_spec.rb @@ -53,7 +53,7 @@ end it "reads [length] characters into the buffer" do - buf = "foo" + buf = +"foo" result = @io.read(10, buf) buf.should == "abcdefghij" diff --git a/library/stringio/readline_spec.rb b/library/stringio/readline_spec.rb index b794e5fade..b16a16e23f 100644 --- a/library/stringio/readline_spec.rb +++ b/library/stringio/readline_spec.rb @@ -113,7 +113,7 @@ describe "StringIO#readline when in write-only mode" do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.readline }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/library/stringio/readlines_spec.rb b/library/stringio/readlines_spec.rb index c471d0fd73..ed7cc22b3d 100644 --- a/library/stringio/readlines_spec.rb +++ b/library/stringio/readlines_spec.rb @@ -83,7 +83,7 @@ describe "StringIO#readlines when in write-only mode" do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.readlines }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/library/stringio/readpartial_spec.rb b/library/stringio/readpartial_spec.rb index 2601fe8c42..f25cef4014 100644 --- a/library/stringio/readpartial_spec.rb +++ b/library/stringio/readpartial_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#readpartial" do before :each do - @string = StringIO.new('Stop, look, listen') + @string = StringIO.new(+'Stop, look, listen') end after :each do @@ -48,7 +48,7 @@ end it "discards the existing buffer content upon successful read" do - buffer = "existing" + buffer = +"existing" @string.readpartial(11, buffer) buffer.should == "Stop, look," end @@ -59,7 +59,7 @@ end it "discards the existing buffer content upon error" do - buffer = 'hello' + buffer = +'hello' @string.readpartial(100) -> { @string.readpartial(1, buffer) }.should raise_error(EOFError) buffer.should be_empty diff --git a/library/stringio/reopen_spec.rb b/library/stringio/reopen_spec.rb index 9851c5b706..151bb58c6f 100644 --- a/library/stringio/reopen_spec.rb +++ b/library/stringio/reopen_spec.rb @@ -3,21 +3,21 @@ describe "StringIO#reopen when passed [Object, Integer]" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "reopens self with the passed Object in the passed mode" do - @io.reopen("reopened", IO::RDONLY) + @io.reopen(+"reopened", IO::RDONLY) @io.closed_read?.should be_false @io.closed_write?.should be_true @io.string.should == "reopened" - @io.reopen("reopened, twice", IO::WRONLY) + @io.reopen(+"reopened, twice", IO::WRONLY) @io.closed_read?.should be_true @io.closed_write?.should be_false @io.string.should == "reopened, twice" - @io.reopen("reopened, another time", IO::RDWR) + @io.reopen(+"reopened, another time", IO::RDWR) @io.closed_read?.should be_false @io.closed_write?.should be_false @io.string.should == "reopened, another time" @@ -25,7 +25,7 @@ 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") + obj.should_receive(:to_str).and_return(+"to_str") @io.reopen(obj, IO::RDWR) @io.string.should == "to_str" end @@ -51,39 +51,39 @@ describe "StringIO#reopen when passed [Object, Object]" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "reopens self with the passed Object in the passed mode" do - @io.reopen("reopened", "r") + @io.reopen(+"reopened", "r") @io.closed_read?.should be_false @io.closed_write?.should be_true @io.string.should == "reopened" - @io.reopen("reopened, twice", "r+") + @io.reopen(+"reopened, twice", "r+") @io.closed_read?.should be_false @io.closed_write?.should be_false @io.string.should == "reopened, twice" - @io.reopen("reopened, another", "w+") + @io.reopen(+"reopened, another", "w+") @io.closed_read?.should be_false @io.closed_write?.should be_false @io.string.should == "" - @io.reopen("reopened, another time", "r+") + @io.reopen(+"reopened, another time", "r+") @io.closed_read?.should be_false @io.closed_write?.should be_false @io.string.should == "reopened, another time" end it "truncates the passed String when opened in truncate mode" do - @io.reopen(str = "reopened", "w") + @io.reopen(str = +"reopened", "w") str.should == "" 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") + obj.should_receive(:to_str).and_return(+"to_str") @io.reopen(obj, "r") @io.string.should == "to_str" end @@ -94,20 +94,20 @@ it "resets self's position to 0" do @io.read(5) - @io.reopen("reopened") + @io.reopen(+"reopened") @io.pos.should eql(0) end it "resets self's line number to 0" do @io.gets - @io.reopen("reopened") + @io.reopen(+"reopened") @io.lineno.should eql(0) end it "tries to convert the passed mode Object to an Integer using #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_return("r") - @io.reopen("reopened", obj) + @io.reopen(+"reopened", obj) @io.closed_read?.should be_false @io.closed_write?.should be_true @io.string.should == "reopened" @@ -128,13 +128,13 @@ describe "StringIO#reopen when passed [String]" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "reopens self with the passed String in read-write mode" do @io.close - @io.reopen("reopened") + @io.reopen(+"reopened") @io.closed_write?.should be_false @io.closed_read?.should be_false @@ -144,20 +144,20 @@ it "resets self's position to 0" do @io.read(5) - @io.reopen("reopened") + @io.reopen(+"reopened") @io.pos.should eql(0) end it "resets self's line number to 0" do @io.gets - @io.reopen("reopened") + @io.reopen(+"reopened") @io.lineno.should eql(0) end end describe "StringIO#reopen when passed [Object]" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "raises a TypeError when passed an Object that can't be converted to a StringIO" do @@ -172,7 +172,7 @@ it "tries to convert the passed Object to a StringIO using #to_strio" do obj = mock("to_strio") - obj.should_receive(:to_strio).and_return(StringIO.new("to_strio")) + obj.should_receive(:to_strio).and_return(StringIO.new(+"to_strio")) @io.reopen(obj) @io.string.should == "to_strio" end @@ -180,7 +180,7 @@ describe "StringIO#reopen when passed no arguments" do before :each do - @io = StringIO.new("example\nsecond line") + @io = StringIO.new(+"example\nsecond line") end it "resets self's mode to read-write" do @@ -208,40 +208,40 @@ # for details. describe "StringIO#reopen" do before :each do - @io = StringIO.new('hello','a') + @io = StringIO.new(+'hello','a') end # TODO: find out if this is really a bug it "reopens a stream when given a String argument" do - @io.reopen('goodbye').should == @io + @io.reopen(+'goodbye').should == @io @io.string.should == 'goodbye' @io << 'x' @io.string.should == 'xoodbye' end it "reopens a stream in append mode when flagged as such" do - @io.reopen('goodbye', 'a').should == @io + @io.reopen(+'goodbye', 'a').should == @io @io.string.should == 'goodbye' @io << 'x' @io.string.should == 'goodbyex' end it "reopens and truncate when reopened in write mode" do - @io.reopen('goodbye', 'wb').should == @io + @io.reopen(+'goodbye', 'wb').should == @io @io.string.should == '' @io << 'x' @io.string.should == 'x' end it "truncates the given string, not a copy" do - str = 'goodbye' + str = +'goodbye' @io.reopen(str, 'w') @io.string.should == '' str.should == '' end it "does not truncate the content even when the StringIO argument is in the truncate mode" do - orig_io = StringIO.new("Original StringIO", IO::RDWR|IO::TRUNC) + orig_io = StringIO.new(+"Original StringIO", IO::RDWR|IO::TRUNC) orig_io.write("BLAH") # make sure the content is not empty @io.reopen(orig_io) diff --git a/library/stringio/shared/codepoints.rb b/library/stringio/shared/codepoints.rb index 9d84aa4919..25333bb0fd 100644 --- a/library/stringio/shared/codepoints.rb +++ b/library/stringio/shared/codepoints.rb @@ -27,7 +27,7 @@ @io.close_read -> { @enum.to_a }.should raise_error(IOError) - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.send(@method).to_a }.should raise_error(IOError) end diff --git a/library/stringio/shared/each.rb b/library/stringio/shared/each.rb index acd8d22c14..e0dd3f9b8f 100644 --- a/library/stringio/shared/each.rb +++ b/library/stringio/shared/each.rb @@ -107,7 +107,7 @@ describe :stringio_each_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("a b c d e", "w") + io = StringIO.new(+"a b c d e", "w") -> { io.send(@method) { |b| b } }.should raise_error(IOError) io = StringIO.new("a b c d e") diff --git a/library/stringio/shared/each_byte.rb b/library/stringio/shared/each_byte.rb index 56734ff99d..b51fa38f2f 100644 --- a/library/stringio/shared/each_byte.rb +++ b/library/stringio/shared/each_byte.rb @@ -38,7 +38,7 @@ describe :stringio_each_byte_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.send(@method) { |b| b } }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/library/stringio/shared/each_char.rb b/library/stringio/shared/each_char.rb index bcdac53282..197237c1c8 100644 --- a/library/stringio/shared/each_char.rb +++ b/library/stringio/shared/each_char.rb @@ -26,7 +26,7 @@ describe :stringio_each_char_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.send(@method) { |b| b } }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/library/stringio/shared/getc.rb b/library/stringio/shared/getc.rb index 6318bcc30f..ba65040bce 100644 --- a/library/stringio/shared/getc.rb +++ b/library/stringio/shared/getc.rb @@ -33,7 +33,7 @@ describe :stringio_getc_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("xyz", "w") + io = StringIO.new(+"xyz", "w") -> { io.send(@method) }.should raise_error(IOError) io = StringIO.new("xyz") diff --git a/library/stringio/shared/isatty.rb b/library/stringio/shared/isatty.rb index 3da5999953..c9e7ee7321 100644 --- a/library/stringio/shared/isatty.rb +++ b/library/stringio/shared/isatty.rb @@ -1,5 +1,5 @@ describe :stringio_isatty, shared: true do it "returns false" do - StringIO.new('tty').send(@method).should be_false + StringIO.new("tty").send(@method).should be_false end end diff --git a/library/stringio/shared/read.rb b/library/stringio/shared/read.rb index 252a85d89d..e3840786d9 100644 --- a/library/stringio/shared/read.rb +++ b/library/stringio/shared/read.rb @@ -5,19 +5,19 @@ it "returns the passed buffer String" do # Note: Rubinius bug: - # @io.send(@method, 7, buffer = "").should equal(buffer) - ret = @io.send(@method, 7, buffer = "") + # @io.send(@method, 7, buffer = +"").should equal(buffer) + ret = @io.send(@method, 7, buffer = +"") ret.should equal(buffer) end it "reads length bytes and writes them to the buffer String" do - @io.send(@method, 7, buffer = "") + @io.send(@method, 7, buffer = +"") buffer.should == "example" end it "tries to convert the passed buffer Object to a String using #to_str" do obj = mock("to_str") - obj.should_receive(:to_str).and_return(buffer = "") + obj.should_receive(:to_str).and_return(buffer = +"") @io.send(@method, 7, obj) buffer.should == "example" @@ -75,7 +75,7 @@ describe :stringio_read_no_arguments, shared: true do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "reads the whole content starting from the current position" do @@ -117,7 +117,7 @@ describe :stringio_read_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("test", "w") + io = StringIO.new(+"test", "w") -> { io.send(@method) }.should raise_error(IOError) io = StringIO.new("test") diff --git a/library/stringio/shared/readchar.rb b/library/stringio/shared/readchar.rb index 4248e75420..72d7446c36 100644 --- a/library/stringio/shared/readchar.rb +++ b/library/stringio/shared/readchar.rb @@ -19,7 +19,7 @@ describe :stringio_readchar_not_readable, shared: true do it "raises an IOError" do - io = StringIO.new("a b c d e", "w") + io = StringIO.new(+"a b c d e", "w") -> { io.send(@method) }.should raise_error(IOError) io = StringIO.new("a b c d e") diff --git a/library/stringio/shared/write.rb b/library/stringio/shared/write.rb index aa67bb73c7..404e08b93d 100644 --- a/library/stringio/shared/write.rb +++ b/library/stringio/shared/write.rb @@ -1,6 +1,6 @@ describe :stringio_write, shared: true do before :each do - @io = StringIO.new('12345') + @io = StringIO.new(+'12345') end it "tries to convert the passed Object to a String using #to_s" do @@ -13,7 +13,7 @@ describe :stringio_write_string, shared: true do before :each do - @io = StringIO.new('12345') + @io = StringIO.new(+'12345') end # TODO: RDoc says that #write appends at the current position. @@ -106,10 +106,10 @@ describe :stringio_write_not_writable, shared: true do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.send(@method, "test") }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.send(@method, "test") }.should raise_error(IOError) end @@ -117,7 +117,7 @@ describe :stringio_write_append, shared: true do before :each do - @io = StringIO.new("example", "a") + @io = StringIO.new(+"example", "a") end it "appends the passed argument to the end of self" do diff --git a/library/stringio/truncate_spec.rb b/library/stringio/truncate_spec.rb index e8d7f1a15d..592ca5a6e1 100644 --- a/library/stringio/truncate_spec.rb +++ b/library/stringio/truncate_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#truncate when passed [length]" do before :each do - @io = StringIO.new('123456789') + @io = StringIO.new(+'123456789') end it "returns an Integer" do @@ -16,7 +16,7 @@ end it "does not create a copy of the underlying string" do - io = StringIO.new(str = "123456789") + io = StringIO.new(str = +"123456789") io.truncate(4) io.string.should equal(str) end @@ -52,10 +52,10 @@ describe "StringIO#truncate when self is not writable" do it "raises an IOError" do - io = StringIO.new("test", "r") + io = StringIO.new(+"test", "r") -> { io.truncate(2) }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.close_write -> { io.truncate(2) }.should raise_error(IOError) end diff --git a/library/stringio/ungetc_spec.rb b/library/stringio/ungetc_spec.rb index 91ef2100a1..bceafa79ff 100644 --- a/library/stringio/ungetc_spec.rb +++ b/library/stringio/ungetc_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#ungetc when passed [char]" do before :each do - @io = StringIO.new('1234') + @io = StringIO.new(+'1234') end it "writes the passed char before the current position" do @@ -45,11 +45,11 @@ describe "StringIO#ungetc when self is not readable" do it "raises an IOError" do - io = StringIO.new("test", "w") + io = StringIO.new(+"test", "w") io.pos = 1 -> { io.ungetc(?A) }.should raise_error(IOError) - io = StringIO.new("test") + io = StringIO.new(+"test") io.pos = 1 io.close_read -> { io.ungetc(?A) }.should raise_error(IOError) @@ -60,11 +60,11 @@ # # describe "StringIO#ungetc when self is not writable" do # it "raises an IOError" do -# io = StringIO.new("test", "r") +# io = StringIO.new(+"test", "r") # io.pos = 1 # lambda { io.ungetc(?A) }.should raise_error(IOError) # -# io = StringIO.new("test") +# io = StringIO.new(+"test") # io.pos = 1 # io.close_write # lambda { io.ungetc(?A) }.should raise_error(IOError) diff --git a/library/stringio/write_nonblock_spec.rb b/library/stringio/write_nonblock_spec.rb index a457b97667..b48ef6698a 100644 --- a/library/stringio/write_nonblock_spec.rb +++ b/library/stringio/write_nonblock_spec.rb @@ -10,7 +10,7 @@ it_behaves_like :stringio_write_string, :write_nonblock it "accepts :exception option" do - io = StringIO.new("12345", "a") + io = StringIO.new(+"12345", "a") io.write_nonblock("67890", exception: true) io.string.should == "1234567890" end diff --git a/library/stringscanner/shared/concat.rb b/library/stringscanner/shared/concat.rb index cb884a5c01..1dbae11f7c 100644 --- a/library/stringscanner/shared/concat.rb +++ b/library/stringscanner/shared/concat.rb @@ -1,6 +1,6 @@ describe :strscan_concat, shared: true do it "concatenates the given argument to self and returns self" do - s = StringScanner.new("hello ") + s = StringScanner.new(+"hello ") s.send(@method, 'world').should == s s.string.should == "hello world" s.eos?.should be_false diff --git a/library/stringscanner/string_spec.rb b/library/stringscanner/string_spec.rb index 28e2f0ed37..cba6bd51dd 100644 --- a/library/stringscanner/string_spec.rb +++ b/library/stringscanner/string_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#string" do before :each do - @string = "This is a test" + @string = +"This is a test" @s = StringScanner.new(@string) end diff --git a/library/zlib/deflate/deflate_spec.rb b/library/zlib/deflate/deflate_spec.rb index 50a563ef6f..e16e6ad0ef 100644 --- a/library/zlib/deflate/deflate_spec.rb +++ b/library/zlib/deflate/deflate_spec.rb @@ -23,7 +23,7 @@ it "deflates chunked data" do random_generator = Random.new(0) - deflated = '' + deflated = +'' Zlib::Deflate.deflate(random_generator.bytes(20000)) do |chunk| deflated << chunk @@ -70,7 +70,7 @@ before :each do @deflator = Zlib::Deflate.new @random_generator = Random.new(0) - @original = '' + @original = +'' @chunks = [] end diff --git a/library/zlib/deflate/params_spec.rb b/library/zlib/deflate/params_spec.rb index 0b1cca8c8a..0242653528 100644 --- a/library/zlib/deflate/params_spec.rb +++ b/library/zlib/deflate/params_spec.rb @@ -3,7 +3,7 @@ describe "Zlib::Deflate#params" do it "changes the deflate parameters" do - data = 'abcdefghijklm' + data = +'abcdefghijklm' d = Zlib::Deflate.new Zlib::NO_COMPRESSION, Zlib::MAX_WBITS, Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY diff --git a/library/zlib/inflate/inflate_spec.rb b/library/zlib/inflate/inflate_spec.rb index 79b72bf91c..b308a4ba67 100644 --- a/library/zlib/inflate/inflate_spec.rb +++ b/library/zlib/inflate/inflate_spec.rb @@ -72,7 +72,7 @@ data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*') z = Zlib::Inflate.new # add bytes, one by one - result = "" + result = +"" data.each_byte { |d| result << z.inflate(d.chr)} result << z.finish result.should == "foo" @@ -82,7 +82,7 @@ data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*')[0,5] z = Zlib::Inflate.new # add bytes, one by one, but not all - result = "" + result = +"" data.each_byte { |d| result << z.inflate(d.chr)} -> { result << z.finish }.should raise_error(Zlib::BufError) end @@ -90,7 +90,7 @@ it "properly handles excessive data, byte-by-byte" do main_data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*') data = main_data * 2 - result = "" + result = +"" z = Zlib::Inflate.new # add bytes, one by one @@ -105,7 +105,7 @@ it "properly handles excessive data, in one go" do main_data = [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*') data = main_data * 2 - result = "" + result = +"" z = Zlib::Inflate.new result << z.inflate(data) diff --git a/optional/capi/encoding_spec.rb b/optional/capi/encoding_spec.rb index b0c38d75a9..1529e012b0 100644 --- a/optional/capi/encoding_spec.rb +++ b/optional/capi/encoding_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative 'spec_helper' require_relative 'fixtures/encoding' diff --git a/optional/capi/file_spec.rb b/optional/capi/file_spec.rb index 96d731e4fa..12449b4e34 100644 --- a/optional/capi/file_spec.rb +++ b/optional/capi/file_spec.rb @@ -69,7 +69,7 @@ end it "does not call #to_str on a String" do - obj = "path" + obj = +"path" obj.should_not_receive(:to_str) @s.FilePathValue(obj).should eql(obj) end diff --git a/optional/capi/object_spec.rb b/optional/capi/object_spec.rb index 6ee6d65680..7bc7bd992a 100644 --- a/optional/capi/object_spec.rb +++ b/optional/capi/object_spec.rb @@ -686,7 +686,7 @@ def reach end it "returns false if object passed to it is not frozen" do - obj = "" + obj = +"" @o.rb_obj_frozen_p(obj).should == false end end @@ -700,7 +700,7 @@ def reach end it "does nothing when object isn't frozen" do - obj = "" + obj = +"" -> { @o.rb_check_frozen(obj) }.should_not raise_error(TypeError) end end @@ -894,9 +894,9 @@ def reach describe "rb_copy_generic_ivar for objects which do not store ivars directly" do it "copies the instance variables from one object to another" do - original = "abc" + original = +"abc" original.instance_variable_set(:@foo, :bar) - clone = "def" + clone = +"def" @o.rb_copy_generic_ivar(clone, original) clone.instance_variable_get(:@foo).should == :bar end @@ -904,7 +904,7 @@ def reach describe "rb_free_generic_ivar for objects which do not store ivars directly" do it "removes the instance variables from an object" do - o = "abc" + o = +"abc" o.instance_variable_set(:@baz, :flibble) @o.rb_free_generic_ivar(o) o.instance_variables.should == [] diff --git a/optional/capi/string_spec.rb b/optional/capi/string_spec.rb index d9c20cf176..24b8219efa 100644 --- a/optional/capi/string_spec.rb +++ b/optional/capi/string_spec.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# frozen_string_literal: false require_relative 'spec_helper' require_relative '../../shared/string/times' diff --git a/security/cve_2010_1330_spec.rb b/security/cve_2010_1330_spec.rb index 33e88d652e..2594439550 100644 --- a/security/cve_2010_1330_spec.rb +++ b/security/cve_2010_1330_spec.rb @@ -8,7 +8,7 @@ # #gsub on a string in the UTF-8 encoding but with invalid an UTF-8 byte # sequence. - str = "\xF6