spec/base_spec.rb in bindata-0.11.0 vs spec/base_spec.rb in bindata-0.11.1
- old
+ new
@@ -28,16 +28,12 @@
def _assign(x); mock._assign(x); end
def _snapshot; mock._snapshot; end
end
describe BinData::Base, "when subclassing" do
- before(:all) do
- eval <<-END
- class SubClassOfBase < BinData::Base
- expose_methods_for_testing
- end
- END
+ class SubClassOfBase < BinData::Base
+ expose_methods_for_testing
end
before(:each) do
@obj = SubClassOfBase.new
end
@@ -61,15 +57,13 @@
lambda { BaseStub.new(:a => nil) }.should raise_error(ArgumentError)
end
it "should raise error if parameter name is invalid" do
lambda {
- eval <<-END
- class InvalidParameterNameBase < BinData::Base
- optional_parameter :eval # i.e. Kernel#eval
- end
- END
+ class InvalidParameterNameBase < BinData::Base
+ optional_parameter :eval # i.e. Kernel#eval
+ end
}.should raise_error(NameError)
end
it "should convert keys to symbols" do
obj = BaseStub.new('a' => 3)
@@ -77,17 +71,13 @@
obj.get_parameter(:a).should == 3
end
end
describe BinData::Base, "with mandatory parameters" do
- before(:all) do
- eval <<-END
- class MandatoryBase < BaseStub
- mandatory_parameter :p1
- mandatory_parameter :p2
- end
- END
+ class MandatoryBase < BaseStub
+ mandatory_parameter :p1
+ mandatory_parameter :p2
end
it "should ensure that all mandatory parameters are present" do
params = {:p1 => "a", :p2 => "b" }
lambda { MandatoryBase.new(params) }.should_not raise_error
@@ -102,16 +92,12 @@
lambda { MandatoryBase.new() }.should raise_error(ArgumentError)
end
end
describe BinData::Base, "with default parameters" do
- before(:all) do
- eval <<-END
- class DefaultBase < BaseStub
- default_parameter :p1 => "a"
- end
- END
+ class DefaultBase < BaseStub
+ default_parameter :p1 => "a"
end
it "should use default parameters when not specified" do
obj = DefaultBase.new
obj.should have_parameter(:p1)
@@ -124,17 +110,13 @@
obj.eval_parameter(:p1).should == "b"
end
end
describe BinData::Base, "with mutually exclusive parameters" do
- before(:all) do
- eval <<-END
- class MutexParamBase < BaseStub
- optional_parameters :p1, :p2
- mutually_exclusive_parameters :p1, :p2
- end
- END
+ class MutexParamBase < BaseStub
+ optional_parameters :p1, :p2
+ mutually_exclusive_parameters :p1, :p2
end
it "should not fail when neither of those parameters are present" do
lambda { MutexParamBase.new }.should_not raise_error
end
@@ -148,18 +130,14 @@
lambda { MutexParamBase.new(:p1 => "a", :p2 => "b") }.should raise_error(ArgumentError)
end
end
describe BinData::Base, "with multiple parameters" do
- before(:all) do
- eval <<-END
- class WithParamBase < BaseStub
- mandatory_parameter :p1
- optional_parameter :p2
- default_parameter :p3 => 3
- end
- END
+ class WithParamBase < BaseStub
+ mandatory_parameter :p1
+ optional_parameter :p2
+ default_parameter :p3 => 3
end
it "should identify internally accepted parameters" do
accepted = WithParamBase.accepted_parameters.all
accepted.should include(:p1)
@@ -218,20 +196,16 @@
obj.get_parameter(:p3).should respond_to(:arity)
end
end
describe BinData::Base, "with :check_offset" do
- before(:all) do
- eval <<-END
- class TenByteOffsetBase < BaseStub
- def do_read(io)
- # advance the io position before checking offset
- io.seekbytes(10)
- super(io)
- end
- end
- END
+ class TenByteOffsetBase < BaseStub
+ def do_read(io)
+ # advance the io position before checking offset
+ io.seekbytes(10)
+ super(io)
+ end
end
before(:each) do
@io = StringIO.new("12345678901234567890")
end
@@ -260,19 +234,15 @@
lambda { obj.read(@io) }.should_not raise_error
end
end
describe BinData::Base, "with :adjust_offset" do
- before(:all) do
- eval <<-END
- class TenByteAdjustingOffsetBase < BaseStub
- def do_read(io)
- # advance the io position before checking offset
- io.seekbytes(10)
- super(io)
- end
- end
- END
+ class TenByteAdjustingOffsetBase < BaseStub
+ def do_read(io)
+ # advance the io position before checking offset
+ io.seekbytes(10)
+ super(io)
+ end
end
before(:each) do
@io = StringIO.new("12345678901234567890")
end