Class: BlueShell::Matchers::OutputMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_output, timeout = 30) ⇒ OutputMatcher

Returns a new instance of OutputMatcher.



6
7
8
9
# File 'lib/blue-shell/matchers/output_matcher.rb', line 6

def initialize(expected_output, timeout = 30)
  @expected_output = expected_output
  @timeout = timeout
end

Instance Attribute Details

#timeoutObject (readonly)

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Instance Method Details

#failure_messageObject



18
19
20
21
22
23
24
25
# File 'lib/blue-shell/matchers/output_matcher.rb', line 18

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:



11
12
13
14
15
16
# File 'lib/blue-shell/matchers/output_matcher.rb', line 11

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

#negative_failure_messageObject



27
28
29
30
31
32
33
34
35
# File 'lib/blue-shell/matchers/output_matcher.rb', line 27

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