diff options
author | Luke Kanies <luke@madstop.com> | 2008-12-02 16:26:54 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-12-02 16:26:54 -0600 |
commit | 99a9b5a045af6f1c68619792a45603cbe450652d (patch) | |
tree | 579963d464c0529d4e9250f937d495e415f1e867 /spec/unit/parser/ast/function.rb | |
parent | f73e13e7464edab73443857d628602b89361c220 (diff) | |
parent | 278bfe83015312292360f727d6532a143610db0d (diff) | |
download | puppet-99a9b5a045af6f1c68619792a45603cbe450652d.tar.gz puppet-99a9b5a045af6f1c68619792a45603cbe450652d.tar.xz puppet-99a9b5a045af6f1c68619792a45603cbe450652d.zip |
Merge branch '0.24.x'
Conflicts:
bin/puppetca
lib/puppet/type/group.rb
lib/puppet/type/tidy.rb
lib/puppet/util/settings.rb
Also edited the following files so tests will pass:
lib/puppet/type/component.rb
spec/unit/ssl/certificate_request.rb
spec/unit/type/computer.rb
spec/unit/type/mcx.rb
spec/unit/type/resources.rb
spec/unit/util/settings.rb
spec/unit/util/storage.rb
test/ral/type/zone.rb
Diffstat (limited to 'spec/unit/parser/ast/function.rb')
-rw-r--r-- | spec/unit/parser/ast/function.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/unit/parser/ast/function.rb b/spec/unit/parser/ast/function.rb new file mode 100644 index 000000000..15420132f --- /dev/null +++ b/spec/unit/parser/ast/function.rb @@ -0,0 +1,77 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::Function do + 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) + + lambda{ Puppet::Parser::AST::Function.new :name => "dontexist" }.should_not raise_error(Puppet::ParseError) + + end + end + + describe "when evaluating" do + + 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" + + lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError) + end + + 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) + + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :rvalue + + lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError, "Function 'exist' does not return a value") + end + + 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) + + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement + + lambda{ func.evaluate(@scope) }.should raise_error(Puppet::ParseError,"Function 'exist' must be the value of a statement") + end + + 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) + + argument.expects(:safeevaluate).with(@scope).returns("argument") + + func.evaluate(@scope) + end + + 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 + + @scope.expects(:function_exist).with("nothing") + + func.evaluate(@scope) + 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 |