spec/base_spec.rb in bindata-1.1.0 vs spec/base_spec.rb in bindata-1.2.0
- old
+ new
@@ -182,11 +182,11 @@
super(io)
end
end
before(:each) do
- @io = BinData::IO.create_string_io("12345678901234567890")
+ @io = StringIO.new("12345678901234567890")
end
it "should fail if offset is incorrect" do
@io.seek(2)
obj = TenByteOffsetBase.new(:check_offset => 8)
@@ -220,11 +220,11 @@
super(io)
end
end
before(:each) do
- @io = BinData::IO.create_string_io("12345678901234567890")
+ @io = StringIO.new("12345678901234567890")
end
it "should be mutually exclusive with :check_offset" do
params = { :check_offset => 8, :adjust_offset => 8 }
lambda { TenByteAdjustingOffsetBase.new(params) }.should raise_error(ArgumentError)
@@ -286,20 +286,33 @@
end
obj = SnapshotBase.new
obj.to_s.should == obj.snapshot.to_s
end
+ it "should pretty print object as snapshot" do
+ class PPBase < BaseStub
+ def snapshot; [1, 2, 3]; end
+ end
+ obj = SnapshotBase.new
+ actual_io = StringIO.new
+ expected_io = StringIO.new
+
+ require 'pp'
+ PP.pp(obj, actual_io)
+ PP.pp(obj.snapshot, expected_io)
+
+ actual_io.value.should == expected_io.value
+ end
+
it "should write the same as to_binary_s" do
class WriteToSBase < BaseStub
def _do_write(io) io.writebytes("abc"); end
end
obj = WriteToSBase.new
- io = BinData::IO.create_string_io
+ io = StringIO.new
obj.write(io)
- io.rewind
- written = io.read
- obj.to_binary_s.should == written
+ io.value.should == obj.to_binary_s
end
end
describe BinData::Base, "as white box" do
before(:each) do