Class: ChefSpec::Matchers::DoNothingMatcher

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

Instance Method Summary collapse

Instance Method Details

#descriptionObject


16
17
18
# File 'lib/chefspec/matchers/do_nothing_matcher.rb', line 16

def description
  'do nothing'
end

#failure_messageObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chefspec/matchers/do_nothing_matcher.rb', line 20

def failure_message
  if @resource
    message =  %|expected #{@resource} to do nothing, but the following |
    message << %|actions were performed:|
    message << %|\n\n|
    @resource.performed_actions.each do |action|
      message << %|  :#{action}|
    end
    message
  else
    message =  %|expected _something_ to do nothing, but the _something_ |
    message << %|you gave me was nil! If you are running a test like:|
    message << %|\n\n|
    message << %|  expect(_something_).to do_nothing|
    message << %|\n\n|
    message << %|make sure that `_something_` exists, because I got nil!|
    message
  end
end

#failure_message_when_negatedObject


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chefspec/matchers/do_nothing_matcher.rb', line 40

def failure_message_when_negated
  if @resource
    message =  %|expected #{@resource} to do something, but no actions |
    message << %|were performed.|
    message
  else
    message =  %|expected _something_ to do something, but no actions |
    message << %|were performed.|
    message
  end
end

#matches?(resource) ⇒ Boolean

Returns:

  • (Boolean)

3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/chefspec/matchers/do_nothing_matcher.rb', line 3

def matches?(resource)
  @resource = resource

  if @resource
    ChefSpec::Coverage.cover!(@resource)

    actions = @resource.performed_actions
    actions.empty? || actions == [:nothing]
  else
    false
  end
end