class RSpec::Puppet::Augeas::Matchers::Execute

<subject>.should execute()

where subject must be an Augeas resource

Attributes

change[R]
idempotent[R]
resource[R]

Public Class Methods

new() click to toggle source
# File lib/rspec-puppet-augeas/matchers/execute.rb, line 9
def initialize
  @change = false
  @idempotent = false
end

Public Instance Methods

description() click to toggle source
# File lib/rspec-puppet-augeas/matchers/execute.rb, line 35
def description
  if idempotent && change
    "change once only (idempotently)"
  elsif idempotent
    "change at most once (idempotently)"
  elsif change
    "change successfully at least once"
  else
    "execute without failure"
  end
end
failure_message_for_should() click to toggle source
# File lib/rspec-puppet-augeas/matchers/execute.rb, line 47
def failure_message_for_should
  if resource.txn.any_failed?
    "#{resource} fails when executing:\n#{format_logs(resource.logs)}"
  elsif change and !resource.txn.changed?.any?
    "#{resource} doesn't change when executed:\n#{format_logs(resource.logs)}"
  elsif idempotent and resource.idempotent.changed?.any?
    "#{resource} isn't idempotent, it changes on every run:\n#{format_logs(resource.logs_idempotent)}"
  end
end
failure_message_for_should_not() click to toggle source
# File lib/rspec-puppet-augeas/matchers/execute.rb, line 57
def failure_message_for_should_not
  if resource.txn.any_failed?
    "#{resource} succeeds when executed:\n#{format_logs(resource.logs)}"
  elsif change and !resource.txn.changed?.any?
    "#{resource} changes when executed:\n#{format_logs(resource.logs)}"
  elsif idempotent and resource.idempotent.changed?.any?
    "#{resource} is idempotent, it doesn't change on every run:\n#{format_logs(resource.logs_idempotent)}"
  end
end
idempotently() click to toggle source

verifies the resource only applies never or once at max

# File lib/rspec-puppet-augeas/matchers/execute.rb, line 30
def idempotently
  @idempotent = true
  self
end
matches?(resource) click to toggle source
# File lib/rspec-puppet-augeas/matchers/execute.rb, line 14
def matches?(resource)
  @resource = resource
  RSpec::Puppet::Coverage.cover!(resource)
  return false if resource.txn.any_failed?
  return false if change and !resource.txn.changed?.any?
  return false if idempotent and resource.idempotent.changed?.any?
  true
end
with_change() click to toggle source

verifies the resource was ‘applied’

# File lib/rspec-puppet-augeas/matchers/execute.rb, line 24
def with_change
  @change = true
  self
end

Private Instance Methods

format_logs(logs) click to toggle source
# File lib/rspec-puppet-augeas/matchers/execute.rb, line 69
def format_logs(logs)
  # Sometimes two transactions are run, sometimes one, so filter out the
  # first (it appears the idempotent test only sees one txn)
  if logs.map { |log| log.message }.grep(/Finishing transaction/).size > 1
    logs = logs.clone.drop_while { |log| log.message !~ /Finishing transaction/ }
    logs.shift
  end
  # Ignore everything after the txn end
  logs = logs.take_while { |log| log.message !~ /Finishing transaction/ }
  logs.map { |log| "#{log.level}: #{log.message}" }.join("\n")
end