class HammerCLI::Testing::OutputMatchers::OutputMatcher

Attributes

expected_lines[RW]

Public Class Methods

new(expected="", options={}) click to toggle source
# 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

Public Instance Methods

assert_match(actual) click to toggle source
# File lib/hammer_cli/testing/output_matchers.rb, line 39
def assert_match(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)
  assert(actual.include?(expected_lines), message)
end

Protected Instance Methods

strip_lines(lines) click to toggle source
# File lib/hammer_cli/testing/output_matchers.rb, line 54
def strip_lines(lines)
  lines.map(&:rstrip)
end