Top Level Namespace

Defined Under Namespace

Modules: Puppet, PuppetlabsSpec, PuppetlabsSpecHelper, RSpec

Instance Method Summary collapse

Instance Method Details

#clone_repo(scm, remote, target, ref = nil, branch = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 59

def clone_repo(scm, remote, target, ref=nil, branch=nil)
  args = []
  case scm
  when 'hg'
    args.push('clone')
    args.push('-u', ref) if ref
    args.push(remote, target)
  when 'git'
    args.push('clone')
    args.push('-b', branch) if branch
    args.push(remote, target)
  else
      fail "Unfortunately #{scm} is not supported yet"
  end
  system("#{scm} #{args.flatten.join ' '}")
end

#fixtures(category) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 30

def fixtures(category)
  begin
    fixtures = YAML.load_file(".fixtures.yml")["fixtures"]
  rescue Errno::ENOENT
    return {}
  end

  if not fixtures
    abort("malformed fixtures.yml")
  end

  result = {}
  if fixtures.include? category and fixtures[category] != nil
    fixtures[category].each do |fixture, opts|
      if opts.instance_of?(String)
        source = opts
        target = "spec/fixtures/modules/#{fixture}"
        real_source = eval('"'+source+'"')
        result[real_source] = target
      elsif opts.instance_of?(Hash)
        target = "spec/fixtures/modules/#{fixture}"
        real_source = eval('"'+opts["repo"]+'"')
        result[real_source] = { "target" => target, "ref" => opts["ref"], "branch" => opts["branch"], "scm" => opts["scm"] }
      end
    end
  end
  return result
end

#param_value(subject, type, title, param) ⇒ Object



5
6
7
# File 'lib/puppetlabs_spec_helper/module_spec_helper.rb', line 5

def param_value(subject, type, title, param)
  subject.resource(type, title).send(:parameters)[param.to_sym]
end

#revision(scm, target, ref) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 76

def revision(scm, target, ref)
  args = []
  case scm
  when 'hg'
    args.push('update', 'clean', '-r', ref)
  when 'git'
    args.push('reset', '--hard', ref)
  else
      fail "Unfortunately #{scm} is not supported yet"
  end
  system("cd #{target} && #{scm} #{args.flatten.join ' '}")
end

#source_dirObject

This is a helper for the self-symlink entry of fixtures.yml



26
27
28
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 26

def source_dir
  Dir.pwd
end

#verify_contents(subject, title, expected_lines) ⇒ Object



9
10
11
12
# File 'lib/puppetlabs_spec_helper/module_spec_helper.rb', line 9

def verify_contents(subject, title, expected_lines)
  content = subject.resource('file', title).send(:parameters)[:content]
  (content.split("\n") & expected_lines).should == expected_lines
end