Class: WIP::Runner::Spec::Helpers::Matchers::ShowMatcher

Inherits:
RSpec::Matchers::BuiltIn::Output
  • Object
show all
Defined in:
lib/wip/runner/spec/helpers/matchers.rb

Defined Under Namespace

Modules: Capturer

Instance Method Summary collapse

Constructor Details

#initialize(example, expected, stream, match) ⇒ ShowMatcher

Returns a new instance of ShowMatcher.



13
14
15
16
17
18
# File 'lib/wip/runner/spec/helpers/matchers.rb', line 13

def initialize(example, expected, stream, match)
  super(expected)
  @example = example
  @stream  = stream
  @match   = match
end

Instance Method Details

#descriptionObject



35
36
37
# File 'lib/wip/runner/spec/helpers/matchers.rb', line 35

def description
  "STD#{@stream.upcase} to receive the following content (#{@match} match):"
end

#failure_messageObject



39
40
41
42
43
44
45
46
47
# File 'lib/wip/runner/spec/helpers/matchers.rb', line 39

def failure_message
  [
    "expected #{description}",
    "Expected:",
    "#{@expected}\n",
    "Actual:",
    "#{@actual}\n\n"
  ].join("\n\n")
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wip/runner/spec/helpers/matchers.rb', line 20

def matches?(block)
  @block = block
  return false unless Proc === block

  @expected = @expected.strip
  @actual = Capturer.capture(@example.ui, @stream, block)
  @actual = @example.strip_heredoc(@actual).strip

  if @match == :partial
    values_match?(/#{Regexp.escape(@expected)}/, @actual)
  else
    values_match?(@expected, @actual)
  end
end