Class: ChefSpec::Matchers::SubscribesMatcher

Inherits:
Object
  • Object
show all
Includes:
Normalize
Defined in:
lib/chefspec/matchers/subscribes_matcher.rb

Instance Method Summary collapse

Methods included from Normalize

#resource_name

Constructor Details

#initialize(signature) ⇒ SubscribesMatcher


5
6
7
8
9
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 5

def initialize(signature)
  signature.match(/^([^\[]*)\[(.*)\]$/)
  @expected_resource_type = $1
  @expected_resource_name = $2
end

Instance Method Details

#delayedObject


46
47
48
49
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 46

def delayed
  @delayed = true
  self
end

#descriptionObject


51
52
53
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 51

def description
  @instance.description
end

#failure_messageObject


55
56
57
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 55

def failure_message
  @instance.failure_message
end

#failure_message_when_negatedObject


59
60
61
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 59

def failure_message_when_negated
  @instance.failure_message_when_negated
end

#immediatelyObject


41
42
43
44
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 41

def immediately
  @immediately = true
  self
end

#matches?(resource) ⇒ Boolean


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 11

def matches?(resource)
  @instance = ChefSpec::Matchers::NotificationsMatcher.new(resource.to_s)

  if @action
    @instance.to(@action)
  end

  if @immediately
    @instance.immediately
  end

  if @delayed
    @instance.delayed
  end

  if resource
    runner   = resource.run_context.node.runner
    expected = runner.find_resource(@expected_resource_type, @expected_resource_name)

    @instance.matches?(expected)
  else
    @instance.matches?(nil)
  end
end

#on(action) ⇒ Object


36
37
38
39
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 36

def on(action)
  @action = action
  self
end