File: generate_spec.rb

package info (click to toggle)
puppet 2.6.2-5%2Bsqueeze10
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 13,728 kB
  • ctags: 8,726
  • sloc: ruby: 110,196; sh: 937; lisp: 263; xml: 122; sql: 103; makefile: 90; python: 84
file content (41 lines) | stat: -rwxr-xr-x 1,477 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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