spec/string_spec.rb in bindata-1.4.3 vs spec/string_spec.rb in bindata-1.4.4

- old
+ new

@@ -5,63 +5,63 @@ require 'bindata/string' describe BinData::String, "with mutually exclusive parameters" do it ":value and :initial_value" do params = {:value => "", :initial_value => ""} - lambda { BinData::String.new(params) }.should raise_error(ArgumentError) + expect { BinData::String.new(params) }.to raise_error(ArgumentError) end it ":length and :read_length" do params = {:length => 5, :read_length => 5} - lambda { BinData::String.new(params) }.should raise_error(ArgumentError) + expect { BinData::String.new(params) }.to raise_error(ArgumentError) end it ":value and :length" do params = {:value => "", :length => 5} - lambda { BinData::String.new(params) }.should raise_error(ArgumentError) + expect { BinData::String.new(params) }.to raise_error(ArgumentError) end end describe BinData::String, "when assigning" do - let(:small) { BinData::String.new(:length => 3, :pad_char => "A") } - let(:large) { BinData::String.new(:length => 5, :pad_char => "B") } + let(:small) { BinData::String.new(:length => 3, :pad_byte => "A") } + let(:large) { BinData::String.new(:length => 5, :pad_byte => "B") } - it "should copy data from small to large" do + it "copies data from small to large" do large.assign(small) large.should == "AAABB" end - it "should copy data from large to small" do + it "copies data from large to small" do small.assign(large) small.should == "BBB" end end describe BinData::String do subject { BinData::String.new("testing") } - it "should compare with regexp" do + it "compares with regexp" do (/es/ =~ subject).should == 1 end - it "should compare with regexp" do + it "compares with regexp" do (subject =~ /es/).should == 1 end end describe BinData::String, "with :read_length" do subject { BinData::String.new(:read_length => 5) } its(:num_bytes) { should == 0 } its(:value) { should == "" } - it "should read :read_length bytes" do + it "reads :read_length bytes" do subject.read("abcdefghij") subject.should == "abcde" end - it "should remember :read_length after value is cleared" do + it "remembers :read_length after value is cleared" do subject.assign("abc") subject.num_bytes.should == 3 subject.clear subject.read("abcdefghij") @@ -73,31 +73,31 @@ subject { BinData::String.new(:length => 5) } its(:num_bytes) { should == 5 } its(:value) { should == "\0\0\0\0\0" } - it "should retain :length after value is set" do + it "retains :length after value is set" do subject.assign("abcdefghij") subject.num_bytes.should == 5 end - it "should read :length bytes" do + it "reads :length bytes" do subject.read("abcdefghij") subject.should == "abcde" end - it "should pad values less than :length" do + it "pads values less than :length" do subject.assign("abc") subject.should == "abc\0\0" end - it "should accept values exactly :length" do + it "accepts values exactly :length" do subject.assign("abcde") subject.should == "abcde" end - it "should truncate values greater than :length" do + it "truncates values greater than :length" do subject.assign("abcdefghij") subject.should == "abcde" end end @@ -105,17 +105,17 @@ subject { BinData::String.new(:read_length => 5, :initial_value => "abcdefghij") } its(:num_bytes) { should == 10 } its(:value) { should == "abcdefghij" } - it "should use :read_length for reading" do + it "uses :read_length for reading" do io = StringIO.new("ABCDEFGHIJKLMNOPQRST") subject.read(io) io.pos.should == 5 end - it "should forget :initial_value after reading" do + it "forgets :initial_value after reading" do subject.read("ABCDEFGHIJKLMNOPQRST") subject.num_bytes.should == 5 subject.should == "ABCDE" end end @@ -124,27 +124,27 @@ subject { BinData::String.new(:read_length => 5, :value => "abcdefghij") } its(:num_bytes) { should == 10 } its(:value) { should == "abcdefghij" } - it "should use :read_length for reading" do + it "uses :read_length for reading" do io = StringIO.new("ABCDEFGHIJKLMNOPQRST") subject.read(io) io.pos.should == 5 end context "after reading" do before(:each) do subject.read("ABCDEFGHIJKLMNOPQRST") end - it "should not be affected by :read_length after reading" do + it "is not affected by :read_length after reading" do subject.num_bytes.should == 10 subject.should == "abcdefghij" end - it "should return read value while reading" do + it "returns read value while reading" do subject.stub(:reading?).and_return(true) subject.should == "ABCDE" end end end @@ -153,34 +153,34 @@ subject { BinData::String.new(:length => 5, :initial_value => "abcdefghij") } its(:num_bytes) { should == 5 } its(:value) { should == "abcde" } - it "should forget :initial_value after reading" do + it "forgets :initial_value after reading" do io = StringIO.new("ABCDEFGHIJKLMNOPQRST") subject.read(io) io.pos.should == 5 subject.num_bytes.should == 5 subject.should == "ABCDE" end end -describe BinData::String, "with :pad_char" do - it "should accept a numeric value for :pad_char" do - str = BinData::String.new(:length => 5, :pad_char => 6) +describe BinData::String, "with :pad_byte" do + it "accepts a numeric value for :pad_byte" do + str = BinData::String.new(:length => 5, :pad_byte => 6) str.assign("abc") str.should == "abc\x06\x06" end - it "should accept a character for :pad_char" do - str = BinData::String.new(:length => 5, :pad_char => "R") + it "accepts a character for :pad_byte" do + str = BinData::String.new(:length => 5, :pad_byte => "R") str.assign("abc") str.should == "abcRR" end - it "should not accept a string for :pad_char" do - params = {:length => 5, :pad_char => "RR"} + it "does not accept a string for :pad_byte" do + params = {:length => 5, :pad_byte => "RR"} lambda { BinData::String.new(params) }.should raise_error(ArgumentError) end end describe BinData::String, "with :trim_padding" do @@ -192,28 +192,28 @@ str1.should == "abc\0\0" str2.should == "abc\0\0" end context "trim padding set" do - subject { BinData::String.new(:pad_char => 'R', :trim_padding => true) } + subject { BinData::String.new(:pad_byte => 'R', :trim_padding => true) } - it "should trim the value" do + it "trims the value" do subject.assign("abcRR") subject.should == "abc" end - it "should not affect num_bytes" do + it "does not affect num_bytes" do subject.assign("abcRR") subject.num_bytes.should == 5 end - it "should trim if last char is :pad_char" do + it "trims if last char is :pad_byte" do subject.assign("abcRR") subject.should == "abc" end - it "should not trim if value contains :pad_char not at the end" do + it "does not trim if value contains :pad_byte not at the end" do subject.assign("abcRRde") subject.should == "abcRRde" end end end @@ -228,28 +228,28 @@ subject { UTF8String.new } let(:binary_str) { "\xC3\x85\xC3\x84\xC3\x96" } let(:utf8_str) { binary_str.dup.force_encoding('UTF-8') } - it "should store assigned values as binary" do + it "stores assigned values as binary" do subject.assign(utf8_str) subject.to_binary_s.should == binary_str end - it "should store read values as binary" do + it "stores read values as binary" do subject = UTF8String.new(:read_length => binary_str.length) subject.read(binary_str) subject.to_binary_s.should == binary_str end - it "should return values in correct encoding" do + it "returns values in correct encoding" do subject.assign(utf8_str) subject.snapshot.should == utf8_str end - it "should have correct num_bytes" do + it "has correct num_bytes" do subject.assign(utf8_str) subject.num_bytes.should == binary_str.length end end