Class: ChefSpec::Matchers::RenderFileMatcher
- Inherits:
-
Object
- Object
- ChefSpec::Matchers::RenderFileMatcher
- Defined in:
- lib/chefspec/matchers/render_file_matcher.rb
Instance Attribute Summary collapse
-
#expected_content ⇒ Object
readonly
Returns the value of attribute expected_content.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(path) ⇒ RenderFileMatcher
constructor
A new instance of RenderFileMatcher.
- #matches?(runner) ⇒ Boolean
- #with_content(expected_content = nil, &block) ⇒ Object
Constructor Details
#initialize(path) ⇒ RenderFileMatcher
Returns a new instance of RenderFileMatcher.
4 5 6 7 |
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 4 def initialize(path) @path = path @expected_content = [] end |
Instance Attribute Details
#expected_content ⇒ Object (readonly)
Returns the value of attribute expected_content.
3 4 5 |
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 3 def expected_content @expected_content end |
Instance Method Details
#description ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 34 def description = %Q{render file "#{@path}"} @expected_content.each do |expected| if expected.to_s.include?("\n") << " with content <suppressed>" else << " with content #{expected.inspect}" end end end |
#failure_message ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 46 def = %Q{expected Chef run to render "#{@path}"} unless @expected_content.empty? << " matching:" << "\n\n" << << "\n\n" << "but got:" << "\n\n" << @actual_content.to_s << "\n " end end |
#failure_message_when_negated ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 61 def = %Q{expected file "#{@path}"} unless @expected_content.empty? << " matching:" << "\n\n" << << "\n\n" end << " to not be in Chef run" end |
#matches?(runner) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 9 def matches?(runner) @runner = runner if resource ChefSpec::Coverage.cover!(resource) has_create_action? && matches_content? else false end end |
#with_content(expected_content = nil, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/chefspec/matchers/render_file_matcher.rb', line 20 def with_content(expected_content = nil, &block) if expected_content && block raise ArgumentError, "Cannot specify expected content and a block!" elsif expected_content @expected_content << expected_content elsif block_given? @expected_content << block else raise ArgumentError, "Must specify expected content or a block!" end self end |