spec/parameters_spec.rb in parameters-0.1.2 vs spec/parameters_spec.rb in parameters-0.1.3
- old
+ new
@@ -13,10 +13,14 @@
:default => 'thing',
:description => 'This parameter has a default value'
parameter :var_without_default,
:description => 'This parameter does not have a default value'
+
+ parameter :var_with_lambda,
+ :default => lambda { rand },
+ :description => 'This parameter uses a lambda instead of a default value'
end
class InheritedParameters < TestParameters
parameter :child_var, :description => 'Child parameter'
@@ -97,9 +101,16 @@
it "should set instance variables for paramters" do
@test.instance_variable_get('@var_with_default').should == 'thing'
@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
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