class ChefSpec::Matchers::StateAttrsMatcher
Public Class Methods
new(state_attrs)
click to toggle source
Create a new state_attrs
matcher.
@param [Array] state_attrs
# File lib/chefspec/matchers/state_attrs_matcher.rb, line 8 def initialize(state_attrs) @expected_attrs = state_attrs.map(&:to_sym) end
Public Instance Methods
description()
click to toggle source
# File lib/chefspec/matchers/state_attrs_matcher.rb, line 17 def description %Q{have state attributes #{@expected_attrs.inspect}} end
failure_message()
click to toggle source
# 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_negated()
click to toggle source
# 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)
click to toggle source
# File lib/chefspec/matchers/state_attrs_matcher.rb, line 12 def matches?(resource) @resource = resource @resource && matches_state_attrs? end
Private Instance Methods
matches_state_attrs?()
click to toggle source
Determine if all the expected state attributes are present on the given resource.
@return [true, false]
# File lib/chefspec/matchers/state_attrs_matcher.rb, line 58 def matches_state_attrs? @expected_attrs == state_attrs end
state_attrs()
click to toggle source
The list of state attributes declared on the given resource.
@return [Array<Symbol>]
# File lib/chefspec/matchers/state_attrs_matcher.rb, line 67 def state_attrs @resource.class.state_attrs.map(&:to_sym) end