Class: HammerCLI::Testing::OutputMatchers::OutputMatcher

Inherits:
MatcherBase
  • Object
show all
Defined in:
lib/hammer_cli/testing/output_matchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected = "", options = {}) ⇒ OutputMatcher

Returns a new instance of OutputMatcher.



34
35
36
37
# File 'lib/hammer_cli/testing/output_matchers.rb', line 34

def initialize(expected="", options={})
  @expected_lines = expected.is_a?(Array) ? expected : [expected]
  @ignore_whitespace = options.fetch(:ignore_whitespace, true)
end

Instance Attribute Details

#expected_linesObject

Returns the value of attribute expected_lines.



32
33
34
# File 'lib/hammer_cli/testing/output_matchers.rb', line 32

def expected_lines
  @expected_lines
end

Instance Method Details

#assert_match(test_ctx, actual) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/hammer_cli/testing/output_matchers.rb', line 39

def assert_match(test_ctx, actual)
  if @ignore_whitespace
    expected_lines = strip_lines(@expected_lines)
    actual = strip_lines(actual.split("\n")).join("\n")
  else
    expected_lines = @expected_lines
  end
  expected_lines = expected_lines.join("\n")

  message = "Output didn't contain expected lines:\n" + diff(expected_lines, actual)
  test_ctx.assert(actual.include?(expected_lines), message)
end