From 10edfdf133da4654d704b2b0fe84387625c92ca0 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 13 Mar 2024 19:06:50 +0100 Subject: [PATCH] Make the spec suite compatible with `--enable-frozen-string-literal` Extracted from: https://github.com/ruby/ruby/pull/10235 Ref: https://bugs.ruby-lang.org/issues/20205 Ruby will gradually move towards enabling frozen string literals by default. Making the ruby spec suite compatible is a good first step. --- .github/workflows/ci.yml | 7 ++ core/argf/readpartial_spec.rb | 2 +- core/argf/shared/getc.rb | 2 +- core/argf/shared/read.rb | 4 +- core/array/fill_spec.rb | 2 +- core/array/fixtures/encoded_strings.rb | 18 ++-- core/array/pack/buffer_spec.rb | 14 ++-- core/array/pack/shared/string.rb | 2 +- core/array/shared/inspect.rb | 6 +- core/complex/inspect_spec.rb | 8 +- core/complex/to_s_spec.rb | 4 +- core/dir/children_spec.rb | 4 +- core/dir/entries_spec.rb | 2 +- core/dir/shared/glob.rb | 2 +- core/encoding/compatible_spec.rb | 74 ++++++++-------- .../converter/asciicompat_encoding_spec.rb | 1 + core/encoding/converter/convert_spec.rb | 1 + core/encoding/converter/finish_spec.rb | 1 + core/encoding/converter/last_error_spec.rb | 1 + core/encoding/converter/new_spec.rb | 1 + .../converter/primitive_convert_spec.rb | 1 + .../converter/primitive_errinfo_spec.rb | 1 + core/encoding/converter/putback_spec.rb | 1 + core/encoding/converter/replacement_spec.rb | 1 + .../incomplete_input_spec.rb | 1 + .../readagain_bytes_spec.rb | 4 +- core/encoding/replicate_spec.rb | 18 ++-- core/enumerator/product/size_spec.rb | 8 ++ core/file/expand_path_spec.rb | 2 +- core/file/shared/path.rb | 2 +- core/hash/assoc_spec.rb | 4 +- core/hash/compare_by_identity_spec.rb | 12 +-- core/hash/element_reference_spec.rb | 2 +- core/hash/shared/store.rb | 8 +- core/hash/shared/to_s.rb | 4 +- core/io/ioctl_spec.rb | 2 +- core/io/pread_spec.rb | 10 +-- core/io/puts_spec.rb | 2 +- core/io/read_nonblock_spec.rb | 8 +- core/io/read_spec.rb | 30 +++---- core/io/readpartial_spec.rb | 6 +- core/io/shared/codepoints.rb | 1 + core/io/shared/readlines.rb | 2 +- core/io/sysread_spec.rb | 14 ++-- core/kernel/Float_spec.rb | 2 +- core/kernel/String_spec.rb | 2 +- core/kernel/catch_spec.rb | 2 +- core/kernel/class_spec.rb | 2 +- core/kernel/eval_spec.rb | 8 +- core/kernel/shared/sprintf_encoding.rb | 8 +- core/marshal/dump_spec.rb | 40 ++++----- core/marshal/fixtures/marshal_data.rb | 8 +- core/marshal/shared/load.rb | 34 ++++---- core/matchdata/element_reference_spec.rb | 2 +- core/matchdata/post_match_spec.rb | 4 +- core/matchdata/pre_match_spec.rb | 4 +- core/matchdata/string_spec.rb | 2 +- core/method/to_proc_spec.rb | 2 +- core/module/using_spec.rb | 2 +- core/objectspace/define_finalizer_spec.rb | 8 +- core/proc/fixtures/proc_aref.rb | 1 + core/regexp/shared/new.rb | 4 +- core/regexp/shared/quote.rb | 10 +-- core/string/ascii_only_spec.rb | 1 + core/string/b_spec.rb | 1 + core/string/byteindex_spec.rb | 1 + core/string/byterindex_spec.rb | 1 + core/string/bytes_spec.rb | 1 + core/string/bytesize_spec.rb | 1 + core/string/byteslice_spec.rb | 1 + core/string/bytesplice_spec.rb | 1 + core/string/capitalize_spec.rb | 1 + core/string/center_spec.rb | 1 + core/string/chomp_spec.rb | 1 + core/string/chop_spec.rb | 1 + core/string/clear_spec.rb | 1 + core/string/codepoints_spec.rb | 1 + core/string/comparison_spec.rb | 1 + core/string/concat_spec.rb | 1 + core/string/delete_prefix_spec.rb | 1 + core/string/delete_spec.rb | 1 + core/string/delete_suffix_spec.rb | 1 + core/string/downcase_spec.rb | 1 + core/string/dup_spec.rb | 1 + core/string/each_byte_spec.rb | 1 + core/string/element_set_spec.rb | 1 + core/string/encode_spec.rb | 1 + core/string/encoding_spec.rb | 1 + core/string/force_encoding_spec.rb | 1 + core/string/freeze_spec.rb | 1 + core/string/gsub_spec.rb | 1 + core/string/include_spec.rb | 1 + core/string/index_spec.rb | 1 + core/string/insert_spec.rb | 2 +- core/string/inspect_spec.rb | 1 + core/string/ljust_spec.rb | 1 + core/string/lstrip_spec.rb | 1 + core/string/ord_spec.rb | 1 + core/string/partition_spec.rb | 1 + core/string/prepend_spec.rb | 1 + core/string/reverse_spec.rb | 1 + core/string/rindex_spec.rb | 1 + core/string/rjust_spec.rb | 1 + core/string/rpartition_spec.rb | 1 + core/string/rstrip_spec.rb | 1 + core/string/scrub_spec.rb | 1 + core/string/setbyte_spec.rb | 1 + core/string/shared/chars.rb | 1 + core/string/shared/codepoints.rb | 1 + core/string/shared/concat.rb | 1 + core/string/shared/dedup.rb | 1 + .../shared/each_codepoint_without_block.rb | 1 + core/string/shared/each_line.rb | 1 + core/string/shared/encode.rb | 1 + core/string/shared/eql.rb | 1 + core/string/shared/length.rb | 1 + core/string/shared/replace.rb | 1 + core/string/shared/slice.rb | 1 + core/string/shared/succ.rb | 1 + core/string/shared/to_sym.rb | 1 + core/string/slice_spec.rb | 2 +- core/string/split_spec.rb | 1 + core/string/squeeze_spec.rb | 1 + core/string/strip_spec.rb | 1 + core/string/sub_spec.rb | 1 + core/string/swapcase_spec.rb | 1 + core/string/tr_s_spec.rb | 1 + core/string/tr_spec.rb | 1 + core/string/uminus_spec.rb | 1 + core/string/unicode_normalize_spec.rb | 1 + core/string/unicode_normalized_spec.rb | 1 + core/string/unpack/a_spec.rb | 1 + core/string/unpack/b_spec.rb | 1 + core/string/unpack/u_spec.rb | 1 + core/string/upcase_spec.rb | 1 + core/string/uplus_spec.rb | 1 + core/string/upto_spec.rb | 1 + core/string/valid_encoding_spec.rb | 1 + core/struct/new_spec.rb | 2 +- core/time/_load_spec.rb | 2 +- core/time/at_spec.rb | 2 +- core/time/fixtures/classes.rb | 1 - language/def_spec.rb | 2 +- language/encoding_spec.rb | 8 +- language/hash_spec.rb | 2 +- language/method_spec.rb | 2 +- language/predefined_spec.rb | 18 ++-- language/regexp/encoding_spec.rb | 42 +++++----- language/send_spec.rb | 2 +- language/singleton_class_spec.rb | 2 +- language/string_spec.rb | 9 +- library/cgi/escapeURIComponent_spec.rb | 2 +- library/csv/generate_spec.rb | 2 +- library/erb/run_spec.rb | 2 +- library/io-wait/fixtures/classes.rb | 2 +- library/net-http/http/post_spec.rb | 2 +- .../net-http/httpgenericrequest/body_spec.rb | 2 +- .../httpgenericrequest/body_stream_spec.rb | 4 +- .../net-http/httpgenericrequest/exec_spec.rb | 10 +-- library/net-http/httpresponse/inspect_spec.rb | 2 +- .../net-http/httpresponse/read_body_spec.rb | 14 ++-- .../httpresponse/reading_body_spec.rb | 2 +- library/net-http/httpresponse/shared/body.rb | 2 +- library/objectspace/fixtures/trace.rb | 1 + library/objectspace/trace_spec.rb | 4 +- library/set/compare_by_identity_spec.rb | 2 +- .../socket/basicsocket/recv_nonblock_spec.rb | 2 +- library/socket/basicsocket/recv_spec.rb | 2 +- library/socket/basicsocket/send_spec.rb | 4 +- .../socket/tcpsocket/recv_nonblock_spec.rb | 2 +- .../udpsocket/recvfrom_nonblock_spec.rb | 2 +- library/socket/udpsocket/send_spec.rb | 2 +- library/stringio/append_spec.rb | 8 +- library/stringio/binmode_spec.rb | 2 +- library/stringio/close_read_spec.rb | 6 +- library/stringio/close_write_spec.rb | 6 +- library/stringio/closed_read_spec.rb | 2 +- library/stringio/closed_spec.rb | 4 +- library/stringio/closed_write_spec.rb | 2 +- library/stringio/fcntl_spec.rb | 2 +- library/stringio/fileno_spec.rb | 2 +- library/stringio/flush_spec.rb | 2 +- library/stringio/fsync_spec.rb | 2 +- library/stringio/getbyte_spec.rb | 2 +- library/stringio/getc_spec.rb | 2 +- library/stringio/getch_spec.rb | 8 +- library/stringio/getpass_spec.rb | 2 +- library/stringio/gets_spec.rb | 18 ++-- library/stringio/initialize_spec.rb | 84 +++++++++---------- library/stringio/inspect_spec.rb | 6 +- library/stringio/lineno_spec.rb | 4 +- library/stringio/open_spec.rb | 60 ++++++------- library/stringio/path_spec.rb | 2 +- library/stringio/pid_spec.rb | 2 +- library/stringio/print_spec.rb | 8 +- library/stringio/printf_spec.rb | 8 +- library/stringio/putc_spec.rb | 10 +-- library/stringio/puts_spec.rb | 8 +- library/stringio/read_nonblock_spec.rb | 10 +-- library/stringio/read_spec.rb | 6 +- library/stringio/readbyte_spec.rb | 2 +- library/stringio/readchar_spec.rb | 2 +- library/stringio/readline_spec.rb | 18 ++-- library/stringio/readlines_spec.rb | 16 ++-- library/stringio/readpartial_spec.rb | 6 +- library/stringio/reopen_spec.rb | 56 ++++++------- library/stringio/rewind_spec.rb | 2 +- library/stringio/seek_spec.rb | 4 +- library/stringio/shared/codepoints.rb | 4 +- library/stringio/shared/each.rb | 24 +++--- library/stringio/shared/each_byte.rb | 6 +- library/stringio/shared/each_char.rb | 6 +- library/stringio/shared/eof.rb | 2 +- library/stringio/shared/getc.rb | 6 +- library/stringio/shared/isatty.rb | 2 +- library/stringio/shared/length.rb | 2 +- library/stringio/shared/read.rb | 20 ++--- library/stringio/shared/readchar.rb | 6 +- library/stringio/shared/sysread.rb | 2 +- library/stringio/shared/write.rb | 10 +-- library/stringio/string_spec.rb | 2 +- library/stringio/sync_spec.rb | 4 +- library/stringio/sysread_spec.rb | 2 +- library/stringio/truncate_spec.rb | 8 +- library/stringio/ungetbyte_spec.rb | 4 +- library/stringio/ungetc_spec.rb | 10 +-- library/stringio/write_nonblock_spec.rb | 2 +- library/stringscanner/check_spec.rb | 2 +- library/stringscanner/check_until_spec.rb | 2 +- library/stringscanner/clear_spec.rb | 2 +- .../stringscanner/element_reference_spec.rb | 2 +- library/stringscanner/empty_spec.rb | 2 +- library/stringscanner/exist_spec.rb | 2 +- library/stringscanner/getbyte_spec.rb | 2 +- library/stringscanner/getch_spec.rb | 2 +- library/stringscanner/initialize_spec.rb | 2 +- library/stringscanner/inspect_spec.rb | 2 +- library/stringscanner/match_spec.rb | 2 +- library/stringscanner/matched_size_spec.rb | 2 +- library/stringscanner/matched_spec.rb | 4 +- library/stringscanner/peep_spec.rb | 2 +- library/stringscanner/post_match_spec.rb | 2 +- library/stringscanner/pre_match_spec.rb | 2 +- library/stringscanner/reset_spec.rb | 2 +- library/stringscanner/rest_spec.rb | 4 +- library/stringscanner/restsize_spec.rb | 2 +- library/stringscanner/scan_full_spec.rb | 2 +- library/stringscanner/scan_spec.rb | 4 +- library/stringscanner/scan_until_spec.rb | 2 +- library/stringscanner/search_full_spec.rb | 2 +- library/stringscanner/shared/bol.rb | 4 +- library/stringscanner/shared/concat.rb | 8 +- library/stringscanner/shared/eos.rb | 2 +- library/stringscanner/shared/get_byte.rb | 2 +- library/stringscanner/shared/peek.rb | 2 +- library/stringscanner/shared/pos.rb | 4 +- library/stringscanner/size_spec.rb | 2 +- library/stringscanner/skip_spec.rb | 2 +- library/stringscanner/skip_until_spec.rb | 2 +- library/stringscanner/string_spec.rb | 4 +- library/stringscanner/unscan_spec.rb | 2 +- library/zlib/deflate/deflate_spec.rb | 4 +- library/zlib/deflate/params_spec.rb | 2 +- library/zlib/inflate/inflate_spec.rb | 8 +- optional/capi/encoding_spec.rb | 1 + optional/capi/file_spec.rb | 2 +- optional/capi/globals_spec.rb | 2 +- optional/capi/object_spec.rb | 10 +-- optional/capi/string_spec.rb | 55 ++++++------ security/cve_2010_1330_spec.rb | 2 +- shared/kernel/object_id.rb | 16 +++- shared/string/end_with.rb | 4 +- shared/string/times.rb | 2 +- 273 files changed, 746 insertions(+), 637 deletions(-) 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/fixtures/encoded_strings.rb b/core/array/fixtures/encoded_strings.rb index 5b85bd0e06..b5888d86ae 100644 --- a/core/array/fixtures/encoded_strings.rb +++ b/core/array/fixtures/encoded_strings.rb @@ -2,14 +2,14 @@ module ArraySpecs def self.array_with_usascii_and_7bit_utf8_strings [ - 'foo'.force_encoding('US-ASCII'), + 'foo'.dup.force_encoding('US-ASCII'), 'bar' ] end def self.array_with_usascii_and_utf8_strings [ - 'foo'.force_encoding('US-ASCII'), + 'foo'.dup.force_encoding('US-ASCII'), 'báz' ] end @@ -17,7 +17,7 @@ def self.array_with_usascii_and_utf8_strings def self.array_with_7bit_utf8_and_usascii_strings [ 'bar', - 'foo'.force_encoding('US-ASCII') + 'foo'.dup.force_encoding('US-ASCII') ] end @@ -25,13 +25,13 @@ def self.array_with_utf8_and_usascii_strings [ 'báz', 'bar', - 'foo'.force_encoding('US-ASCII') + 'foo'.dup.force_encoding('US-ASCII') ] end def self.array_with_usascii_and_utf8_strings [ - 'foo'.force_encoding('US-ASCII'), + 'foo'.dup.force_encoding('US-ASCII'), 'bar', 'báz' ] @@ -41,7 +41,7 @@ def self.array_with_utf8_and_7bit_binary_strings [ 'bar', 'báz', - 'foo'.force_encoding('BINARY') + 'foo'.dup.force_encoding('BINARY') ] end @@ -55,14 +55,14 @@ def self.array_with_utf8_and_binary_strings def self.array_with_usascii_and_7bit_binary_strings [ - 'bar'.force_encoding('US-ASCII'), - 'foo'.force_encoding('BINARY') + 'bar'.dup.force_encoding('US-ASCII'), + 'foo'.dup.force_encoding('BINARY') ] end def self.array_with_usascii_and_binary_strings [ - 'bar'.force_encoding('US-ASCII'), + 'bar'.dup.force_encoding('US-ASCII'), [255].pack('C').force_encoding('BINARY') ] end diff --git a/core/array/pack/buffer_spec.rb b/core/array/pack/buffer_spec.rb index ecb40bfd06..efa7ac51cf 100644 --- a/core/array/pack/buffer_spec.rb +++ b/core/array/pack/buffer_spec.rb @@ -5,7 +5,7 @@ describe "Array#pack with :buffer option" do it "returns specified buffer" do n = [ 65, 66, 67 ] - buffer = " "*3 + buffer = +" "*3 result = n.pack("ccc", buffer: buffer) #=> "ABC" result.should equal(buffer) end @@ -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/pack/shared/string.rb b/core/array/pack/shared/string.rb index 8c82e8c617..2f70dc3951 100644 --- a/core/array/pack/shared/string.rb +++ b/core/array/pack/shared/string.rb @@ -40,7 +40,7 @@ f = pack_format("*") [ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::BINARY], [["abcde\xd1", "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY], - [["a".force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY], + [["a".dup.force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY], # under discussion [ruby-dev:37294] [["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::BINARY] ].should be_computed_by(:encoding) diff --git a/core/array/shared/inspect.rb b/core/array/shared/inspect.rb index a2b43d4959..ac422e98fb 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">.dup.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..0ca2d2f7be 100644 --- a/core/complex/inspect_spec.rb +++ b/core/complex/inspect_spec.rb @@ -17,18 +17,18 @@ it "calls #inspect on real and imaginary" do real = NumericSpecs::Subclass.new - real.should_receive(:inspect).and_return("1") + real.should_receive(:inspect).and_return(+"1") imaginary = NumericSpecs::Subclass.new - imaginary.should_receive(:inspect).and_return("2") + imaginary.should_receive(:inspect).and_return(+"2") imaginary.should_receive(:<).any_number_of_times.and_return(false) Complex(real, imaginary).inspect.should == "(1+2i)" end 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)") + real.should_receive(:inspect).and_return(+"(1)") imaginary = NumericSpecs::Subclass.new - imaginary.should_receive(:inspect).and_return("(2)") + imaginary.should_receive(:inspect).and_return(+"(2)") imaginary.should_receive(:<).any_number_of_times.and_return(false) Complex(real, imaginary).inspect.should == "((1)+(2)*i)" end diff --git a/core/complex/to_s_spec.rb b/core/complex/to_s_spec.rb index 7677dcd0b5..754aaff213 100644 --- a/core/complex/to_s_spec.rb +++ b/core/complex/to_s_spec.rb @@ -45,9 +45,9 @@ it "treats real and imaginary parts as strings" do real = NumericSpecs::Subclass.new - real.should_receive(:to_s).and_return("1") + real.should_receive(:to_s).and_return(+"1") imaginary = NumericSpecs::Subclass.new - imaginary.should_receive(:to_s).and_return("2") + imaginary.should_receive(:to_s).and_return(+"2") imaginary.should_receive(:<).any_number_of_times.and_return(false) Complex(real, imaginary).to_s.should == "1+2i" end diff --git a/core/dir/children_spec.rb b/core/dir/children_spec.rb index 03698cc246..92c593e5ba 100644 --- a/core/dir/children_spec.rb +++ b/core/dir/children_spec.rb @@ -47,7 +47,7 @@ encoding = Encoding.find("filesystem") encoding = Encoding::BINARY if encoding == Encoding::US_ASCII platform_is_not :windows do - children.should include("こんにちは.txt".force_encoding(encoding)) + children.should include("こんにちは.txt".dup.force_encoding(encoding)) end children.first.encoding.should equal(Encoding.find("filesystem")) end @@ -113,7 +113,7 @@ encoding = Encoding.find("filesystem") encoding = Encoding::BINARY if encoding == Encoding::US_ASCII platform_is_not :windows do - children.should include("こんにちは.txt".force_encoding(encoding)) + children.should include("こんにちは.txt".dup.force_encoding(encoding)) end children.first.encoding.should equal(Encoding.find("filesystem")) end diff --git a/core/dir/entries_spec.rb b/core/dir/entries_spec.rb index 91c30fccae..7462542acf 100644 --- a/core/dir/entries_spec.rb +++ b/core/dir/entries_spec.rb @@ -47,7 +47,7 @@ encoding = Encoding.find("filesystem") encoding = Encoding::BINARY if encoding == Encoding::US_ASCII platform_is_not :windows do - entries.should include("こんにちは.txt".force_encoding(encoding)) + entries.should include("こんにちは.txt".dup.force_encoding(encoding)) end entries.first.encoding.should equal(Encoding.find("filesystem")) end diff --git a/core/dir/shared/glob.rb b/core/dir/shared/glob.rb index 27ae0e3000..745f02d46b 100644 --- a/core/dir/shared/glob.rb +++ b/core/dir/shared/glob.rb @@ -12,7 +12,7 @@ end it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do - pattern = "file*".force_encoding Encoding::UTF_16BE + pattern = "file*".dup.force_encoding Encoding::UTF_16BE -> { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError) end diff --git a/core/encoding/compatible_spec.rb b/core/encoding/compatible_spec.rb index 80ecab6155..f18d8680a9 100644 --- a/core/encoding/compatible_spec.rb +++ b/core/encoding/compatible_spec.rb @@ -7,7 +7,7 @@ describe "Encoding.compatible? String, String" do describe "when the first's Encoding is valid US-ASCII" do before :each do - @str = "abc".force_encoding Encoding::US_ASCII + @str = "abc".dup.force_encoding Encoding::US_ASCII end it "returns US-ASCII when the second's is US-ASCII" do @@ -33,28 +33,28 @@ describe "when the first's Encoding is ASCII compatible and ASCII only" do it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do - [ [Encoding, "abc".force_encoding("UTF-8"), "123".force_encoding("Shift_JIS"), Encoding::UTF_8], - [Encoding, "123".force_encoding("Shift_JIS"), "abc".force_encoding("UTF-8"), Encoding::Shift_JIS] + [ [Encoding, "abc".dup.force_encoding("UTF-8"), "123".dup.force_encoding("Shift_JIS"), Encoding::UTF_8], + [Encoding, "123".dup.force_encoding("Shift_JIS"), "abc".dup.force_encoding("UTF-8"), Encoding::Shift_JIS] ].should be_computed_by(:compatible?) end it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do - [ [Encoding, "abc".force_encoding("BINARY"), "123".force_encoding("US-ASCII"), Encoding::BINARY], - [Encoding, "123".force_encoding("US-ASCII"), "abc".force_encoding("BINARY"), Encoding::US_ASCII] + [ [Encoding, "abc".dup.force_encoding("BINARY"), "123".dup.force_encoding("US-ASCII"), Encoding::BINARY], + [Encoding, "123".dup.force_encoding("US-ASCII"), "abc".dup.force_encoding("BINARY"), Encoding::US_ASCII] ].should be_computed_by(:compatible?) end it "returns the second's Encoding if the second is ASCII compatible but not ASCII only" do - [ [Encoding, "abc".force_encoding("UTF-8"), "\xff".force_encoding("Shift_JIS"), Encoding::Shift_JIS], - [Encoding, "123".force_encoding("Shift_JIS"), "\xff".force_encoding("UTF-8"), Encoding::UTF_8], - [Encoding, "abc".force_encoding("BINARY"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII], - [Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("BINARY"), Encoding::BINARY], + [ [Encoding, "abc".dup.force_encoding("UTF-8"), "\xff".dup.force_encoding("Shift_JIS"), Encoding::Shift_JIS], + [Encoding, "123".dup.force_encoding("Shift_JIS"), "\xff".dup.force_encoding("UTF-8"), Encoding::UTF_8], + [Encoding, "abc".dup.force_encoding("BINARY"), "\xff".dup.force_encoding("US-ASCII"), Encoding::US_ASCII], + [Encoding, "123".dup.force_encoding("US-ASCII"), "\xff".dup.force_encoding("BINARY"), Encoding::BINARY], ].should be_computed_by(:compatible?) end it "returns nil if the second's Encoding is not ASCII compatible" do - a = "abc".force_encoding("UTF-8") - b = "1234".force_encoding("UTF-16LE") + a = "abc".dup.force_encoding("UTF-8") + b = "1234".dup.force_encoding("UTF-16LE") Encoding.compatible?(a, b).should be_nil end end @@ -75,7 +75,7 @@ describe "when the first's Encoding is not ASCII compatible" do before :each do - @str = "abc".force_encoding Encoding::UTF_7 + @str = "abc".dup.force_encoding Encoding::UTF_7 end it "returns nil when the second String is US-ASCII" do @@ -91,14 +91,14 @@ end it "returns the Encoding when the second's Encoding is not ASCII compatible but the same as the first's Encoding" do - encoding = Encoding.compatible?(@str, "def".force_encoding("utf-7")) + encoding = Encoding.compatible?(@str, "def".dup.force_encoding("utf-7")) encoding.should == Encoding::UTF_7 end end describe "when the first's Encoding is invalid" do before :each do - @str = "\xff".force_encoding Encoding::UTF_8 + @str = "\xff".dup.force_encoding Encoding::UTF_8 end it "returns the first's Encoding when the second's Encoding is US-ASCII" do @@ -114,11 +114,11 @@ end it "returns nil when the second's Encoding is invalid and ASCII only" do - Encoding.compatible?(@str, "\x7f".force_encoding("utf-16be")).should be_nil + Encoding.compatible?(@str, "\x7f".dup.force_encoding("utf-16be")).should be_nil end it "returns nil when the second's Encoding is invalid and not ASCII only" do - Encoding.compatible?(@str, "\xff".force_encoding("utf-16be")).should be_nil + Encoding.compatible?(@str, "\xff".dup.force_encoding("utf-16be")).should be_nil end it "returns the Encoding when the second's Encoding is invalid but the same as the first" do @@ -129,7 +129,7 @@ describe "when the first String is empty and the second is not" do describe "and the first's Encoding is ASCII compatible" do before :each do - @str = "".force_encoding("utf-8") + @str = "".dup.force_encoding("utf-8") end it "returns the first's encoding when the second String is ASCII only" do @@ -143,7 +143,7 @@ describe "when the first's Encoding is not ASCII compatible" do before :each do - @str = "".force_encoding Encoding::UTF_7 + @str = "".dup.force_encoding Encoding::UTF_7 end it "returns the second string's encoding" do @@ -154,7 +154,7 @@ describe "when the second String is empty" do before :each do - @str = "abc".force_encoding("utf-7") + @str = "abc".dup.force_encoding("utf-7") end it "returns the first Encoding" do @@ -165,7 +165,7 @@ describe "Encoding.compatible? String, Regexp" do it "returns US-ASCII if both are US-ASCII" do - str = "abc".force_encoding("us-ascii") + str = "abc".dup.force_encoding("us-ascii") Encoding.compatible?(str, /abc/).should == Encoding::US_ASCII end @@ -180,15 +180,15 @@ it "returns the String's Encoding if the String is not ASCII only" do [ [Encoding, "\xff", Encoding::BINARY], [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8], - [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP], - [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS], + [Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP], + [Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS], ].should be_computed_by(:compatible?, /abc/) end end describe "Encoding.compatible? String, Symbol" do it "returns US-ASCII if both are ASCII only" do - str = "abc".force_encoding("us-ascii") + str = "abc".dup.force_encoding("us-ascii") Encoding.compatible?(str, :abc).should == Encoding::US_ASCII end @@ -203,8 +203,8 @@ it "returns the String's Encoding if the String is not ASCII only" do [ [Encoding, "\xff", Encoding::BINARY], [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8], - [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP], - [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS], + [Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP], + [Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS], ].should be_computed_by(:compatible?, :abc) end end @@ -221,8 +221,8 @@ it "returns the String's encoding if the Encoding is US-ASCII" do [ [Encoding, "\xff", Encoding::BINARY], [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8], - [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP], - [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS], + [Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP], + [Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS], ].should be_computed_by(:compatible?, Encoding::US_ASCII) end @@ -242,7 +242,7 @@ describe "Encoding.compatible? Regexp, String" do it "returns US-ASCII if both are US-ASCII" do - str = "abc".force_encoding("us-ascii") + str = "abc".dup.force_encoding("us-ascii") Encoding.compatible?(/abc/, str).should == Encoding::US_ASCII end @@ -256,8 +256,8 @@ it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do [ [Encoding, Regexp.new("\xff"), Encoding::BINARY], [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8], - [Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP], - [Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS], + [Encoding, Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp")), Encoding::EUC_JP], + [Encoding, Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")), Encoding::Shift_JIS], ].should be_computed_by(:compatible?, /abc/) end end @@ -270,15 +270,15 @@ it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do [ [Encoding, Regexp.new("\xff"), Encoding::BINARY], [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8], - [Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP], - [Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS], + [Encoding, Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp")), Encoding::EUC_JP], + [Encoding, Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")), Encoding::Shift_JIS], ].should be_computed_by(:compatible?, /abc/) end end describe "Encoding.compatible? Symbol, String" do it "returns US-ASCII if both are ASCII only" do - str = "abc".force_encoding("us-ascii") + str = "abc".dup.force_encoding("us-ascii") Encoding.compatible?(str, :abc).should == Encoding::US_ASCII end end @@ -291,8 +291,8 @@ it "returns the Regexp's Encoding if it is not US-ASCII and not ASCII only" do a = Regexp.new("\xff") b = Regexp.new("\u3042".encode("utf-8")) - c = Regexp.new("\xa4\xa2".force_encoding("euc-jp")) - d = Regexp.new("\x82\xa0".force_encoding("shift_jis")) + c = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp")) + d = Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")) [ [Encoding, :abc, a, Encoding::BINARY], [Encoding, :abc, b, Encoding::UTF_8], @@ -310,8 +310,8 @@ it "returns the first's Encoding if it is not ASCII only" do [ [Encoding, "\xff".to_sym, Encoding::BINARY], [Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8], - [Encoding, "\xa4\xa2".force_encoding("euc-jp").to_sym, Encoding::EUC_JP], - [Encoding, "\x82\xa0".force_encoding("shift_jis").to_sym, Encoding::Shift_JIS], + [Encoding, "\xa4\xa2".dup.force_encoding("euc-jp").to_sym, Encoding::EUC_JP], + [Encoding, "\x82\xa0".dup.force_encoding("shift_jis").to_sym, Encoding::Shift_JIS], ].should be_computed_by(:compatible?, :abc) end end diff --git a/core/encoding/converter/asciicompat_encoding_spec.rb b/core/encoding/converter/asciicompat_encoding_spec.rb index 1beb40af3f..16b64569f8 100644 --- a/core/encoding/converter/asciicompat_encoding_spec.rb +++ b/core/encoding/converter/asciicompat_encoding_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter.asciicompat_encoding" do diff --git a/core/encoding/converter/convert_spec.rb b/core/encoding/converter/convert_spec.rb index 95a9e0b758..37dab80c4b 100644 --- a/core/encoding/converter/convert_spec.rb +++ b/core/encoding/converter/convert_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter#convert" do diff --git a/core/encoding/converter/finish_spec.rb b/core/encoding/converter/finish_spec.rb index 11ca7e8510..3c57ec1c6c 100644 --- a/core/encoding/converter/finish_spec.rb +++ b/core/encoding/converter/finish_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter#finish" do diff --git a/core/encoding/converter/last_error_spec.rb b/core/encoding/converter/last_error_spec.rb index 68567737b7..455b4bcc35 100644 --- a/core/encoding/converter/last_error_spec.rb +++ b/core/encoding/converter/last_error_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter#last_error" do diff --git a/core/encoding/converter/new_spec.rb b/core/encoding/converter/new_spec.rb index 1f7affc72b..e1fa210cd0 100644 --- a/core/encoding/converter/new_spec.rb +++ b/core/encoding/converter/new_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter.new" do 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..239195964e 100644 --- a/core/encoding/converter/putback_spec.rb +++ b/core/encoding/converter/putback_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter#putback" do diff --git a/core/encoding/converter/replacement_spec.rb b/core/encoding/converter/replacement_spec.rb index 5ca42e7e5a..5f2c74d81c 100644 --- a/core/encoding/converter/replacement_spec.rb +++ b/core/encoding/converter/replacement_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::Converter#replacement" do 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..cb4cba54ed 100644 --- a/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb +++ b/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' describe "Encoding::InvalidByteSequenceError#incomplete_input?" do diff --git a/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb b/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb index 9866310c25..a5e2824984 100644 --- a/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb +++ b/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb @@ -15,11 +15,11 @@ it "returns the bytes to be read again" do @exception.readagain_bytes.size.should == 1 - @exception.readagain_bytes.should == "a".force_encoding('binary') + @exception.readagain_bytes.should == "a".dup.force_encoding('binary') @exception.readagain_bytes.should == @errinfo[-1] @exception2.readagain_bytes.size.should == 1 - @exception2.readagain_bytes.should == "\xFF".force_encoding('binary') + @exception2.readagain_bytes.should == "\xFF".dup.force_encoding('binary') @exception2.readagain_bytes.should == @errinfo2[-1] end diff --git a/core/encoding/replicate_spec.rb b/core/encoding/replicate_spec.rb index 68c285158d..e22673db7d 100644 --- a/core/encoding/replicate_spec.rb +++ b/core/encoding/replicate_spec.rb @@ -18,8 +18,8 @@ e.name.should == name Encoding.find(name).should == e - "a".force_encoding(e).valid_encoding?.should be_true - "\x80".force_encoding(e).valid_encoding?.should be_false + "a".dup.force_encoding(e).valid_encoding?.should be_true + "\x80".dup.force_encoding(e).valid_encoding?.should be_false end it "returns a replica of UTF-8" do @@ -28,9 +28,9 @@ e.name.should == name Encoding.find(name).should == e - "a".force_encoding(e).valid_encoding?.should be_true - "\u3042".force_encoding(e).valid_encoding?.should be_true - "\x80".force_encoding(e).valid_encoding?.should be_false + "a".dup.force_encoding(e).valid_encoding?.should be_true + "\u3042".dup.force_encoding(e).valid_encoding?.should be_true + "\x80".dup.force_encoding(e).valid_encoding?.should be_false end it "returns a replica of UTF-16BE" do @@ -39,9 +39,9 @@ e.name.should == name Encoding.find(name).should == e - "a".force_encoding(e).valid_encoding?.should be_false - "\x30\x42".force_encoding(e).valid_encoding?.should be_true - "\x80".force_encoding(e).valid_encoding?.should be_false + "a".dup.force_encoding(e).valid_encoding?.should be_false + "\x30\x42".dup.force_encoding(e).valid_encoding?.should be_true + "\x80".dup.force_encoding(e).valid_encoding?.should be_false end it "returns a replica of ISO-2022-JP" do @@ -61,7 +61,7 @@ e.name.should == name Encoding.find(name).should == e - s = "abc".force_encoding(e) + s = "abc".dup.force_encoding(e) s.encoding.should == e s.encoding.name.should == name end diff --git a/core/enumerator/product/size_spec.rb b/core/enumerator/product/size_spec.rb index 46958b1a22..fb0efdf748 100644 --- a/core/enumerator/product/size_spec.rb +++ b/core/enumerator/product/size_spec.rb @@ -23,6 +23,14 @@ def enum.size; Float::INFINITY; end product.size.should == Float::INFINITY end + it "returns -Float::INFINITY if any enumerable reports its size as -Float::INFINITY" do + enum = Object.new + def enum.size; -Float::INFINITY; end + + product = Enumerator::Product.new(1..2, enum) + product.size.should == -Float::INFINITY + end + it "returns nil if any enumerable reports its size as Float::NAN" do enum = Object.new def enum.size; Float::NAN; end diff --git a/core/file/expand_path_spec.rb b/core/file/expand_path_spec.rb index c31f885b92..1abcf93900 100644 --- a/core/file/expand_path_spec.rb +++ b/core/file/expand_path_spec.rb @@ -137,7 +137,7 @@ it "returns a String in the same encoding as the argument" do Encoding.default_external = Encoding::SHIFT_JIS - path = "./a".force_encoding Encoding::CP1251 + path = "./a".dup.force_encoding Encoding::CP1251 File.expand_path(path).encoding.should equal(Encoding::CP1251) weird_path = [222, 173, 190, 175].pack('C*') diff --git a/core/file/shared/path.rb b/core/file/shared/path.rb index ee8109ba05..f65031eb6b 100644 --- a/core/file/shared/path.rb +++ b/core/file/shared/path.rb @@ -1,6 +1,6 @@ describe :file_path, shared: true do before :each do - @name = "file_to_path" + @name = +"file_to_path" @path = tmp(@name) touch @path end diff --git a/core/hash/assoc_spec.rb b/core/hash/assoc_spec.rb index 64442918d1..06223ed994 100644 --- a/core/hash/assoc_spec.rb +++ b/core/hash/assoc_spec.rb @@ -24,9 +24,9 @@ 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 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..9a7b0f2297 100644 --- a/core/hash/compare_by_identity_spec.rb +++ b/core/hash/compare_by_identity_spec.rb @@ -87,15 +87,15 @@ def o.hash; 123; end # Behaviour confirmed in bug #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 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 end @@ -109,8 +109,8 @@ def o.hash; 123; end end it "gives different identity for string literals" do - @idh['foo'] = 1 - @idh['foo'] = 2 + @idh['foo'.dup] = 1 + @idh['foo'.dup] = 2 @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..08f7f39c64 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">.dup.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..eb3652e692 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,13 +588,13 @@ 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 it "sets the buffer's encoding to the internal encoding" do - buf = "".force_encoding Encoding::ISO_8859_1 + buf = "".dup.force_encoding Encoding::ISO_8859_1 @io.read(nil, buf) buf.encoding.should equal(Encoding::UTF_8) end @@ -612,14 +612,14 @@ end it "does not change the buffer's encoding when passed a limit" do - buf = "".force_encoding Encoding::ISO_8859_1 + buf = "".dup.force_encoding Encoding::ISO_8859_1 @io.read(4, buf) buf.should == [164, 162, 164, 234].pack('C*').force_encoding(Encoding::ISO_8859_1) buf.encoding.should equal(Encoding::ISO_8859_1) end it "truncates the buffer but does not change the buffer's encoding when no data remains" do - buf = "abc".force_encoding Encoding::ISO_8859_1 + buf = "abc".dup.force_encoding Encoding::ISO_8859_1 @io.read @io.read(1, buf).should be_nil 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/shared/codepoints.rb b/core/io/shared/codepoints.rb index 6872846c1a..d10c435a86 100644 --- a/core/io/shared/codepoints.rb +++ b/core/io/shared/codepoints.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../fixtures/classes' describe :io_codepoints, shared: true do diff --git a/core/io/shared/readlines.rb b/core/io/shared/readlines.rb index d2b604bba3..6c1fa11a59 100644 --- a/core/io/shared/readlines.rb +++ b/core/io/shared/readlines.rb @@ -99,7 +99,7 @@ end it "accepts non-ASCII data as separator" do - result = IO.send(@method, @name, "\303\250".force_encoding("utf-8"), &@object) + result = IO.send(@method, @name, "\303\250".dup.force_encoding("utf-8"), &@object) (result ? result : ScratchPad.recorded).should == IOSpecs.lines_arbitrary_separator end 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/kernel/shared/sprintf_encoding.rb b/core/kernel/shared/sprintf_encoding.rb index 9cedb8b662..7ec0fe4c48 100644 --- a/core/kernel/shared/sprintf_encoding.rb +++ b/core/kernel/shared/sprintf_encoding.rb @@ -14,14 +14,14 @@ end it "returns a String in the same encoding as the format String if compatible" do - string = "%s".force_encoding(Encoding::KOI8_U) + string = "%s".dup.force_encoding(Encoding::KOI8_U) result = @method.call(string, "dogs") result.encoding.should equal(Encoding::KOI8_U) end it "returns a String in the argument's encoding if format encoding is more restrictive" do - string = "foo %s".force_encoding(Encoding::US_ASCII) - argument = "b\303\274r".force_encoding(Encoding::UTF_8) + string = "foo %s".dup.force_encoding(Encoding::US_ASCII) + argument = "b\303\274r".dup.force_encoding(Encoding::UTF_8) result = @method.call(string, argument) result.encoding.should equal(Encoding::UTF_8) @@ -56,7 +56,7 @@ end it "uses the encoding of the format string to interpret codepoints" do - format = "%c".force_encoding("euc-jp") + format = "%c".dup.force_encoding("euc-jp") result = @method.call(format, 9415601) result.encoding.should == Encoding::EUC_JP diff --git a/core/marshal/dump_spec.rb b/core/marshal/dump_spec.rb index 34db6fef83..0f77279a4f 100644 --- a/core/marshal/dump_spec.rb +++ b/core/marshal/dump_spec.rb @@ -76,7 +76,7 @@ end it "dumps a binary encoded Symbol" do - s = "\u2192".force_encoding("binary").to_sym + s = "\u2192".dup.force_encoding("binary").to_sym Marshal.dump(s).should == "\x04\b:\b\xE2\x86\x92" end @@ -85,8 +85,8 @@ symbol1 = "I:\t\xE2\x82\xACa\x06:\x06ET" symbol2 = "I:\t\xE2\x82\xACb\x06;\x06T" value = [ - "€a".force_encoding(Encoding::UTF_8).to_sym, - "€b".force_encoding(Encoding::UTF_8).to_sym + "€a".dup.force_encoding(Encoding::UTF_8).to_sym, + "€b".dup.force_encoding(Encoding::UTF_8).to_sym ] Marshal.dump(value).should == "\x04\b[\a#{symbol1}#{symbol2}" @@ -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 @@ -194,7 +194,7 @@ def _dump(level) end it "dumps a class with multibyte characters in name" do - source_object = eval("MarshalSpec::MultibyteぁあぃいClass".force_encoding(Encoding::UTF_8)) + source_object = eval("MarshalSpec::MultibyteぁあぃいClass".dup.force_encoding(Encoding::UTF_8)) Marshal.dump(source_object).should == "\x04\bc,MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Class" end @@ -217,7 +217,7 @@ def _dump(level) end it "dumps a module with multibyte characters in name" do - source_object = eval("MarshalSpec::MultibyteけげこごModule".force_encoding(Encoding::UTF_8)) + source_object = eval("MarshalSpec::MultibyteけげこごModule".dup.force_encoding(Encoding::UTF_8)) Marshal.dump(source_object).should == "\x04\bm-MarshalSpec::Multibyte\xE3\x81\x91\xE3\x81\x92\xE3\x81\x93\xE3\x81\x94Module" end @@ -285,11 +285,11 @@ def _dump(level) describe "with a String" do it "dumps a blank String" do - Marshal.dump("".force_encoding("binary")).should == "\004\b\"\000" + Marshal.dump("".dup.force_encoding("binary")).should == "\004\b\"\000" end it "dumps a short String" do - Marshal.dump("short".force_encoding("binary")).should == "\004\b\"\012short" + Marshal.dump("short".dup.force_encoding("binary")).should == "\004\b\"\012short" end it "dumps a long String" do @@ -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,23 +314,23 @@ 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 it "dumps a US-ASCII String" do - str = "abc".force_encoding("us-ascii") + str = "abc".dup.force_encoding("us-ascii") Marshal.dump(str).should == "\x04\bI\"\babc\x06:\x06EF" end it "dumps a UTF-8 String" do - str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8") + str = "\x6d\xc3\xb6\x68\x72\x65".dup.force_encoding("utf-8") Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET" end it "dumps a String in another encoding" do - str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le") + str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".dup.force_encoding("utf-16le") result = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE" Marshal.dump(str).should == result end @@ -364,7 +364,7 @@ def _dump(level) end it "dumps a binary Regexp" do - o = Regexp.new("".force_encoding("binary"), Regexp::FIXEDENCODING) + o = Regexp.new("".dup.force_encoding("binary"), Regexp::FIXEDENCODING) Marshal.dump(o).should == "\x04\b/\x00\x10" end @@ -383,18 +383,18 @@ def _dump(level) end it "dumps a UTF-8 Regexp" do - o = Regexp.new("".force_encoding("utf-8"), Regexp::FIXEDENCODING) + o = Regexp.new("".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING) Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\x06ET" - o = Regexp.new("a".force_encoding("utf-8"), Regexp::FIXEDENCODING) + o = Regexp.new("a".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING) Marshal.dump(o).should == "\x04\bI/\x06a\x10\x06:\x06ET" - o = Regexp.new("\u3042".force_encoding("utf-8"), Regexp::FIXEDENCODING) + o = Regexp.new("\u3042".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING) Marshal.dump(o).should == "\x04\bI/\b\xE3\x81\x82\x10\x06:\x06ET" end it "dumps a Regexp in another encoding" do - o = Regexp.new("".force_encoding("utf-16le"), Regexp::FIXEDENCODING) + o = Regexp.new("".dup.force_encoding("utf-16le"), Regexp::FIXEDENCODING) Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\rencoding\"\rUTF-16LE" o = Regexp.new("a".encode("utf-16le"), Regexp::FIXEDENCODING) @@ -553,7 +553,7 @@ def _dump(level) it "dumps an Object with a non-US-ASCII instance variable" do obj = Object.new - ivar = "@é".force_encoding(Encoding::UTF_8).to_sym + ivar = "@é".dup.force_encoding(Encoding::UTF_8).to_sym obj.instance_variable_set(ivar, 1) Marshal.dump(obj).should == "\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06" end @@ -685,7 +685,7 @@ def finalizer.noop(_) end it "dumps a Time subclass with multibyte characters in name" do - source_object = eval("MarshalSpec::MultibyteぁあぃいTime".force_encoding(Encoding::UTF_8)) + source_object = eval("MarshalSpec::MultibyteぁあぃいTime".dup.force_encoding(Encoding::UTF_8)) Marshal.dump(source_object).should == "\x04\bc+MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Time" 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..1c8fa4c38c 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' @@ -600,7 +600,7 @@ end it "loads a binary encoded Symbol" do - s = "\u2192".force_encoding("binary").to_sym + s = "\u2192".dup.force_encoding("binary").to_sym sym = Marshal.send(@method, "\x04\b:\b\xE2\x86\x92") sym.should == s sym.encoding.should == Encoding::BINARY @@ -614,8 +614,8 @@ value = Marshal.send(@method, dump) value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8] expected = [ - "€a".force_encoding(Encoding::UTF_8).to_sym, - "€b".force_encoding(Encoding::UTF_8).to_sym + "€a".dup.force_encoding(Encoding::UTF_8).to_sym, + "€b".dup.force_encoding(Encoding::UTF_8).to_sym ] value.should == expected @@ -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 @@ -663,7 +663,7 @@ def io.binmode; raise "binmode"; end end it "loads a US-ASCII String" do - str = "abc".force_encoding("us-ascii") + str = "abc".dup.force_encoding("us-ascii") data = "\x04\bI\"\babc\x06:\x06EF" result = Marshal.send(@method, data) result.should == str @@ -671,7 +671,7 @@ def io.binmode; raise "binmode"; end end it "loads a UTF-8 String" do - str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8") + str = "\x6d\xc3\xb6\x68\x72\x65".dup.force_encoding("utf-8") data = "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET" result = Marshal.send(@method, data) result.should == str @@ -679,7 +679,7 @@ def io.binmode; raise "binmode"; end end it "loads a String in another encoding" do - str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le") + str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".dup.force_encoding("utf-16le") data = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE" result = Marshal.send(@method, data) result.should == str @@ -687,8 +687,8 @@ def io.binmode; raise "binmode"; end end it "loads a String as BINARY if no encoding is specified at the end" do - str = "\xC3\xB8".force_encoding("BINARY") - data = "\x04\b\"\a\xC3\xB8".force_encoding("UTF-8") + str = "\xC3\xB8".dup.force_encoding("BINARY") + data = "\x04\b\"\a\xC3\xB8".dup.force_encoding("UTF-8") result = Marshal.send(@method, data) result.encoding.should == Encoding::BINARY result.should == str @@ -823,7 +823,7 @@ def io.binmode; raise "binmode"; end end it "loads an Object with a non-US-ASCII instance variable" do - ivar = "@é".force_encoding(Encoding::UTF_8).to_sym + ivar = "@é".dup.force_encoding(Encoding::UTF_8).to_sym obj = Marshal.send(@method, "\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06") obj.instance_variables.should == [ivar] obj.instance_variables[0].encoding.should == Encoding::UTF_8 diff --git a/core/matchdata/element_reference_spec.rb b/core/matchdata/element_reference_spec.rb index 1be399cfe1..806db2d7b5 100644 --- a/core/matchdata/element_reference_spec.rb +++ b/core/matchdata/element_reference_spec.rb @@ -113,7 +113,7 @@ it "returns matches in the String's encoding" do rex = /(?t(?ack))/u - md = 'haystack'.force_encoding('euc-jp').match(rex) + md = 'haystack'.dup.force_encoding('euc-jp').match(rex) md[:t].encoding.should == Encoding::EUC_JP end end diff --git a/core/matchdata/post_match_spec.rb b/core/matchdata/post_match_spec.rb index b8d1e032eb..7bfe6df119 100644 --- a/core/matchdata/post_match_spec.rb +++ b/core/matchdata/post_match_spec.rb @@ -8,12 +8,12 @@ end it "sets the encoding to the encoding of the source String" do - str = "abc".force_encoding Encoding::EUC_JP + str = "abc".dup.force_encoding Encoding::EUC_JP str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP) end it "sets an empty result to the encoding of the source String" do - str = "abc".force_encoding Encoding::ISO_8859_1 + str = "abc".dup.force_encoding Encoding::ISO_8859_1 str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1) end diff --git a/core/matchdata/pre_match_spec.rb b/core/matchdata/pre_match_spec.rb index 741cb6e923..2f1ba9b8f6 100644 --- a/core/matchdata/pre_match_spec.rb +++ b/core/matchdata/pre_match_spec.rb @@ -8,12 +8,12 @@ end it "sets the encoding to the encoding of the source String" do - str = "abc".force_encoding Encoding::EUC_JP + str = "abc".dup.force_encoding Encoding::EUC_JP str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP) end it "sets an empty result to the encoding of the source String" do - str = "abc".force_encoding Encoding::ISO_8859_1 + str = "abc".dup.force_encoding Encoding::ISO_8859_1 str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1) end diff --git a/core/matchdata/string_spec.rb b/core/matchdata/string_spec.rb index 420233e1f3..f53d00f075 100644 --- a/core/matchdata/string_spec.rb +++ b/core/matchdata/string_spec.rb @@ -18,7 +18,7 @@ end it "returns a frozen copy of the matched string for gsub(String)" do - 'he[[o'.gsub!('[', ']') + 'he[[o'.dup.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/regexp/shared/new.rb b/core/regexp/shared/new.rb index 06c32e36cd..7c3fabf612 100644 --- a/core/regexp/shared/new.rb +++ b/core/regexp/shared/new.rb @@ -489,12 +489,12 @@ def obj.to_int() ScratchPad.record(:called) end end it "returns a Regexp with the input String's encoding" do - str = "\x82\xa0".force_encoding(Encoding::Shift_JIS) + str = "\x82\xa0".dup.force_encoding(Encoding::Shift_JIS) Regexp.send(@method, str).encoding.should == Encoding::Shift_JIS end it "returns a Regexp with source String having the input String's encoding" do - str = "\x82\xa0".force_encoding(Encoding::Shift_JIS) + str = "\x82\xa0".dup.force_encoding(Encoding::Shift_JIS) Regexp.send(@method, str).source.encoding.should == Encoding::Shift_JIS end end diff --git a/core/regexp/shared/quote.rb b/core/regexp/shared/quote.rb index 9533102766..b5ecc35f04 100644 --- a/core/regexp/shared/quote.rb +++ b/core/regexp/shared/quote.rb @@ -18,23 +18,23 @@ end it "works for broken strings" do - Regexp.send(@method, "a.\x85b.".force_encoding("US-ASCII")).should =="a\\.\x85b\\.".force_encoding("US-ASCII") - Regexp.send(@method, "a.\x80".force_encoding("UTF-8")).should == "a\\.\x80".force_encoding("UTF-8") + Regexp.send(@method, "a.\x85b.".dup.force_encoding("US-ASCII")).should =="a\\.\x85b\\.".dup.force_encoding("US-ASCII") + Regexp.send(@method, "a.\x80".dup.force_encoding("UTF-8")).should == "a\\.\x80".dup.force_encoding("UTF-8") end it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do - str = "abc".force_encoding("euc-jp") + str = "abc".dup.force_encoding("euc-jp") Regexp.send(@method, str).encoding.should == Encoding::US_ASCII end it "sets the encoding of the result to the encoding of the String if any non-US-ASCII characters are present in an input String with valid encoding" do - str = "ありがとう".force_encoding("utf-8") + str = "ありがとう".dup.force_encoding("utf-8") str.valid_encoding?.should be_true Regexp.send(@method, str).encoding.should == Encoding::UTF_8 end it "sets the encoding of the result to BINARY if any non-US-ASCII characters are present in an input String with invalid encoding" do - str = "\xff".force_encoding "us-ascii" + str = "\xff".dup.force_encoding "us-ascii" str.valid_encoding?.should be_false Regexp.send(@method, "\xff").encoding.should == Encoding::BINARY end diff --git a/core/string/ascii_only_spec.rb b/core/string/ascii_only_spec.rb index c7e02fd874..d583dd4033 100644 --- a/core/string/ascii_only_spec.rb +++ b/core/string/ascii_only_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/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/byteindex_spec.rb b/core/string/byteindex_spec.rb index 7be0c7ec1e..af9f9c9706 100644 --- a/core/string/byteindex_spec.rb +++ b/core/string/byteindex_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/byte_index_common.rb' diff --git a/core/string/byterindex_spec.rb b/core/string/byterindex_spec.rb index 717708c97d..b9e4c601db 100644 --- a/core/string/byterindex_spec.rb +++ b/core/string/byterindex_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/byte_index_common.rb' diff --git a/core/string/bytes_spec.rb b/core/string/bytes_spec.rb index 859b346550..f465417cb3 100644 --- a/core/string/bytes_spec.rb +++ b/core/string/bytes_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#bytes" do diff --git a/core/string/bytesize_spec.rb b/core/string/bytesize_spec.rb index a31f3ae671..7991485056 100644 --- a/core/string/bytesize_spec.rb +++ b/core/string/bytesize_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/byteslice_spec.rb b/core/string/byteslice_spec.rb index 312229523d..f078663544 100644 --- a/core/string/byteslice_spec.rb +++ b/core/string/byteslice_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/slice' 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..debfe556c4 100644 --- a/core/string/capitalize_spec.rb +++ b/core/string/capitalize_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/center_spec.rb b/core/string/center_spec.rb index a59dd2a91b..ff5375d907 100644 --- a/core/string/center_spec.rb +++ b/core/string/center_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/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/codepoints_spec.rb b/core/string/codepoints_spec.rb index 0b6cde82f7..1d9628105a 100644 --- a/core/string/codepoints_spec.rb +++ b/core/string/codepoints_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'shared/codepoints' require_relative 'shared/each_codepoint_without_block' diff --git a/core/string/comparison_spec.rb b/core/string/comparison_spec.rb index 91cfdca25a..ad05c73a5e 100644 --- a/core/string/comparison_spec.rb +++ b/core/string/comparison_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/concat_spec.rb b/core/string/concat_spec.rb index 6f487eaa3a..3016a19438 100644 --- a/core/string/concat_spec.rb +++ b/core/string/concat_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/concat' 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..f443ce171b 100644 --- a/core/string/dup_spec.rb +++ b/core/string/dup_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/each_byte_spec.rb b/core/string/each_byte_spec.rb index e04dca807f..d4e3895aa3 100644 --- a/core/string/each_byte_spec.rb +++ b/core/string/each_byte_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' 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..3286bd949c 100644 --- a/core/string/encode_spec.rb +++ b/core/string/encode_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'shared/encode' diff --git a/core/string/encoding_spec.rb b/core/string/encoding_spec.rb index 574a1e2f92..25bf3e8520 100644 --- a/core/string/encoding_spec.rb +++ b/core/string/encoding_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: us-ascii -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/iso-8859-9-encoding' 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/include_spec.rb b/core/string/include_spec.rb index 23e1e134ec..465c766f8f 100644 --- a/core/string/include_spec.rb +++ b/core/string/include_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/index_spec.rb b/core/string/index_spec.rb index b500cf6ca7..c514513028 100644 --- a/core/string/index_spec.rb +++ b/core/string/index_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/inspect_spec.rb b/core/string/inspect_spec.rb index 8bf3d3161f..d0d74e841e 100644 --- a/core/string/inspect_spec.rb +++ b/core/string/inspect_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/ljust_spec.rb b/core/string/ljust_spec.rb index 9208ec5897..f6fd98ba77 100644 --- a/core/string/ljust_spec.rb +++ b/core/string/ljust_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/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/ord_spec.rb b/core/string/ord_spec.rb index 4cf26990fe..7c463ffe49 100644 --- a/core/string/ord_spec.rb +++ b/core/string/ord_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#ord" do diff --git a/core/string/partition_spec.rb b/core/string/partition_spec.rb index 9cb3672881..d1458eb3d8 100644 --- a/core/string/partition_spec.rb +++ b/core/string/partition_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/partition' 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/rindex_spec.rb b/core/string/rindex_spec.rb index f6271b270d..ff2e5e115d 100644 --- a/core/string/rindex_spec.rb +++ b/core/string/rindex_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/rjust_spec.rb b/core/string/rjust_spec.rb index fcbaf3b938..8098e00481 100644 --- a/core/string/rjust_spec.rb +++ b/core/string/rjust_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/rpartition_spec.rb b/core/string/rpartition_spec.rb index 21e87f530a..3f118531bb 100644 --- a/core/string/rpartition_spec.rb +++ b/core/string/rpartition_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/partition' 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..7f67d6724f 100644 --- a/core/string/shared/chars.rb +++ b/core/string/shared/chars.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/shared/codepoints.rb b/core/string/shared/codepoints.rb index 0b2e078e0a..834349e8f5 100644 --- a/core/string/shared/codepoints.rb +++ b/core/string/shared/codepoints.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false describe :string_codepoints, shared: true do it "returns self" do s = "foo" 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_codepoint_without_block.rb b/core/string/shared/each_codepoint_without_block.rb index 92b7f76032..8596d61ae5 100644 --- a/core/string/shared/each_codepoint_without_block.rb +++ b/core/string/shared/each_codepoint_without_block.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false describe :string_each_codepoint_without_block, shared: true do describe "when no block is given" do it "returns an Enumerator" do diff --git a/core/string/shared/each_line.rb b/core/string/shared/each_line.rb index a14b4d7779..f82738d81f 100644 --- a/core/string/shared/each_line.rb +++ b/core/string/shared/each_line.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false describe :string_each_line, shared: true do it "splits using default newline separator when none is specified" do a = [] 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/eql.rb b/core/string/shared/eql.rb index 6f268c929c..d972f10d8e 100644 --- a/core/string/shared/eql.rb +++ b/core/string/shared/eql.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' require_relative '../fixtures/classes' diff --git a/core/string/shared/length.rb b/core/string/shared/length.rb index 94e5ec135b..1e73a4a561 100644 --- a/core/string/shared/length.rb +++ b/core/string/shared/length.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# frozen_string_literal: false describe :string_length, shared: true do it "returns the length of self" do 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/slice.rb b/core/string/shared/slice.rb index 3ef4bc50d7..5f945c72e6 100644 --- a/core/string/shared/slice.rb +++ b/core/string/shared/slice.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false describe :string_slice, shared: true do it "returns the character code of the character at the given index" do "hello".send(@method, 0).should == ?h diff --git a/core/string/shared/succ.rb b/core/string/shared/succ.rb index 24a729ce26..71bd56f384 100644 --- a/core/string/shared/succ.rb +++ b/core/string/shared/succ.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false describe :string_succ, shared: true do it "returns an empty string for empty strings" do "".send(@method).should == "" diff --git a/core/string/shared/to_sym.rb b/core/string/shared/to_sym.rb index 52d8314211..f6ecf81a18 100644 --- a/core/string/shared/to_sym.rb +++ b/core/string/shared/to_sym.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false describe :string_to_sym, shared: true do it "returns the symbol corresponding to self" do "Koala".send(@method).should equal :Koala 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..0b7d667e04 100644 --- a/core/string/split_spec.rb +++ b/core/string/split_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/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/uminus_spec.rb b/core/string/uminus_spec.rb index 46d88f6704..d144fe4441 100644 --- a/core/string/uminus_spec.rb +++ b/core/string/uminus_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'shared/dedup' 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/unpack/a_spec.rb b/core/string/unpack/a_spec.rb index 2d83b4c824..0896ff05cd 100644 --- a/core/string/unpack/a_spec.rb +++ b/core/string/unpack/a_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/core/string/unpack/b_spec.rb b/core/string/unpack/b_spec.rb index 5c53eff721..175d76df0b 100644 --- a/core/string/unpack/b_spec.rb +++ b/core/string/unpack/b_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/core/string/unpack/u_spec.rb b/core/string/unpack/u_spec.rb index 7845e6d5f2..ff17edd1c8 100644 --- a/core/string/unpack/u_spec.rb +++ b/core/string/unpack/u_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' 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/upto_spec.rb b/core/string/upto_spec.rb index 3799e338e0..47819f8aef 100644 --- a/core/string/upto_spec.rb +++ b/core/string/upto_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/core/string/valid_encoding_spec.rb b/core/string/valid_encoding_spec.rb index bb26062c0f..508cee6a67 100644 --- a/core/string/valid_encoding_spec.rb +++ b/core/string/valid_encoding_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require_relative '../../spec_helper' describe "String#valid_encoding?" do diff --git a/core/struct/new_spec.rb b/core/struct/new_spec.rb index 8758051a81..a94eb852e1 100644 --- a/core/struct/new_spec.rb +++ b/core/struct/new_spec.rb @@ -48,7 +48,7 @@ def obj.to_str() "Foo" end end it "allows non-ASCII member name" do - name = "r\xe9sum\xe9".force_encoding(Encoding::ISO_8859_1).to_sym + name = "r\xe9sum\xe9".dup.force_encoding(Encoding::ISO_8859_1).to_sym struct = Struct.new(name) struct.new("foo").send(name).should == "foo" end diff --git a/core/time/_load_spec.rb b/core/time/_load_spec.rb index 152934370f..13290d4920 100644 --- a/core/time/_load_spec.rb +++ b/core/time/_load_spec.rb @@ -44,7 +44,7 @@ end it "treats the data as binary data" do - data = "\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE" + data = +"\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE" data.force_encoding Encoding::UTF_8 t = Marshal.load(data) t.to_s.should == "2013-04-08 12:47:45 UTC" 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/core/time/fixtures/classes.rb b/core/time/fixtures/classes.rb index 1a9511b261..21c4e1effb 100644 --- a/core/time/fixtures/classes.rb +++ b/core/time/fixtures/classes.rb @@ -59,7 +59,6 @@ def self.result Zone = Struct.new(:std, :dst, :dst_range) Zones = { "Asia/Colombo" => Zone[Z[5*3600+30*60, "MMT"], nil, nil], - "Europe/Kiev" => Zone[Z[2*3600, "EET"], Z[3*3600, "EEST"], 4..10], "PST" => Zone[Z[(-9*60*60), "PST"], nil, nil], } 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/encoding_spec.rb b/language/encoding_spec.rb index 5430c9cb98..e761a53cb6 100644 --- a/language/encoding_spec.rb +++ b/language/encoding_spec.rb @@ -13,15 +13,15 @@ end it "is the evaluated strings's one inside an eval" do - eval("__ENCODING__".force_encoding("US-ASCII")).should == Encoding::US_ASCII - eval("__ENCODING__".force_encoding("BINARY")).should == Encoding::BINARY + eval("__ENCODING__".dup.force_encoding("US-ASCII")).should == Encoding::US_ASCII + eval("__ENCODING__".dup.force_encoding("BINARY")).should == Encoding::BINARY end it "is the encoding specified by a magic comment inside an eval" do - code = "# encoding: BINARY\n__ENCODING__".force_encoding("US-ASCII") + code = "# encoding: BINARY\n__ENCODING__".dup.force_encoding("US-ASCII") eval(code).should == Encoding::BINARY - code = "# encoding: us-ascii\n__ENCODING__".force_encoding("BINARY") + code = "# encoding: us-ascii\n__ENCODING__".dup.force_encoding("BINARY") eval(code).should == Encoding::US_ASCII 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/predefined_spec.rb b/language/predefined_spec.rb index ed823f185a..516a9c5ea0 100644 --- a/language/predefined_spec.rb +++ b/language/predefined_spec.rb @@ -133,7 +133,7 @@ def obj.foo2(&proc); proc.call; end end it "sets the encoding to the encoding of the source String" do - "abc".force_encoding(Encoding::EUC_JP) =~ /b/ + "abc".dup.force_encoding(Encoding::EUC_JP) =~ /b/ $&.encoding.should equal(Encoding::EUC_JP) end end @@ -146,12 +146,12 @@ def obj.foo2(&proc); proc.call; end end it "sets the encoding to the encoding of the source String" do - "abc".force_encoding(Encoding::EUC_JP) =~ /b/ + "abc".dup.force_encoding(Encoding::EUC_JP) =~ /b/ $`.encoding.should equal(Encoding::EUC_JP) end it "sets an empty result to the encoding of the source String" do - "abc".force_encoding(Encoding::ISO_8859_1) =~ /a/ + "abc".dup.force_encoding(Encoding::ISO_8859_1) =~ /a/ $`.encoding.should equal(Encoding::ISO_8859_1) end end @@ -164,12 +164,12 @@ def obj.foo2(&proc); proc.call; end end it "sets the encoding to the encoding of the source String" do - "abc".force_encoding(Encoding::EUC_JP) =~ /b/ + "abc".dup.force_encoding(Encoding::EUC_JP) =~ /b/ $'.encoding.should equal(Encoding::EUC_JP) end it "sets an empty result to the encoding of the source String" do - "abc".force_encoding(Encoding::ISO_8859_1) =~ /c/ + "abc".dup.force_encoding(Encoding::ISO_8859_1) =~ /c/ $'.encoding.should equal(Encoding::ISO_8859_1) end end @@ -187,7 +187,7 @@ def obj.foo2(&proc); proc.call; end end it "sets the encoding to the encoding of the source String" do - "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/ + "abc".dup.force_encoding(Encoding::EUC_JP) =~ /(b)/ $+.encoding.should equal(Encoding::EUC_JP) end end @@ -214,7 +214,7 @@ def test(arg) end it "sets the encoding to the encoding of the source String" do - "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/ + "abc".dup.force_encoding(Encoding::EUC_JP) =~ /(b)/ $1.encoding.should equal(Encoding::EUC_JP) end end @@ -730,7 +730,7 @@ def foo describe "Predefined global $_" do it "is set to the last line read by e.g. StringIO#gets" do - stdin = StringIO.new("foo\nbar\n", "r") + stdin = StringIO.new(+"foo\nbar\n", "r") read = stdin.gets read.should == "foo\n" @@ -750,7 +750,7 @@ def foo def obj.foo; yield; end def obj.foo2; yield; end - stdin = StringIO.new("foo\nbar\nbaz\nqux\n", "r") + stdin = StringIO.new(+"foo\nbar\nbaz\nqux\n", "r") match = stdin.gets obj.foo { match = stdin.gets } diff --git a/language/regexp/encoding_spec.rb b/language/regexp/encoding_spec.rb index febc3fdb37..0571b2d3cf 100644 --- a/language/regexp/encoding_spec.rb +++ b/language/regexp/encoding_spec.rb @@ -4,18 +4,18 @@ describe "Regexps with encoding modifiers" do it "supports /e (EUC encoding)" do - match = /./e.match("\303\251".force_encoding(Encoding::EUC_JP)) - match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)] + match = /./e.match("\303\251".dup.force_encoding(Encoding::EUC_JP)) + match.to_a.should == ["\303\251".dup.force_encoding(Encoding::EUC_JP)] end it "supports /e (EUC encoding) with interpolation" do - match = /#{/./}/e.match("\303\251".force_encoding(Encoding::EUC_JP)) - match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)] + match = /#{/./}/e.match("\303\251".dup.force_encoding(Encoding::EUC_JP)) + match.to_a.should == ["\303\251".dup.force_encoding(Encoding::EUC_JP)] end it "supports /e (EUC encoding) with interpolation /o" do - match = /#{/./}/e.match("\303\251".force_encoding(Encoding::EUC_JP)) - match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)] + match = /#{/./}/e.match("\303\251".dup.force_encoding(Encoding::EUC_JP)) + match.to_a.should == ["\303\251".dup.force_encoding(Encoding::EUC_JP)] end it 'uses EUC-JP as /e encoding' do @@ -39,7 +39,7 @@ end it "warns when using /n with a match string with non-ASCII characters and an encoding other than ASCII-8BIT" do - -> { /./n.match("\303\251".force_encoding('utf-8')) }.should complain(%r{historical binary regexp match /.../n against UTF-8 string}) + -> { /./n.match("\303\251".dup.force_encoding('utf-8')) }.should complain(%r{historical binary regexp match /.../n against UTF-8 string}) end it 'uses US-ASCII as /n encoding if all chars are 7-bit' do @@ -63,18 +63,18 @@ end it "supports /s (Windows_31J encoding)" do - match = /./s.match("\303\251".force_encoding(Encoding::Windows_31J)) - match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)] + match = /./s.match("\303\251".dup.force_encoding(Encoding::Windows_31J)) + match.to_a.should == ["\303".dup.force_encoding(Encoding::Windows_31J)] end it "supports /s (Windows_31J encoding) with interpolation" do - match = /#{/./}/s.match("\303\251".force_encoding(Encoding::Windows_31J)) - match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)] + match = /#{/./}/s.match("\303\251".dup.force_encoding(Encoding::Windows_31J)) + match.to_a.should == ["\303".dup.force_encoding(Encoding::Windows_31J)] end it "supports /s (Windows_31J encoding) with interpolation and /o" do - match = /#{/./}/s.match("\303\251".force_encoding(Encoding::Windows_31J)) - match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)] + match = /#{/./}/s.match("\303\251".dup.force_encoding(Encoding::Windows_31J)) + match.to_a.should == ["\303".dup.force_encoding(Encoding::Windows_31J)] end it 'uses Windows-31J as /s encoding' do @@ -86,15 +86,15 @@ end it "supports /u (UTF8 encoding)" do - /./u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"] + /./u.match("\303\251".dup.force_encoding('utf-8')).to_a.should == ["\u{e9}"] end it "supports /u (UTF8 encoding) with interpolation" do - /#{/./}/u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"] + /#{/./}/u.match("\303\251".dup.force_encoding('utf-8')).to_a.should == ["\u{e9}"] end it "supports /u (UTF8 encoding) with interpolation and /o" do - /#{/./}/u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"] + /#{/./}/u.match("\303\251".dup.force_encoding('utf-8')).to_a.should == ["\u{e9}"] end it 'uses UTF-8 as /u encoding' do @@ -122,26 +122,26 @@ end it "raises Encoding::CompatibilityError when the regexp has a fixed, non-ASCII-compatible encoding" do - -> { Regexp.new("".force_encoding("UTF-16LE"), Regexp::FIXEDENCODING) =~ " ".encode("UTF-8") }.should raise_error(Encoding::CompatibilityError) + -> { Regexp.new("".dup.force_encoding("UTF-16LE"), Regexp::FIXEDENCODING) =~ " ".encode("UTF-8") }.should raise_error(Encoding::CompatibilityError) end it "raises Encoding::CompatibilityError when the regexp has a fixed encoding and the match string has non-ASCII characters" do - -> { Regexp.new("".force_encoding("US-ASCII"), Regexp::FIXEDENCODING) =~ "\303\251".force_encoding('UTF-8') }.should raise_error(Encoding::CompatibilityError) + -> { Regexp.new("".dup.force_encoding("US-ASCII"), Regexp::FIXEDENCODING) =~ "\303\251".dup.force_encoding('UTF-8') }.should raise_error(Encoding::CompatibilityError) end it "raises ArgumentError when trying to match a broken String" do - s = "\x80".force_encoding('UTF-8') + s = "\x80".dup.force_encoding('UTF-8') -> { s =~ /./ }.should raise_error(ArgumentError, "invalid byte sequence in UTF-8") end it "computes the Regexp Encoding for each interpolated Regexp instance" do make_regexp = -> str { /#{str}/ } - r = make_regexp.call("été".force_encoding(Encoding::UTF_8)) + r = make_regexp.call("été".dup.force_encoding(Encoding::UTF_8)) r.should.fixed_encoding? r.encoding.should == Encoding::UTF_8 - r = make_regexp.call("abc".force_encoding(Encoding::UTF_8)) + r = make_regexp.call("abc".dup.force_encoding(Encoding::UTF_8)) r.should_not.fixed_encoding? r.encoding.should == Encoding::US_ASCII end 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..f2764eada0 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 @@ -251,12 +252,12 @@ def long_string_literals it "returns a string with the source encoding by default" do "a#{"b"}c".encoding.should == Encoding::BINARY - eval('"a#{"b"}c"'.force_encoding("us-ascii")).encoding.should == Encoding::US_ASCII + eval('"a#{"b"}c"'.dup.force_encoding("us-ascii")).encoding.should == Encoding::US_ASCII eval("# coding: US-ASCII \n 'a#{"b"}c'").encoding.should == Encoding::US_ASCII end it "returns a string with the source encoding, even if the components have another encoding" do - a = "abc".force_encoding("euc-jp") + a = "abc".dup.force_encoding("euc-jp") "#{a}".encoding.should == Encoding::BINARY b = "abc".encode("utf-8") @@ -265,7 +266,7 @@ def long_string_literals it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do a = "\u3042" - b = "\xff".force_encoding "binary" + b = "\xff".dup.force_encoding "binary" -> { "#{a} #{b}" }.should raise_error(Encoding::CompatibilityError) end diff --git a/library/cgi/escapeURIComponent_spec.rb b/library/cgi/escapeURIComponent_spec.rb index 2cf283c778..f05795a2f5 100644 --- a/library/cgi/escapeURIComponent_spec.rb +++ b/library/cgi/escapeURIComponent_spec.rb @@ -14,7 +14,7 @@ end it "supports String with invalid encoding" do - string = "\xC0\<\<".force_encoding("UTF-8") + string = "\xC0\<\<".dup.force_encoding("UTF-8") CGI.escapeURIComponent(string).should == "%C0%3C%3C" end 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/io-wait/fixtures/classes.rb b/library/io-wait/fixtures/classes.rb index 837c7edd06..6de3b492bc 100644 --- a/library/io-wait/fixtures/classes.rb +++ b/library/io-wait/fixtures/classes.rb @@ -1,7 +1,7 @@ module IOWaitSpec def self.exhaust_write_buffer(io) written = 0 - buf = " " * 4096 + buf = +" " * 4096 begin written += io.write_nonblock(buf) 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/body_spec.rb b/library/net-http/httpgenericrequest/body_spec.rb index 5f7315f303..d8a2bc7a5c 100644 --- a/library/net-http/httpgenericrequest/body_spec.rb +++ b/library/net-http/httpgenericrequest/body_spec.rb @@ -23,7 +23,7 @@ end it "sets self's body stream to nil" do - @request.body_stream = StringIO.new("") + @request.body_stream = StringIO.new(+"") @request.body = "Some Content" @request.body_stream.should be_nil end diff --git a/library/net-http/httpgenericrequest/body_stream_spec.rb b/library/net-http/httpgenericrequest/body_stream_spec.rb index dea1c8c883..f3b0e14294 100644 --- a/library/net-http/httpgenericrequest/body_stream_spec.rb +++ b/library/net-http/httpgenericrequest/body_stream_spec.rb @@ -7,7 +7,7 @@ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") request.body_stream.should be_nil - stream = StringIO.new("test") + stream = StringIO.new(+"test") request.body_stream = stream request.body_stream.should equal(stream) end @@ -16,7 +16,7 @@ describe "Net::HTTPGenericRequest#body_stream=" do before :each do @request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path") - @stream = StringIO.new("test") + @stream = StringIO.new(+"test") end it "sets self's body stream to the passed Object" do diff --git a/library/net-http/httpgenericrequest/exec_spec.rb b/library/net-http/httpgenericrequest/exec_spec.rb index cf13e9dfd6..bd072747b6 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 @@ -65,7 +65,7 @@ it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path", "Content-Length" => "10") - request.body_stream = StringIO.new("a" * 20) + request.body_stream = StringIO.new(+"a" * 20) request.exec(@buffered_socket, "1.1", "/some/other/path") str = @socket.string @@ -81,7 +81,7 @@ request = Net::HTTPGenericRequest.new("POST", true, true,"/some/path", "Content-Type" => "text/html", "Content-Length" => "10") - request.body_stream = StringIO.new("a" * 20) + request.body_stream = StringIO.new(+"a" * 20) request.exec(@buffered_socket, "1.1", "/some/other/path") str = @socket.string @@ -98,7 +98,7 @@ "Content-Type" => "text/html", "Transfer-Encoding" => "chunked") datasize = 1024 * 10 - request.body_stream = StringIO.new("a" * datasize) + request.body_stream = StringIO.new(+"a" * datasize) request.exec(@buffered_socket, "1.1", "/some/other/path") str = @socket.string @@ -123,7 +123,7 @@ it "raises an ArgumentError when the 'Content-Length' is not set or 'Transfer-Encoding' is not set to 'chunked'" do request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path", "Content-Type" => "text/html") - request.body_stream = StringIO.new("Some Content") + request.body_stream = StringIO.new(+"Some Content") -> { request.exec(@buffered_socket, "1.1", "/some/other/path") }.should raise_error(ArgumentError) 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/tcpsocket/recv_nonblock_spec.rb b/library/socket/tcpsocket/recv_nonblock_spec.rb index 6ce5a41b58..7e89a8e268 100644 --- a/library/socket/tcpsocket/recv_nonblock_spec.rb +++ b/library/socket/tcpsocket/recv_nonblock_spec.rb @@ -36,7 +36,7 @@ # # TODO: Figure out a good way to test non-blocking. IO.select([@socket]) - buffer = "".b + buffer = +"".b @socket.recv_nonblock(50, 0, buffer) buffer.should == 'TCPSocket#recv_nonblock' end diff --git a/library/socket/udpsocket/recvfrom_nonblock_spec.rb b/library/socket/udpsocket/recvfrom_nonblock_spec.rb index 650a061221..5d6334ee86 100644 --- a/library/socket/udpsocket/recvfrom_nonblock_spec.rb +++ b/library/socket/udpsocket/recvfrom_nonblock_spec.rb @@ -52,7 +52,7 @@ end it 'writes the data to the buffer when one is present' do - buffer = "".b + buffer = +"".b IO.select([@server]) @server.recvfrom_nonblock(1, 0, buffer) buffer.should == 'h' 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/binmode_spec.rb b/library/stringio/binmode_spec.rb index 853d9c9bd6..9e92c63814 100644 --- a/library/stringio/binmode_spec.rb +++ b/library/stringio/binmode_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#binmode" do it "returns self" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.binmode.should equal(io) end diff --git a/library/stringio/close_read_spec.rb b/library/stringio/close_read_spec.rb index 80bd547e85..564a2cdad1 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,10 +21,10 @@ 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") + io = StringIO.new(+"example") io.close_read io.close_read.should == nil end 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/fileno_spec.rb b/library/stringio/fileno_spec.rb index eea03a5af3..70085e42dd 100644 --- a/library/stringio/fileno_spec.rb +++ b/library/stringio/fileno_spec.rb @@ -4,6 +4,6 @@ describe "StringIO#fileno" do it "returns nil" do - StringIO.new("nuffin").fileno.should be_nil + StringIO.new(+"nuffin").fileno.should be_nil 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/getbyte_spec.rb b/library/stringio/getbyte_spec.rb index 3daa3d8e02..1459dcf81b 100644 --- a/library/stringio/getbyte_spec.rb +++ b/library/stringio/getbyte_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :stringio_getc, :getbyte it "returns the 8-bit byte at the current position" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.getbyte.should == 101 io.getbyte.should == 120 diff --git a/library/stringio/getc_spec.rb b/library/stringio/getc_spec.rb index 263d418316..d04a2d7141 100644 --- a/library/stringio/getc_spec.rb +++ b/library/stringio/getc_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :stringio_getc, :getc it "returns the character at the current position" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.getc.should == ?e io.getc.should == ?x diff --git a/library/stringio/getch_spec.rb b/library/stringio/getch_spec.rb index 113b4971bf..9d881e394b 100644 --- a/library/stringio/getch_spec.rb +++ b/library/stringio/getch_spec.rb @@ -10,7 +10,7 @@ it_behaves_like :stringio_getc, :getch it "returns the character at the current position" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.getch.should == ?e io.getch.should == ?x @@ -18,7 +18,7 @@ end it "increments #pos by the byte size of the character in multibyte strings" do - io = StringIO.new("föóbar") + io = StringIO.new(+"föóbar") io.getch; io.pos.should == 1 # "f" has byte size 1 io.getch; io.pos.should == 3 # "ö" has byte size 2 @@ -28,12 +28,12 @@ it "returns nil at the end of the string" do # empty string case - io = StringIO.new("") + io = StringIO.new(+"") io.getch.should == nil io.getch.should == nil # non-empty string case - io = StringIO.new("a") + io = StringIO.new(+"a") io.getch # skip one io.getch.should == nil end diff --git a/library/stringio/getpass_spec.rb b/library/stringio/getpass_spec.rb index 60fc64f0c5..69e7a15357 100644 --- a/library/stringio/getpass_spec.rb +++ b/library/stringio/getpass_spec.rb @@ -6,6 +6,6 @@ require 'io/console' it "is defined by io/console" do - StringIO.new("example").should.respond_to?(:getpass) + StringIO.new(+"example").should.respond_to?(:getpass) end end diff --git a/library/stringio/gets_spec.rb b/library/stringio/gets_spec.rb index d597ec0e45..c004db0dff 100644 --- a/library/stringio/gets_spec.rb +++ b/library/stringio/gets_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#gets when passed [separator]" do before :each do - @io = StringIO.new("this>is>an>example") + @io = StringIO.new(+"this>is>an>example") end it "returns the data read till the next occurrence of the passed separator" do @@ -49,13 +49,13 @@ end it "returns the next paragraph when the passed separator is an empty String" do - io = StringIO.new("this is\n\nan example") + io = StringIO.new(+"this is\n\nan example") io.gets("").should == "this is\n\n" io.gets("").should == "an example" end it "returns the remaining content starting at the current position when passed nil" do - io = StringIO.new("this is\n\nan example") + io = StringIO.new(+"this is\n\nan example") io.pos = 5 io.gets(nil).should == "is\n\nan example" end @@ -69,7 +69,7 @@ describe "StringIO#gets when passed no argument" do before :each do - @io = StringIO.new("this is\nan example\nfor StringIO#gets") + @io = StringIO.new(+"this is\nan example\nfor StringIO#gets") end it "returns the data read till the next occurrence of $/ or till eof" do @@ -128,7 +128,7 @@ describe "StringIO#gets when passed [limit]" do before :each do - @io = StringIO.new("this>is>an>example") + @io = StringIO.new(+"this>is>an>example") end it "returns the data read until the limit is met" do @@ -179,7 +179,7 @@ describe "StringIO#gets when passed [separator] and [limit]" do before :each do - @io = StringIO.new("this>is>an>example") + @io = StringIO.new(+"this>is>an>example") end it "returns the data read until the limit is consumed or the separator is met" do @@ -233,10 +233,10 @@ 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") + io = StringIO.new(+"xyz") io.close_read -> { io.gets }.should raise_error(IOError) end @@ -244,7 +244,7 @@ describe "StringIO#gets when passed [chomp]" do it "returns the data read without a trailing newline character" do - io = StringIO.new("this>is>an>example\n") + io = StringIO.new(+"this>is>an>example\n") io.gets(chomp: true).should == "this>is>an>example" end end diff --git a/library/stringio/initialize_spec.rb b/library/stringio/initialize_spec.rb index 158c08488b..5aac206db9 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 @@ -143,7 +143,7 @@ end it "sets the mode to read-write" do - @io.send(:initialize, "example") + @io.send(:initialize, +"example") @io.closed_read?.should be_false @io.closed_write?.should be_false end @@ -166,28 +166,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 +196,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 +258,7 @@ end it "sets the mode to read-write" do - @io.send(:initialize, "example") + @io.send(:initialize, +"example") @io.closed_read?.should be_false @io.closed_write?.should be_false end @@ -289,13 +289,13 @@ end it "the encoding to the encoding of the String when passed a String" do - s = ''.force_encoding(Encoding::EUC_JP) + s = ''.dup.force_encoding(Encoding::EUC_JP) io = StringIO.new(s) io.string.encoding.should == Encoding::EUC_JP end it "the #external_encoding to the encoding of the String when passed a String" do - s = ''.force_encoding(Encoding::EUC_JP) + s = ''.dup.force_encoding(Encoding::EUC_JP) io = StringIO.new(s) io.external_encoding.should == Encoding::EUC_JP end diff --git a/library/stringio/inspect_spec.rb b/library/stringio/inspect_spec.rb index 7c02f8d360..95ccfe6338 100644 --- a/library/stringio/inspect_spec.rb +++ b/library/stringio/inspect_spec.rb @@ -3,17 +3,17 @@ describe "StringIO#inspect" do it "returns the same as #to_s" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.inspect.should == io.to_s end it "does not include the contents" do - io = StringIO.new("contents") + io = StringIO.new(+"contents") io.inspect.should_not include("contents") end it "uses the regular Object#inspect without any instance variable" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.inspect.should =~ /\A#\z/ end end diff --git a/library/stringio/lineno_spec.rb b/library/stringio/lineno_spec.rb index c620a1a686..65be187783 100644 --- a/library/stringio/lineno_spec.rb +++ b/library/stringio/lineno_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#lineno" do before :each do - @io = StringIO.new("this\nis\nan\nexample") + @io = StringIO.new(+"this\nis\nan\nexample") end it "returns the number of lines read" do @@ -16,7 +16,7 @@ describe "StringIO#lineno=" do before :each do - @io = StringIO.new("this\nis\nan\nexample") + @io = StringIO.new(+"this\nis\nan\nexample") end it "sets the current line number, but has no impact on the position" do 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/path_spec.rb b/library/stringio/path_spec.rb index 1184ca523f..86a68509f4 100644 --- a/library/stringio/path_spec.rb +++ b/library/stringio/path_spec.rb @@ -3,6 +3,6 @@ describe "StringIO#path" do it "is not defined" do - -> { StringIO.new("path").path }.should raise_error(NoMethodError) + -> { StringIO.new(+"path").path }.should raise_error(NoMethodError) end end diff --git a/library/stringio/pid_spec.rb b/library/stringio/pid_spec.rb index 08f2d7ab1a..76d22db153 100644 --- a/library/stringio/pid_spec.rb +++ b/library/stringio/pid_spec.rb @@ -3,6 +3,6 @@ describe "StringIO#pid" do it "returns nil" do - StringIO.new("pid").pid.should be_nil + StringIO.new(+"pid").pid.should be_nil end 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..f233eafdd0 100644 --- a/library/stringio/read_nonblock_spec.rb +++ b/library/stringio/read_nonblock_spec.rb @@ -7,8 +7,8 @@ it_behaves_like :stringio_read, :read_nonblock it "accepts :exception option" do - io = StringIO.new("example") - io.read_nonblock(3, buffer = "", exception: true) + io = StringIO.new(+"example") + io.read_nonblock(3, buffer = +"", exception: true) buffer.should == "exa" end end @@ -17,7 +17,7 @@ it_behaves_like :stringio_read_length, :read_nonblock it "accepts :exception option" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.read_nonblock(3, exception: true).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..553e3dc926 100644 --- a/library/stringio/read_spec.rb +++ b/library/stringio/read_spec.rb @@ -34,7 +34,7 @@ describe "StringIO#read when passed [length]" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns nil when self's position is at the end" do @@ -49,11 +49,11 @@ describe "StringIO#read when passed length and a buffer" do before :each do - @io = StringIO.new("abcdefghijklmnopqrstuvwxyz") + @io = StringIO.new(+"abcdefghijklmnopqrstuvwxyz") 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/readbyte_spec.rb b/library/stringio/readbyte_spec.rb index 41a0911293..31b01123cd 100644 --- a/library/stringio/readbyte_spec.rb +++ b/library/stringio/readbyte_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :stringio_readchar, :readbyte it "reads the next 8-bit byte from self's current position" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.readbyte.should == 101 diff --git a/library/stringio/readchar_spec.rb b/library/stringio/readchar_spec.rb index 38944819a2..8fd959bb82 100644 --- a/library/stringio/readchar_spec.rb +++ b/library/stringio/readchar_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :stringio_readchar, :readchar it "reads the next 8-bit byte from self's current position" do - io = StringIO.new("example") + io = StringIO.new(+"example") io.readchar.should == ?e diff --git a/library/stringio/readline_spec.rb b/library/stringio/readline_spec.rb index b794e5fade..4bbbb5772b 100644 --- a/library/stringio/readline_spec.rb +++ b/library/stringio/readline_spec.rb @@ -4,7 +4,7 @@ describe "StringIO#readline when passed [separator]" do before :each do - @io = StringIO.new("this>is>an>example") + @io = StringIO.new(+"this>is>an>example") end it "returns the data read till the next occurrence of the passed separator" do @@ -37,13 +37,13 @@ end it "returns the next paragraph when the passed separator is an empty String" do - io = StringIO.new("this is\n\nan example") + io = StringIO.new(+"this is\n\nan example") io.readline("").should == "this is\n\n" io.readline("").should == "an example" end it "returns the remaining content starting at the current position when passed nil" do - io = StringIO.new("this is\n\nan example") + io = StringIO.new(+"this is\n\nan example") io.pos = 5 io.readline(nil).should == "is\n\nan example" end @@ -57,7 +57,7 @@ describe "StringIO#readline when passed no argument" do before :each do - @io = StringIO.new("this is\nan example\nfor StringIO#readline") + @io = StringIO.new(+"this is\nan example\nfor StringIO#readline") end it "returns the data read till the next occurrence of $/ or till eof" do @@ -113,10 +113,10 @@ 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") + io = StringIO.new(+"xyz") io.close_read -> { io.readline }.should raise_error(IOError) end @@ -124,18 +124,18 @@ describe "StringIO#readline when passed [chomp]" do it "returns the data read without a trailing newline character" do - io = StringIO.new("this>is>an>example\n") + io = StringIO.new(+"this>is>an>example\n") io.readline(chomp: true).should == "this>is>an>example" end end describe "StringIO#readline when passed [limit]" do before :each do - @io = StringIO.new("this>is>an>example") + @io = StringIO.new(+"this>is>an>example") end it "returns the data read until the limit is met" do - io = StringIO.new("this>is>an>example\n") + io = StringIO.new(+"this>is>an>example\n") io.readline(3).should == "thi" end diff --git a/library/stringio/readlines_spec.rb b/library/stringio/readlines_spec.rb index c471d0fd73..916c236df3 100644 --- a/library/stringio/readlines_spec.rb +++ b/library/stringio/readlines_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#readlines when passed [separator]" do before :each do - @io = StringIO.new("this>is>an>example") + @io = StringIO.new(+"this>is>an>example") end it "returns an Array containing lines based on the passed separator" do @@ -27,12 +27,12 @@ end it "returns an Array containing all paragraphs when the passed separator is an empty String" do - io = StringIO.new("this is\n\nan example") + io = StringIO.new(+"this is\n\nan example") io.readlines("").should == ["this is\n\n", "an example"] end it "returns the remaining content as one line starting at the current position when passed nil" do - io = StringIO.new("this is\n\nan example") + io = StringIO.new(+"this is\n\nan example") io.pos = 5 io.readlines(nil).should == ["is\n\nan example"] end @@ -46,7 +46,7 @@ describe "StringIO#readlines when passed no argument" do before :each do - @io = StringIO.new("this is\nan example\nfor StringIO#readlines") + @io = StringIO.new(+"this is\nan example\nfor StringIO#readlines") end it "returns an Array containing lines based on $/" do @@ -83,10 +83,10 @@ 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") + io = StringIO.new(+"xyz") io.close_read -> { io.readlines }.should raise_error(IOError) end @@ -94,14 +94,14 @@ describe "StringIO#readlines when passed [chomp]" do it "returns the data read without a trailing newline character" do - io = StringIO.new("this>is\nan>example\r\n") + io = StringIO.new(+"this>is\nan>example\r\n") io.readlines(chomp: true).should == ["this>is", "an>example"] end end describe "StringIO#readlines when passed [limit]" do before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") + @io = StringIO.new(+"a b c d e\n1 2 3 4 5") end it "returns the data read until the limit is met" do 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/rewind_spec.rb b/library/stringio/rewind_spec.rb index 5f885ecf81..df78033ae1 100644 --- a/library/stringio/rewind_spec.rb +++ b/library/stringio/rewind_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#rewind" do before :each do - @io = StringIO.new("hello\nworld") + @io = StringIO.new(+"hello\nworld") @io.pos = 3 @io.lineno = 1 end diff --git a/library/stringio/seek_spec.rb b/library/stringio/seek_spec.rb index 253b5027a9..9568fef1d9 100644 --- a/library/stringio/seek_spec.rb +++ b/library/stringio/seek_spec.rb @@ -3,7 +3,7 @@ describe "StringIO#seek" do before :each do - @io = StringIO.new("12345678") + @io = StringIO.new(+"12345678") end it "seeks from the current position when whence is IO::SEEK_CUR" do @@ -57,7 +57,7 @@ describe "StringIO#seek when self is closed" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") @io.close end diff --git a/library/stringio/shared/codepoints.rb b/library/stringio/shared/codepoints.rb index 9d84aa4919..75c72f617a 100644 --- a/library/stringio/shared/codepoints.rb +++ b/library/stringio/shared/codepoints.rb @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- describe :stringio_codepoints, shared: true do before :each do - @io = StringIO.new("∂φ/∂x = gaîté") + @io = StringIO.new(+"∂φ/∂x = gaîté") @enum = @io.send(@method) end @@ -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..d8b1bd7422 100644 --- a/library/stringio/shared/each.rb +++ b/library/stringio/shared/each.rb @@ -1,6 +1,6 @@ describe :stringio_each_separator, shared: true do before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") + @io = StringIO.new(+"a b c d e\n1 2 3 4 5") end it "uses the passed argument as the line separator" do @@ -30,7 +30,7 @@ it "yields self's content starting from the current position when the passed separator is nil" do seen = [] - io = StringIO.new("1 2 1 2 1 2") + io = StringIO.new(+"1 2 1 2 1 2") io.pos = 2 io.send(@method, nil) {|s| seen << s} seen.should == ["2 1 2 1 2"] @@ -39,7 +39,7 @@ version_is StringIO::VERSION, ""..."3.0.4" do #ruby_version_is ""..."3.2" do it "yields each paragraph with two separation characters when passed an empty String as separator" do seen = [] - io = StringIO.new("para1\n\npara2\n\n\npara3") + io = StringIO.new(+"para1\n\npara2\n\n\npara3") io.send(@method, "") {|s| seen << s} seen.should == ["para1\n\n", "para2\n\n", "para3"] end @@ -48,7 +48,7 @@ version_is StringIO::VERSION, "3.0.4" do #ruby_version_is "3.2" do it "yields each paragraph with all separation characters when passed an empty String as separator" do seen = [] - io = StringIO.new("para1\n\npara2\n\n\npara3") + io = StringIO.new(+"para1\n\npara2\n\n\npara3") io.send(@method, "") {|s| seen << s} seen.should == ["para1\n\n", "para2\n\n\n", "para3"] end @@ -57,7 +57,7 @@ describe :stringio_each_no_arguments, shared: true do before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") + @io = StringIO.new(+"a b c d e\n1 2 3 4 5") end it "yields each line to the passed block" do @@ -107,10 +107,10 @@ 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") + io = StringIO.new(+"a b c d e") io.close_read -> { io.send(@method) { |b| b } }.should raise_error(IOError) end @@ -119,14 +119,14 @@ describe :stringio_each_chomp, shared: true do it "yields each line with removed newline characters to the passed block" do seen = [] - io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end") + io = StringIO.new(+"a b \rc d e\n1 2 3 4 5\r\nthe end") io.send(@method, chomp: true) {|s| seen << s } seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] end it "returns each line with removed newline characters when called without block" do seen = [] - io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end") + io = StringIO.new(+"a b \rc d e\n1 2 3 4 5\r\nthe end") enum = io.send(@method, chomp: true) enum.each {|s| seen << s } seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] @@ -136,14 +136,14 @@ describe :stringio_each_separator_and_chomp, shared: true do it "yields each line with removed separator to the passed block" do seen = [] - io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") + io = StringIO.new(+"a b \nc d e|1 2 3 4 5\n|the end") io.send(@method, "|", chomp: true) {|s| seen << s } seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] end it "returns each line with removed separator when called without block" do seen = [] - io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") + io = StringIO.new(+"a b \nc d e|1 2 3 4 5\n|the end") enum = io.send(@method, "|", chomp: true) enum.each {|s| seen << s } seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] @@ -152,7 +152,7 @@ describe :stringio_each_limit, shared: true do before :each do - @io = StringIO.new("a b c d e\n1 2 3 4 5") + @io = StringIO.new(+"a b c d e\n1 2 3 4 5") end it "returns the data read until the limit is met" do diff --git a/library/stringio/shared/each_byte.rb b/library/stringio/shared/each_byte.rb index 56734ff99d..917d5a1498 100644 --- a/library/stringio/shared/each_byte.rb +++ b/library/stringio/shared/each_byte.rb @@ -1,6 +1,6 @@ describe :stringio_each_byte, shared: true do before :each do - @io = StringIO.new("xyz") + @io = StringIO.new(+"xyz") end it "yields each character code in turn" do @@ -38,10 +38,10 @@ 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") + io = StringIO.new(+"xyz") io.close_read -> { io.send(@method) { |b| b } }.should raise_error(IOError) end diff --git a/library/stringio/shared/each_char.rb b/library/stringio/shared/each_char.rb index bcdac53282..4801ffe15a 100644 --- a/library/stringio/shared/each_char.rb +++ b/library/stringio/shared/each_char.rb @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- describe :stringio_each_char, shared: true do before :each do - @io = StringIO.new("xyz äöü") + @io = StringIO.new(+"xyz äöü") end it "yields each character code in turn" do @@ -26,10 +26,10 @@ 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") + io = StringIO.new(+"xyz") io.close_read -> { io.send(@method) { |b| b } }.should raise_error(IOError) end diff --git a/library/stringio/shared/eof.rb b/library/stringio/shared/eof.rb index e0368a2892..3a77894587 100644 --- a/library/stringio/shared/eof.rb +++ b/library/stringio/shared/eof.rb @@ -1,6 +1,6 @@ describe :stringio_eof, shared: true do before :each do - @io = StringIO.new("eof") + @io = StringIO.new(+"eof") end it "returns true when self's position is greater than or equal to self's size" do diff --git a/library/stringio/shared/getc.rb b/library/stringio/shared/getc.rb index 6318bcc30f..a481063133 100644 --- a/library/stringio/shared/getc.rb +++ b/library/stringio/shared/getc.rb @@ -1,6 +1,6 @@ describe :stringio_getc, shared: true do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "increases self's position by one" do @@ -33,10 +33,10 @@ 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") + io = StringIO.new(+"xyz") io.close_read -> { io.send(@method) }.should raise_error(IOError) end diff --git a/library/stringio/shared/isatty.rb b/library/stringio/shared/isatty.rb index 3da5999953..29d40c61bd 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/length.rb b/library/stringio/shared/length.rb index 60a4eb1bdd..84ae9cee8b 100644 --- a/library/stringio/shared/length.rb +++ b/library/stringio/shared/length.rb @@ -1,5 +1,5 @@ describe :stringio_length, shared: true do it "returns the length of the wrapped string" do - StringIO.new("example").send(@method).should == 7 + StringIO.new(+"example").send(@method).should == 7 end end diff --git a/library/stringio/shared/read.rb b/library/stringio/shared/read.rb index 252a85d89d..7ad4dbfcbc 100644 --- a/library/stringio/shared/read.rb +++ b/library/stringio/shared/read.rb @@ -1,23 +1,23 @@ describe :stringio_read, shared: true do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end 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" @@ -34,7 +34,7 @@ describe :stringio_read_length, shared: true do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "reads length bytes from the current position and returns them" do @@ -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 @@ -99,7 +99,7 @@ describe :stringio_read_nil, shared: true do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns the remaining content from the current position" do @@ -117,10 +117,10 @@ 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") + io = StringIO.new(+"test") io.close_read -> { io.send(@method) }.should raise_error(IOError) end diff --git a/library/stringio/shared/readchar.rb b/library/stringio/shared/readchar.rb index 4248e75420..bd9bb368b8 100644 --- a/library/stringio/shared/readchar.rb +++ b/library/stringio/shared/readchar.rb @@ -1,6 +1,6 @@ describe :stringio_readchar, shared: true do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "correctly updates the current position" do @@ -19,10 +19,10 @@ 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") + io = StringIO.new(+"a b c d e") io.close_read -> { io.send(@method) }.should raise_error(IOError) end diff --git a/library/stringio/shared/sysread.rb b/library/stringio/shared/sysread.rb index 937bac705c..af3ab53c40 100644 --- a/library/stringio/shared/sysread.rb +++ b/library/stringio/shared/sysread.rb @@ -1,6 +1,6 @@ describe :stringio_sysread_length, shared: true do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "returns an empty String when passed 0 and no data remains" do 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/string_spec.rb b/library/stringio/string_spec.rb index 1ed5233ba6..5cb3b3ddcd 100644 --- a/library/stringio/string_spec.rb +++ b/library/stringio/string_spec.rb @@ -10,7 +10,7 @@ describe "StringIO#string=" do before :each do - @io = StringIO.new("example\nstring") + @io = StringIO.new(+"example\nstring") end it "returns the passed String" do diff --git a/library/stringio/sync_spec.rb b/library/stringio/sync_spec.rb index e717a5697b..797c198daa 100644 --- a/library/stringio/sync_spec.rb +++ b/library/stringio/sync_spec.rb @@ -3,13 +3,13 @@ describe "StringIO#sync" do it "returns true" do - StringIO.new('').sync.should be_true + StringIO.new(+'').sync.should be_true end end describe "StringIO#sync=" do before :each do - @io = StringIO.new('') + @io = StringIO.new(+'') end it "does not change 'sync' status" do diff --git a/library/stringio/sysread_spec.rb b/library/stringio/sysread_spec.rb index 8f78073f42..4d1e67db11 100644 --- a/library/stringio/sysread_spec.rb +++ b/library/stringio/sysread_spec.rb @@ -34,7 +34,7 @@ describe "StringIO#sysread when passed [length]" do before :each do - @io = StringIO.new("example") + @io = StringIO.new(+"example") end it "raises an EOFError when self's position is at the end" 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/ungetbyte_spec.rb b/library/stringio/ungetbyte_spec.rb index 87b27b837e..3855cbc687 100644 --- a/library/stringio/ungetbyte_spec.rb +++ b/library/stringio/ungetbyte_spec.rb @@ -5,7 +5,7 @@ describe "StringIO#ungetbyte" do it "ungets a single byte from a string starting with a single byte character" do str = 'This is a simple string.' - io = StringIO.new("#{str}") + io = StringIO.new(+"#{str}") c = io.getc c.should == 'T' io.ungetbyte(83) @@ -23,7 +23,7 @@ it "constrains the value of a numeric argument to a single byte" do str = 'This is a simple string.' - io = StringIO.new("#{str}") + io = StringIO.new(+"#{str}") c = io.getc c.should == 'T' io.ungetbyte(83 | 0xff00) 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/check_spec.rb b/library/stringscanner/check_spec.rb index a97c26af83..b7edbd50ab 100644 --- a/library/stringscanner/check_spec.rb +++ b/library/stringscanner/check_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#check" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the value that scan would return, without advancing the scan pointer" do diff --git a/library/stringscanner/check_until_spec.rb b/library/stringscanner/check_until_spec.rb index ad222fd76b..306a50e364 100644 --- a/library/stringscanner/check_until_spec.rb +++ b/library/stringscanner/check_until_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#check_until" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the same value of scan_until, but don't advances the scan pointer" do diff --git a/library/stringscanner/clear_spec.rb b/library/stringscanner/clear_spec.rb index 7ae089704a..78c072830d 100644 --- a/library/stringscanner/clear_spec.rb +++ b/library/stringscanner/clear_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :strscan_terminate, :clear it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") + s = StringScanner.new(+"abc") -> { s.clear }.should complain(/clear.*obsolete.*terminate/, verbose: true) diff --git a/library/stringscanner/element_reference_spec.rb b/library/stringscanner/element_reference_spec.rb index 60fe15d807..104bd719c6 100644 --- a/library/stringscanner/element_reference_spec.rb +++ b/library/stringscanner/element_reference_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#[]" do before :each do - @s = StringScanner.new("Fri Jun 13 2008 22:43") + @s = StringScanner.new(+"Fri Jun 13 2008 22:43") end it "returns nil if there is no current match" do diff --git a/library/stringscanner/empty_spec.rb b/library/stringscanner/empty_spec.rb index d9449bea6e..e68afc99f9 100644 --- a/library/stringscanner/empty_spec.rb +++ b/library/stringscanner/empty_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :strscan_eos, :empty? it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") + s = StringScanner.new(+"abc") -> { s.empty? }.should complain(/empty?.*obsolete.*eos?/, verbose: true) diff --git a/library/stringscanner/exist_spec.rb b/library/stringscanner/exist_spec.rb index ff860a0d3e..ca620fcdaf 100644 --- a/library/stringscanner/exist_spec.rb +++ b/library/stringscanner/exist_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#exist?" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the index of the first occurrence of the given pattern" do diff --git a/library/stringscanner/getbyte_spec.rb b/library/stringscanner/getbyte_spec.rb index e0659a5829..509ed3c5aa 100644 --- a/library/stringscanner/getbyte_spec.rb +++ b/library/stringscanner/getbyte_spec.rb @@ -7,7 +7,7 @@ it_behaves_like :strscan_get_byte, :getbyte it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") + s = StringScanner.new(+"abc") -> { s.getbyte }.should complain(/getbyte.*obsolete.*get_byte/, verbose: true) diff --git a/library/stringscanner/getch_spec.rb b/library/stringscanner/getch_spec.rb index a6be0d4221..449c20ad3b 100644 --- a/library/stringscanner/getch_spec.rb +++ b/library/stringscanner/getch_spec.rb @@ -13,7 +13,7 @@ it "is multi-byte character sensitive" do # Japanese hiragana "A" in EUC-JP - src = "\244\242".force_encoding("euc-jp") + src = "\244\242".dup.force_encoding("euc-jp") s = StringScanner.new(src) s.getch.should == src diff --git a/library/stringscanner/initialize_spec.rb b/library/stringscanner/initialize_spec.rb index 047d9d058b..d65fcbe3ce 100644 --- a/library/stringscanner/initialize_spec.rb +++ b/library/stringscanner/initialize_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#initialize" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "is a private method" do diff --git a/library/stringscanner/inspect_spec.rb b/library/stringscanner/inspect_spec.rb index ff6b97eb91..018233aae8 100644 --- a/library/stringscanner/inspect_spec.rb +++ b/library/stringscanner/inspect_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#inspect" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns a String object" do diff --git a/library/stringscanner/match_spec.rb b/library/stringscanner/match_spec.rb index ec59680914..7a05d3f0d0 100644 --- a/library/stringscanner/match_spec.rb +++ b/library/stringscanner/match_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#match?" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the length of the match and the scan pointer is not advanced" do diff --git a/library/stringscanner/matched_size_spec.rb b/library/stringscanner/matched_size_spec.rb index d9c338a07e..21e85e4be9 100644 --- a/library/stringscanner/matched_size_spec.rb +++ b/library/stringscanner/matched_size_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#matched_size" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the size of the most recent match" do diff --git a/library/stringscanner/matched_spec.rb b/library/stringscanner/matched_spec.rb index c020bd3eae..aef0ce9186 100644 --- a/library/stringscanner/matched_spec.rb +++ b/library/stringscanner/matched_spec.rb @@ -4,7 +4,7 @@ describe "StringScanner#matched" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the last matched string" do @@ -26,7 +26,7 @@ describe "StringScanner#matched?" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns true if the last match was successful" do diff --git a/library/stringscanner/peep_spec.rb b/library/stringscanner/peep_spec.rb index bf6d579325..2a32057ac1 100644 --- a/library/stringscanner/peep_spec.rb +++ b/library/stringscanner/peep_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :strscan_peek, :peep it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") + s = StringScanner.new(+"abc") -> { s.peep(1) }.should complain(/peep.*obsolete.*peek/, verbose: true) diff --git a/library/stringscanner/post_match_spec.rb b/library/stringscanner/post_match_spec.rb index 720dc3530d..76dec5ec04 100644 --- a/library/stringscanner/post_match_spec.rb +++ b/library/stringscanner/post_match_spec.rb @@ -4,7 +4,7 @@ describe "StringScanner#post_match" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the post-match (in the regular expression sense) of the last scan" do diff --git a/library/stringscanner/pre_match_spec.rb b/library/stringscanner/pre_match_spec.rb index 1c2c511d5c..29e25f4fc0 100644 --- a/library/stringscanner/pre_match_spec.rb +++ b/library/stringscanner/pre_match_spec.rb @@ -4,7 +4,7 @@ describe "StringScanner#pre_match" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the pre-match (in the regular expression sense) of the last scan" do diff --git a/library/stringscanner/reset_spec.rb b/library/stringscanner/reset_spec.rb index a10ca2d838..0c89ac401f 100644 --- a/library/stringscanner/reset_spec.rb +++ b/library/stringscanner/reset_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#reset" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "reset the scan pointer and clear matching data" do diff --git a/library/stringscanner/rest_spec.rb b/library/stringscanner/rest_spec.rb index 67072f880d..b66feb3f68 100644 --- a/library/stringscanner/rest_spec.rb +++ b/library/stringscanner/rest_spec.rb @@ -4,7 +4,7 @@ describe "StringScanner#rest" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the rest of the string" do @@ -28,7 +28,7 @@ describe "StringScanner#rest?" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns true if there is more data in the string" do diff --git a/library/stringscanner/restsize_spec.rb b/library/stringscanner/restsize_spec.rb index 710520afae..dc53d98d7b 100644 --- a/library/stringscanner/restsize_spec.rb +++ b/library/stringscanner/restsize_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :strscan_rest_size, :restsize it "warns in verbose mode that the method is obsolete" do - s = StringScanner.new("abc") + s = StringScanner.new(+"abc") -> { s.restsize }.should complain(/restsize.*obsolete.*rest_size/, verbose: true) diff --git a/library/stringscanner/scan_full_spec.rb b/library/stringscanner/scan_full_spec.rb index ed34d7d3f6..47ada0edbf 100644 --- a/library/stringscanner/scan_full_spec.rb +++ b/library/stringscanner/scan_full_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#scan_full" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the number of bytes advanced" do diff --git a/library/stringscanner/scan_spec.rb b/library/stringscanner/scan_spec.rb index ea711767b9..f0f5e5ab36 100644 --- a/library/stringscanner/scan_spec.rb +++ b/library/stringscanner/scan_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#scan" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the matched string" do @@ -64,7 +64,7 @@ describe "StringScanner#scan with fixed_anchor: true" do before :each do - @s = StringScanner.new("This\nis\na\ntest", fixed_anchor: true) + @s = StringScanner.new(+"This\nis\na\ntest", fixed_anchor: true) end it "returns the matched string" do diff --git a/library/stringscanner/scan_until_spec.rb b/library/stringscanner/scan_until_spec.rb index 6b7782572d..1f404d2f2d 100644 --- a/library/stringscanner/scan_until_spec.rb +++ b/library/stringscanner/scan_until_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#scan_until" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the substring up to and including the end of the match" do diff --git a/library/stringscanner/search_full_spec.rb b/library/stringscanner/search_full_spec.rb index 7d2a714fa5..9ec7480b5c 100644 --- a/library/stringscanner/search_full_spec.rb +++ b/library/stringscanner/search_full_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#search_full" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the number of bytes advanced" do diff --git a/library/stringscanner/shared/bol.rb b/library/stringscanner/shared/bol.rb index ebcdd7938f..0b76b069fa 100644 --- a/library/stringscanner/shared/bol.rb +++ b/library/stringscanner/shared/bol.rb @@ -1,13 +1,13 @@ describe :strscan_bol, shared: true do it "returns true if the scan pointer is at the beginning of the line, false otherwise" do - s = StringScanner.new("This is a test") + s = StringScanner.new(+"This is a test") s.send(@method).should be_true s.scan(/This/) s.send(@method).should be_false s.terminate s.send(@method).should be_false - s = StringScanner.new("hello\nworld") + s = StringScanner.new(+"hello\nworld") s.bol?.should be_true s.scan(/\w+/) s.bol?.should be_false diff --git a/library/stringscanner/shared/concat.rb b/library/stringscanner/shared/concat.rb index cb884a5c01..674e69e53f 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 @@ -14,9 +14,9 @@ describe :strscan_concat_fixnum, shared: true do it "raises a TypeError" do - a = StringScanner.new("hello world") + a = StringScanner.new(+"hello world") -> { a.send(@method, 333) }.should raise_error(TypeError) - b = StringScanner.new("") + b = StringScanner.new(+"") -> { b.send(@method, (256 * 3 + 64)) }.should raise_error(TypeError) -> { b.send(@method, -200) }.should raise_error(TypeError) end @@ -25,6 +25,6 @@ x = mock('x') x.should_not_receive(:to_int) - -> { StringScanner.new("").send(@method, x) }.should raise_error(TypeError) + -> { StringScanner.new(+"").send(@method, x) }.should raise_error(TypeError) end end diff --git a/library/stringscanner/shared/eos.rb b/library/stringscanner/shared/eos.rb index ea04c764a2..96a93da817 100644 --- a/library/stringscanner/shared/eos.rb +++ b/library/stringscanner/shared/eos.rb @@ -1,6 +1,6 @@ describe :strscan_eos, shared: true do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns true if the scan pointer is at the end of the string" do diff --git a/library/stringscanner/shared/get_byte.rb b/library/stringscanner/shared/get_byte.rb index 763ab6f4a4..4b628b72b9 100644 --- a/library/stringscanner/shared/get_byte.rb +++ b/library/stringscanner/shared/get_byte.rb @@ -10,7 +10,7 @@ end it "is not multi-byte character sensitive" do - s = StringScanner.new("\244\242") + s = StringScanner.new(+"\244\242") s.send(@method).should == "\244" s.send(@method).should == "\242" end diff --git a/library/stringscanner/shared/peek.rb b/library/stringscanner/shared/peek.rb index 4c757866c1..9f21b31bbc 100644 --- a/library/stringscanner/shared/peek.rb +++ b/library/stringscanner/shared/peek.rb @@ -10,7 +10,7 @@ @s.send(@method, 2).should == "is" @s.send(@method, 1000).should == "is a test" - s = StringScanner.new("été") + s = StringScanner.new(+"été") s.send(@method, 2).should == "é" end diff --git a/library/stringscanner/shared/pos.rb b/library/stringscanner/shared/pos.rb index 6d540881f2..98d756832c 100644 --- a/library/stringscanner/shared/pos.rb +++ b/library/stringscanner/shared/pos.rb @@ -1,6 +1,6 @@ describe :strscan_pos, shared: true do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the position of the scan pointer" do @@ -26,7 +26,7 @@ describe :strscan_pos_set, shared: true do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "modify the scan pointer" do diff --git a/library/stringscanner/size_spec.rb b/library/stringscanner/size_spec.rb index 3e475489e3..0188c20a1e 100644 --- a/library/stringscanner/size_spec.rb +++ b/library/stringscanner/size_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#size" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the number of captures groups of the last match" do diff --git a/library/stringscanner/skip_spec.rb b/library/stringscanner/skip_spec.rb index 473361782c..75706880fb 100644 --- a/library/stringscanner/skip_spec.rb +++ b/library/stringscanner/skip_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#skip" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns length of the match" do diff --git a/library/stringscanner/skip_until_spec.rb b/library/stringscanner/skip_until_spec.rb index 7b56f13e4f..deb9e06369 100644 --- a/library/stringscanner/skip_until_spec.rb +++ b/library/stringscanner/skip_until_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#skip_until" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "returns the number of bytes advanced and advances the scan pointer until pattern is matched and consumed" do diff --git a/library/stringscanner/string_spec.rb b/library/stringscanner/string_spec.rb index 28e2f0ed37..f256238569 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 @@ -20,7 +20,7 @@ describe "StringScanner#string=" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "changes the string being scanned to the argument and resets the scanner" do diff --git a/library/stringscanner/unscan_spec.rb b/library/stringscanner/unscan_spec.rb index df0ea43367..25deaeb882 100644 --- a/library/stringscanner/unscan_spec.rb +++ b/library/stringscanner/unscan_spec.rb @@ -3,7 +3,7 @@ describe "StringScanner#unscan" do before :each do - @s = StringScanner.new("This is a test") + @s = StringScanner.new(+"This is a test") end it "set the scan pointer to the previous position" do 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/globals_spec.rb b/optional/capi/globals_spec.rb index 48677620bc..8d18260886 100644 --- a/optional/capi/globals_spec.rb +++ b/optional/capi/globals_spec.rb @@ -266,7 +266,7 @@ describe "rb_lastline_get" do before do - @io = StringIO.new("last line") + @io = StringIO.new(+"last line") end it "gets the value of $_" do 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..21554001f8 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' @@ -47,7 +48,7 @@ def inspect [Encoding::BINARY, Encoding::UTF_8].each do |enc| describe "rb_str_set_len on a #{enc.name} String" do before :each do - @str = "abcdefghij".force_encoding(enc) + @str = "abcdefghij".dup.force_encoding(enc) # Make sure to unshare the string @s.rb_str_modify(@str) end @@ -99,7 +100,7 @@ def inspect describe "rb_str_set_len on a UTF-16 String" do before :each do - @str = "abcdefghij".force_encoding(Encoding::UTF_16BE) + @str = "abcdefghij".dup.force_encoding(Encoding::UTF_16BE) # Make sure to unshare the string @s.rb_str_modify(@str) end @@ -112,7 +113,7 @@ def inspect describe "rb_str_set_len on a UTF-32 String" do before :each do - @str = "abcdefghijkl".force_encoding(Encoding::UTF_32BE) + @str = "abcdefghijkl".dup.force_encoding(Encoding::UTF_32BE) # Make sure to unshare the string @s.rb_str_modify(@str) end @@ -231,7 +232,7 @@ def inspect describe "rb_usascii_str_new" do it "creates a new String with US-ASCII Encoding from a char buffer of len characters" do - str = "abc".force_encoding("us-ascii") + str = "abc".dup.force_encoding("us-ascii") result = @s.rb_usascii_str_new("abcdef", 3) result.should == str result.encoding.should == Encoding::US_ASCII @@ -247,14 +248,14 @@ def inspect it "returns US-ASCII string for non-US-ASCII string literal" do str = @s.rb_usascii_str_new_lit_non_ascii - str.should == "r\xC3\xA9sum\xC3\xA9".force_encoding(Encoding::US_ASCII) + str.should == "r\xC3\xA9sum\xC3\xA9".dup.force_encoding(Encoding::US_ASCII) str.encoding.should == Encoding::US_ASCII end end describe "rb_usascii_str_new_cstr" do it "creates a new String with US-ASCII Encoding" do - str = "abc".force_encoding("us-ascii") + str = "abc".dup.force_encoding("us-ascii") result = @s.rb_usascii_str_new_cstr("abc") result.should == str result.encoding.should == Encoding::US_ASCII @@ -418,7 +419,7 @@ def inspect describe "rb_enc_str_buf_cat" do it "concatenates a C string literal to a ruby string with the given encoding" do - input = "hello ".force_encoding(Encoding::US_ASCII) + input = "hello ".dup.force_encoding(Encoding::US_ASCII) result = @s.rb_enc_str_buf_cat(input, "résumé", Encoding::UTF_8) result.should == "hello résumé" result.encoding.should == Encoding::UTF_8 @@ -500,8 +501,8 @@ def inspect describe "rb_str_subseq" do it "returns a byte-indexed substring" do - str = "\x00\x01\x02\x03\x04".force_encoding("binary") - @s.rb_str_subseq(str, 1, 2).should == "\x01\x02".force_encoding("binary") + str = "\x00\x01\x02\x03\x04".dup.force_encoding("binary") + @s.rb_str_subseq(str, 1, 2).should == "\x01\x02".dup.force_encoding("binary") end end @@ -712,7 +713,7 @@ def inspect end it "increases the size of the string" do - expected = "test".force_encoding("US-ASCII") + expected = "test".dup.force_encoding("US-ASCII") str = @s.rb_str_resize(expected.dup, 12) str.size.should == 12 str.bytesize.should == 12 @@ -843,11 +844,11 @@ def inspect # it "transcodes a String to Encoding.default_internal if it is set" do # Encoding.default_internal = Encoding::EUC_JP # -# - a = "\xE3\x81\x82\xe3\x82\x8c".force_encoding("utf-8") +# - a = "\xE3\x81\x82\xe3\x82\x8c".dup.force_encoding("utf-8") # + a = [0xE3, 0x81, 0x82, 0xe3, 0x82, 0x8c].pack('C6').force_encoding("utf-8") # s = @s.rb_external_str_new_with_enc(a, a.bytesize, Encoding::UTF_8) # - -# - s.should == "\xA4\xA2\xA4\xEC".force_encoding("euc-jp") +# - s.should == "\xA4\xA2\xA4\xEC".dup.force_encoding("euc-jp") # + x = [0xA4, 0xA2, 0xA4, 0xEC].pack('C4')#.force_encoding('binary') # + s.should == x # s.encoding.should equal(Encoding::EUC_JP) @@ -867,7 +868,7 @@ def inspect describe "rb_locale_str_new" do it "returns a String with 'locale' encoding" do s = @s.rb_locale_str_new("abc", 3) - s.should == "abc".force_encoding(Encoding.find("locale")) + s.should == "abc".dup.force_encoding(Encoding.find("locale")) s.encoding.should equal(Encoding.find("locale")) end end @@ -875,14 +876,14 @@ def inspect describe "rb_locale_str_new_cstr" do it "returns a String with 'locale' encoding" do s = @s.rb_locale_str_new_cstr("abc") - s.should == "abc".force_encoding(Encoding.find("locale")) + s.should == "abc".dup.force_encoding(Encoding.find("locale")) s.encoding.should equal(Encoding.find("locale")) end end describe "rb_str_conv_enc" do it "returns the original String when to encoding is not specified" do - a = "abc".force_encoding("us-ascii") + a = "abc".dup.force_encoding("us-ascii") @s.rb_str_conv_enc(a, Encoding::US_ASCII, nil).should equal(a) end @@ -892,7 +893,7 @@ def inspect end it "returns a transcoded String" do - a = "\xE3\x81\x82\xE3\x82\x8C".force_encoding("utf-8") + a = "\xE3\x81\x82\xE3\x82\x8C".dup.force_encoding("utf-8") result = @s.rb_str_conv_enc(a, Encoding::UTF_8, Encoding::EUC_JP) x = [0xA4, 0xA2, 0xA4, 0xEC].pack('C4').force_encoding('utf-8') result.should == x.force_encoding("euc-jp") @@ -901,7 +902,7 @@ def inspect describe "when the String encoding is equal to the destination encoding" do it "returns the original String" do - a = "abc".force_encoding("us-ascii") + a = "abc".dup.force_encoding("us-ascii") @s.rb_str_conv_enc(a, Encoding::US_ASCII, Encoding::US_ASCII).should equal(a) end @@ -911,7 +912,7 @@ def inspect end it "returns the origin String if the destination encoding is BINARY" do - a = "abc".force_encoding("binary") + a = "abc".dup.force_encoding("binary") @s.rb_str_conv_enc(a, Encoding::US_ASCII, Encoding::BINARY).should equal(a) end end @@ -919,7 +920,7 @@ def inspect describe "rb_str_conv_enc_opts" do it "returns the original String when to encoding is not specified" do - a = "abc".force_encoding("us-ascii") + a = "abc".dup.force_encoding("us-ascii") @s.rb_str_conv_enc_opts(a, Encoding::US_ASCII, nil, 0, nil).should equal(a) end @@ -930,7 +931,7 @@ def inspect end it "returns a transcoded String" do - a = "\xE3\x81\x82\xE3\x82\x8C".force_encoding("utf-8") + a = "\xE3\x81\x82\xE3\x82\x8C".dup.force_encoding("utf-8") result = @s.rb_str_conv_enc_opts(a, Encoding::UTF_8, Encoding::EUC_JP, 0, nil) x = [0xA4, 0xA2, 0xA4, 0xEC].pack('C4').force_encoding('utf-8') result.should == x.force_encoding("euc-jp") @@ -939,7 +940,7 @@ def inspect describe "when the String encoding is equal to the destination encoding" do it "returns the original String" do - a = "abc".force_encoding("us-ascii") + a = "abc".dup.force_encoding("us-ascii") @s.rb_str_conv_enc_opts(a, Encoding::US_ASCII, Encoding::US_ASCII, 0, nil).should equal(a) end @@ -951,7 +952,7 @@ def inspect end it "returns the origin String if the destination encoding is BINARY" do - a = "abc".force_encoding("binary") + a = "abc".dup.force_encoding("binary") @s.rb_str_conv_enc_opts(a, Encoding::US_ASCII, Encoding::BINARY, 0, nil).should equal(a) end @@ -969,7 +970,7 @@ def inspect describe "rb_str_export_locale" do it "returns the original String with the locale encoding" do s = @s.rb_str_export_locale("abc") - s.should == "abc".force_encoding(Encoding.find("locale")) + s.should == "abc".dup.force_encoding(Encoding.find("locale")) s.encoding.should equal(Encoding.find("locale")) end end @@ -1198,14 +1199,14 @@ def inspect describe "rb_str_unlocktmp" do it "unlocks a locked string" do - str = "test" + str = +"test" @s.rb_str_locktmp(str) @s.rb_str_unlocktmp(str).should == str str.upcase!.should == "TEST" end it "raises an error when trying to unlock an already unlocked string" do - -> { @s.rb_str_unlocktmp("test") }.should raise_error(RuntimeError, 'temporal unlocking already unlocked string') + -> { @s.rb_str_unlocktmp(+"test") }.should raise_error(RuntimeError, 'temporal unlocking already unlocked string') end end @@ -1254,8 +1255,8 @@ def inspect end it "returns different frozen strings for different encodings" do - result1 = @s.rb_str_to_interned_str("hello".force_encoding(Encoding::US_ASCII)) - result2 = @s.rb_str_to_interned_str("hello".force_encoding(Encoding::UTF_8)) + result1 = @s.rb_str_to_interned_str("hello".dup.force_encoding(Encoding::US_ASCII)) + result2 = @s.rb_str_to_interned_str("hello".dup.force_encoding(Encoding::UTF_8)) result1.should_not.equal?(result2) end 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