class Puppet::Application::Spec

Attributes

reporter[R]

Public Instance Methods

catalog(path) click to toggle source
# File lib/puppet/application/spec.rb, line 54
def catalog(path)
  Puppet::Test::TestHelper.before_each_test
  Puppet[:code] = File.read(path)

  node = Puppet::Node.new("spec")
  modulepath = get_modulepath(node)
  link_module(modulepath)
  catalog = Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node)
  catalog.to_ral

  Puppet::Test::TestHelper.after_each_test
  catalog
end
evaluate_assertions() click to toggle source
# File lib/puppet/application/spec.rb, line 27
def evaluate_assertions
  if options[:manifest]
    process_spec(options[:manifest])
  else
    process_spec_directory(specdir)
  end
end
get_modulepath(node) click to toggle source

Given a node object, return the first modulepath

# File lib/puppet/application/spec.rb, line 70
def get_modulepath(node)
  node.environment.full_modulepath[0]
end
process_spec(path) click to toggle source
# File lib/puppet/application/spec.rb, line 39
def process_spec(path)
  catalog = catalog(path)

  assertions = catalog.resources.select {|res| res.type == 'Assertion' }
  assertions.each do |res|
    # Get the subject resource from the catalog rather than the
    # reference provided from the parser. The reference's resource
    # object does not contain any parameters for whatever reason.
    catalog_subject = catalog.resource(res[:subject].to_s)
    res[:subject] = catalog_subject if catalog_subject

    reporter << res.to_ral
  end
end
process_spec_directory(specdir) click to toggle source
# File lib/puppet/application/spec.rb, line 35
def process_spec_directory(specdir)
  Dir.glob("#{specdir}/**/*_spec.pp").map { |spec| process_spec(spec) }
end
run_command() click to toggle source
# File lib/puppet/application/spec.rb, line 12
def run_command
  @reporter = Puppet::Util::Assertion::Reporter.new

  begin
    Puppet::Test::TestHelper.initialize
    evaluate_assertions
    reporter.print_footer
  rescue Exception => e
    reporter.print_error(e)
  end

  exit 1 unless reporter.failed == 0
  exit 0
end
specdir() click to toggle source

Return the specdir under the CWD or raise an error if not found.

# File lib/puppet/application/spec.rb, line 94
def specdir
  pwd = Dir.pwd
  specdir = File.join(pwd, 'spec')
  unless Dir.exist?(specdir)
    raise 'No spec directory was found under the CWD. A spec manifest can be specified with the --manifest flag'
  end
  specdir
end