Class: RSpec::Puppet::Matchers::CreateGeneric
- Inherits:
-
Object
- Object
- RSpec::Puppet::Matchers::CreateGeneric
show all
- Defined in:
- lib/rspec-puppet/matchers/create_generic.rb
Instance Method Summary
collapse
Constructor Details
#initialize(*args, &block) ⇒ CreateGeneric
Returns a new instance of CreateGeneric.
4
5
6
7
8
9
10
|
# File 'lib/rspec-puppet/matchers/create_generic.rb', line 4
def initialize(*args, &block)
@exp_resource_type = args.shift.to_s.gsub(/^(create|contain)_/, '')
@args = args
@block = block
@referenced_type = referenced_type(@exp_resource_type)
@title = args[0]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/rspec-puppet/matchers/create_generic.rb', line 12
def method_missing(method, *args, &block)
if method.to_s =~ /^with_/
param = method.to_s.gsub(/^with_/, '')
(@expected_params ||= []) << [param, args[0]]
self
else
super
end
end
|
Instance Method Details
#description ⇒ Object
50
51
52
|
# File 'lib/rspec-puppet/matchers/create_generic.rb', line 50
def description
"create #{@referenced_type}[\"#{@title}\"]"
end
|
#failure_message_for_should ⇒ Object
42
43
44
|
# File 'lib/rspec-puppet/matchers/create_generic.rb', line 42
def failure_message_for_should
"expected that the catalogue would contain #{@referenced_type}[\"#{@title}\"]#{errors}"
end
|
#failure_message_for_should_not ⇒ Object
46
47
48
|
# File 'lib/rspec-puppet/matchers/create_generic.rb', line 46
def failure_message_for_should_not
"expected that the catalogue would not contain #{@referenced_type}[\"#{@title}\"]#{errors}"
end
|
#matches?(catalogue) ⇒ Boolean
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/rspec-puppet/matchers/create_generic.rb', line 22
def matches?(catalogue)
ret = true
resource = catalogue.resource(@referenced_type, @title)
if resource.nil?
ret = false
else
if @expected_params
@expected_params.each do |name, value|
unless resource.send(:parameters)[name.to_sym].to_s == value.to_s
ret = false
(@errors ||= []) << "#{name.to_s} set to `#{value.inspect}`"
end
end
end
end
ret
end
|