spec/parameters_spec.rb in parameters-0.1.6 vs spec/parameters_spec.rb in parameters-0.1.7
- old
+ new
@@ -1,10 +1,11 @@
require 'parameters/parameters'
require 'spec_helper'
require 'classes/test_parameters'
+require 'classes/custom_parameters'
require 'classes/inherited_parameters'
require 'classes/other_parameters'
describe Parameters do
describe "in a Class" do
@@ -39,10 +40,36 @@
it "should provide descriptions for parameters" do
TestParameters.describe_param(:var).should_not be_empty
end
+ it "should be able to initialize parameters" do
+ obj = TestParameters.new
+
+ obj.params.should_not be_empty
+ end
+
+ it "should set initialize parameters with initial nil values" do
+ obj = CustomParameters.new
+
+ obj.var_with_default.should == 10
+ end
+
+ it "should not override previous parameter values" do
+ obj = CustomParameters.new(:test,5)
+
+ obj.var.should == :test
+ obj.var_with_default.should == 5
+ end
+
+ it "should not override previous 'false' values of parameters" do
+ obj = CustomParameters.new(false,false)
+
+ obj.var.should == false
+ obj.var_with_default.should == false
+ end
+
it "should be able to create an object with initial parameter values" do
obj = TestParameters.new(:var => 2, :var_with_default => 'stuff')
obj.var.should == 2
obj.var_with_default.should == 'stuff'
@@ -126,8 +153,54 @@
it "should require that certain parameters have non nil values" do
lambda {
@test.instance_eval { require_params(:var_without_default) }
}.should raise_error(Parameters::MissingParam)
+ end
+ end
+
+ describe "runtime" do
+ before(:each) do
+ @test = TestParameters.new
+
+ @test.parameter :new_param
+ @test.parameter :new_param_with_default,
+ :default => 5
+ @test.parameter :new_param_with_lambda,
+ :default => lambda { |obj| obj.new_param_with_default + 2 }
+ end
+
+ it "should allow for the addition of parameters" do
+ @test.has_param?(:new_param).should == true
+ end
+
+ it "should provide direct access to all parameters" do
+ @test.params[:new_param].should_not be_nil
+ @test.params[:new_param_with_default].should_not be_nil
+ @test.params[:new_param_with_lambda].should_not be_nil
+ end
+
+ it "should add reader methods for parameters" do
+ @test.new_param.should be_nil
+ end
+
+ it "should add writer methods for parameters" do
+ @test.new_param = 10
+ @test.new_param.should == 10
+ end
+
+ it "should set the instance variables of parameters" do
+ @test.instance_variable_get(:@new_param_with_default).should == 5
+
+ @test.new_param_with_default = 10
+ @test.instance_variable_get(:@new_param_with_default).should == 10
+ end
+
+ it "should initialize parameters with default values" do
+ @test.new_param_with_default.should == 5
+ end
+
+ it "should initialize pamareters with default lambda values" do
+ @test.new_param_with_lambda.should == 7
end
end
end