Class: RSpec::Puppet::TypeAliasMatchers::AllowValue

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

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ AllowValue

Returns a new instance of AllowValue.



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

def initialize(values)
  @values = values
  @error_msgs = []
end

Instance Method Details

#descriptionObject



22
23
24
25
26
27
28
# File 'lib/rspec-puppet/matchers/allow_value.rb', line 22

def description
  if @values.length == 1
    "match value #{@values.first.inspect}"
  else
    "match values #{@values.map(&:inspect).join(', ')}"
  end
end

#failure_messageObject



30
31
32
# File 'lib/rspec-puppet/matchers/allow_value.rb', line 30

def failure_message
  "expected that the type alias would " + description + " but it raised the #{@error_msgs.length == 1 ? 'error' : 'errors'} #{@error_msgs.join(', ')}"
end

#failure_message_when_negatedObject



34
35
36
# File 'lib/rspec-puppet/matchers/allow_value.rb', line 34

def failure_message_when_negated
  "expected that the type alias would not " + description + " but it does"
end

#matches?(catalogue) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rspec-puppet/matchers/allow_value.rb', line 9

def matches?(catalogue)
  matches = @values.map do |test_value|
    begin
      catalogue.call(test_value)
      true
    rescue Puppet::Error => e
      @error_msgs << e.message
      false
    end
  end
  matches.all?
end

#supports_block_expectationsObject



38
39
40
# File 'lib/rspec-puppet/matchers/allow_value.rb', line 38

def supports_block_expectations
  true
end

#supports_value_expectationsObject



42
43
44
# File 'lib/rspec-puppet/matchers/allow_value.rb', line 42

def supports_value_expectations
  true
end