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.



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

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

Instance Method Details

#and_raise_error(error) ⇒ Object



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

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
  unless @cycles.empty?
    "dependency cycles found: #{@cycles.join('; ')}"
  else
    unless @error_msg.empty?
      "error during compilation: #{@error_msg}"
    else
      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
    end
  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)


21
22
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 21

def matches?(catalogue)
  begin
    @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
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



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

def with_all_deps
  @check_deps = true
  self
end