Class: ChefSpec::Matchers::StateAttrsMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/chefspec/matchers/state_attrs_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(state_attrs) ⇒ StateAttrsMatcher

Create a new state_attrs matcher.

Parameters:

  • state_attrs (Array)

8
9
10
# File 'lib/chefspec/matchers/state_attrs_matcher.rb', line 8

def initialize(state_attrs)
  @expected_attrs = state_attrs.map(&:to_sym)
end

Instance Method Details

#descriptionObject


17
18
19
# File 'lib/chefspec/matchers/state_attrs_matcher.rb', line 17

def description
  %Q{have state attributes #{@expected_attrs.inspect}}
end

#failure_messageObject


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chefspec/matchers/state_attrs_matcher.rb', line 21

def failure_message
  if @resource
    "expected #{state_attrs.inspect} to equal #{@expected_attrs.inspect}"
  else
    "expected _something_ to have state attributes, but the " \
    "_something_ you gave me was nil!" \
    "\n" \
    "Ensure the resource exists before making assertions:" \
    "\n\n" \
    "  expect(resource).to be" \
    "\n "
  end
end

#failure_message_when_negatedObject


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chefspec/matchers/state_attrs_matcher.rb', line 35

def failure_message_when_negated
  if @resource
    "expected #{state_attrs.inspect} to not equal " \
    "#{@expected_attrs.inspect}"
  else
    "expected _something_ to not have state attributes, but the " \
    "_something_ you gave me was nil!" \
    "\n" \
    "Ensure the resource exists before making assertions:" \
    "\n\n" \
    "  expect(resource).to be" \
    "\n "
  end
end

#matches?(resource) ⇒ Boolean

Returns:

  • (Boolean)

12
13
14
15
# File 'lib/chefspec/matchers/state_attrs_matcher.rb', line 12

def matches?(resource)
  @resource = resource
  @resource && matches_state_attrs?
end