Class: RSpec::Puppet::ManifestMatchers::Compile

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-puppet/matchers/compile.rb

Instance Method Summary collapse

Constructor Details

#initializeCompile

Returns a new instance of Compile.



6
7
8
9
10
11
# File 'lib/rspec-puppet/matchers/compile.rb', line 6

def initialize
  @failed_resource = ''
  @check_deps = false
  @cycles = []
  @error_msg = ''
end

Instance Method Details

#and_raise_error(error) ⇒ Object



18
19
20
21
# File 'lib/rspec-puppet/matchers/compile.rb', line 18

def and_raise_error(error)
  @expected_error = error
  self
end

#descriptionObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/rspec-puppet/matchers/compile.rb', line 43

def description
  case @expected_error
  when nil
    'compile into a catalogue without dependency cycles'
  when Regexp
    "fail to compile and raise an error matching #{@expected_error.inspect}"
  else
    "fail to compile and raise the error #{@expected_error.inspect}"
  end
end

#failure_messageObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rspec-puppet/matchers/compile.rb', line 54

def failure_message
  if @cycles.empty?
    if @error_msg.empty?
      case @expected_error
      when nil
        "expected that the catalogue would include #{@failed_resource}"
      when Regexp
        "expected that the catalogue would fail to compile and raise an error matching #{@expected_error.inspect}"
      else
        "expected that the catalogue would fail to compile and raise the error #{@expected_error.inspect}"
      end
    else
      "error during compilation: #{@error_msg}"
    end
  else
    "dependency cycles found: #{@cycles.join('; ')}"
  end
end

#failure_message_when_negatedObject



73
74
75
76
77
78
79
# File 'lib/rspec-puppet/matchers/compile.rb', line 73

def failure_message_when_negated
  if @expected_error.nil?
    'expected that the catalogue would not compile but it does'
  else
    'expected that the catalogue would compile but it does not'
  end
end

#matches?(catalogue) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rspec-puppet/matchers/compile.rb', line 23

def matches?(catalogue)
  @catalogue = catalogue.call

  if cycles_found?
    false
  elsif @check_deps == true && missing_dependencies?
    false
  else
    @expected_error.nil?
  end
rescue Puppet::Error => e
  @error_msg = e.message
  if @expected_error.nil?
    false
  else
    method = @expected_error.is_a?(Regexp) ? :=~ : :==
    e.message.send(method, @expected_error)
  end
end

#supports_block_expectationsObject



81
82
83
# File 'lib/rspec-puppet/matchers/compile.rb', line 81

def supports_block_expectations
  true
end

#supports_value_expectationsObject



85
86
87
# File 'lib/rspec-puppet/matchers/compile.rb', line 85

def supports_value_expectations
  true
end

#with_all_depsObject



13
14
15
16
# File 'lib/rspec-puppet/matchers/compile.rb', line 13

def with_all_deps
  @check_deps = true
  self
end