spec/parameters_spec.rb in parameters-0.1.5 vs spec/parameters_spec.rb in parameters-0.1.6

- old
+ new

@@ -1,11 +1,12 @@ require 'parameters/parameters' require 'spec_helper' -require 'helpers/test_parameters' -require 'helpers/inherited_parameters' +require 'classes/test_parameters' +require 'classes/inherited_parameters' +require 'classes/other_parameters' describe Parameters do describe "in a Class" do it "should provide parameters" do TestParameters.params.should_not be_empty @@ -47,28 +48,20 @@ obj.var_with_default.should == 'stuff' end end describe "in an Object" do - before(:all) do + before(:each) do @test = TestParameters.new @test_inherited = InheritedParameters.new end it "should provide direct access to all parameters" do @test.params[:var].should_not be_nil @test.params[:var_with_default].should_not be_nil end - it "should allow for mass assignment of parameters" do - test2 = TestParameters.new - test2.params = {:var => 5, :var_with_default => 'hello'} - - test2.var.should == 5 - test2.var_with_default.should == 'hello' - end - it "can have default values for parameters" do @test.param_value(:var_with_default).should == 'thing' end it "should provide instance methods for parameters" do @@ -82,14 +75,13 @@ @test.var = 3 @test.instance_variable_get(:@var).should == 3 end it "should allow using lambdas for the default values of parameters" do - test1 = TestParameters.new test2 = TestParameters.new - test1.var_with_lambda.should_not == test2.var_with_lambda + @test.var_with_lambda.should_not == test2.var_with_lambda end it "should contain the parameters from all ancestors" do @test_inherited.has_param?(:var).should == true @test_inherited.has_param?(:child_var).should == true @@ -109,9 +101,24 @@ it "should allow for setting parameters en-mass" do @test.params = {:var => 3, :var_with_default => 7} @test.param_value(:var).should == 3 @test.param_value(:var_with_default).should == 7 + end + + it "should allow for setting parameters en-mass from another object" do + obj = TestParameters.new(:var => 5, :var_with_default => 'hello') + @test.params = obj.params + + @test.var.should == 5 + @test.var_with_default.should == 'hello' + end + + it "should allow for setting parameters en-mass from another class" do + @test.params = OtherParameters.params + + @test.var.should be_nil + @test.var_with_default.should == 'other' end it "should provide descriptions for parameters" do @test.describe_param(:var).should_not be_empty end