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: CaptureHighline

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ShowMatcher.



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

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

Instance Method Details

#descriptionObject



38
39
40
# File 'lib/wip/runner/spec/helpers/matchers.rb', line 38

def description
  "#{@stream_capturer.name} to receive the following content (#{@match} match):"
end

#failure_messageObject



42
43
44
45
46
47
48
49
50
# File 'lib/wip/runner/spec/helpers/matchers.rb', line 42

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

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


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

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

  @expected = @expected.strip

  if @output == :highline
    @actual = @stream_capturer.capture(@example.io, block)
    @actual = @example.strip_heredoc(@actual).strip
  else
    @actual = @stream_capturer.capture(block).strip
  end

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

#to_highlineObject



52
53
54
55
# File 'lib/wip/runner/spec/helpers/matchers.rb', line 52

def to_highline
  @stream_capturer = CaptureHighline
  self
end