From fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Mon, 28 Jun 2010 17:10:20 -0700 Subject: [#3994-part 3] rename spec tests from *_spec_spec to *_spec.rb Part 2 re-did the change on the spec files, which it shouldn't have. --- spec/unit/parser/ast/function_spec.rb | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 spec/unit/parser/ast/function_spec.rb (limited to 'spec/unit/parser/ast/function_spec.rb') diff --git a/spec/unit/parser/ast/function_spec.rb b/spec/unit/parser/ast/function_spec.rb new file mode 100644 index 000000000..bb687eac0 --- /dev/null +++ b/spec/unit/parser/ast/function_spec.rb @@ -0,0 +1,83 @@ +#!/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 + + 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 + + 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 -- cgit