Class: BlueShell::Matchers::OutputMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/blue-shell/matchers/output_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_output) ⇒ OutputMatcher

Returns a new instance of OutputMatcher.



4
5
6
# File 'lib/blue-shell/matchers/output_matcher.rb', line 4

def initialize(expected_output)
  @expected_output = expected_output
end

Instance Method Details

#failure_messageObject



15
16
17
18
19
20
21
22
# File 'lib/blue-shell/matchers/output_matcher.rb', line 15

def failure_message
  if @expected_output.is_a?(Hash)
    expected_keys = @expected_output.keys.map{|key| "'#{key}'"}.join(', ')
    "expected one of #{expected_keys} to be printed, but it wasn't. full output:\n#@full_output"
  else
    "expected '#{@expected_output}' to be printed, but it wasn't. full output:\n#@full_output"
  end
end

#matches?(runner) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



8
9
10
11
12
13
# File 'lib/blue-shell/matchers/output_matcher.rb', line 8

def matches?(runner)
  raise Errors::InvalidInputError unless runner.respond_to?(:expect)
  @matched = runner.expect(@expected_output)
  @full_output = runner.output
  !!@matched
end

#negative_failure_messageObject



24
25
26
27
28
29
30
31
32
# File 'lib/blue-shell/matchers/output_matcher.rb', line 24

def negative_failure_message
  if @expected_output.is_a?(Hash)
    match = @matched
  else
    match = @expected_output
  end

  "expected '#{match}' to not be printed, but it was. full output:\n#@full_output"
end