Class: ChefSpec::Matchers::RenderFileMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ RenderFileMatcher

Returns a new instance of RenderFileMatcher


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

def initialize(path)
  @path = path
end

Instance Method Details

#descriptionObject


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 23

def description
  message = %Q{render file "#{@path}"}
  if @expected_content
    if @expected_content.to_s.include?("\n")
      message << " with content <suppressed>"
    else
      message << " with content #{@expected_content.inspect}"
    end
  end
  message
end

#failure_messageObject


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 35

def failure_message
  message = %Q{expected Chef run to render "#{@path}"}
  if @expected_content
    message << " matching:"
    message << "\n\n"
    message << expected_content_message
    message << "\n\n"
    message << "but got:"
    message << "\n\n"
    message << @actual_content.to_s
    message << "\n "
  end
  message
end

#failure_message_when_negatedObject


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 50

def failure_message_when_negated
  message = %Q{expected file "#{@path}"}
  if @expected_content
    message << " matching:"
    message << "\n\n"
    message << expected_content_message
    message << "\n\n"
  end
  message << " to not be in Chef run"
  message
end

#matches?(runner) ⇒ Boolean

Returns:

  • (Boolean)

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

def matches?(runner)
  @runner = runner

  if resource
    ChefSpec::Coverage.cover!(resource)
    has_create_action? && matches_content?
  else
    false
  end
end

#with_content(expected_content) ⇒ Object


18
19
20
21
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 18

def with_content(expected_content)
  @expected_content = expected_content
  self
end