spec/base_spec.rb in bindata-0.9.2 vs spec/base_spec.rb in bindata-0.9.3

- old
+ new

@@ -16,11 +16,11 @@ describe BinData::Base, "with mandatory parameters" do before(:all) do eval <<-END class MandatoryBase < BinData::Base - mandatory_parameter :p1 + bindata_mandatory_parameter :p1 end END end it "should ensure that those parameters are present" do @@ -34,35 +34,35 @@ describe BinData::Base, "with default parameters" do before(:all) do eval <<-END class DefaultBase < BinData::Base - default_parameter :p1 => "a" - public :has_param?, :param + bindata_default_parameter :p1 => "a" + public :has_param?, :no_eval_param end END end it "should set default parameters if they are not specified" do obj = DefaultBase.new obj.should have_param(:p1) - obj.param(:p1).should == "a" + obj.no_eval_param(:p1).should == "a" end it "should be able to override default parameters" do obj = DefaultBase.new(:p1 => "b") obj.should have_param(:p1) - obj.param(:p1).should == "b" + obj.no_eval_param(:p1).should == "b" end end describe BinData::Base, "with mutually exclusive parameters" do before(:all) do eval <<-END class MutexParamBase < BinData::Base - optional_parameters :p1, :p2 - mutually_exclusive_parameters :p1, :p2 + bindata_optional_parameters :p1, :p2 + bindata_mutually_exclusive_parameters :p1, :p2 end END end it "should not fail when neither of those parameters is present" do @@ -81,27 +81,25 @@ describe BinData::Base, "with multiple parameters" do before(:all) do eval <<-END class WithParamBase < BinData::Base - mandatory_parameter :p1 - optional_parameter :p2 - default_parameter :p3 => '3' - public :has_param?, :eval_param, :param + bindata_mandatory_parameter :p1 + bindata_optional_parameter :p2 + bindata_default_parameter :p3 => '3' + public :has_param?, :eval_param, :no_eval_param end END end it "should not allow parameters with nil values" do lambda { WithParamBase.new(:p1 => 1, :p2 => nil) }.should raise_error(ArgumentError) end it "should identify extra parameters" do - env = mock("env") - env.should_receive(:params=).with(:p4 => 4, :p5 => 5) - env.should_receive(:data_object=) - obj = WithParamBase.new({:p1 => 1, :p3 => 3, :p4 => 4, :p5 => 5}, env) + obj = WithParamBase.new({:p1 => 1, :p3 => 3, :p4 => 4, :p5 => 5}) + obj.parameters.should == {:p4 => 4, :p5 => 5} end it "should only recall mandatory, default and optional parameters" do obj = WithParamBase.new(:p1 => 1, :p3 => 3, :p4 => 4, :p5 => 5) obj.should have_param(:p1) @@ -120,21 +118,21 @@ obj.eval_param(:p5).should be_nil end it "should be able to access without evaluating" do obj = WithParamBase.new(:p1 => :asym, :p3 => lambda {1 + 2}) - obj.param(:p1).should == :asym - obj.param(:p2).should be_nil - obj.param(:p3).should respond_to(:arity) + obj.no_eval_param(:p1).should == :asym + obj.no_eval_param(:p2).should be_nil + obj.no_eval_param(:p3).should respond_to(:arity) end it "should identify accepted parameters" do - accepted_parameters = WithParamBase.accepted_parameters - accepted_parameters.should include(:p1) - accepted_parameters.should include(:p2) - accepted_parameters.should include(:p3) - accepted_parameters.should_not include(:p4) + internal_parameters = WithParamBase.internal_parameters + internal_parameters.should include(:p1) + internal_parameters.should include(:p2) + internal_parameters.should include(:p3) + internal_parameters.should_not include(:p4) end end describe BinData::Base, "with :check_offset" do before(:all) do @@ -263,19 +261,19 @@ describe BinData::Base, "with :readwrite" do before(:all) do eval <<-END class NoIOBase < BinData::Base - public :has_param?, :param + public :has_param?, :no_eval_param end END end it "should alias to :onlyif" do obj = NoIOBase.new(:readwrite => "a") obj.should_not have_param(:readwrite) obj.should have_param(:onlyif) - obj.param(:onlyif).should == "a" + obj.no_eval_param(:onlyif).should == "a" end end describe BinData::Base, "when subclassing" do before(:all) do