diff options
157 files changed, 578 insertions, 540 deletions
diff --git a/spec/ruby/.mspec.constants b/spec/ruby/.mspec.constants index 44f0011df9..68a877711b 100644 --- a/spec/ruby/.mspec.constants +++ b/spec/ruby/.mspec.constants @@ -78,7 +78,7 @@ Find Forwardable GetoptLong HMACConstants -HashStringsASCII8BIT +HashStringsBinary HashStringsUSASCII HashStringsUTF8 IPAddr diff --git a/spec/ruby/command_line/dash_upper_k_spec.rb b/spec/ruby/command_line/dash_upper_k_spec.rb index ef1248b19c..a060eab793 100644 --- a/spec/ruby/command_line/dash_upper_k_spec.rb +++ b/spec/ruby/command_line/dash_upper_k_spec.rb @@ -6,24 +6,24 @@ describe 'The -K command line option' do end describe 'sets __ENCODING__ and Encoding.default_external' do - it "to Encoding::ASCII_8BIT with -Ka" do + it "to Encoding::BINARY with -Ka" do ruby_exe(@test_string, options: '-Ka').should == - [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect + [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect end - it "to Encoding::ASCII_8BIT with -KA" do + it "to Encoding::BINARY with -KA" do ruby_exe(@test_string, options: '-KA').should == - [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect + [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect end - it "to Encoding::ASCII_8BIT with -Kn" do + it "to Encoding::BINARY with -Kn" do ruby_exe(@test_string, options: '-Kn').should == - [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect + [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect end - it "to Encoding::ASCII_8BIT with -KN" do + it "to Encoding::BINARY with -KN" do ruby_exe(@test_string, options: '-KN').should == - [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect + [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect end it "to Encoding::EUC_JP with -Ke" do diff --git a/spec/ruby/command_line/dash_x_spec.rb b/spec/ruby/command_line/dash_x_spec.rb index ad6be23063..eb89db0144 100644 --- a/spec/ruby/command_line/dash_x_spec.rb +++ b/spec/ruby/command_line/dash_x_spec.rb @@ -18,6 +18,4 @@ describe "The -x command line option" do result = ruby_exe(embedded_ruby) result.should == "success\n" end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/argf/binmode_spec.rb b/spec/ruby/core/argf/binmode_spec.rb index 061145a0c7..c2dd578d95 100644 --- a/spec/ruby/core/argf/binmode_spec.rb +++ b/spec/ruby/core/argf/binmode_spec.rb @@ -31,13 +31,13 @@ describe "ARGF.binmode" do end end - it "sets the file's encoding to ASCII-8BIT" do + it "sets the file's encoding to BINARY" do argf [@bin_file, @file1] do @argf.binmode @argf.binmode?.should == true - @argf.gets.encoding.should == Encoding::ASCII_8BIT + @argf.gets.encoding.should == Encoding::BINARY @argf.skip - @argf.read.encoding.should == Encoding::ASCII_8BIT + @argf.read.encoding.should == Encoding::BINARY end end end diff --git a/spec/ruby/core/array/equal_value_spec.rb b/spec/ruby/core/array/equal_value_spec.rb index 1ef8774873..a82e07b218 100644 --- a/spec/ruby/core/array/equal_value_spec.rb +++ b/spec/ruby/core/array/equal_value_spec.rb @@ -43,4 +43,9 @@ describe "Array#==" do obj.should_receive(:==).and_return(true) [obj].should == [5] end + + # See https://bugs.ruby-lang.org/issues/1720 + it "returns true for [NaN] == [NaN] because Array#== first checks with #equal? and NaN.equal?(NaN) is true" do + [Float::NAN].should == [Float::NAN] + end end diff --git a/spec/ruby/core/array/fixtures/encoded_strings.rb b/spec/ruby/core/array/fixtures/encoded_strings.rb index e31e247afe..5b85bd0e06 100644 --- a/spec/ruby/core/array/fixtures/encoded_strings.rb +++ b/spec/ruby/core/array/fixtures/encoded_strings.rb @@ -37,33 +37,33 @@ module ArraySpecs ] end - def self.array_with_utf8_and_7bit_ascii8bit_strings + def self.array_with_utf8_and_7bit_binary_strings [ 'bar', 'báz', - 'foo'.force_encoding('ASCII-8BIT') + 'foo'.force_encoding('BINARY') ] end - def self.array_with_utf8_and_ascii8bit_strings + def self.array_with_utf8_and_binary_strings [ 'bar', 'báz', - [255].pack('C').force_encoding('ASCII-8BIT') + [255].pack('C').force_encoding('BINARY') ] end - def self.array_with_usascii_and_7bit_ascii8bit_strings + def self.array_with_usascii_and_7bit_binary_strings [ 'bar'.force_encoding('US-ASCII'), - 'foo'.force_encoding('ASCII-8BIT') + 'foo'.force_encoding('BINARY') ] end - def self.array_with_usascii_and_ascii8bit_strings + def self.array_with_usascii_and_binary_strings [ 'bar'.force_encoding('US-ASCII'), - [255].pack('C').force_encoding('ASCII-8BIT') + [255].pack('C').force_encoding('BINARY') ] end end diff --git a/spec/ruby/core/array/pack/a_spec.rb b/spec/ruby/core/array/pack/a_spec.rb index 1cee3858ff..7af7a16c68 100644 --- a/spec/ruby/core/array/pack/a_spec.rb +++ b/spec/ruby/core/array/pack/a_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/array/pack/at_spec.rb b/spec/ruby/core/array/pack/at_spec.rb index 00763c70f1..3942677913 100644 --- a/spec/ruby/core/array/pack/at_spec.rb +++ b/spec/ruby/core/array/pack/at_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/array/pack/b_spec.rb b/spec/ruby/core/array/pack/b_spec.rb index 8a75825e3e..759aec13d1 100644 --- a/spec/ruby/core/array/pack/b_spec.rb +++ b/spec/ruby/core/array/pack/b_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -47,8 +47,8 @@ describe "Array#pack with format 'B'" do ].should be_computed_by(:pack, "B*") end - it "returns an ASCII-8BIT string" do - ["1"].pack("B").encoding.should == Encoding::ASCII_8BIT + it "returns an BINARY string" do + ["1"].pack("B").encoding.should == Encoding::BINARY end it "encodes the string as a sequence of bytes" do @@ -98,8 +98,8 @@ describe "Array#pack with format 'b'" do ].should be_computed_by(:pack, "b*") end - it "returns an ASCII-8BIT string" do - ["1"].pack("b").encoding.should == Encoding::ASCII_8BIT + it "returns an BINARY string" do + ["1"].pack("b").encoding.should == Encoding::BINARY end it "encodes the string as a sequence of bytes" do diff --git a/spec/ruby/core/array/pack/buffer_spec.rb b/spec/ruby/core/array/pack/buffer_spec.rb index 28b317eacb..a3a582996a 100644 --- a/spec/ruby/core/array/pack/buffer_spec.rb +++ b/spec/ruby/core/array/pack/buffer_spec.rb @@ -1,4 +1,4 @@ -# encoding: ascii-8bit +# encoding: binary require_relative '../../../spec_helper' diff --git a/spec/ruby/core/array/pack/c_spec.rb b/spec/ruby/core/array/pack/c_spec.rb index 225f0970fd..7200830331 100644 --- a/spec/ruby/core/array/pack/c_spec.rb +++ b/spec/ruby/core/array/pack/c_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' diff --git a/spec/ruby/core/array/pack/comment_spec.rb b/spec/ruby/core/array/pack/comment_spec.rb index 07daa2d6fb..254c827ccc 100644 --- a/spec/ruby/core/array/pack/comment_spec.rb +++ b/spec/ruby/core/array/pack/comment_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' diff --git a/spec/ruby/core/array/pack/h_spec.rb b/spec/ruby/core/array/pack/h_spec.rb index 51bf551ba3..81fca7d989 100644 --- a/spec/ruby/core/array/pack/h_spec.rb +++ b/spec/ruby/core/array/pack/h_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -97,8 +97,8 @@ describe "Array#pack with format 'H'" do ].should be_computed_by(:pack, "H") end - it "returns an ASCII-8BIT string" do - ["41"].pack("H").encoding.should == Encoding::ASCII_8BIT + it "returns an BINARY string" do + ["41"].pack("H").encoding.should == Encoding::BINARY end end @@ -194,7 +194,7 @@ describe "Array#pack with format 'h'" do ].should be_computed_by(:pack, "h") end - it "returns an ASCII-8BIT string" do - ["41"].pack("h").encoding.should == Encoding::ASCII_8BIT + it "returns an BINARY string" do + ["41"].pack("h").encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/array/pack/m_spec.rb b/spec/ruby/core/array/pack/m_spec.rb index 24acf2cef2..40c2e3f1fa 100644 --- a/spec/ruby/core/array/pack/m_spec.rb +++ b/spec/ruby/core/array/pack/m_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/array/pack/shared/float.rb b/spec/ruby/core/array/pack/shared/float.rb index b9864adef5..6cd326ce9c 100644 --- a/spec/ruby/core/array/pack/shared/float.rb +++ b/spec/ruby/core/array/pack/shared/float.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :array_pack_float_le, shared: true do it "encodes a positive Float" do diff --git a/spec/ruby/core/array/pack/shared/integer.rb b/spec/ruby/core/array/pack/shared/integer.rb index 0df03bbfd1..6592f85022 100644 --- a/spec/ruby/core/array/pack/shared/integer.rb +++ b/spec/ruby/core/array/pack/shared/integer.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :array_pack_16bit_le, shared: true do it "encodes the least significant 16 bits of a positive number" do diff --git a/spec/ruby/core/array/pack/shared/numeric_basic.rb b/spec/ruby/core/array/pack/shared/numeric_basic.rb index 9224d6080e..632d259ab8 100644 --- a/spec/ruby/core/array/pack/shared/numeric_basic.rb +++ b/spec/ruby/core/array/pack/shared/numeric_basic.rb @@ -15,9 +15,9 @@ describe :array_pack_numeric_basic, shared: true do lambda { [false].pack(pack_format) }.should raise_error(TypeError) end - it "returns an ASCII-8BIT string" do - [0xFF].pack(pack_format).encoding.should == Encoding::ASCII_8BIT - [0xE3, 0x81, 0x82].pack(pack_format(3)).encoding.should == Encoding::ASCII_8BIT + it "returns an BINARY string" do + [0xFF].pack(pack_format).encoding.should == Encoding::BINARY + [0xE3, 0x81, 0x82].pack(pack_format(3)).encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/array/pack/shared/string.rb b/spec/ruby/core/array/pack/shared/string.rb index 256c1c08e8..98e8c4d562 100644 --- a/spec/ruby/core/array/pack/shared/string.rb +++ b/spec/ruby/core/array/pack/shared/string.rb @@ -38,11 +38,11 @@ describe :array_pack_string, shared: true do it "returns a string in encoding of common to the concatenated results" do f = pack_format("*") - [ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::ASCII_8BIT], - [["abcde\xd1", "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::ASCII_8BIT], - [["a".force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::ASCII_8BIT], + [ [["\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], # under discussion [ruby-dev:37294] - [["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::ASCII_8BIT] + [["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::BINARY] ].should be_computed_by(:encoding) end end diff --git a/spec/ruby/core/array/pack/u_spec.rb b/spec/ruby/core/array/pack/u_spec.rb index d708518c16..8c3eb3a177 100644 --- a/spec/ruby/core/array/pack/u_spec.rb +++ b/spec/ruby/core/array/pack/u_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/array/pack/w_spec.rb b/spec/ruby/core/array/pack/w_spec.rb index 76be1f925f..ac37a0e1c0 100644 --- a/spec/ruby/core/array/pack/w_spec.rb +++ b/spec/ruby/core/array/pack/w_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -36,7 +36,7 @@ describe "Array#pack with format 'w'" do lambda { [-1].pack("w") }.should raise_error(ArgumentError) end - it "returns an ASCII-8BIT string" do - [1].pack('w').encoding.should == Encoding::ASCII_8BIT + it "returns an BINARY string" do + [1].pack('w').encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/array/pack/x_spec.rb b/spec/ruby/core/array/pack/x_spec.rb index 45fe34d08d..2662873d03 100644 --- a/spec/ruby/core/array/pack/x_spec.rb +++ b/spec/ruby/core/array/pack/x_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/array/pack/z_spec.rb b/spec/ruby/core/array/pack/z_spec.rb index d0600f0c26..82ce7b4a1c 100644 --- a/spec/ruby/core/array/pack/z_spec.rb +++ b/spec/ruby/core/array/pack/z_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/array/shared/join.rb b/spec/ruby/core/array/shared/join.rb index 28b3d8c04c..0d07e93b2c 100644 --- a/spec/ruby/core/array/shared/join.rb +++ b/spec/ruby/core/array/shared/join.rb @@ -89,8 +89,8 @@ describe :array_join_with_default_separator, shared: true do it "uses the first encoding when other strings are compatible" do ary1 = ArraySpecs.array_with_7bit_utf8_and_usascii_strings ary2 = ArraySpecs.array_with_usascii_and_7bit_utf8_strings - ary3 = ArraySpecs.array_with_utf8_and_7bit_ascii8bit_strings - ary4 = ArraySpecs.array_with_usascii_and_7bit_ascii8bit_strings + ary3 = ArraySpecs.array_with_utf8_and_7bit_binary_strings + ary4 = ArraySpecs.array_with_usascii_and_7bit_binary_strings ary1.send(@method).encoding.should == Encoding::UTF_8 ary2.send(@method).encoding.should == Encoding::US_ASCII @@ -107,9 +107,9 @@ describe :array_join_with_default_separator, shared: true do end it "fails for arrays with incompatibly-encoded strings" do - ary_utf8_bad_ascii8bit = ArraySpecs.array_with_utf8_and_ascii8bit_strings + ary_utf8_bad_binary = ArraySpecs.array_with_utf8_and_binary_strings - lambda { ary_utf8_bad_ascii8bit.send(@method) }.should raise_error(EncodingError) + lambda { ary_utf8_bad_binary.send(@method) }.should raise_error(EncodingError) end end diff --git a/spec/ruby/core/array/to_h_spec.rb b/spec/ruby/core/array/to_h_spec.rb index 27a0b6112f..4431430216 100644 --- a/spec/ruby/core/array/to_h_spec.rb +++ b/spec/ruby/core/array/to_h_spec.rb @@ -35,6 +35,10 @@ describe "Array#to_h" do lambda { [].to_h(:a, :b) }.should raise_error(ArgumentError) end + it "produces a hash that returns nil for a missing element" do + [[:a, 1], [:b, 2]].to_h[:c].should be_nil + end + ruby_version_is "2.6" do context "with block" do it "converts [key, value] pairs returned by the block to a Hash" do diff --git a/spec/ruby/core/dir/children_spec.rb b/spec/ruby/core/dir/children_spec.rb index d28f1b1346..ef8b20b1f0 100644 --- a/spec/ruby/core/dir/children_spec.rb +++ b/spec/ruby/core/dir/children_spec.rb @@ -43,10 +43,10 @@ ruby_version_is "2.5" do it "returns children encoded with the filesystem encoding by default" do # This spec depends on the locale not being US-ASCII because if it is, the - # children that are not ascii_only? will be ASCII-8BIT encoded. + # children that are not ascii_only? will be BINARY encoded. children = Dir.children(File.join(DirSpecs.mock_dir, 'special')).sort encoding = Encoding.find("filesystem") - encoding = Encoding::ASCII_8BIT if encoding == Encoding::US_ASCII + encoding = Encoding::BINARY if encoding == Encoding::US_ASCII platform_is_not :windows do children.should include("こんにちは.txt".force_encoding(encoding)) end @@ -110,11 +110,11 @@ ruby_version_is "2.6" do it "returns children encoded with the filesystem encoding by default" do # This spec depends on the locale not being US-ASCII because if it is, the - # children that are not ascii_only? will be ASCII-8BIT encoded. + # children that are not ascii_only? will be BINARY encoded. @dir = Dir.new(File.join(DirSpecs.mock_dir, 'special')) children = @dir.children.sort encoding = Encoding.find("filesystem") - encoding = Encoding::ASCII_8BIT if encoding == Encoding::US_ASCII + encoding = Encoding::BINARY if encoding == Encoding::US_ASCII platform_is_not :windows do children.should include("こんにちは.txt".force_encoding(encoding)) end diff --git a/spec/ruby/core/dir/entries_spec.rb b/spec/ruby/core/dir/entries_spec.rb index 488acec81b..ed45287e82 100644 --- a/spec/ruby/core/dir/entries_spec.rb +++ b/spec/ruby/core/dir/entries_spec.rb @@ -42,10 +42,10 @@ describe "Dir.entries" do it "returns entries encoded with the filesystem encoding by default" do # This spec depends on the locale not being US-ASCII because if it is, the - # entries that are not ascii_only? will be ASCII-8BIT encoded. + # entries that are not ascii_only? will be BINARY encoded. entries = Dir.entries(File.join(DirSpecs.mock_dir, 'special')).sort encoding = Encoding.find("filesystem") - encoding = Encoding::ASCII_8BIT if encoding == Encoding::US_ASCII + encoding = Encoding::BINARY if encoding == Encoding::US_ASCII platform_is_not :windows do entries.should include("こんにちは.txt".force_encoding(encoding)) end diff --git a/spec/ruby/core/dir/shared/pwd.rb b/spec/ruby/core/dir/shared/pwd.rb index 94fc2fa7fb..2a8d7fe790 100644 --- a/spec/ruby/core/dir/shared/pwd.rb +++ b/spec/ruby/core/dir/shared/pwd.rb @@ -37,7 +37,7 @@ describe :dir_pwd, shared: true do it "returns a String with the filesystem encoding" do enc = Dir.send(@method).encoding if @fs_encoding == Encoding::US_ASCII - [Encoding::US_ASCII, Encoding::ASCII_8BIT].should include(enc) + [Encoding::US_ASCII, Encoding::BINARY].should include(enc) else enc.should equal(@fs_encoding) end diff --git a/spec/ruby/core/encoding/compatible_spec.rb b/spec/ruby/core/encoding/compatible_spec.rb index 8c2e4d7e09..dc47a6553a 100644 --- a/spec/ruby/core/encoding/compatible_spec.rb +++ b/spec/ruby/core/encoding/compatible_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../spec_helper' @@ -14,12 +14,12 @@ describe "Encoding.compatible? String, String" do Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII end - it "returns US-ASCII if the second String is ASCII-8BIT and ASCII only" do + it "returns US-ASCII if the second String is BINARY and ASCII only" do Encoding.compatible?(@str, "\x7f").should == Encoding::US_ASCII end - it "returns ASCII-8BIT if the second String is ASCII-8BIT but not ASCII only" do - Encoding.compatible?(@str, "\xff").should == Encoding::ASCII_8BIT + it "returns BINARY if the second String is BINARY but not ASCII only" do + Encoding.compatible?(@str, "\xff").should == Encoding::BINARY end it "returns US-ASCII if the second String is UTF-8 and ASCII only" do @@ -39,16 +39,16 @@ describe "Encoding.compatible? String, String" do end it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do - [ [Encoding, "abc".force_encoding("ASCII-8BIT"), "123".force_encoding("US-ASCII"), Encoding::ASCII_8BIT], - [Encoding, "123".force_encoding("US-ASCII"), "abc".force_encoding("ASCII-8BIT"), Encoding::US_ASCII] + [ [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] ].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("ASCII-8BIT"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII], - [Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("ASCII-8BIT"), Encoding::ASCII_8BIT], + [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], ].should be_computed_by(:compatible?) end @@ -61,11 +61,11 @@ describe "Encoding.compatible? String, String" do describe "when the first's Encoding is ASCII compatible but not ASCII only" do it "returns the first's Encoding if the second's is valid US-ASCII" do - Encoding.compatible?("\xff", "def".encode("us-ascii")).should == Encoding::ASCII_8BIT + Encoding.compatible?("\xff", "def".encode("us-ascii")).should == Encoding::BINARY end it "returns the first's Encoding if the second's is UTF-8 and ASCII only" do - Encoding.compatible?("\xff", "\u{7f}".encode("utf-8")).should == Encoding::ASCII_8BIT + Encoding.compatible?("\xff", "\u{7f}".encode("utf-8")).should == Encoding::BINARY end it "returns nil if the second encoding is ASCII compatible but neither String's encoding is ASCII only" do @@ -82,11 +82,11 @@ describe "Encoding.compatible? String, String" do Encoding.compatible?(@str, "def".encode("us-ascii")).should be_nil end - it "returns nil when the second String is ASCII-8BIT and ASCII only" do + it "returns nil when the second String is BINARY and ASCII only" do Encoding.compatible?(@str, "\x7f").should be_nil end - it "returns nil when the second String is ASCII-8BIT but not ASCII only" do + it "returns nil when the second String is BINARY but not ASCII only" do Encoding.compatible?(@str, "\xff").should be_nil end @@ -109,7 +109,7 @@ describe "Encoding.compatible? String, String" do Encoding.compatible?(@str, "\x7f").should == Encoding::UTF_8 end - it "returns nil when the second's Encoding is ASCII-8BIT but not ASCII only" do + it "returns nil when the second's Encoding is BINARY but not ASCII only" do Encoding.compatible?(@str, "\xff").should be_nil end @@ -170,7 +170,7 @@ describe "Encoding.compatible? String, Regexp" do end it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do - [ [Encoding, "abc", Encoding::ASCII_8BIT], + [ [Encoding, "abc", Encoding::BINARY], [Encoding, "abc".encode("utf-8"), Encoding::UTF_8], [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP], [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS], @@ -178,7 +178,7 @@ describe "Encoding.compatible? String, Regexp" do end it "returns the String's Encoding if the String is not ASCII only" do - [ [Encoding, "\xff", Encoding::ASCII_8BIT], + [ [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], @@ -193,7 +193,7 @@ describe "Encoding.compatible? String, Symbol" do end it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do - [ [Encoding, "abc", Encoding::ASCII_8BIT], + [ [Encoding, "abc", Encoding::BINARY], [Encoding, "abc".encode("utf-8"), Encoding::UTF_8], [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP], [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS], @@ -201,7 +201,7 @@ describe "Encoding.compatible? String, Symbol" do end it "returns the String's Encoding if the String is not ASCII only" do - [ [Encoding, "\xff", Encoding::ASCII_8BIT], + [ [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], @@ -219,7 +219,7 @@ describe "Encoding.compatible? String, Encoding" do end it "returns the String's encoding if the Encoding is US-ASCII" do - [ [Encoding, "\xff", Encoding::ASCII_8BIT], + [ [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], @@ -229,14 +229,14 @@ describe "Encoding.compatible? String, Encoding" do it "returns the Encoding if the String's encoding is ASCII compatible and the String is ASCII only" do str = "abc".encode("utf-8") - Encoding.compatible?(str, Encoding::ASCII_8BIT).should == Encoding::ASCII_8BIT + Encoding.compatible?(str, Encoding::BINARY).should == Encoding::BINARY Encoding.compatible?(str, Encoding::UTF_8).should == Encoding::UTF_8 Encoding.compatible?(str, Encoding::EUC_JP).should == Encoding::EUC_JP Encoding.compatible?(str, Encoding::Shift_JIS).should == Encoding::Shift_JIS end it "returns nil if the String's encoding is ASCII compatible but the string is not ASCII only" do - Encoding.compatible?("\u3042".encode("utf-8"), Encoding::ASCII_8BIT).should be_nil + Encoding.compatible?("\u3042".encode("utf-8"), Encoding::BINARY).should be_nil end end @@ -254,7 +254,7 @@ describe "Encoding.compatible? Regexp, Regexp" do end it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do - [ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT], + [ [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], @@ -268,7 +268,7 @@ describe "Encoding.compatible? Regexp, Symbol" do end it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do - [ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT], + [ [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], @@ -294,7 +294,7 @@ describe "Encoding.compatible? Symbol, Regexp" do c = Regexp.new("\xa4\xa2".force_encoding("euc-jp")) d = Regexp.new("\x82\xa0".force_encoding("shift_jis")) - [ [Encoding, :abc, a, Encoding::ASCII_8BIT], + [ [Encoding, :abc, a, Encoding::BINARY], [Encoding, :abc, b, Encoding::UTF_8], [Encoding, :abc, c, Encoding::EUC_JP], [Encoding, :abc, d, Encoding::Shift_JIS], @@ -308,7 +308,7 @@ describe "Encoding.compatible? Symbol, Symbol" do end it "returns the first's Encoding if it is not ASCII only" do - [ [Encoding, "\xff".to_sym, Encoding::ASCII_8BIT], + [ [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], @@ -322,15 +322,15 @@ describe "Encoding.compatible? Encoding, Encoding" do [Encoding, Encoding::US_ASCII, Encoding::UTF_7, nil], [Encoding, Encoding::EUC_JP, Encoding::UTF_7, nil], [Encoding, Encoding::UTF_7, Encoding::EUC_JP, nil], - [Encoding, Encoding::UTF_7, Encoding::ASCII_8BIT, nil], - [Encoding, Encoding::ASCII_8BIT, Encoding::UTF_7, nil], + [Encoding, Encoding::UTF_7, Encoding::BINARY, nil], + [Encoding, Encoding::BINARY, Encoding::UTF_7, nil], ].should be_computed_by(:compatible?) end it "returns nil if one of the encodings is not US-ASCII" do - [ [Encoding, Encoding::UTF_8, Encoding::ASCII_8BIT, nil], - [Encoding, Encoding::ASCII_8BIT, Encoding::UTF_8, nil], - [Encoding, Encoding::ASCII_8BIT, Encoding::EUC_JP, nil], + [ [Encoding, Encoding::UTF_8, Encoding::BINARY, nil], + [Encoding, Encoding::BINARY, Encoding::UTF_8, nil], + [Encoding, Encoding::BINARY, Encoding::EUC_JP, nil], [Encoding, Encoding::Shift_JIS, Encoding::EUC_JP, nil], ].should be_computed_by(:compatible?) end @@ -339,14 +339,14 @@ describe "Encoding.compatible? Encoding, Encoding" do [ [Encoding, Encoding::UTF_8, Encoding::US_ASCII, Encoding::UTF_8], [Encoding, Encoding::EUC_JP, Encoding::US_ASCII, Encoding::EUC_JP], [Encoding, Encoding::Shift_JIS, Encoding::US_ASCII, Encoding::Shift_JIS], - [Encoding, Encoding::ASCII_8BIT, Encoding::US_ASCII, Encoding::ASCII_8BIT], + [Encoding, Encoding::BINARY, Encoding::US_ASCII, Encoding::BINARY], ].should be_computed_by(:compatible?) end it "returns the Encoding if both are the same" do [ [Encoding, Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8], [Encoding, Encoding::US_ASCII, Encoding::US_ASCII, Encoding::US_ASCII], - [Encoding, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT], + [Encoding, Encoding::BINARY, Encoding::BINARY, Encoding::BINARY], [Encoding, Encoding::UTF_7, Encoding::UTF_7, Encoding::UTF_7], ].should be_computed_by(:compatible?) end diff --git a/spec/ruby/core/encoding/converter/new_spec.rb b/spec/ruby/core/encoding/converter/new_spec.rb index d62b709c52..6b9c76a093 100644 --- a/spec/ruby/core/encoding/converter/new_spec.rb +++ b/spec/ruby/core/encoding/converter/new_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' describe "Encoding::Converter.new" do @@ -96,12 +96,12 @@ describe "Encoding::Converter.new" do describe "when passed nil for the replacement object" do describe "when the destination encoding is not UTF-8" do it "sets the replacement String to '?'" do - conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil) + conv = Encoding::Converter.new("us-ascii", "binary", replace: nil) conv.replacement.should == "?" end it "sets the replacement String encoding to US-ASCII" do - conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil) + conv = Encoding::Converter.new("us-ascii", "binary", replace: nil) conv.replacement.encoding.should == Encoding::US_ASCII end diff --git a/spec/ruby/core/encoding/converter/search_convpath_spec.rb b/spec/ruby/core/encoding/converter/search_convpath_spec.rb index 03cb435528..bd7530405b 100644 --- a/spec/ruby/core/encoding/converter/search_convpath_spec.rb +++ b/spec/ruby/core/encoding/converter/search_convpath_spec.rb @@ -26,7 +26,7 @@ describe "Encoding::Converter.search_convpath" do it "raises an Encoding::ConverterNotFoundError if no conversion path exists" do lambda do - Encoding::Converter.search_convpath(Encoding::ASCII_8BIT, Encoding::Emacs_Mule) + Encoding::Converter.search_convpath(Encoding::BINARY, Encoding::Emacs_Mule) end.should raise_error(Encoding::ConverterNotFoundError) end end diff --git a/spec/ruby/core/encoding/default_internal_spec.rb b/spec/ruby/core/encoding/default_internal_spec.rb index d8bbb2d11d..47a6887eee 100644 --- a/spec/ruby/core/encoding/default_internal_spec.rb +++ b/spec/ruby/core/encoding/default_internal_spec.rb @@ -24,8 +24,8 @@ describe "Encoding.default_internal" do end it "returns the default internal encoding" do - Encoding.default_internal = Encoding::ASCII_8BIT - Encoding.default_internal.should == Encoding::ASCII_8BIT + Encoding.default_internal = Encoding::BINARY + Encoding.default_internal.should == Encoding::BINARY end end diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb index 4b24e1611b..a8f7354b16 100644 --- a/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb +++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb @@ -22,9 +22,9 @@ describe "Encoding::InvalidByteSequenceError#error_bytes" do @exception2.error_bytes.should == @errinfo2[-2] end - it "uses ASCII-8BIT as the encoding" do - @exception.error_bytes.encoding.should == Encoding::ASCII_8BIT + it "uses BINARY as the encoding" do + @exception.error_bytes.encoding.should == Encoding::BINARY - @exception2.error_bytes.encoding.should == Encoding::ASCII_8BIT + @exception2.error_bytes.encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb index 6f0ff524f5..93823b5db4 100644 --- a/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb +++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb @@ -22,9 +22,9 @@ describe "Encoding::InvalidByteSequenceError#readagain_bytes" do @exception2.readagain_bytes.should == @errinfo2[-1] end - it "uses ASCII-8BIT as the encoding" do - @exception.readagain_bytes.encoding.should == Encoding::ASCII_8BIT + it "uses BINARY as the encoding" do + @exception.readagain_bytes.encoding.should == Encoding::BINARY - @exception2.readagain_bytes.encoding.should == Encoding::ASCII_8BIT + @exception2.readagain_bytes.encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/enumerator/each_with_index_spec.rb b/spec/ruby/core/enumerator/each_with_index_spec.rb index 0a3c11e0b4..7332fd628b 100644 --- a/spec/ruby/core/enumerator/each_with_index_spec.rb +++ b/spec/ruby/core/enumerator/each_with_index_spec.rb @@ -10,7 +10,7 @@ describe "Enumerator#each_with_index" do enum1 = [1,2,3].select enum2 = enum1.each_with_index enum2.should be_an_instance_of(Enumerator) - enum1.should_not === enum2 + enum1.should_not == enum2 end it "raises an ArgumentError if passed extra arguments" do @@ -28,9 +28,7 @@ describe "Enumerator#each_with_index" do it "returns the iterator's return value" do [1,2,3].select.with_index { |a,b| false }.should == [] end -end -describe "Enumerator#each_with_index" do it "returns the correct value if chained with itself" do [:a].each_with_index.each_with_index.to_a.should == [[[:a,0],0]] [:a].each.with_index.with_index.to_a.should == [[[:a,0],0]] diff --git a/spec/ruby/core/env/element_reference_spec.rb b/spec/ruby/core/env/element_reference_spec.rb index 0a10cd27b8..59b53fc4b1 100644 --- a/spec/ruby/core/env/element_reference_spec.rb +++ b/spec/ruby/core/env/element_reference_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../spec_helper' describe "ENV.[]" do @@ -34,7 +34,7 @@ describe "ENV.[]" do @external = Encoding.default_external @internal = Encoding.default_internal - Encoding.default_external = Encoding::ASCII_8BIT + Encoding.default_external = Encoding::BINARY end after :each do @@ -48,7 +48,7 @@ describe "ENV.[]" do Encoding.default_internal = nil locale = Encoding.find('locale') - locale = Encoding::ASCII_8BIT if locale == Encoding::US_ASCII + locale = Encoding::BINARY if locale == Encoding::US_ASCII ENV[@variable] = "\xC3\xB8" ENV[@variable].encoding.should == locale end diff --git a/spec/ruby/core/env/shared/each.rb b/spec/ruby/core/env/shared/each.rb index 4039dd1f83..8a262e4862 100644 --- a/spec/ruby/core/env/shared/each.rb +++ b/spec/ruby/core/env/shared/each.rb @@ -30,7 +30,7 @@ describe :env_each, shared: true do @external = Encoding.default_external @internal = Encoding.default_internal - Encoding.default_external = Encoding::ASCII_8BIT + Encoding.default_external = Encoding::BINARY @locale_encoding = Encoding.find "locale" end diff --git a/spec/ruby/core/env/shared/key.rb b/spec/ruby/core/env/shared/key.rb index c40a56093e..43299beadb 100644 --- a/spec/ruby/core/env/shared/key.rb +++ b/spec/ruby/core/env/shared/key.rb @@ -1,6 +1,4 @@ describe :env_key, shared: true do - it "needs to be reviewed for completeness" - it "returns the index associated with the passed value" do ENV["foo"] = "bar" ENV.send(@method, "bar").should == "foo" diff --git a/spec/ruby/core/env/shift_spec.rb b/spec/ruby/core/env/shift_spec.rb index 8a74f4ecac..c03b5d50c5 100644 --- a/spec/ruby/core/env/shift_spec.rb +++ b/spec/ruby/core/env/shift_spec.rb @@ -30,7 +30,7 @@ describe "ENV.shift" do @external = Encoding.default_external @internal = Encoding.default_internal - Encoding.default_external = Encoding::ASCII_8BIT + Encoding.default_external = Encoding::BINARY end after :each do diff --git a/spec/ruby/core/file/chown_spec.rb b/spec/ruby/core/file/chown_spec.rb index 8660534825..512d5b4738 100644 --- a/spec/ruby/core/file/chown_spec.rb +++ b/spec/ruby/core/file/chown_spec.rb @@ -142,11 +142,3 @@ describe "File#chown" do @file.chown(nil, nil).should == 0 end end - -describe "File.chown" do - it "needs to be reviewed for spec completeness" -end - -describe "File#chown" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb index 1d972023a3..aa6a3c9c63 100644 --- a/spec/ruby/core/file/expand_path_spec.rb +++ b/spec/ruby/core/file/expand_path_spec.rb @@ -141,12 +141,12 @@ describe "File.expand_path" do File.expand_path(path).encoding.should equal(Encoding::CP1251) weird_path = [222, 173, 190, 175].pack('C*') - File.expand_path(weird_path).encoding.should equal(Encoding::ASCII_8BIT) + File.expand_path(weird_path).encoding.should equal(Encoding::BINARY) end platform_is_not :windows do - it "expands a path when the default external encoding is ASCII-8BIT" do - Encoding.default_external = Encoding::ASCII_8BIT + it "expands a path when the default external encoding is BINARY" do + Encoding.default_external = Encoding::BINARY path_8bit = [222, 173, 190, 175].pack('C*') File.expand_path( path_8bit, @rootdir).should == "#{@rootdir}" + path_8bit end diff --git a/spec/ruby/core/file/fixtures/file_types.rb b/spec/ruby/core/file/fixtures/file_types.rb index 1dd0752f73..109bcfe42e 100644 --- a/spec/ruby/core/file/fixtures/file_types.rb +++ b/spec/ruby/core/file/fixtures/file_types.rb @@ -52,15 +52,10 @@ module FileSpecs end def self.socket - require 'socket' - name = tmp("ftype_socket.socket") - rm_r name - begin - socket = UNIXServer.new name - rescue ArgumentError => error - error.message.should =~ /too long/ - return - end + require_relative '../../../library/socket/fixtures/classes.rb' + + name = SocketSpecs.socket_path + socket = UNIXServer.new name begin yield name ensure diff --git a/spec/ruby/core/file/initialize_spec.rb b/spec/ruby/core/file/initialize_spec.rb index 00e2228031..9a76a95260 100644 --- a/spec/ruby/core/file/initialize_spec.rb +++ b/spec/ruby/core/file/initialize_spec.rb @@ -1,10 +1,6 @@ require_relative '../../spec_helper' describe "File#initialize" do - it "needs to be reviewed for spec completeness" -end - -describe "File#initialize" do after :each do @io.close if @io end diff --git a/spec/ruby/core/file/lchown_spec.rb b/spec/ruby/core/file/lchown_spec.rb index 7889d68559..8d95d287ba 100644 --- a/spec/ruby/core/file/lchown_spec.rb +++ b/spec/ruby/core/file/lchown_spec.rb @@ -57,7 +57,3 @@ as_superuser do end end end - -describe "File.lchown" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb index 14be5aa32a..59c13f08ed 100644 --- a/spec/ruby/core/file/open_spec.rb +++ b/spec/ruby/core/file/open_spec.rb @@ -552,9 +552,9 @@ describe "File.open" do lambda { File.open(@file, 'fake') }.should raise_error(ArgumentError) end - it "defaults external_encoding to ASCII-8BIT for binary modes" do - File.open(@file, 'rb') {|f| f.external_encoding.should == Encoding::ASCII_8BIT} - File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::ASCII_8BIT} + it "defaults external_encoding to BINARY for binary modes" do + File.open(@file, 'rb') {|f| f.external_encoding.should == Encoding::BINARY} + File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::BINARY} end it "uses the second argument as an options Hash" do diff --git a/spec/ruby/core/file/stat/ftype_spec.rb b/spec/ruby/core/file/stat/ftype_spec.rb index a19e7c43d7..eb892eae5f 100644 --- a/spec/ruby/core/file/stat/ftype_spec.rb +++ b/spec/ruby/core/file/stat/ftype_spec.rb @@ -55,10 +55,6 @@ describe "File::Stat#ftype" do end end - # This will silently not execute the block if no socket - # can be found. However, if you are running X, there is - # a good chance that if nothing else, at least the X - # Server socket exists. it "returns 'socket' when the file is a socket" do FileSpecs.socket do |socket| File.lstat(socket).ftype.should == 'socket' diff --git a/spec/ruby/core/file/stat/setgid_spec.rb b/spec/ruby/core/file/stat/setgid_spec.rb index 9b972f5a6d..c0748ede57 100644 --- a/spec/ruby/core/file/stat/setgid_spec.rb +++ b/spec/ruby/core/file/stat/setgid_spec.rb @@ -5,7 +5,3 @@ require_relative 'fixtures/classes' describe "File::Stat#setgid?" do it_behaves_like :file_setgid, :setgid?, FileStat end - -describe "File::Stat#setgid?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/file/stat/setuid_spec.rb b/spec/ruby/core/file/stat/setuid_spec.rb index 892776a0ef..6408120fc4 100644 --- a/spec/ruby/core/file/stat/setuid_spec.rb +++ b/spec/ruby/core/file/stat/setuid_spec.rb @@ -5,7 +5,3 @@ require_relative 'fixtures/classes' describe "File::Stat#setuid?" do it_behaves_like :file_setuid, :setuid?, FileStat end - -describe "File::Stat#setuid?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/file/stat/socket_spec.rb b/spec/ruby/core/file/stat/socket_spec.rb index 8dd43ec44a..09740be110 100644 --- a/spec/ruby/core/file/stat/socket_spec.rb +++ b/spec/ruby/core/file/stat/socket_spec.rb @@ -5,7 +5,3 @@ require_relative 'fixtures/classes' describe "File::Stat#socket?" do it_behaves_like :file_socket, :socket?, FileStat end - -describe "File::Stat#socket?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/file/stat/sticky_spec.rb b/spec/ruby/core/file/stat/sticky_spec.rb index 8634253a02..7083e644e9 100644 --- a/spec/ruby/core/file/stat/sticky_spec.rb +++ b/spec/ruby/core/file/stat/sticky_spec.rb @@ -5,7 +5,3 @@ require_relative 'fixtures/classes' describe "File::Stat#sticky?" do it_behaves_like :file_sticky, :sticky?, FileStat end - -describe "File::Stat#sticky?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/filetest/owned_spec.rb b/spec/ruby/core/filetest/owned_spec.rb index 5ffd8ced26..b26165f98d 100644 --- a/spec/ruby/core/filetest/owned_spec.rb +++ b/spec/ruby/core/filetest/owned_spec.rb @@ -4,7 +4,3 @@ require_relative '../../shared/file/owned' describe "FileTest.owned?" do it_behaves_like :file_owned, :owned?, FileTest end - -describe "FileTest.owned?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/filetest/pipe_spec.rb b/spec/ruby/core/filetest/pipe_spec.rb index 912635b25f..8ce67568fb 100644 --- a/spec/ruby/core/filetest/pipe_spec.rb +++ b/spec/ruby/core/filetest/pipe_spec.rb @@ -4,7 +4,3 @@ require_relative '../../shared/file/pipe' describe "FileTest.pipe?" do it_behaves_like :file_pipe, :pipe?, FileTest end - -describe "FileTest.pipe?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/filetest/setgid_spec.rb b/spec/ruby/core/filetest/setgid_spec.rb index e0feb3c8a9..c83ffccb2a 100644 --- a/spec/ruby/core/filetest/setgid_spec.rb +++ b/spec/ruby/core/filetest/setgid_spec.rb @@ -4,7 +4,3 @@ require_relative '../../shared/file/setgid' describe "FileTest.setgid?" do it_behaves_like :file_setgid, :setgid?, FileTest end - -describe "FileTest.setgid?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/filetest/setuid_spec.rb b/spec/ruby/core/filetest/setuid_spec.rb index 4371a215ba..1c1fd2efe4 100644 --- a/spec/ruby/core/filetest/setuid_spec.rb +++ b/spec/ruby/core/filetest/setuid_spec.rb @@ -4,7 +4,3 @@ require_relative '../../shared/file/setuid' describe "FileTest.setuid?" do it_behaves_like :file_setuid, :setuid?, FileTest end - -describe "FileTest.setuid?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/filetest/socket_spec.rb b/spec/ruby/core/filetest/socket_spec.rb index 1373c7e370..63a6a31ecb 100644 --- a/spec/ruby/core/filetest/socket_spec.rb +++ b/spec/ruby/core/filetest/socket_spec.rb @@ -4,7 +4,3 @@ require_relative '../../shared/file/socket' describe "FileTest.socket?" do it_behaves_like :file_socket, :socket?, FileTest end - -describe "FileTest.socket?" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/core/hash/merge_spec.rb b/spec/ruby/core/hash/merge_spec.rb index 54abcb816d..77e5c42071 100644 --- a/spec/ruby/core/hash/merge_spec.rb +++ b/spec/ruby/core/hash/merge_spec.rb @@ -99,11 +99,4 @@ end describe "Hash#merge!" do it_behaves_like :hash_update, :merge! - - it "does not raise an exception if changing the value of an existing key during iteration" do - hash = {1 => 2, 3 => 4, 5 => 6} - hash2 = {1 => :foo, 3 => :bar} - hash.each { hash.merge!(hash2) } - hash.should == {1 => :foo, 3 => :bar, 5 => 6} - end end diff --git a/spec/ruby/core/hash/shared/update.rb b/spec/ruby/core/hash/shared/update.rb index 250c5ab440..e808add5c0 100644 --- a/spec/ruby/core/hash/shared/update.rb +++ b/spec/ruby/core/hash/shared/update.rb @@ -57,6 +57,13 @@ describe :hash_update, shared: true do end.should raise_error(frozen_error_class) end + it "does not raise an exception if changing the value of an existing key during iteration" do + hash = {1 => 2, 3 => 4, 5 => 6} + hash2 = {1 => :foo, 3 => :bar} + hash.each { hash.send(@method, hash2) } + hash.should == {1 => :foo, 3 => :bar, 5 => 6} + end + ruby_version_is "2.6" do it "accepts multiple hashes" do result = { a: 1 }.send(@method, { b: 2 }, { c: 3 }, { d: 4 }) diff --git a/spec/ruby/core/integer/chr_spec.rb b/spec/ruby/core/integer/chr_spec.rb index 8420d85cf6..a519961d7c 100644 --- a/spec/ruby/core/integer/chr_spec.rb +++ b/spec/ruby/core/integer/chr_spec.rb @@ -30,9 +30,9 @@ describe "Integer#chr without argument" do end describe "and self is between 128 and 255 (inclusive)" do - it "returns an ASCII-8BIT String" do + it "returns an BINARY String" do (128..255).each do |c| - c.chr.encoding.should == Encoding::ASCII_8BIT + c.chr.encoding.should == Encoding::BINARY end end @@ -81,13 +81,13 @@ describe "Integer#chr without argument" do end describe "and self is between 128 and 255 (inclusive)" do - it "returns an ASCII-8BIT String" do + it "returns an BINARY String" do (128..255).each do |c| Encoding.default_internal = Encoding::UTF_8 - c.chr.encoding.should == Encoding::ASCII_8BIT + c.chr.encoding.should == Encoding::BINARY Encoding.default_internal = Encoding::SHIFT_JIS - c.chr.encoding.should == Encoding::ASCII_8BIT + c.chr.encoding.should == Encoding::BINARY end end @@ -126,7 +126,7 @@ describe "Integer#chr without argument" do # #5864 it "raises RangeError if self is invalid as a codepoint in the default internal encoding" do [ [0x0100, "US-ASCII"], - [0x0100, "ASCII-8BIT"], + [0x0100, "BINARY"], [0x0100, "EUC-JP"], [0xA1A0, "EUC-JP"], [0x0100, "ISO-8859-9"], @@ -173,10 +173,10 @@ describe "Integer#chr with an encoding argument" do 0x0000.chr(Encoding::US_ASCII).encoding.should == Encoding::US_ASCII 0x007F.chr(Encoding::US_ASCII).encoding.should == Encoding::US_ASCII - 0x0000.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT - 0x007F.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT - 0x0080.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT - 0x00FF.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT + 0x0000.chr(Encoding::BINARY).encoding.should == Encoding::BINARY + 0x007F.chr(Encoding::BINARY).encoding.should == Encoding::BINARY + 0x0080.chr(Encoding::BINARY).encoding.should == Encoding::BINARY + 0x00FF.chr(Encoding::BINARY).encoding.should == Encoding::BINARY 0x0000.chr(Encoding::UTF_8).encoding.should == Encoding::UTF_8 0x007F.chr(Encoding::UTF_8).encoding.should == Encoding::UTF_8 @@ -197,10 +197,10 @@ describe "Integer#chr with an encoding argument" do 0x0000.chr(Encoding::US_ASCII).bytes.to_a.should == [0x00] 0x007F.chr(Encoding::US_ASCII).bytes.to_a.should == [0x7F] - 0x0000.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x00] - 0x007F.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x7F] - 0x0080.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x80] - 0x00FF.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0xFF] + 0x0000.chr(Encoding::BINARY).bytes.to_a.should == [0x00] + 0x007F.chr(Encoding::BINARY).bytes.to_a.should == [0x7F] + 0x0080.chr(Encoding::BINARY).bytes.to_a.should == [0x80] + 0x00FF.chr(Encoding::BINARY).bytes.to_a.should == [0xFF] 0x0000.chr(Encoding::UTF_8).bytes.to_a.should == [0x00] 0x007F.chr(Encoding::UTF_8).bytes.to_a.should == [0x7F] @@ -220,7 +220,7 @@ describe "Integer#chr with an encoding argument" do # #5864 it "raises RangeError if self is invalid as a codepoint in the specified encoding" do [ [0x80, "US-ASCII"], - [0x0100, "ASCII-8BIT"], + [0x0100, "BINARY"], [0x0100, "EUC-JP"], [0xA1A0, "EUC-JP"], [0xA1, "EUC-JP"], diff --git a/spec/ruby/core/integer/round_spec.rb b/spec/ruby/core/integer/round_spec.rb index 622a55280e..a45a7b5fb3 100644 --- a/spec/ruby/core/integer/round_spec.rb +++ b/spec/ruby/core/integer/round_spec.rb @@ -67,12 +67,15 @@ describe "Integer#round" do 25.round(-1, half: :up).should eql(30) 25.round(-1, half: :down).should eql(20) 25.round(-1, half: :even).should eql(20) + 25.round(-1, half: nil).should eql(30) 35.round(-1, half: :up).should eql(40) 35.round(-1, half: :down).should eql(30) 35.round(-1, half: :even).should eql(40) + 35.round(-1, half: nil).should eql(40) (-25).round(-1, half: :up).should eql(-30) (-25).round(-1, half: :down).should eql(-20) (-25).round(-1, half: :even).should eql(-20) + (-25).round(-1, half: nil).should eql(-30) end ruby_version_is "2.4"..."2.5" do @@ -90,4 +93,9 @@ describe "Integer#round" do 35.round(1, half: :even).should eql(35) end end + + it "raises ArgumentError for an unknown rounding mode" do + lambda { 42.round(-1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/) + lambda { 42.round(1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/) + end end diff --git a/spec/ruby/core/io/binread_spec.rb b/spec/ruby/core/io/binread_spec.rb index 5e936ac6ba..961044da58 100644 --- a/spec/ruby/core/io/binread_spec.rb +++ b/spec/ruby/core/io/binread_spec.rb @@ -28,13 +28,13 @@ describe "IO.binread" do IO.binread(@fname, 5, 3).should == @contents.slice(3, 5) end - it "returns a String in ASCII-8BIT encoding" do - IO.binread(@fname).encoding.should == Encoding::ASCII_8BIT + it "returns a String in BINARY encoding" do + IO.binread(@fname).encoding.should == Encoding::BINARY end - it "returns a String in ASCII-8BIT encoding regardless of Encoding.default_internal" do + it "returns a String in BINARY encoding regardless of Encoding.default_internal" do Encoding.default_internal = Encoding::EUC_JP - IO.binread(@fname).encoding.should == Encoding::ASCII_8BIT + IO.binread(@fname).encoding.should == Encoding::BINARY end it "raises an ArgumentError when not passed a valid length" do diff --git a/spec/ruby/core/io/binwrite_spec.rb b/spec/ruby/core/io/binwrite_spec.rb index e28ea8ebb1..8ebc86a52e 100644 --- a/spec/ruby/core/io/binwrite_spec.rb +++ b/spec/ruby/core/io/binwrite_spec.rb @@ -3,6 +3,4 @@ require_relative 'shared/binwrite' describe "IO.binwrite" do it_behaves_like :io_binwrite, :binwrite - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/io/external_encoding_spec.rb b/spec/ruby/core/io/external_encoding_spec.rb index 3581019207..9666974647 100644 --- a/spec/ruby/core/io/external_encoding_spec.rb +++ b/spec/ruby/core/io/external_encoding_spec.rb @@ -171,9 +171,9 @@ describe "IO#external_encoding" do end describe "with 'rb' mode" do - it "returns Encoding::ASCII_8BIT" do + it "returns Encoding::BINARY" do @io = new_io @name, "rb" - @io.external_encoding.should equal(Encoding::ASCII_8BIT) + @io.external_encoding.should equal(Encoding::BINARY) end it "returns the external encoding specified by the mode argument" do @@ -191,9 +191,9 @@ describe "IO#external_encoding" do end describe "with 'wb' mode" do - it "returns Encoding::ASCII_8BIT" do + it "returns Encoding::BINARY" do @io = new_io @name, "wb" - @io.external_encoding.should equal(Encoding::ASCII_8BIT) + @io.external_encoding.should equal(Encoding::BINARY) end it "returns the external encoding specified by the mode argument" do diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb index ac763f2a13..371c1c3d3b 100644 --- a/spec/ruby/core/io/gets_spec.rb +++ b/spec/ruby/core/io/gets_spec.rb @@ -295,25 +295,25 @@ describe "IO#gets" do end it "overwrites the default external encoding with the IO object's own external encoding" do - Encoding.default_external = Encoding::ASCII_8BIT + Encoding.default_external = Encoding::BINARY Encoding.default_internal = Encoding::UTF_8 @io = new_io @name, 'r' @io.set_encoding Encoding::IBM866 @io.gets.encoding.should == Encoding::UTF_8 end - it "ignores the internal encoding if the default external encoding is ASCII-8BIT" do - Encoding.default_external = Encoding::ASCII_8BIT + it "ignores the internal encoding if the default external encoding is BINARY" do + Encoding.default_external = Encoding::BINARY Encoding.default_internal = Encoding::UTF_8 @io = new_io @name, 'r' - @io.gets.encoding.should == Encoding::ASCII_8BIT + @io.gets.encoding.should == Encoding::BINARY end - it "transcodes to internal encoding if the IO object's external encoding is ASCII-8BIT" do - Encoding.default_external = Encoding::ASCII_8BIT + it "transcodes to internal encoding if the IO object's external encoding is BINARY" do + Encoding.default_external = Encoding::BINARY Encoding.default_internal = Encoding::UTF_8 @io = new_io @name, 'r' - @io.set_encoding Encoding::ASCII_8BIT, Encoding::UTF_8 + @io.set_encoding Encoding::BINARY, Encoding::UTF_8 @io.gets.encoding.should == Encoding::UTF_8 end end diff --git a/spec/ruby/core/io/internal_encoding_spec.rb b/spec/ruby/core/io/internal_encoding_spec.rb index 772cdeeaaf..10ebf28707 100644 --- a/spec/ruby/core/io/internal_encoding_spec.rb +++ b/spec/ruby/core/io/internal_encoding_spec.rb @@ -82,14 +82,14 @@ describe :io_internal_encoding, shared: true do @io.internal_encoding.should equal(Encoding::IBM437) end - it "returns nil when Encoding.default_external is ASCII-8BIT and the internal encoding is not set" do - Encoding.default_external = Encoding::ASCII_8BIT + it "returns nil when Encoding.default_external is BINARY and the internal encoding is not set" do + Encoding.default_external = Encoding::BINARY @io = new_io @name, @object @io.internal_encoding.should be_nil end - it "returns nil when the external encoding is ASCII-8BIT and the internal encoding is not set" do - @io = new_io @name, "#{@object}:ascii-8bit" + it "returns nil when the external encoding is BINARY and the internal encoding is not set" do + @io = new_io @name, "#{@object}:binary" @io.internal_encoding.should be_nil end end diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb index ccb341a1f9..e005e14fdf 100644 --- a/spec/ruby/core/io/read_spec.rb +++ b/spec/ruby/core/io/read_spec.rb @@ -380,16 +380,16 @@ describe "IO#read in binary mode" do result = File.open(@name, "rb") { |f| f.read }.chomp - result.encoding.should == Encoding::ASCII_8BIT + result.encoding.should == Encoding::BINARY xE2 = [226].pack('C*') - result.should == ("abc" + xE2 + "def").force_encoding(Encoding::ASCII_8BIT) + result.should == ("abc" + xE2 + "def").force_encoding(Encoding::BINARY) end it "does not transcode file contents when an internal encoding is specified" do result = File.open(@name, "r:binary:utf-8") { |f| f.read }.chomp - result.encoding.should == Encoding::ASCII_8BIT + result.encoding.should == Encoding::BINARY xE2 = [226].pack('C*') - result.should == ("abc" + xE2 + "def").force_encoding(Encoding::ASCII_8BIT) + result.should == ("abc" + xE2 + "def").force_encoding(Encoding::BINARY) end end @@ -420,37 +420,37 @@ describe "IO.read with BOM" do it "reads a file without a bom" do name = fixture __FILE__, "no_bom_UTF-8.txt" result = File.read(name, mode: "rb:BOM|utf-8") - result.force_encoding("ascii-8bit").should == "UTF-8\n" + result.force_encoding("binary").should == "UTF-8\n" end it "reads a file with a utf-8 bom" do name = fixture __FILE__, "bom_UTF-8.txt" result = File.read(name, mode: "rb:BOM|utf-16le") - result.force_encoding("ascii-8bit").should == "UTF-8\n" + result.force_encoding("binary").should == "UTF-8\n" end it "reads a file with a utf-16le bom" do name = fixture __FILE__, "bom_UTF-16LE.txt" result = File.read(name, mode: "rb:BOM|utf-8") - result.force_encoding("ascii-8bit").should == "U\x00T\x00F\x00-\x001\x006\x00L\x00E\x00\n\x00" + result.force_encoding("binary").should == "U\x00T\x00F\x00-\x001\x006\x00L\x00E\x00\n\x00" end it "reads a file with a utf-16be bom" do name = fixture __FILE__, "bom_UTF-16BE.txt" result = File.read(name, mode: "rb:BOM|utf-8") - result.force_encoding("ascii-8bit").should == "\x00U\x00T\x00F\x00-\x001\x006\x00B\x00E\x00\n" + result.force_encoding("binary").should == "\x00U\x00T\x00F\x00-\x001\x006\x00B\x00E\x00\n" end it "reads a file with a utf-32le bom" do name = fixture __FILE__, "bom_UTF-32LE.txt" result = File.read(name, mode: "rb:BOM|utf-8") - result.force_encoding("ascii-8bit").should == "U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00L\x00\x00\x00E\x00\x00\x00\n\x00\x00\x00" + result.force_encoding("binary").should == "U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00L\x00\x00\x00E\x00\x00\x00\n\x00\x00\x00" end it "reads a file with a utf-32be bom" do name = fixture __FILE__, "bom_UTF-32BE.txt" result = File.read(name, mode: "rb:BOM|utf-8") - result.force_encoding("ascii-8bit").should == "\x00\x00\x00U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00B\x00\x00\x00E\x00\x00\x00\n" + result.force_encoding("binary").should == "\x00\x00\x00U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00B\x00\x00\x00E\x00\x00\x00\n" end end @@ -480,11 +480,11 @@ end describe :io_read_size_internal_encoding, shared: true do it "reads bytes when passed a size" do - @io.read(2).should == [164, 162].pack('C*').force_encoding(Encoding::ASCII_8BIT) + @io.read(2).should == [164, 162].pack('C*').force_encoding(Encoding::BINARY) end - it "returns a String in ASCII-8BIT when passed a size" do - @io.read(4).encoding.should equal(Encoding::ASCII_8BIT) + it "returns a String in BINARY when passed a size" do + @io.read(4).encoding.should equal(Encoding::BINARY) end it "does not change the buffer's encoding when passed a limit" do diff --git a/spec/ruby/core/io/readbyte_spec.rb b/spec/ruby/core/io/readbyte_spec.rb index f7653bf3bb..eb25975f58 100644 --- a/spec/ruby/core/io/readbyte_spec.rb +++ b/spec/ruby/core/io/readbyte_spec.rb @@ -21,6 +21,4 @@ describe "IO#readbyte" do @io.readbyte end.should raise_error EOFError end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/io/readlines_spec.rb b/spec/ruby/core/io/readlines_spec.rb index 9e145f12f4..5a7e9b5aa8 100644 --- a/spec/ruby/core/io/readlines_spec.rb +++ b/spec/ruby/core/io/readlines_spec.rb @@ -201,10 +201,10 @@ describe "IO.readlines" do lines.all? { |s| s.encoding == Encoding::UTF_16 }.should be_true end - it "ignores the default internal encoding if the external encoding is ASCII-8BIT" do - Encoding.default_external = Encoding::ASCII_8BIT + it "ignores the default internal encoding if the external encoding is BINARY" do + Encoding.default_external = Encoding::BINARY Encoding.default_internal = Encoding::UTF_8 lines = IO.readlines(@name) - lines.all? { |s| s.encoding == Encoding::ASCII_8BIT }.should be_true + lines.all? { |s| s.encoding == Encoding::BINARY }.should be_true end end diff --git a/spec/ruby/core/io/readpartial_spec.rb b/spec/ruby/core/io/readpartial_spec.rb index 53160ca337..1ab01dcf49 100644 --- a/spec/ruby/core/io/readpartial_spec.rb +++ b/spec/ruby/core/io/readpartial_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../spec_helper' require_relative 'fixtures/classes' diff --git a/spec/ruby/core/io/set_encoding_spec.rb b/spec/ruby/core/io/set_encoding_spec.rb index a9d783325c..5aec6a96c3 100644 --- a/spec/ruby/core/io/set_encoding_spec.rb +++ b/spec/ruby/core/io/set_encoding_spec.rb @@ -87,7 +87,7 @@ describe "IO#set_encoding when passed nil, nil" do describe "with 'rb' mode" do it "returns Encoding.default_external" do @io = new_io @name, "rb" - @io.external_encoding.should equal(Encoding::ASCII_8BIT) + @io.external_encoding.should equal(Encoding::BINARY) @io.set_encoding nil, nil @io.external_encoding.should equal(Encoding.default_external) diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb index ea22f40090..f6069a4cdc 100644 --- a/spec/ruby/core/io/shared/new.rb +++ b/spec/ruby/core/io/shared/new.rb @@ -168,13 +168,13 @@ describe :io_new, shared: true do it "sets external encoding to binary with binmode in mode string" do @io = IO.send(@method, @fd, 'wb') - @io.external_encoding.to_s.should == 'ASCII-8BIT' + @io.external_encoding.should == Encoding::BINARY end # #5917 it "sets external encoding to binary with :binmode option" do @io = IO.send(@method, @fd, 'w', {binmode: true}) - @io.external_encoding.to_s.should == 'ASCII-8BIT' + @io.external_encoding.should == Encoding::BINARY end it "does not use binary encoding when mode encoding is specified" do diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb index 5fb3941505..5fb5cc7013 100644 --- a/spec/ruby/core/io/write_spec.rb +++ b/spec/ruby/core/io/write_spec.rb @@ -70,7 +70,7 @@ describe "IO#write on a file" do ë = ([235].pack('U')).encode('ISO-8859-1') ö = ([246].pack('U')).encode('ISO-8859-1') res = "H#{ë}ll#{ö}" - File.binread(@filename).should == res.force_encoding(Encoding::ASCII_8BIT) + File.binread(@filename).should == res.force_encoding(Encoding::BINARY) end end @@ -94,7 +94,7 @@ describe "IO.write" do IO.write(@filename, 'Hëllö'.encode('ISO-8859-1')) xEB = [235].pack('C*') xF6 = [246].pack('C*') - File.binread(@filename).should == ("H" + xEB + "ll" + xF6).force_encoding(Encoding::ASCII_8BIT) + File.binread(@filename).should == ("H" + xEB + "ll" + xF6).force_encoding(Encoding::BINARY) end platform_is_not :windows do diff --git a/spec/ruby/core/kernel/open_spec.rb b/spec/ruby/core/kernel/open_spec.rb index 5d3da871f0..3a9f5ea2d5 100644 --- a/spec/ruby/core/kernel/open_spec.rb +++ b/spec/ruby/core/kernel/open_spec.rb @@ -45,8 +45,10 @@ describe "Kernel#open" do end it "opens an io for writing" do - bytes = open("|cat", "w") { |io| io.write(".") } - bytes.should == 1 + -> do + bytes = open("|cat", "w") { |io| io.write(".") } + bytes.should == 1 + end.should output_to_fd(".") end end diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb index 8c56946874..e3acfa8dfd 100644 --- a/spec/ruby/core/kernel/proc_spec.rb +++ b/spec/ruby/core/kernel/proc_spec.rb @@ -59,6 +59,4 @@ describe "Kernel#proc" do }.should complain(/Capturing the given block using Proc.new is deprecated/) end end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/kernel/require_relative_spec.rb b/spec/ruby/core/kernel/require_relative_spec.rb index a16e7164e6..6604d30ab1 100644 --- a/spec/ruby/core/kernel/require_relative_spec.rb +++ b/spec/ruby/core/kernel/require_relative_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' require_relative '../../fixtures/code_loading' describe "Kernel#require_relative with a relative path" do - it "needs to be reviewed for spec completeness" - before :each do CodeLoadingSpecs.spec_setup @dir = "../../fixtures/code" @@ -267,8 +265,6 @@ describe "Kernel#require_relative with a relative path" do end describe "Kernel#require_relative with an absolute path" do - it "needs to be reviewed for spec completeness" - before :each do CodeLoadingSpecs.spec_setup @dir = File.expand_path "../../fixtures/code", File.dirname(__FILE__) diff --git a/spec/ruby/core/kernel/select_spec.rb b/spec/ruby/core/kernel/select_spec.rb index 2661bbfac7..e0d82f3079 100644 --- a/spec/ruby/core/kernel/select_spec.rb +++ b/spec/ruby/core/kernel/select_spec.rb @@ -8,8 +8,6 @@ describe "Kernel#select" do end describe "Kernel.select" do - it "needs to be reviewed for spec completeness" - it 'does not block when timeout is 0' do IO.pipe do |read, write| IO.select([read], [], [], 0).should == nil diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb index a10885346e..cb041ec25c 100644 --- a/spec/ruby/core/marshal/shared/load.rb +++ b/spec/ruby/core/marshal/shared/load.rb @@ -446,11 +446,11 @@ describe :marshal_load, shared: true do result.encoding.should equal(Encoding::UTF_16LE) end - it "loads a String as ASCII-8BIT if no encoding is specified at the end" do - str = "\xC3\xB8".force_encoding("ASCII-8BIT") + 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") result = Marshal.send(@method, data) - result.encoding.should == Encoding::ASCII_8BIT + result.encoding.should == Encoding::BINARY result.should == str end end diff --git a/spec/ruby/core/method/hash_spec.rb b/spec/ruby/core/method/hash_spec.rb index b6807ca1e2..d6c8440acc 100644 --- a/spec/ruby/core/method/hash_spec.rb +++ b/spec/ruby/core/method/hash_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "Method#hash" do - it "needs to be reviewed for spec completeness" - it "returns the same value for user methods that are eql?" do obj = MethodSpecs::Methods.new obj.method(:foo).hash.should == obj.method(:bar).hash diff --git a/spec/ruby/core/module/define_singleton_method_spec.rb b/spec/ruby/core/module/define_singleton_method_spec.rb index 38a4fc51b7..f2b8a5ada4 100644 --- a/spec/ruby/core/module/define_singleton_method_spec.rb +++ b/spec/ruby/core/module/define_singleton_method_spec.rb @@ -12,6 +12,4 @@ describe "Module#define_singleton_method" do klass.a.should == 42 klass.b(10).should == 20 end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb index 46b21dd083..de021692e2 100644 --- a/spec/ruby/core/proc/shared/to_s.rb +++ b/spec/ruby/core/proc/shared/to_s.rb @@ -4,8 +4,8 @@ describe :proc_to_s, shared: true do Proc.new { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:4)?>$/ end - it "has an ASCII-8BIT encoding" do - Proc.new { "hello" }.send(@method).encoding.should == Encoding::ASCII_8BIT + it "has an BINARY encoding" do + Proc.new { "hello" }.send(@method).encoding.should == Encoding::BINARY end end @@ -14,8 +14,8 @@ describe :proc_to_s, shared: true do lambda { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:10)? \(lambda\)>$/ end - it "has an ASCII-8BIT encoding" do - lambda { "hello" }.send(@method).encoding.should == Encoding::ASCII_8BIT + it "has an BINARY encoding" do + lambda { "hello" }.send(@method).encoding.should == Encoding::BINARY end end @@ -24,8 +24,8 @@ describe :proc_to_s, shared: true do proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:16)?>$/ end - it "has an ASCII-8BIT encoding" do - proc { "hello" }.send(@method).encoding.should == Encoding::ASCII_8BIT + it "has an BINARY encoding" do + proc { "hello" }.send(@method).encoding.should == Encoding::BINARY end end @@ -35,9 +35,9 @@ describe :proc_to_s, shared: true do method("hello").to_proc.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:22)? \(lambda\)>$/ end - it "has an ASCII-8BIT encoding" do + it "has an BINARY encoding" do def hello; end - method("hello").to_proc.send(@method).encoding.should == Encoding::ASCII_8BIT + method("hello").to_proc.send(@method).encoding.should == Encoding::BINARY end end @@ -47,9 +47,9 @@ describe :proc_to_s, shared: true do proc.send(@method).should =~ /^#<Proc:0x\h+\(&:foobar\)>$/ end - it "has an ASCII-8BIT encoding" do + it "has an BINARY encoding" do proc = :foobar.to_proc - proc.send(@method).encoding.should == Encoding::ASCII_8BIT + proc.send(@method).encoding.should == Encoding::BINARY end end end diff --git a/spec/ruby/core/process/fixtures/clocks.rb b/spec/ruby/core/process/fixtures/clocks.rb index 7acc8fbd58..2b4916661c 100644 --- a/spec/ruby/core/process/fixtures/clocks.rb +++ b/spec/ruby/core/process/fixtures/clocks.rb @@ -11,7 +11,7 @@ module ProcessSpecs clocks -= [:CLOCK_BOOTTIME_ALARM, :CLOCK_REALTIME_ALARM] end - clocks.map { |c| + clocks.sort.map { |c| [c, Process.const_get(c)] } end diff --git a/spec/ruby/core/process/getrlimit_spec.rb b/spec/ruby/core/process/getrlimit_spec.rb index 0258bb3d80..d866a48186 100644 --- a/spec/ruby/core/process/getrlimit_spec.rb +++ b/spec/ruby/core/process/getrlimit_spec.rb @@ -41,9 +41,9 @@ platform_is_not :windows do end context "when passed a Symbol" do - Process.constants.grep(/\ARLIMIT_/) do |fullname| - short = $' - it "coerces :#{short} into #{fullname}" do + it "coerces the short name into the full RLIMIT_ prefixed name" do + Process.constants.grep(/\ARLIMIT_/) do |fullname| + short = fullname[/\ARLIMIT_(.+)/, 1] Process.getrlimit(short.to_sym).should == Process.getrlimit(Process.const_get(fullname)) end end @@ -54,9 +54,9 @@ platform_is_not :windows do end context "when passed a String" do - Process.constants.grep(/\ARLIMIT_/) do |fullname| - short = $' - it "coerces '#{short}' into #{fullname}" do + it "coerces the short name into the full RLIMIT_ prefixed name" do + Process.constants.grep(/\ARLIMIT_/) do |fullname| + short = fullname[/\ARLIMIT_(.+)/, 1] Process.getrlimit(short).should == Process.getrlimit(Process.const_get(fullname)) end end diff --git a/spec/ruby/core/process/waitpid_spec.rb b/spec/ruby/core/process/waitpid_spec.rb index fdd6be1287..f7cf1a45a8 100644 --- a/spec/ruby/core/process/waitpid_spec.rb +++ b/spec/ruby/core/process/waitpid_spec.rb @@ -1,8 +1,6 @@ require_relative '../../spec_helper' describe "Process.waitpid" do - it "needs to be reviewed for spec completeness" - it "returns nil when the process has not yet completed and WNOHANG is specified" do pid = spawn("sleep 5") begin diff --git a/spec/ruby/core/random/shared/bytes.rb b/spec/ruby/core/random/shared/bytes.rb index 3485d0f221..54b6b0e4df 100644 --- a/spec/ruby/core/random/shared/bytes.rb +++ b/spec/ruby/core/random/shared/bytes.rb @@ -7,8 +7,8 @@ describe :random_bytes, shared: true do @object.bytes(15).length.should == 15 end - it "returns an ASCII-8BIT String" do - @object.bytes(15).encoding.should == Encoding::ASCII_8BIT + it "returns an BINARY String" do + @object.bytes(15).encoding.should == Encoding::BINARY end it "returns a random binary String" do diff --git a/spec/ruby/core/random/shared/urandom.rb b/spec/ruby/core/random/shared/urandom.rb index f50d30c9de..e5ffcffca6 100644 --- a/spec/ruby/core/random/shared/urandom.rb +++ b/spec/ruby/core/random/shared/urandom.rb @@ -13,8 +13,8 @@ describe :random_urandom, shared: true do }.should raise_error(ArgumentError) end - it "returns an ASCII-8BIT String" do - Random.send(@method, 15).encoding.should == Encoding::ASCII_8BIT + it "returns an BINARY String" do + Random.send(@method, 15).encoding.should == Encoding::BINARY end it "returns a random binary String" do diff --git a/spec/ruby/core/range/cover_spec.rb b/spec/ruby/core/range/cover_spec.rb index 47b75742b2..29c0e0bfa8 100644 --- a/spec/ruby/core/range/cover_spec.rb +++ b/spec/ruby/core/range/cover_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../spec_helper' require_relative 'shared/cover_and_include' require_relative 'shared/cover' diff --git a/spec/ruby/core/range/include_spec.rb b/spec/ruby/core/range/include_spec.rb index e1c5954917..b2c7a54545 100644 --- a/spec/ruby/core/range/include_spec.rb +++ b/spec/ruby/core/range/include_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../spec_helper' require_relative 'shared/cover_and_include' require_relative 'shared/include' diff --git a/spec/ruby/core/range/member_spec.rb b/spec/ruby/core/range/member_spec.rb index ca9deabd35..ab61f92951 100644 --- a/spec/ruby/core/range/member_spec.rb +++ b/spec/ruby/core/range/member_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../spec_helper' require_relative 'shared/cover_and_include' require_relative 'shared/include' diff --git a/spec/ruby/core/range/shared/cover.rb b/spec/ruby/core/range/shared/cover.rb index 7d2367d712..33d416fef5 100644 --- a/spec/ruby/core/range/shared/cover.rb +++ b/spec/ruby/core/range/shared/cover.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' diff --git a/spec/ruby/core/range/shared/cover_and_include.rb b/spec/ruby/core/range/shared/cover_and_include.rb index d3c0700f1a..bed2c77038 100644 --- a/spec/ruby/core/range/shared/cover_and_include.rb +++ b/spec/ruby/core/range/shared/cover_and_include.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' describe :range_cover_and_include, shared: true do diff --git a/spec/ruby/core/range/shared/include.rb b/spec/ruby/core/range/shared/include.rb index b0fc5c2915..c6c5c2becf 100644 --- a/spec/ruby/core/range/shared/include.rb +++ b/spec/ruby/core/range/shared/include.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' diff --git a/spec/ruby/core/regexp/encoding_spec.rb b/spec/ruby/core/regexp/encoding_spec.rb index 1d5bd8890c..6ce6f8b3ca 100644 --- a/spec/ruby/core/regexp/encoding_spec.rb +++ b/spec/ruby/core/regexp/encoding_spec.rb @@ -14,8 +14,8 @@ describe "Regexp#encoding" do /ASCII/n.encoding.should == Encoding::US_ASCII end - it "returns ASCII-8BIT if the 'n' modifier is supplied and non-US-ASCII characters are present" do - /\xc2\xa1/n.encoding.should == Encoding::ASCII_8BIT + it "returns BINARY if the 'n' modifier is supplied and non-US-ASCII characters are present" do + /\xc2\xa1/n.encoding.should == Encoding::BINARY end it "defaults to UTF-8 if \\u escapes appear" do diff --git a/spec/ruby/core/regexp/shared/new.rb b/spec/ruby/core/regexp/shared/new.rb index e8b80ad7c7..ab833ec236 100644 --- a/spec/ruby/core/regexp/shared/new.rb +++ b/spec/ruby/core/regexp/shared/new.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :regexp_new, shared: true do it "requires one argument and creates a new regular expression object" do @@ -135,10 +135,10 @@ describe :regexp_new_string, shared: true do a = "(?:[\x8E\xA1-\xFE])" str = "\A(?:#{a}|x*)\z" - Regexp.send(@method, str, nil, 'N').encoding.should == Encoding::ASCII_8BIT - Regexp.send(@method, str, nil, 'n').encoding.should == Encoding::ASCII_8BIT - Regexp.send(@method, str, nil, 'none').encoding.should == Encoding::ASCII_8BIT - Regexp.send(@method, str, nil, 'NONE').encoding.should == Encoding::ASCII_8BIT + Regexp.send(@method, str, nil, 'N').encoding.should == Encoding::BINARY + Regexp.send(@method, str, nil, 'n').encoding.should == Encoding::BINARY + Regexp.send(@method, str, nil, 'none').encoding.should == Encoding::BINARY + Regexp.send(@method, str, nil, 'NONE').encoding.should == Encoding::BINARY end describe "with escaped characters" do @@ -499,7 +499,7 @@ describe :regexp_new_regexp, shared: true do end it "sets the encoding to source String's encoding if the Regexp literal has the 'n' option and the source String is not ASCII only" do - Regexp.send(@method, Regexp.new("\\xff", nil, 'n')).encoding.should == Encoding::ASCII_8BIT + Regexp.send(@method, Regexp.new("\\xff", nil, 'n')).encoding.should == Encoding::BINARY end end end diff --git a/spec/ruby/core/regexp/shared/quote.rb b/spec/ruby/core/regexp/shared/quote.rb index 016cb0b164..a55adb5bf2 100644 --- a/spec/ruby/core/regexp/shared/quote.rb +++ b/spec/ruby/core/regexp/shared/quote.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :regexp_quote, shared: true do it "escapes any characters with special meaning in a regular expression" do @@ -23,9 +23,9 @@ describe :regexp_quote, shared: true do Regexp.send(@method, str).encoding.should == Encoding::UTF_8 end - it "sets the encoding of the result to ASCII-8BIT if any non-US-ASCII characters are present in an input String with invalid encoding" do + 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.valid_encoding?.should be_false - Regexp.send(@method, "\xff").encoding.should == Encoding::ASCII_8BIT + Regexp.send(@method, "\xff").encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/signal/fixtures/trap_all.rb b/spec/ruby/core/signal/fixtures/trap_all.rb index b2e85df247..afa00b498d 100644 --- a/spec/ruby/core/signal/fixtures/trap_all.rb +++ b/spec/ruby/core/signal/fixtures/trap_all.rb @@ -1,8 +1,15 @@ -reserved_signals = ARGV +cannot_be_trapped = %w[KILL STOP] # See man 2 signal -(Signal.list.keys - reserved_signals).each do |signal| - Signal.trap(signal, -> {}) - Signal.trap(signal, "DEFAULT") +(Signal.list.keys - cannot_be_trapped).each do |signal| + begin + Signal.trap(signal, -> {}) + rescue ArgumentError => e + unless /can't trap reserved signal|Signal already used by VM or OS/ =~ e.message + raise e + end + else + Signal.trap(signal, "DEFAULT") + end end puts "OK" diff --git a/spec/ruby/core/signal/trap_spec.rb b/spec/ruby/core/signal/trap_spec.rb index a3298c71e1..91ce1f1348 100644 --- a/spec/ruby/core/signal/trap_spec.rb +++ b/spec/ruby/core/signal/trap_spec.rb @@ -4,8 +4,7 @@ platform_is_not :windows do describe "Signal.trap" do before :each do ScratchPad.clear - - @proc = lambda { ScratchPad.record :proc_trap } + @proc = -> {} @saved_trap = Signal.trap(:HUP, @proc) end @@ -48,49 +47,34 @@ platform_is_not :windows do ScratchPad.recorded.should be_true end + it "registers an handler doing nothing with :IGNORE" do + Signal.trap :HUP, :IGNORE + Process.kill(:HUP, Process.pid).should == 1 + end + it "ignores the signal when passed nil" do Signal.trap :HUP, nil Signal.trap(:HUP, @saved_trap).should be_nil end - it "accepts 'DEFAULT' as a symbol in place of a proc" do + it "accepts :DEFAULT in place of a proc" do Signal.trap :HUP, :DEFAULT - Signal.trap(:HUP, :DEFAULT).should == "DEFAULT" + Signal.trap(:HUP, @saved_trap).should == "DEFAULT" end - it "accepts 'SIG_DFL' as a symbol in place of a proc" do + it "accepts :SIG_DFL in place of a proc" do Signal.trap :HUP, :SIG_DFL - Signal.trap(:HUP, :SIG_DFL).should == "DEFAULT" + Signal.trap(:HUP, @saved_trap).should == "DEFAULT" end - it "accepts 'SIG_IGN' as a symbol in place of a proc" do + it "accepts :SIG_IGN in place of a proc" do Signal.trap :HUP, :SIG_IGN - Signal.trap(:HUP, :SIG_IGN).should == "IGNORE" + Signal.trap(:HUP, @saved_trap).should == "IGNORE" end - it "accepts 'IGNORE' as a symbol in place of a proc" do + it "accepts :IGNORE in place of a proc" do Signal.trap :HUP, :IGNORE - Signal.trap(:HUP, :IGNORE).should == "IGNORE" - end - - it "accepts long names as Strings" do - Signal.trap "SIGHUP", @proc - Signal.trap("SIGHUP", @saved_trap).should equal(@proc) - end - - it "accepts short names as Strings" do - Signal.trap "HUP", @proc - Signal.trap("HUP", @saved_trap).should equal(@proc) - end - - it "accepts long names as Symbols" do - Signal.trap :SIGHUP, @proc - Signal.trap(:SIGHUP, @saved_trap).should equal(@proc) - end - - it "accepts short names as Symbols" do - Signal.trap :HUP, @proc - Signal.trap(:HUP, @saved_trap).should equal(@proc) + Signal.trap(:HUP, @saved_trap).should == "IGNORE" end it "accepts 'SIG_DFL' in place of a proc" do @@ -105,34 +89,38 @@ platform_is_not :windows do it "accepts 'SIG_IGN' in place of a proc" do Signal.trap :HUP, "SIG_IGN" - Signal.trap(:HUP, "SIG_IGN").should == "IGNORE" + Signal.trap(:HUP, @saved_trap).should == "IGNORE" end it "accepts 'IGNORE' in place of a proc" do Signal.trap :HUP, "IGNORE" - Signal.trap(:HUP, "IGNORE").should == "IGNORE" + Signal.trap(:HUP, @saved_trap).should == "IGNORE" end - end - describe "Signal.trap" do - cannot_be_trapped = %w[KILL STOP] # See man 2 signal - reserved_signals = %w[VTALRM] + it "accepts long names as Strings" do + Signal.trap "SIGHUP", @proc + Signal.trap("SIGHUP", @saved_trap).should equal(@proc) + end - if PlatformGuard.implementation?(:ruby) - reserved_signals += %w[SEGV ILL FPE BUS] + it "accepts short names as Strings" do + Signal.trap "HUP", @proc + Signal.trap("HUP", @saved_trap).should equal(@proc) end - if PlatformGuard.implementation?(:truffleruby) - if !TruffleRuby.native? - reserved_signals += %w[SEGV ILL FPE USR1 QUIT] - end + it "accepts long names as Symbols" do + Signal.trap :SIGHUP, @proc + Signal.trap(:SIGHUP, @saved_trap).should equal(@proc) end - if PlatformGuard.implementation?(:jruby) - reserved_signals += %w[SEGV ILL FPE BUS USR1 QUIT] + it "accepts short names as Symbols" do + Signal.trap :HUP, @proc + Signal.trap(:HUP, @saved_trap).should equal(@proc) end + end - cannot_be_trapped.each do |signal| + describe "Signal.trap" do + # See man 2 signal + %w[KILL STOP].each do |signal| it "raises ArgumentError or Errno::EINVAL for SIG#{signal}" do -> { trap(signal, -> {}) @@ -143,17 +131,8 @@ platform_is_not :windows do end end - reserved_signals.each do |signal| - it "raises ArgumentError for reserved signal: SIG#{signal}" do - -> { - trap(signal, -> {}) - }.should raise_error(ArgumentError, /can't trap reserved signal|Signal already used by VM or OS/) - end - end - - it "allows to register a handler for all known signals, except reserved signals" do - excluded = cannot_be_trapped + reserved_signals - out = ruby_exe(fixture(__FILE__, "trap_all.rb"), args: [*excluded, "2>&1"]) + it "allows to register a handler for all known signals, except reserved signals for which it raises ArgumentError" do + out = ruby_exe(fixture(__FILE__, "trap_all.rb"), args: "2>&1") out.should == "OK\n" $?.exitstatus.should == 0 end diff --git a/spec/ruby/core/string/ascii_only_spec.rb b/spec/ruby/core/string/ascii_only_spec.rb index e9f2dc1a36..c7e02fd874 100644 --- a/spec/ruby/core/string/ascii_only_spec.rb +++ b/spec/ruby/core/string/ascii_only_spec.rb @@ -24,9 +24,9 @@ describe "String#ascii_only?" do end describe "with non-ASCII only characters" do - it "returns false if the encoding is ASCII-8BIT" do + it "returns false if the encoding is BINARY" do chr = 128.chr - chr.encoding.should == Encoding::ASCII_8BIT + chr.encoding.should == Encoding::BINARY chr.ascii_only?.should be_false end diff --git a/spec/ruby/core/string/b_spec.rb b/spec/ruby/core/string/b_spec.rb index 638971f9ce..8555dd8dc7 100644 --- a/spec/ruby/core/string/b_spec.rb +++ b/spec/ruby/core/string/b_spec.rb @@ -2,9 +2,9 @@ require_relative '../../spec_helper' describe "String#b" do - it "returns an ASCII-8BIT encoded string" do - "Hello".b.should == "Hello".force_encoding(Encoding::ASCII_8BIT) - "こんちには".b.should == "こんちには".force_encoding(Encoding::ASCII_8BIT) + it "returns an BINARY encoded string" do + "Hello".b.should == "Hello".force_encoding(Encoding::BINARY) + "こんちには".b.should == "こんちには".force_encoding(Encoding::BINARY) end it "returns new string without modifying self" do diff --git a/spec/ruby/core/string/bytesize_spec.rb b/spec/ruby/core/string/bytesize_spec.rb index b63d718c6c..b8b07cfbec 100644 --- a/spec/ruby/core/string/bytesize_spec.rb +++ b/spec/ruby/core/string/bytesize_spec.rb @@ -3,8 +3,6 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "#String#bytesize" do - it "needs to be reviewed for spec completeness" - it "returns the length of self in bytes" do "hello".bytesize.should == 5 " ".bytesize.should == 1 diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb index f85256d36e..1fdf72ab0f 100644 --- a/spec/ruby/core/string/element_set_spec.rb +++ b/spec/ruby/core/string/element_set_spec.rb @@ -134,9 +134,9 @@ describe "String#[]= with Fixnum index" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[0] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do @@ -190,9 +190,9 @@ describe "String#[]= with String index" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[" "] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do @@ -303,9 +303,9 @@ describe "String#[]= with a Regexp index" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[/ /] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do @@ -424,9 +424,9 @@ describe "String#[]= with a Range index" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[0..1] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do @@ -589,9 +589,9 @@ describe "String#[]= with Fixnum index, count" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[0, 1] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb index 0be26011ea..67a25aff04 100644 --- a/spec/ruby/core/string/encode_spec.rb +++ b/spec/ruby/core/string/encode_spec.rb @@ -30,7 +30,7 @@ describe "String#encode" do it "encodes an ascii substring of a binary string to UTF-8" do x82 = [0x82].pack('C') - str = "#{x82}foo".force_encoding("ascii-8bit")[1..-1].encode("utf-8") + str = "#{x82}foo".force_encoding("binary")[1..-1].encode("utf-8") str.should == "foo".force_encoding("utf-8") str.encoding.should equal(Encoding::UTF_8) end @@ -60,12 +60,18 @@ describe "String#encode" do "\rfoo".encode(universal_newline: true).should == "\nfoo" end + + it "replaces invalid encoding" do + encoded = "ち\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace, replace: "?") + encoded.should == "\u3061??".encode("UTF-16LE") + encoded.encode("UTF-8").should == "ち??" + end end describe "when passed to, from" do it "returns a copy in the destination encoding when both encodings are the same" do str = "あ" - str.force_encoding("ascii-8bit") + str.force_encoding("binary") encoded = str.encode("utf-8", "utf-8") encoded.should_not equal(str) diff --git a/spec/ruby/core/string/encoding_spec.rb b/spec/ruby/core/string/encoding_spec.rb index 6182e8eb50..4d17a39f29 100644 --- a/spec/ruby/core/string/encoding_spec.rb +++ b/spec/ruby/core/string/encoding_spec.rb @@ -125,13 +125,13 @@ describe "String#encoding for Strings with \\x escapes" do s.encoding.should == Encoding::US_ASCII end - it "returns ASCII-8BIT when an escape creates a byte with the 8th bit set if the source encoding is US-ASCII" do + it "returns BINARY when an escape creates a byte with the 8th bit set if the source encoding is US-ASCII" do __ENCODING__.should == Encoding::US_ASCII str = " " str.encoding.should == Encoding::US_ASCII str += [0xDF].pack('C') str.ascii_only?.should be_false - str.encoding.should == Encoding::ASCII_8BIT + str.encoding.should == Encoding::BINARY end # TODO: Deal with case when the byte in question isn't valid in the source @@ -155,7 +155,7 @@ describe "String#encoding for Strings with \\x escapes" do default_external = Encoding.default_external Encoding.default_external = Encoding::SHIFT_JIS "\x50".encoding.should == Encoding::US_ASCII - [0xD4].pack('C').encoding.should == Encoding::ASCII_8BIT + [0xD4].pack('C').encoding.should == Encoding::BINARY Encoding.default_external = default_external end @@ -166,7 +166,7 @@ describe "String#encoding for Strings with \\x escapes" do Encoding.default_external = Encoding::SHIFT_JIS x50 = "\x50" x50.encoding.should == Encoding::US_ASCII - [0xD4].pack('C').encoding.should == Encoding::ASCII_8BIT + [0xD4].pack('C').encoding.should == Encoding::BINARY Encoding.default_external = default_external Encoding.default_internal = default_internal end diff --git a/spec/ruby/core/string/force_encoding_spec.rb b/spec/ruby/core/string/force_encoding_spec.rb index 83641a37b4..7a5503de56 100644 --- a/spec/ruby/core/string/force_encoding_spec.rb +++ b/spec/ruby/core/string/force_encoding_spec.rb @@ -19,9 +19,9 @@ describe "String#force_encoding" do "abc".force_encoding("internal").encoding.should == Encoding::US_ASCII end - it "defaults to ASCII-8BIT if special encoding name is not set" do + it "defaults to BINARY if special encoding name is not set" do Encoding.default_internal = nil - "abc".force_encoding("internal").encoding.should == Encoding::ASCII_8BIT + "abc".force_encoding("internal").encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb index a94010edea..29b65c72a7 100644 --- a/spec/ruby/core/string/gsub_spec.rb +++ b/spec/ruby/core/string/gsub_spec.rb @@ -528,8 +528,8 @@ describe "String#gsub with pattern and block" do s = "hello" s2 = "#{195.chr}#{192.chr}#{195.chr}" - s.gsub(/l/) { |bar| 195.chr }.encoding.should == Encoding::ASCII_8BIT - s2.gsub("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::ASCII_8BIT + s.gsub(/l/) { |bar| 195.chr }.encoding.should == Encoding::BINARY + s2.gsub("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::BINARY end it "raises an Encoding::CompatibilityError if the encodings are not compatible" do @@ -653,8 +653,8 @@ describe "String#gsub! with pattern and block" do s = "hello" s2 = "#{195.chr}#{192.chr}#{195.chr}" - s.gsub!(/l/) { |bar| 195.chr }.encoding.should == Encoding::ASCII_8BIT - s2.gsub!("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::ASCII_8BIT + s.gsub!(/l/) { |bar| 195.chr }.encoding.should == Encoding::BINARY + s2.gsub!("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::BINARY end it "raises an Encoding::CompatibilityError if the encodings are not compatible" do diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb index 72738ece24..fc4972b9d7 100644 --- a/spec/ruby/core/string/modulo_spec.rb +++ b/spec/ruby/core/string/modulo_spec.rb @@ -21,13 +21,13 @@ describe "String#%" do describe "output's encoding" do it "is the same as the format string if passed value is encoding-compatible" do - [Encoding::ASCII_8BIT, Encoding::US_ASCII, Encoding::UTF_8, Encoding::SHIFT_JIS].each do |encoding| + [Encoding::BINARY, Encoding::US_ASCII, Encoding::UTF_8, Encoding::SHIFT_JIS].each do |encoding| ("hello %s!".encode(encoding) % "world").encoding.should == encoding end end it "negotiates a compatible encoding if necessary" do - ("hello %s" % 195.chr).encoding.should == Encoding::ASCII_8BIT + ("hello %s" % 195.chr).encoding.should == Encoding::BINARY ("hello %s".encode("shift_jis") % "wörld").encoding.should == Encoding::UTF_8 end diff --git a/spec/ruby/core/string/shared/chars.rb b/spec/ruby/core/string/shared/chars.rb index d37bc50675..c8716521bd 100644 --- a/spec/ruby/core/string/shared/chars.rb +++ b/spec/ruby/core/string/shared/chars.rb @@ -22,7 +22,7 @@ describe :string_chars, shared: true do it "returns characters in the same encoding as self" do "&%".force_encoding('Shift_JIS').send(@method).to_a.all? {|c| c.encoding.name.should == 'Shift_JIS'} - "&%".encode('ASCII-8BIT').send(@method).to_a.all? {|c| c.encoding.name.should == 'ASCII-8BIT'} + "&%".encode('BINARY').send(@method).to_a.all? {|c| c.encoding.should == Encoding::BINARY } end it "works with multibyte characters" do diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb index bc38ba9a8b..0a87410f2f 100644 --- a/spec/ruby/core/string/shared/concat.rb +++ b/spec/ruby/core/string/shared/concat.rb @@ -60,13 +60,13 @@ describe :string_concat, shared: true do end # #5855 - it "returns a ASCII-8BIT string if self is US-ASCII and the argument is between 128-255 (inclusive)" do + it "returns a BINARY string if self is US-ASCII and the argument is between 128-255 (inclusive)" do a = ("".encode(Encoding::US_ASCII).send(@method, 128)) - a.encoding.should == Encoding::ASCII_8BIT + a.encoding.should == Encoding::BINARY a.should == 128.chr a = ("".encode(Encoding::US_ASCII).send(@method, 255)) - a.encoding.should == Encoding::ASCII_8BIT + a.encoding.should == Encoding::BINARY a.should == 255.chr end @@ -152,9 +152,9 @@ describe :string_concat_encoding, shared: true do end end - describe "when self is ASCII-8BIT and argument is US-ASCII" do - it "uses ASCII-8BIT encoding" do - "abc".encode("ASCII-8BIT").send(@method, "123".encode("US-ASCII")).encoding.should == Encoding::ASCII_8BIT + describe "when self is BINARY and argument is US-ASCII" do + it "uses BINARY encoding" do + "abc".encode("BINARY").send(@method, "123".encode("US-ASCII")).encoding.should == Encoding::BINARY end end end diff --git a/spec/ruby/core/string/shared/encode.rb b/spec/ruby/core/string/shared/encode.rb index 71d46b1bd3..d13db1945e 100644 --- a/spec/ruby/core/string/shared/encode.rb +++ b/spec/ruby/core/string/shared/encode.rb @@ -9,18 +9,18 @@ describe :string_encode, shared: true do it "transcodes a 7-bit String despite no generic converting being available" do lambda do - Encoding::Converter.new Encoding::Emacs_Mule, Encoding::ASCII_8BIT + Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY end.should raise_error(Encoding::ConverterNotFoundError) Encoding.default_internal = Encoding::Emacs_Mule - str = "\x79".force_encoding Encoding::ASCII_8BIT + str = "\x79".force_encoding Encoding::BINARY - str.send(@method).should == "y".force_encoding(Encoding::ASCII_8BIT) + str.send(@method).should == "y".force_encoding(Encoding::BINARY) end it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do Encoding.default_internal = Encoding::Emacs_Mule - str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT + str = [0x80].pack('C').force_encoding Encoding::BINARY lambda { str.send(@method) }.should raise_error(Encoding::ConverterNotFoundError) end end @@ -52,15 +52,15 @@ describe :string_encode, shared: true do it "transcodes a 7-bit String despite no generic converting being available" do lambda do - Encoding::Converter.new Encoding::Emacs_Mule, Encoding::ASCII_8BIT + Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY end.should raise_error(Encoding::ConverterNotFoundError) - str = "\x79".force_encoding Encoding::ASCII_8BIT - str.send(@method, Encoding::Emacs_Mule).should == "y".force_encoding(Encoding::ASCII_8BIT) + str = "\x79".force_encoding Encoding::BINARY + str.send(@method, Encoding::Emacs_Mule).should == "y".force_encoding(Encoding::BINARY) end it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do - str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT + str = [0x80].pack('C').force_encoding Encoding::BINARY lambda do str.send(@method, Encoding::Emacs_Mule) end.should raise_error(Encoding::ConverterNotFoundError) @@ -95,7 +95,7 @@ describe :string_encode, shared: true do it "raises an Encoding::ConverterNotFoundError when no conversion is possible despite 'invalid: :replace, undef: :replace'" do Encoding.default_internal = Encoding::Emacs_Mule - str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT + str = [0x80].pack('C').force_encoding Encoding::BINARY lambda do str.send(@method, invalid: :replace, undef: :replace) end.should raise_error(Encoding::ConverterNotFoundError) @@ -153,7 +153,7 @@ describe :string_encode, shared: true do describe "when passed to, from, options" do it "replaces undefined characters in the destination encoding" do - str = "あ?あ".force_encoding Encoding::ASCII_8BIT + str = "あ?あ".force_encoding Encoding::BINARY result = str.send(@method, "euc-jp", "utf-8", undef: :replace) xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding('utf-8') result.should == "#{xA4xA2}?#{xA4xA2}".force_encoding("euc-jp") @@ -161,7 +161,7 @@ describe :string_encode, shared: true do it "replaces invalid characters in the destination encoding" do xFF = [0xFF].pack('C').force_encoding('utf-8') - str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT + str = "ab#{xFF}c".force_encoding Encoding::BINARY str.send(@method, "iso-8859-1", "utf-8", invalid: :replace).should == "ab?c" end @@ -170,7 +170,7 @@ describe :string_encode, shared: true do to.should_receive(:to_str).and_return("iso-8859-1") xFF = [0xFF].pack('C').force_encoding('utf-8') - str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT + str = "ab#{xFF}c".force_encoding Encoding::BINARY str.send(@method, to, "utf-8", invalid: :replace).should == "ab?c" end @@ -179,7 +179,7 @@ describe :string_encode, shared: true do from.should_receive(:to_str).and_return("utf-8") xFF = [0xFF].pack('C').force_encoding('utf-8') - str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT + str = "ab#{xFF}c".force_encoding Encoding::BINARY str.send(@method, "iso-8859-1", from, invalid: :replace).should == "ab?c" end @@ -188,7 +188,7 @@ describe :string_encode, shared: true do options.should_receive(:to_hash).and_return({ invalid: :replace }) xFF = [0xFF].pack('C').force_encoding('utf-8') - str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT + str = "ab#{xFF}c".force_encoding Encoding::BINARY str.send(@method, "iso-8859-1", "utf-8", options).should == "ab?c" end end diff --git a/spec/ruby/core/string/shared/length.rb b/spec/ruby/core/string/shared/length.rb index cea287d7a2..f387fb251c 100644 --- a/spec/ruby/core/string/shared/length.rb +++ b/spec/ruby/core/string/shared/length.rb @@ -21,6 +21,6 @@ describe :string_length, shared: true do str = 'こにちわ' str.send(@method) - str.force_encoding('ASCII-8BIT').send(@method).should == 12 + str.force_encoding('BINARY').send(@method).should == 12 end end diff --git a/spec/ruby/core/string/undump_spec.rb b/spec/ruby/core/string/undump_spec.rb index ec13308c16..315d27cad4 100644 --- a/spec/ruby/core/string/undump_spec.rb +++ b/spec/ruby/core/string/undump_spec.rb @@ -430,7 +430,7 @@ ruby_version_is '2.5' do end it "raises RuntimeError if there is malformed dump of non ASCII-compatible string" do - -> { '"".force_encoding("ASCII-8BIT"'.undump }.should raise_error(RuntimeError, /invalid dumped string/) + -> { '"".force_encoding("BINARY"'.undump }.should raise_error(RuntimeError, /invalid dumped string/) -> { '"".force_encoding("Unknown")'.undump }.should raise_error(RuntimeError, /dumped string has unknown encoding name/) -> { '"".force_encoding()'.undump }.should raise_error(RuntimeError, /invalid dumped string/) end diff --git a/spec/ruby/core/string/unpack/a_spec.rb b/spec/ruby/core/string/unpack/a_spec.rb index 3de338e2e1..2d83b4c824 100644 --- a/spec/ruby/core/string/unpack/a_spec.rb +++ b/spec/ruby/core/string/unpack/a_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -32,7 +32,7 @@ describe "String#unpack with format 'A'" do it "decodes into raw (ascii) string values" do str = "str".force_encoding('UTF-8').unpack("A*")[0] - str.encoding.name.should == 'ASCII-8BIT' + str.encoding.should == Encoding::BINARY end end @@ -60,7 +60,7 @@ describe "String#unpack with format 'a'" do it "decodes into raw (ascii) string values" do str = "".unpack("a*")[0] - str.encoding.name.should == 'ASCII-8BIT' + str.encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/string/unpack/at_spec.rb b/spec/ruby/core/string/unpack/at_spec.rb index a5f97b64f0..d8e55a1020 100644 --- a/spec/ruby/core/string/unpack/at_spec.rb +++ b/spec/ruby/core/string/unpack/at_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/b_spec.rb b/spec/ruby/core/string/unpack/b_spec.rb index a0bbc3d421..1a838d6c7c 100644 --- a/spec/ruby/core/string/unpack/b_spec.rb +++ b/spec/ruby/core/string/unpack/b_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/c_spec.rb b/spec/ruby/core/string/unpack/c_spec.rb index bdcbd87663..ed8caa4895 100644 --- a/spec/ruby/core/string/unpack/c_spec.rb +++ b/spec/ruby/core/string/unpack/c_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/comment_spec.rb b/spec/ruby/core/string/unpack/comment_spec.rb index 7e7adbf54f..e18a53df3c 100644 --- a/spec/ruby/core/string/unpack/comment_spec.rb +++ b/spec/ruby/core/string/unpack/comment_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' diff --git a/spec/ruby/core/string/unpack/h_spec.rb b/spec/ruby/core/string/unpack/h_spec.rb index 07d52149d1..f2f5dcf396 100644 --- a/spec/ruby/core/string/unpack/h_spec.rb +++ b/spec/ruby/core/string/unpack/h_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -63,6 +63,10 @@ describe "String#unpack with format 'H'" do it "ignores spaces between directives" do "\x01\x10".unpack("H H").should == ["0", "1"] end + + it "should make strings with US_ASCII encoding" do + "\x01".unpack("H")[0].encoding.should == Encoding::US_ASCII + end end describe "String#unpack with format 'h'" do @@ -124,4 +128,8 @@ describe "String#unpack with format 'h'" do it "ignores spaces between directives" do "\x01\x10".unpack("h h").should == ["1", "0"] end + + it "should make strings with US_ASCII encoding" do + "\x01".unpack("h")[0].encoding.should == Encoding::US_ASCII + end end diff --git a/spec/ruby/core/string/unpack/m_spec.rb b/spec/ruby/core/string/unpack/m_spec.rb index d714f6fbcb..96841f24cb 100644 --- a/spec/ruby/core/string/unpack/m_spec.rb +++ b/spec/ruby/core/string/unpack/m_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/shared/float.rb b/spec/ruby/core/string/unpack/shared/float.rb index 208dc357af..99bd8a3401 100644 --- a/spec/ruby/core/string/unpack/shared/float.rb +++ b/spec/ruby/core/string/unpack/shared/float.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :string_unpack_float_le, shared: true do it "decodes one float for a single format character" do diff --git a/spec/ruby/core/string/unpack/shared/integer.rb b/spec/ruby/core/string/unpack/shared/integer.rb index 03dfb5c682..cbaa743683 100644 --- a/spec/ruby/core/string/unpack/shared/integer.rb +++ b/spec/ruby/core/string/unpack/shared/integer.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :string_unpack_16bit_le, shared: true do it "decodes one short for a single format character" do diff --git a/spec/ruby/core/string/unpack/u_spec.rb b/spec/ruby/core/string/unpack/u_spec.rb index ee1d6c68e7..8db6de1ab3 100644 --- a/spec/ruby/core/string/unpack/u_spec.rb +++ b/spec/ruby/core/string/unpack/u_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -31,10 +31,10 @@ describe "String#unpack with format 'u'" do it "decodes into raw (ascii) string values" do str = "".unpack("u")[0] - str.encoding.name.should == 'ASCII-8BIT' + str.encoding.should == Encoding::BINARY str = "1".force_encoding('UTF-8').unpack("u")[0] - str.encoding.name.should == 'ASCII-8BIT' + str.encoding.should == Encoding::BINARY end it "decodes the complete string ignoring newlines when given a single directive" do diff --git a/spec/ruby/core/string/unpack/w_spec.rb b/spec/ruby/core/string/unpack/w_spec.rb index 8ff926783e..166ae58869 100644 --- a/spec/ruby/core/string/unpack/w_spec.rb +++ b/spec/ruby/core/string/unpack/w_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/x_spec.rb b/spec/ruby/core/string/unpack/x_spec.rb index 22b641b732..5adcb720d1 100644 --- a/spec/ruby/core/string/unpack/x_spec.rb +++ b/spec/ruby/core/string/unpack/x_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/z_spec.rb b/spec/ruby/core/string/unpack/z_spec.rb index 2de624a74d..552851ce04 100644 --- a/spec/ruby/core/string/unpack/z_spec.rb +++ b/spec/ruby/core/string/unpack/z_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/valid_encoding_spec.rb b/spec/ruby/core/string/valid_encoding_spec.rb index 54109386ba..09916df079 100644 --- a/spec/ruby/core/string/valid_encoding_spec.rb +++ b/spec/ruby/core/string/valid_encoding_spec.rb @@ -9,12 +9,12 @@ describe "String#valid_encoding?" do it "returns true if self is valid in the current encoding and other encodings" do str = "\x77" str.force_encoding('utf-8').valid_encoding?.should be_true - str.force_encoding('ascii-8bit').valid_encoding?.should be_true + str.force_encoding('binary').valid_encoding?.should be_true end it "returns true for all encodings self is valid in" do str = "\u{6754}" - str.force_encoding('ASCII-8BIT').valid_encoding?.should be_true + str.force_encoding('BINARY').valid_encoding?.should be_true str.force_encoding('UTF-8').valid_encoding?.should be_true str.force_encoding('US-ASCII').valid_encoding?.should be_false str.force_encoding('Big5').valid_encoding?.should be_false diff --git a/spec/ruby/core/time/shared/now.rb b/spec/ruby/core/time/shared/now.rb index 80f66a1134..d8e5ac9d50 100644 --- a/spec/ruby/core/time/shared/now.rb +++ b/spec/ruby/core/time/shared/now.rb @@ -18,16 +18,18 @@ describe :time_now, shared: true do end end - it "has at least microsecond precision" do - times = [] - 10_000.times do - times << Time.now.nsec - end + guard_not -> { platform_is :windows and ruby_version_is ""..."2.5" } do + it "has at least microsecond precision" do + times = [] + 10_000.times do + times << Time.now.nsec + end - # The clock should not be less accurate than expected (times should - # not all be a multiple of the next precision up, assuming precisions - # are multiples of ten.) - expected = 1_000 - times.select { |t| t % (expected * 10) == 0 }.size.should_not == times.size + # The clock should not be less accurate than expected (times should + # not all be a multiple of the next precision up, assuming precisions + # are multiples of ten.) + expected = 1_000 + times.select { |t| t % (expected * 10) == 0 }.size.should_not == times.size + end end end diff --git a/spec/ruby/core/unboundmethod/hash_spec.rb b/spec/ruby/core/unboundmethod/hash_spec.rb index 2ea8c8d8a6..12dce0020f 100644 --- a/spec/ruby/core/unboundmethod/hash_spec.rb +++ b/spec/ruby/core/unboundmethod/hash_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "UnboundMethod#hash" do - it "needs to be reviewed for spec completeness" - it "returns the same value for user methods that are eql?" do foo, bar = UnboundMethodSpecs::Methods.instance_method(:foo), UnboundMethodSpecs::Methods.instance_method(:bar) foo.hash.should == bar.hash diff --git a/spec/ruby/language/encoding_spec.rb b/spec/ruby/language/encoding_spec.rb index 31b403a704..fb36a9618e 100644 --- a/spec/ruby/language/encoding_spec.rb +++ b/spec/ruby/language/encoding_spec.rb @@ -14,14 +14,14 @@ describe "The __ENCODING__ pseudo-variable" do 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("ASCII-8BIT")).should == Encoding::ASCII_8BIT + eval("__ENCODING__".force_encoding("BINARY")).should == Encoding::BINARY end it "is the encoding specified by a magic comment inside an eval" do - code = "# encoding: ASCII-8BIT\n__ENCODING__".force_encoding("US-ASCII") - eval(code).should == Encoding::ASCII_8BIT + code = "# encoding: BINARY\n__ENCODING__".force_encoding("US-ASCII") + eval(code).should == Encoding::BINARY - code = "# encoding: us-ascii\n__ENCODING__".force_encoding("ASCII-8BIT") + code = "# encoding: us-ascii\n__ENCODING__".force_encoding("BINARY") eval(code).should == Encoding::US_ASCII end diff --git a/spec/ruby/language/fixtures/hash_strings_ascii8bit.rb b/spec/ruby/language/fixtures/hash_strings_binary.rb index 4ac11b9930..44b99cbf80 100644 --- a/spec/ruby/language/fixtures/hash_strings_ascii8bit.rb +++ b/spec/ruby/language/fixtures/hash_strings_binary.rb @@ -1,6 +1,6 @@ -# encoding: ascii-8bit +# encoding: binary -module HashStringsASCII8BIT +module HashStringsBinary def self.literal_hash {"foo" => "bar"} end diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb index 475b1094ab..3d29f4bc72 100644 --- a/spec/ruby/language/hash_spec.rb +++ b/spec/ruby/language/hash_spec.rb @@ -1,5 +1,5 @@ require_relative '../spec_helper' -require_relative 'fixtures/hash_strings_ascii8bit' +require_relative 'fixtures/hash_strings_binary' require_relative 'fixtures/hash_strings_utf8' require_relative 'fixtures/hash_strings_usascii' @@ -141,12 +141,12 @@ describe "Hash literal" do end it "does not change encoding of literal string keys during creation" do - ascii8bit_hash = HashStringsASCII8BIT.literal_hash + binary_hash = HashStringsBinary.literal_hash utf8_hash = HashStringsUTF8.literal_hash usascii_hash = HashStringsUSASCII.literal_hash - ascii8bit_hash.keys.first.encoding.should == Encoding::ASCII_8BIT - ascii8bit_hash.keys.first.should == utf8_hash.keys.first + binary_hash.keys.first.encoding.should == Encoding::BINARY + binary_hash.keys.first.should == utf8_hash.keys.first utf8_hash.keys.first.encoding.should == Encoding::UTF_8 utf8_hash.keys.first.should == usascii_hash.keys.first usascii_hash.keys.first.encoding.should == Encoding::US_ASCII diff --git a/spec/ruby/language/regexp/encoding_spec.rb b/spec/ruby/language/regexp/encoding_spec.rb index f9979e7ea3..dce64a4753 100644 --- a/spec/ruby/language/regexp/encoding_spec.rb +++ b/spec/ruby/language/regexp/encoding_spec.rb @@ -42,16 +42,16 @@ describe "Regexps with encoding modifiers" do /./n.encoding.should == Encoding::US_ASCII end - it 'uses ASCII-8BIT as /n encoding if not all chars are 7-bit' do - /\xFF/n.encoding.should == Encoding::ASCII_8BIT + it 'uses BINARY as /n encoding if not all chars are 7-bit' do + /\xFF/n.encoding.should == Encoding::BINARY end it 'preserves US-ASCII as /n encoding through interpolation if all chars are 7-bit' do /.#{/./}/n.encoding.should == Encoding::US_ASCII end - it 'preserves ASCII-8BIT as /n encoding through interpolation if all chars are 7-bit' do - /\xFF#{/./}/n.encoding.should == Encoding::ASCII_8BIT + it 'preserves BINARY as /n encoding through interpolation if all chars are 7-bit' do + /\xFF#{/./}/n.encoding.should == Encoding::BINARY end it "supports /s (Windows_31J encoding)" do diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb index 78ee5ff2c4..308485d546 100644 --- a/spec/ruby/language/string_spec.rb +++ b/spec/ruby/language/string_spec.rb @@ -195,11 +195,11 @@ describe "Ruby character strings" do # TODO: spec other source encodings describe "with ASCII_8BIT source encoding" do it "produces an ASCII string when escaping ASCII characters via \\u" do - "\u0000".encoding.should == Encoding::ASCII_8BIT + "\u0000".encoding.should == Encoding::BINARY end it "produces an ASCII string when escaping ASCII characters via \\u{}" do - "\u{0000}".encoding.should == Encoding::ASCII_8BIT + "\u{0000}".encoding.should == Encoding::BINARY end it "produces a UTF-8-encoded string when escaping non-ASCII characters via \\u" do @@ -260,7 +260,7 @@ end describe "Ruby String interpolation" do it "creates a String having an Encoding compatible with all components" do a = "\u3042" - b = "abc".encode("ascii-8bit") + b = "abc".encode("binary") str = "#{a} x #{b}" @@ -280,7 +280,7 @@ describe "Ruby String interpolation" do it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do a = "\u3042" - b = "\xff".force_encoding "ascii-8bit" + b = "\xff".force_encoding "binary" lambda { "#{a} #{b}" }.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/language/super_spec.rb b/spec/ruby/language/super_spec.rb index ba5300bb99..5aff5e8eea 100644 --- a/spec/ruby/language/super_spec.rb +++ b/spec/ruby/language/super_spec.rb @@ -102,6 +102,25 @@ describe "The super keyword" do c2.new.m(:dump) { :value }.should == :value end + it "uses block argument given to method when used in a block" do + c1 = Class.new do + def m + yield + end + end + c2 = Class.new(c1) do + def m(v) + ary = [] + 1.times do + ary << super() + end + ary + end + end + + c2.new.m(:dump) { :value }.should == [ :value ] + end + it "calls the superclass method when in a block" do SuperSpecs::S6.new.here.should == :good end diff --git a/spec/ruby/language/symbol_spec.rb b/spec/ruby/language/symbol_spec.rb index 9ecb44ba87..d6a41d3059 100644 --- a/spec/ruby/language/symbol_spec.rb +++ b/spec/ruby/language/symbol_spec.rb @@ -38,7 +38,7 @@ describe "A Symbol literal" do it 'inherits the encoding of the magic comment and can have a binary encoding' do ruby_exe(fixture(__FILE__, "binary_symbol.rb")) - .should == "[105, 108, 95, 195, 169, 116, 97, 105, 116]\nASCII-8BIT\n" + .should == "[105, 108, 95, 195, 169, 116, 97, 105, 116]\n#{Encoding::BINARY.name}\n" end it "may contain '::' in the string" do diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index 98b3f47703..ec38c6f113 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -150,8 +150,13 @@ describe "Kernel#BigDecimal" do BigDecimal("-12345.6E-1").should == -reference end - it 'raises ArgumentError when Float is used without precision' do + it "raises ArgumentError when Float is used without precision" do lambda { BigDecimal(1.0) }.should raise_error(ArgumentError) end + it "returns appropriate BigDecimal zero for signed zero" do + BigDecimal(-0.0, Float::DIG).sign.should == -1 + BigDecimal(0.0, Float::DIG).sign.should == 1 + end + end diff --git a/spec/ruby/library/bigdecimal/inspect_spec.rb b/spec/ruby/library/bigdecimal/inspect_spec.rb index 18e9ca9a0c..7ce47142b2 100644 --- a/spec/ruby/library/bigdecimal/inspect_spec.rb +++ b/spec/ruby/library/bigdecimal/inspect_spec.rb @@ -15,6 +15,12 @@ describe "BigDecimal#inspect" do @bigdec.inspect.should == "0.12345678e4" end + it "does not add an exponent for zero values" do + BigDecimal("0").inspect.should == "0.0" + BigDecimal("+0").inspect.should == "0.0" + BigDecimal("-0").inspect.should == "-0.0" + end + it "properly cases non-finite values" do BigDecimal("NaN").inspect.should == "NaN" BigDecimal("Infinity").inspect.should == "Infinity" diff --git a/spec/ruby/library/bigdecimal/to_d_spec.rb b/spec/ruby/library/bigdecimal/to_d_spec.rb index 8e20901fd9..50aea99bf7 100644 --- a/spec/ruby/library/bigdecimal/to_d_spec.rb +++ b/spec/ruby/library/bigdecimal/to_d_spec.rb @@ -2,7 +2,6 @@ require_relative '../../spec_helper' require 'bigdecimal' require 'bigdecimal/util' - describe "Float#to_d" do it "returns appropriate BigDecimal zero for signed zero" do -0.0.to_d.sign.should == -1 diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb index 247db1a5d2..c7ee6a01b0 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -19,6 +19,12 @@ describe "BigDecimal#to_s" do @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/ end + it "does not add an exponent for zero values" do + BigDecimal("0").to_s.should == "0.0" + BigDecimal("+0").to_s.should == "0.0" + BigDecimal("-0").to_s.should == "-0.0" + end + it "takes an optional argument" do lambda {@bigdec.to_s("F")}.should_not raise_error() end diff --git a/spec/ruby/library/matrix/coerce_spec.rb b/spec/ruby/library/matrix/coerce_spec.rb index b8d5484657..280243d372 100644 --- a/spec/ruby/library/matrix/coerce_spec.rb +++ b/spec/ruby/library/matrix/coerce_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' require 'matrix' describe "Matrix#coerce" do - it "needs to be reviewed for spec completeness" - it "allows the division of fixnum by a Matrix " do (1/Matrix[[0,1],[-1,0]]).should == Matrix[[0,-1],[1,0]] end diff --git a/spec/ruby/library/net/ftp/set_socket_spec.rb b/spec/ruby/library/net/ftp/set_socket_spec.rb index 3aa5686326..7ca3bbbe27 100644 --- a/spec/ruby/library/net/ftp/set_socket_spec.rb +++ b/spec/ruby/library/net/ftp/set_socket_spec.rb @@ -4,5 +4,5 @@ require_relative 'spec_helper' describe "Net::FTP#set_socket" do # TODO: I won't spec this method, as it is not used # anywhere and it should be private anyway. - #it "needs to be reviewed for spec completeness" + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/open3/popen3_spec.rb b/spec/ruby/library/open3/popen3_spec.rb index 9afb5f5382..d3103ad3cb 100644 --- a/spec/ruby/library/open3/popen3_spec.rb +++ b/spec/ruby/library/open3/popen3_spec.rb @@ -38,6 +38,4 @@ describe "Open3.popen3" do out.read.should == "foo" end end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/pp/pp_spec.rb b/spec/ruby/library/pp/pp_spec.rb index dba20d190d..c4559b35ca 100644 --- a/spec/ruby/library/pp/pp_spec.rb +++ b/spec/ruby/library/pp/pp_spec.rb @@ -20,6 +20,4 @@ describe "PP.pp" do other_out.to_s.should == "[1, 2, 3]\n" end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb index 1b6027d26c..26683b3d23 100644 --- a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb @@ -35,6 +35,11 @@ describe "Socket::BasicSocket#recv_nonblock" do } end + it "returns :wait_readable with exception: false" do + @s1.bind(Socket.pack_sockaddr_in(0, ip_address)) + @s1.recv_nonblock(5, exception: false).should == :wait_readable + end + it "receives data after it's ready" do @s1.bind(Socket.pack_sockaddr_in(0, ip_address)) @s2.send("aaa", 0, @s1.getsockname) diff --git a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb index 8f6b75029c..c440bac8bf 100644 --- a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb @@ -31,6 +31,10 @@ describe 'BasicSocket#recvmsg_nonblock' do it 'raises an exception extending IO::WaitReadable' do lambda { @server.recvmsg_nonblock }.should raise_error(IO::WaitReadable) end + + it 'returns :wait_readable with exception: false' do + @server.recvmsg_nonblock(exception: false).should == :wait_readable + end end describe 'with data available' do diff --git a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb index de5e2aa749..000971f6af 100644 --- a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb @@ -98,6 +98,15 @@ describe 'BasicSocket#sendmsg_nonblock' do 10.times { @client.sendmsg_nonblock('hello' * 1_000_000) } }.should raise_error(IO::WaitWritable) end + + it 'returns :wait_writable when the underlying buffer is full with exception: false' do + ret = nil + 10.times { + ret = @client.sendmsg_nonblock('hello' * 1_000_000, exception: false) + break unless ret.is_a?(Integer) + } + ret.should == :wait_writable + end end end end diff --git a/spec/ruby/library/socket/socket/gethostbyname_spec.rb b/spec/ruby/library/socket/socket/gethostbyname_spec.rb index 9367030e25..2696f44566 100644 --- a/spec/ruby/library/socket/socket/gethostbyname_spec.rb +++ b/spec/ruby/library/socket/socket/gethostbyname_spec.rb @@ -2,15 +2,15 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "Socket#gethostbyname" do +describe "Socket.gethostbyname" do it "returns broadcast address info for '<broadcast>'" do addr = Socket.gethostbyname('<broadcast>'); - addr.should == ["255.255.255.255", [], 2, "\377\377\377\377"] + addr.should == ["255.255.255.255", [], 2, "\xFF\xFF\xFF\xFF"] end it "returns broadcast address info for '<any>'" do addr = Socket.gethostbyname('<any>'); - addr.should == ["0.0.0.0", [], 2, "\000\000\000\000"] + addr.should == ["0.0.0.0", [], 2, "\x00\x00\x00\x00"] end end diff --git a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb index 74fd286c42..5f717d4b54 100644 --- a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb @@ -31,6 +31,10 @@ describe 'Socket#recvfrom_nonblock' do it 'raises IO::WaitReadable' do lambda { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) end + + it 'returns :wait_readable with exception: false' do + @server.recvfrom_nonblock(1, exception: false).should == :wait_readable + end end describe 'with data available' do diff --git a/spec/ruby/library/socket/udpsocket/initialize_spec.rb b/spec/ruby/library/socket/udpsocket/initialize_spec.rb index 9497d0dcbc..1d635149f7 100644 --- a/spec/ruby/library/socket/udpsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/udpsocket/initialize_spec.rb @@ -31,12 +31,10 @@ describe 'UDPSocket#initialize' do end it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do - begin + -> { UDPSocket.new(666) - rescue Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT => e + }.should raise_error(SystemCallError) { |e| [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class) - else - raise "expected Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT exception raised" - end + } end end diff --git a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb index 62bbaf0dc9..fb88a2dc13 100644 --- a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb @@ -34,6 +34,10 @@ describe 'UDPSocket#recvfrom_nonblock' do it 'raises IO::WaitReadable' do lambda { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) end + + it 'returns :wait_readable with exception: false' do + @server.recvfrom_nonblock(1, exception: false).should == :wait_readable + end end platform_is_not :windows do diff --git a/spec/ruby/library/socket/unixsocket/local_address_spec.rb b/spec/ruby/library/socket/unixsocket/local_address_spec.rb index 56b3ccc557..cbf315f9f4 100644 --- a/spec/ruby/library/socket/unixsocket/local_address_spec.rb +++ b/spec/ruby/library/socket/unixsocket/local_address_spec.rb @@ -47,3 +47,50 @@ with_feature :unix_socket do end end end + +with_feature :unix_socket do + describe 'UNIXSocket#local_address with a UNIX socket pair' do + before :each do + @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) + end + + after :each do + @sock.close + @sock2.close + end + + it 'returns an Addrinfo' do + @sock.local_address.should be_an_instance_of(Addrinfo) + end + + describe 'the returned Addrinfo' do + it 'uses AF_UNIX as the address family' do + @sock.local_address.afamily.should == Socket::AF_UNIX + end + + it 'uses PF_UNIX as the protocol family' do + @sock.local_address.pfamily.should == Socket::PF_UNIX + end + + it 'uses SOCK_STREAM as the socket type' do + @sock.local_address.socktype.should == Socket::SOCK_STREAM + end + + it 'raises SocketError for #ip_address' do + -> { + @sock.local_address.ip_address + }.should raise_error(SocketError, "need IPv4 or IPv6 address") + end + + it 'raises SocketError for #ip_port' do + -> { + @sock.local_address.ip_port + }.should raise_error(SocketError, "need IPv4 or IPv6 address") + end + + it 'uses 0 as the protocol' do + @sock.local_address.protocol.should == 0 + end + end + end +end diff --git a/spec/ruby/library/stringio/read_nonblock_spec.rb b/spec/ruby/library/stringio/read_nonblock_spec.rb index 7a79eef3c5..2a8f926bd0 100644 --- a/spec/ruby/library/stringio/read_nonblock_spec.rb +++ b/spec/ruby/library/stringio/read_nonblock_spec.rb @@ -26,4 +26,17 @@ describe "StringIO#read_nonblock" do 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 << "hello" + stringio.rewind + + stringio.read_nonblock(5).should == "hello" + stringio.read_nonblock(5, exception: false).should be_nil + end + end + end + end diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb index 604bf880e5..139c4fb02f 100644 --- a/spec/ruby/library/stringio/shared/read.rb +++ b/spec/ruby/library/stringio/shared/read.rb @@ -69,7 +69,7 @@ describe :stringio_read_length, shared: true do end it "returns a binary String" do - @io.send(@method, 4).encoding.should == Encoding::ASCII_8BIT + @io.send(@method, 4).encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/library/stringscanner/shared/concat.rb b/spec/ruby/library/stringscanner/shared/concat.rb index 28788d3ff1..214455d1b9 100644 --- a/spec/ruby/library/stringscanner/shared/concat.rb +++ b/spec/ruby/library/stringscanner/shared/concat.rb @@ -25,6 +25,6 @@ describe :strscan_concat_fixnum, shared: true do x = mock('x') x.should_not_receive(:to_int) - lambda { "".send(@method, x) }.should raise_error(TypeError) + lambda { StringScanner.new("").send(@method, x) }.should raise_error(TypeError) end end diff --git a/spec/ruby/library/uri/mailto/build_spec.rb b/spec/ruby/library/uri/mailto/build_spec.rb index 80af931c8c..ca3b270c2c 100644 --- a/spec/ruby/library/uri/mailto/build_spec.rb +++ b/spec/ruby/library/uri/mailto/build_spec.rb @@ -90,9 +90,3 @@ describe "URI::Mailto.build" do ok.flatten.join("\0").should == ok_all end end - - - -describe "URI::MailTo.build" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/library/zlib/gzipwriter/append_spec.rb b/spec/ruby/library/zlib/gzipwriter/append_spec.rb index 9404dbd8b2..6aa2824180 100644 --- a/spec/ruby/library/zlib/gzipwriter/append_spec.rb +++ b/spec/ruby/library/zlib/gzipwriter/append_spec.rb @@ -12,6 +12,4 @@ describe "Zlib::GzipWriter#<<" do (gzio << "test").should equal(gzio) end end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/optional/capi/encoding_spec.rb b/spec/ruby/optional/capi/encoding_spec.rb index ce3bb9fa54..42e7899c9f 100644 --- a/spec/ruby/optional/capi/encoding_spec.rb +++ b/spec/ruby/optional/capi/encoding_spec.rb @@ -95,7 +95,7 @@ describe "C-API Encoding function" do end describe "rb_ascii8bit_encoding" do - it "returns the encoding for Encoding::ASCII_8BIT" do + it "returns the encoding for Encoding::BINARY" do @s.rb_ascii8bit_encoding.should == "ASCII-8BIT" end end @@ -125,16 +125,16 @@ describe "C-API Encoding function" do end describe "rb_enc_get" do - it "returns the encoding ossociated with an object" do - str = "abc".encode Encoding::ASCII_8BIT + it "returns the encoding associated with an object" do + str = "abc".encode Encoding::BINARY @s.rb_enc_get(str).should == "ASCII-8BIT" end end describe "rb_obj_encoding" do - it "returns the encoding ossociated with an object" do - str = "abc".encode Encoding::ASCII_8BIT - @s.rb_obj_encoding(str).should == Encoding::ASCII_8BIT + it "returns the encoding associated with an object" do + str = "abc".encode Encoding::BINARY + @s.rb_obj_encoding(str).should == Encoding::BINARY end end @@ -174,15 +174,15 @@ describe "C-API Encoding function" do end describe "rb_enc_str_coderange" do - describe "when the encoding is ASCII-8BIT" do + describe "when the encoding is BINARY" do it "returns ENC_CODERANGE_7BIT if there are no high bits set" do - result = @s.rb_enc_str_coderange("abc".force_encoding("ascii-8bit")) + result = @s.rb_enc_str_coderange("abc".force_encoding("binary")) result.should == :coderange_7bit end it "returns ENC_CODERANGE_VALID if there are high bits set" do xEE = [0xEE].pack('C').force_encoding('utf-8') - result = @s.rb_enc_str_coderange(xEE.force_encoding("ascii-8bit")) + result = @s.rb_enc_str_coderange(xEE.force_encoding("binary")) result.should == :coderange_valid end end @@ -283,7 +283,7 @@ describe "C-API Encoding function" do describe "rb_enc_compatible" do it "returns 0 if the encodings of the Strings are not compatible" do - a = [0xff].pack('C').force_encoding "ascii-8bit" + a = [0xff].pack('C').force_encoding "binary" b = "\u3042".encode("utf-8") @s.rb_enc_compatible(a, b).should == 0 end @@ -348,14 +348,14 @@ describe "C-API Encoding function" do end it "returns the encoding for Encoding.default_external" do - Encoding.default_external = "BINARY" + Encoding.default_external = "ASCII-8BIT" @s.rb_default_external_encoding.should == "ASCII-8BIT" end end describe "rb_enc_associate" do it "sets the encoding of a String to the encoding" do - @s.rb_enc_associate("string", "ASCII-8BIT").encoding.should == Encoding::ASCII_8BIT + @s.rb_enc_associate("string", "BINARY").encoding.should == Encoding::BINARY end it "raises a RuntimeError if the argument is Symbol" do @@ -363,19 +363,19 @@ describe "C-API Encoding function" do end it "sets the encoding of a Regexp to the encoding" do - @s.rb_enc_associate(/regexp/, "ASCII-8BIT").encoding.should == Encoding::ASCII_8BIT + @s.rb_enc_associate(/regexp/, "BINARY").encoding.should == Encoding::BINARY end it "sets the encoding of a String to a default when the encoding is NULL" do - @s.rb_enc_associate("string", nil).encoding.should == Encoding::ASCII_8BIT + @s.rb_enc_associate("string", nil).encoding.should == Encoding::BINARY end end describe "rb_enc_associate_index" do it "sets the encoding of a String to the encoding" do - index = @s.rb_enc_find_index("ASCII-8BIT") + index = @s.rb_enc_find_index("BINARY") enc = @s.rb_enc_associate_index("string", index).encoding - enc.should == Encoding::ASCII_8BIT + enc.should == Encoding::BINARY end it "sets the encoding of a Regexp to the encoding" do diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 79cdb524ad..2c8263d22a 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -35,7 +35,7 @@ describe :rb_str_new2, shared: true do end it "encodes the string with ASCII_8BIT" do - @s.send(@method, "hello").encoding.should == Encoding::ASCII_8BIT + @s.send(@method, "hello").encoding.should == Encoding::BINARY end end @@ -159,8 +159,8 @@ describe "C-API String function" do end describe "rb_str_new" do - it "creates a new String with ASCII-8BIT Encoding" do - @s.rb_str_new("", 0).encoding.should == Encoding::ASCII_8BIT + it "creates a new String with BINARY Encoding" do + @s.rb_str_new("", 0).encoding.should == Encoding::BINARY end it "returns a new string object from a char buffer of len characters" do @@ -676,10 +676,10 @@ describe :rb_external_str_new, shared: true do @s.send(@method, "abc").encoding.should == Encoding::UTF_8 end - it "returns an ASCII-8BIT encoded string if any non-ascii bytes are present and default external is US-ASCII" do + it "returns an BINARY encoded string if any non-ascii bytes are present and default external is US-ASCII" do Encoding.default_external = "US-ASCII" x80 = [0x80].pack('C') - @s.send(@method, "#{x80}abc").encoding.should == Encoding::ASCII_8BIT + @s.send(@method, "#{x80}abc").encoding.should == Encoding::BINARY end it "returns a tainted String" do @@ -735,10 +735,10 @@ describe "C-API String function" do s.encoding.should == Encoding::UTF_8 end - it "returns an ASCII-8BIT encoded String if any non-ascii bytes are present and the specified encoding is US-ASCII" do + it "returns an BINARY encoded String if any non-ascii bytes are present and the specified encoding is US-ASCII" do x80 = [0x80].pack('C') s = @s.rb_external_str_new_with_enc("#{x80}abc", 4, Encoding::US_ASCII) - s.encoding.should == Encoding::ASCII_8BIT + s.encoding.should == Encoding::BINARY end @@ -750,7 +750,7 @@ describe "C-API String function" do # s = @s.rb_external_str_new_with_enc(a, a.bytesize, Encoding::UTF_8) # - # - s.should == "\xA4\xA2\xA4\xEC".force_encoding("euc-jp") -# + x = [0xA4, 0xA2, 0xA4, 0xEC].pack('C4')#.force_encoding('ascii-8bit') +# + x = [0xA4, 0xA2, 0xA4, 0xEC].pack('C4')#.force_encoding('binary') # + s.should == x # s.encoding.should equal(Encoding::EUC_JP) # end @@ -817,9 +817,9 @@ describe "C-API String function" do @s.rb_str_conv_enc(a, Encoding::UTF_8, Encoding::US_ASCII).should equal(a) end - it "returns the origin String if the destination encoding is ASCII-8BIT" do - a = "abc".force_encoding("ascii-8bit") - @s.rb_str_conv_enc(a, Encoding::US_ASCII, Encoding::ASCII_8BIT).should equal(a) + it "returns the origin String if the destination encoding is BINARY" do + a = "abc".force_encoding("binary") + @s.rb_str_conv_enc(a, Encoding::US_ASCII, Encoding::BINARY).should equal(a) end end end @@ -857,10 +857,10 @@ describe "C-API String function" do Encoding::US_ASCII, 0, nil).should equal(a) end - it "returns the origin String if the destination encoding is ASCII-8BIT" do - a = "abc".force_encoding("ascii-8bit") + it "returns the origin String if the destination encoding is BINARY" do + a = "abc".force_encoding("binary") @s.rb_str_conv_enc_opts(a, Encoding::US_ASCII, - Encoding::ASCII_8BIT, 0, nil).should equal(a) + Encoding::BINARY, 0, nil).should equal(a) end end end diff --git a/spec/ruby/security/cve_2010_1330_spec.rb b/spec/ruby/security/cve_2010_1330_spec.rb index c41a5e0a2e..5593bc0845 100644 --- a/spec/ruby/security/cve_2010_1330_spec.rb +++ b/spec/ruby/security/cve_2010_1330_spec.rb @@ -10,7 +10,7 @@ describe "String#gsub" do # sequence. str = "\xF6<script>" - str.force_encoding Encoding::ASCII_8BIT + str.force_encoding Encoding::BINARY str.gsub(/</, "<").should == "\xF6<script>".b str.force_encoding Encoding::UTF_8 lambda { diff --git a/spec/ruby/shared/enumerator/with_index.rb b/spec/ruby/shared/enumerator/with_index.rb index 4f459bd9a8..89f40070e0 100644 --- a/spec/ruby/shared/enumerator/with_index.rb +++ b/spec/ruby/shared/enumerator/with_index.rb @@ -5,17 +5,18 @@ describe :enum_with_index, shared: true do require_relative '../../fixtures/enumerator/classes' before :each do - @enum = [1, 2, 3, 4].to_enum + @origin = [1, 2, 3, 4] + @enum = @origin.to_enum end it "passes each element and its index to block" do - @a = [] - @enum.send(@method) { |o, i| @a << [o, i] } - @a.should == [[1, 0], [2, 1], [3, 2], [4, 3]] + a = [] + @enum.send(@method) { |o, i| a << [o, i] } + a.should == [[1, 0], [2, 1], [3, 2], [4, 3]] end it "returns the object being enumerated when given a block" do - [1, 2, 3, 4].should == @enum.send(@method) { |o, i| :glark } + @enum.send(@method) { |o, i| :glark }.should equal(@origin) end it "binds splat arguments properly" do diff --git a/spec/ruby/shared/io/putc.rb b/spec/ruby/shared/io/putc.rb index 5f620f183f..b71443e219 100644 --- a/spec/ruby/shared/io/putc.rb +++ b/spec/ruby/shared/io/putc.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :io_putc, shared: true do after :each do @io.close if @io && !@io.closed? |