Class: ChefSpec::Matchers::LinkToMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LinkToMatcher

Returns a new instance of LinkToMatcher.



3
4
5
# File 'lib/chefspec/matchers/link_to_matcher.rb', line 3

def initialize(path)
  @path = path
end

Instance Method Details

#descriptionObject



21
22
23
# File 'lib/chefspec/matchers/link_to_matcher.rb', line 21

def description
  %Q{link to "#{@path}"}
end

#failure_messageObject



25
26
27
28
29
30
31
# File 'lib/chefspec/matchers/link_to_matcher.rb', line 25

def failure_message
  if @link.nil?
    %Q{expected "link[#{@path}]" with action :create to be in Chef run}
  else
    %Q{expected "#{@link}" to link to "#{@path}" but was "#{@link.to}"}
  end
end

#failure_message_when_negatedObject



33
34
35
# File 'lib/chefspec/matchers/link_to_matcher.rb', line 33

def failure_message_when_negated
  %Q{expected "#{@link}" to not link to "#{@path}"}
end

#matches?(link) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/chefspec/matchers/link_to_matcher.rb', line 7

def matches?(link)
  @link = link

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

    @link.is_a?(Chef::Resource::Link) &&
      @link.performed_action?(:create) &&
      @path === @link.to
  else
    false
  end
end