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

Returns a new instance of 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

#beforeObject


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

def before
  @before = true
  self
end

#delayedObject


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

def delayed
  @delayed = true
  self
end

#descriptionObject


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

def description
  @instance.description
end

#failure_messageObject


64
65
66
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 64

def failure_message
  @instance.failure_message
end

#failure_message_when_negatedObject


68
69
70
# File 'lib/chefspec/matchers/subscribes_matcher.rb', line 68

def failure_message_when_negated
  @instance.failure_message_when_negated
end

#immediatelyObject


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

def immediately
  @immediately = true
  self
end

#matches?(resource) ⇒ Boolean

Returns:

  • (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
35
36
37
38
# 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 @before
    @instance.before
  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


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

def on(action)
  @action = action
  self
end