diff options
Diffstat (limited to 'spec/unit/parser/ast/function_spec.rb')
-rw-r--r-- | spec/unit/parser/ast/function_spec.rb | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/spec/unit/parser/ast/function_spec.rb b/spec/unit/parser/ast/function_spec.rb index bb687eac0..c57c7f098 100644 --- a/spec/unit/parser/ast/function_spec.rb +++ b/spec/unit/parser/ast/function_spec.rb @@ -3,81 +3,81 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::Function do - before :each do - @scope = mock 'scope' - end + before :each do + @scope = mock 'scope' + end - describe "when initializing" do - it "should not fail if the function doesn't exist" do - Puppet::Parser::Functions.stubs(:function).returns(false) + describe "when initializing" do + it "should not fail if the function doesn't exist" do + Puppet::Parser::Functions.stubs(:function).returns(false) - lambda{ Puppet::Parser::AST::Function.new :name => "dontexist" }.should_not raise_error(Puppet::ParseError) + lambda{ Puppet::Parser::AST::Function.new :name => "dontexist" }.should_not raise_error(Puppet::ParseError) - end end + end - it "should return its representation with to_s" do - args = stub 'args', :is_a? => true, :to_s => "[a, b]" - - Puppet::Parser::AST::Function.new(:name => "func", :arguments => args).to_s.should == "func(a, b)" - end + it "should return its representation with to_s" do + args = stub 'args', :is_a? => true, :to_s => "[a, b]" - describe "when evaluating" do + Puppet::Parser::AST::Function.new(:name => "func", :arguments => args).to_s.should == "func(a, b)" + end - it "should fail if the function doesn't exist" do - Puppet::Parser::Functions.stubs(:function).returns(false) - func = Puppet::Parser::AST::Function.new :name => "dontexist" + describe "when evaluating" do - lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError) - end + it "should fail if the function doesn't exist" do + Puppet::Parser::Functions.stubs(:function).returns(false) + func = Puppet::Parser::AST::Function.new :name => "dontexist" - it "should fail if the function is a statement used as rvalue" do - Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) - Puppet::Parser::Functions.stubs(:rvalue?).with("exist").returns(false) + lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError) + end - func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :rvalue + it "should fail if the function is a statement used as rvalue" do + Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) + Puppet::Parser::Functions.stubs(:rvalue?).with("exist").returns(false) - lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError, "Function 'exist' does not return a value") - end + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :rvalue - it "should fail if the function is an rvalue used as statement" do - Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) - Puppet::Parser::Functions.stubs(:rvalue?).with("exist").returns(true) + lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError, "Function 'exist' does not return a value") + end - func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement + it "should fail if the function is an rvalue used as statement" do + Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) + Puppet::Parser::Functions.stubs(:rvalue?).with("exist").returns(true) - lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError,"Function 'exist' must be the value of a statement") - end + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement - it "should evaluate its arguments" do - argument = stub 'arg' - Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) - func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument - @scope.stubs(:function_exist) + lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError,"Function 'exist' must be the value of a statement") + end - argument.expects(:safeevaluate).with(@scope).returns("argument") + it "should evaluate its arguments" do + argument = stub 'arg' + Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument + @scope.stubs(:function_exist) - func.evaluate(@scope) - end + argument.expects(:safeevaluate).with(@scope).returns("argument") - it "should call the underlying ruby function" do - argument = stub 'arg', :safeevaluate => "nothing" - Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) - func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument + func.evaluate(@scope) + end - @scope.expects(:function_exist).with("nothing") + it "should call the underlying ruby function" do + argument = stub 'arg', :safeevaluate => "nothing" + Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument - func.evaluate(@scope) - end + @scope.expects(:function_exist).with("nothing") - it "should return the ruby function return for rvalue functions" do - argument = stub 'arg', :safeevaluate => "nothing" - Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) - func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument - @scope.stubs(:function_exist).with("nothing").returns("returning") + func.evaluate(@scope) + end - func.evaluate(@scope).should == "returning" - end + it "should return the ruby function return for rvalue functions" do + argument = stub 'arg', :safeevaluate => "nothing" + Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument + @scope.stubs(:function_exist).with("nothing").returns("returning") + func.evaluate(@scope).should == "returning" end + + end end |