class Puppet::Util::Assertion::Reporter

Attributes

evaluated[R]
failed[R]

Public Class Methods

new() click to toggle source
# File lib/puppet/util/assertion/reporter.rb, line 10
def initialize
  @evaluated = 0
  @failed = 0
end

Public Instance Methods

<<(assertion) click to toggle source

Given an assertion resource, evaluate it for success, and on failure, call the appropriate method responsible to render the message, and increment the counter(s).

# File lib/puppet/util/assertion/reporter.rb, line 18
def <<(assertion)
  count

  # If ensure is present, and the resource is not in the catalog
  if assertion[:ensure] == 'present' and not assertion[:subject].catalog
    fail
    expected_present(assertion)
    return

  # If ensure is absent, and the resource is in the catalog
  elsif assertion[:ensure] == 'absent' and assertion[:subject].catalog
    fail
    expected_absent(assertion)
    return
  end

  if assertion.provider.failed?
    fail
    inequal_value(assertion)
    return
  end

end
count() click to toggle source
# File lib/puppet/util/assertion/reporter.rb, line 126
def count
  @evaluated += 1
end
expected_absent(assertion) click to toggle source

Print the appropriate error message when an assertion’s subject is found in the catalog but was intended to be absent.

# File lib/puppet/util/assertion/reporter.rb, line 69
def expected_absent(assertion)
  # Shim the value of failed into the
  # local scope in order to access it
  # from the style proc.
  failed = @failed

  style do
    red      "#{failed}) Assertion #{assertion[:name]} failed on #{assertion[:subject].to_s}"
    newline
    blue     "  Subject was expected to be absent from the catalog, but was present"
    newline
    newline
  end
end
expected_present(assertion) click to toggle source

Print the appropriate error message when an assertion’s subject is not found in the catalog.

# File lib/puppet/util/assertion/reporter.rb, line 86
def expected_present(assertion)
  # Shim the value of failed into the
  # local scope in order to access it
  # from the style proc.
  failed = @failed

  style do
    red      "#{failed}) Assertion #{assertion[:name]} failed on #{assertion[:subject].to_s}"
    newline
    blue     "  Subject was expected to be present in the catalog, but was absent"
    newline
    newline
  end
end
fail() click to toggle source
# File lib/puppet/util/assertion/reporter.rb, line 130
def fail
  @failed += 1
end
inequal_value(assertion) click to toggle source

Pretty print the results of an assertion to the console

# File lib/puppet/util/assertion/reporter.rb, line 102
def inequal_value(assertion)
  # Shim the value of failed into the
  # local scope in order to access it
  # from the style proc.
  failed = @failed

  style do
    red      "#{failed}) Assertion #{assertion[:name]} failed on #{assertion[:subject].to_s}"
    newline

    yellow   "  On line #{assertion[:subject].line} of #{assertion.provider.relative_path}"
    newline

    blue     "  Wanted: "
    white    assertion.provider.wanted.to_s
    newline

    blue     "  Got:    "
    white    assertion.provider.got.to_s
    newline
    newline
  end
end
print_error(err) click to toggle source