spec/stringz_spec.rb in bindata-0.9.3 vs spec/stringz_spec.rb in bindata-0.10.0
- old
+ new
@@ -15,14 +15,11 @@
it "should not append the zero byte terminator to the value" do
@str.value.should == ""
end
it "should write the zero byte terminator" do
- io = StringIO.new
- @str.write(io)
- io.rewind
- io.read.should == "\0"
+ @str.to_binary_s.should == "\0"
end
end
describe BinData::Stringz, "with value set" do
before(:each) do
@@ -37,14 +34,11 @@
it "should not append the zero byte terminator to the value" do
@str.value.should == "abcd"
end
it "should write the zero byte terminator" do
- io = StringIO.new
- @str.write(io)
- io.rewind
- io.read.should == "abcd\0"
+ @str.to_binary_s.should == "abcd\0"
end
end
describe BinData::Stringz, "when reading" do
before(:each) do
@@ -64,12 +58,11 @@
@str.value.should == ""
io.read(1).should == "a"
end
it "should fail if no zero byte is found" do
- io = StringIO.new("abcd")
- lambda {@str.read(io) }.should raise_error(EOFError)
+ lambda {@str.read("abcd") }.should raise_error(EOFError)
end
end
describe BinData::Stringz, " when setting the value" do
before(:each) do
@@ -139,21 +132,20 @@
it "should trim values greater than max_length" do
@str.value = "abcde"
@str.value.should == "abcd"
end
+ it "should write values greater than max_length" do
+ @str.value = "abcde"
+ @str.to_binary_s.should == "abcd\0"
+ end
+
it "should write values less than max_length" do
- io = StringIO.new
@str.value = "abc"
- @str.write(io)
- io.rewind
- io.read.should == "abc\0"
+ @str.to_binary_s.should == "abc\0"
end
it "should write values exactly max_length" do
- io = StringIO.new
@str.value = "abcd"
- @str.write(io)
- io.rewind
- io.read.should == "abcd\0"
+ @str.to_binary_s.should == "abcd\0"
end
end