[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585
Brice Figureau
brice-puppet at daysofwonder.com
Fri Jan 23 14:21:47 UTC 2009
The following commit has been merged in the master branch:
commit d8c741f9d3b07b11f11af0765d740d9e78889794
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date: Wed Nov 26 23:18:45 2008 +0100
Fix #1741 - Puppet::Parser::Functions rmfunctions and unit test
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index 5fb0439..b1cd0d0 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -54,6 +54,20 @@ module Functions
end
end
+ # Remove a function added by newfunction
+ def self.rmfunction(name)
+ name = symbolize(name)
+
+ unless @functions.include? name
+ raise Puppet::DevError, "Function %s is not defined" % name
+ end
+
+ @functions.delete(name)
+
+ fname = "function_" + name.to_s
+ Puppet::Parser::Scope.send(:remove_method, fname)
+ end
+
# Determine if a given name is a function
def self.function(name)
name = symbolize(name)
diff --git a/spec/unit/parser/functions.rb b/spec/unit/parser/functions.rb
new file mode 100644
index 0000000..8d0492d
--- /dev/null
+++ b/spec/unit/parser/functions.rb
@@ -0,0 +1,83 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Parser::Functions do
+
+ before(:each) do
+ end
+
+ after(:each) do
+ # Rationale:
+ # our various tests will almost all register to Pupet::Parser::Functions
+ # a new function called "name". All tests are required to stub Puppet::Parser::Scope
+ # so that +no+ new real ruby method are defined.
+ # After each test, we want to leave the whole Puppet::Parser::Functions environment
+ # as it was before we were called, hence we call rmfunction (which might not succeed
+ # if the function hasn't been registered in the test). It is also important in this
+ # section to stub +remove_method+ here so that we don't pollute the scope.
+ Puppet::Parser::Scope.stubs(:remove_method)
+ begin
+ Puppet::Parser::Functions.rmfunction("name")
+ rescue
+ end
+ end
+
+ describe "when calling newfunction" do
+ it "should create the function in the scope class" do
+ Puppet::Parser::Scope.expects(:define_method).with("function_name", nil)
+
+ Puppet::Parser::Functions.newfunction("name", :type => :rvalue)
+ end
+
+ it "should raise an error if the function already exists" do
+ Puppet::Parser::Scope.expects(:define_method).with("function_name", nil).once
+ Puppet::Parser::Functions.newfunction("name", :type => :rvalue)
+
+ lambda { Puppet::Parser::Functions.newfunction("name", :type => :rvalue) }.should raise_error
+ end
+
+ it "should raise an error if the function type is not correct" do
+ Puppet::Parser::Scope.expects(:define_method).with("function_name", nil).never
+
+ lambda { Puppet::Parser::Functions.newfunction("name", :type => :unknown) }.should raise_error
+ end
+ end
+
+ describe "when calling rmfunction" do
+ it "should remove the function in the scope class" do
+ Puppet::Parser::Scope.stubs(:define_method).with("function_name", nil)
+ Puppet::Parser::Functions.newfunction("name", :type => :rvalue)
+
+ Puppet::Parser::Scope.expects(:remove_method).with("function_name").once
+
+ Puppet::Parser::Functions.rmfunction("name")
+ end
+
+ it "should raise an error if the function doesn't exists" do
+ lambda { Puppet::Parser::Functions.rmfunction("name") }.should raise_error
+ end
+ end
+
+ describe "when calling function to test function existance" do
+
+ it "should return false if the function doesn't exist" do
+ Puppet::Parser::Functions.autoloader.stubs(:load)
+
+ Puppet::Parser::Functions.function("name").should be_false
+ end
+
+ it "should return it's name if the function exists" do
+ Puppet::Parser::Scope.stubs(:define_method).with("function_name", nil)
+ Puppet::Parser::Functions.newfunction("name", :type => :rvalue)
+
+ Puppet::Parser::Functions.function("name").should == "function_name"
+ end
+
+ it "should try to autoload the function if it doesn't exist yet" do
+ Puppet::Parser::Functions.autoloader.expects(:load)
+
+ Puppet::Parser::Functions.function("name")
+ end
+ end
+end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list