summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/functions/generate.rb
diff options
context:
space:
mode:
authorPaul Lathrop <plathrop@digg.com>2010-04-06 18:19:34 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit3d395e857b588a8832430bf450c45b2fc37765e4 (patch)
tree1630c02705b7d7f3e773c32f8d0add8d33d4bfa5 /spec/unit/parser/functions/generate.rb
parent0f077c78922994e74025c207436b3fb1d32c4249 (diff)
downloadpuppet-3d395e857b588a8832430bf450c45b2fc37765e4.tar.gz
puppet-3d395e857b588a8832430bf450c45b2fc37765e4.tar.xz
puppet-3d395e857b588a8832430bf450c45b2fc37765e4.zip
Fixes #3295 - generate() now sets the working directory to the directory containing the specified command.
Also adds rspec tests for generate().
Diffstat (limited to 'spec/unit/parser/functions/generate.rb')
-rwxr-xr-xspec/unit/parser/functions/generate.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/generate.rb b/spec/unit/parser/functions/generate.rb
new file mode 100755
index 000000000..05c2cb7dc
--- /dev/null
+++ b/spec/unit/parser/functions/generate.rb
@@ -0,0 +1,41 @@
+#! /usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the generate function" do
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("generate").should == "function_generate"
+ end
+
+ it "should accept a fully-qualified path as a command" do
+ command = File::SEPARATOR + "command"
+ Puppet::Util.expects(:execute).with([command]).returns("yay")
+ lambda { @scope.function_generate([command]) }.should_not raise_error(Puppet::ParseError)
+ end
+
+ it "should not accept a relative path as a command" do
+ command = "command"
+ lambda { @scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
+ end
+
+ # Really not sure how to implement this test, just sure it needs
+ # to be implemented.
+ it "should not accept a command containing illegal characters"
+
+ it "should not accept a command containing '..'" do
+ command = File::SEPARATOR + "command" + File::SEPARATOR + ".." + File::SEPARATOR
+ lambda { @scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should execute the generate script with the correct working directory" do
+ command = File::SEPARATOR + "command"
+ Dir.expects(:chdir).with(File.dirname(command)).yields
+ Puppet::Util.expects(:execute).with([command]).returns("yay")
+ lambda { @scope.function_generate([command]) }.should_not raise_error(Puppet::ParseError)
+ end
+end