diff options
Diffstat (limited to 'spec/ruby/core/array/pack/b_spec.rb')
| -rw-r--r-- | spec/ruby/core/array/pack/b_spec.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/spec/ruby/core/array/pack/b_spec.rb b/spec/ruby/core/array/pack/b_spec.rb index 8a75825e3e..f7576846ef 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' @@ -13,11 +13,16 @@ describe "Array#pack with format 'B'" do it_behaves_like :array_pack_taint, 'B' it "calls #to_str to convert an Object to a String" do - obj = mock("pack H string") + obj = mock("pack B string") obj.should_receive(:to_str).and_return("``abcdef") [obj].pack("B*").should == "\x2a" end + it "will not implicitly convert a number to a string" do + -> { [0].pack('B') }.should.raise(TypeError) + -> { [0].pack('b') }.should.raise(TypeError) + end + it "encodes one bit for each character starting with the most significant bit" do [ [["0"], "\x00"], [["1"], "\x80"] @@ -47,8 +52,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 a binary string" do + ["1"].pack("B").encoding.should == Encoding::BINARY end it "encodes the string as a sequence of bytes" do @@ -98,8 +103,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 a binary string" do + ["1"].pack("b").encoding.should == Encoding::BINARY end it "encodes the string as a sequence of bytes" do |
