Class: RSpec::Matchers::BuiltIn::Output Private

Inherits:
BaseMatcher show all
Defined in:
lib/rspec/matchers/built_in/output.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides the implementation for output. Not intended to be instantiated directly.

Constant Summary

Constant Summary

Constants inherited from BaseMatcher

BaseMatcher::UNDEFINED

Instance Method Summary collapse

Methods inherited from BaseMatcher

#expects_call_stack_jump?, #match_unless_raises

Methods included from Composable

#===, #and, #description_of, enumerable?, #or, surface_descriptions_in, #values_match?

Methods included from Pretty

#name, split_words, #to_sentence, #to_word

Constructor Details

#initialize(expected) ⇒ Output

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Output



10
11
12
13
14
15
# File 'lib/rspec/matchers/built_in/output.rb', line 10

def initialize(expected)
  @expected        = expected
  @actual          = ""
  @block           = nil
  @stream_capturer = NullCapture
end

Instance Method Details

#descriptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


56
57
58
59
60
61
62
# File 'lib/rspec/matchers/built_in/output.rb', line 56

def description
  if @expected
    "output #{description_of @expected} to #{@stream_capturer.name}"
  else
    "output to #{@stream_capturer.name}"
  end
end

#diffable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


66
67
68
# File 'lib/rspec/matchers/built_in/output.rb', line 66

def diffable?
  true
end

#does_not_match?(block) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


24
25
26
# File 'lib/rspec/matchers/built_in/output.rb', line 24

def does_not_match?(block)
  !matches?(block) && Proc === block
end

#failure_messageString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


44
45
46
# File 'lib/rspec/matchers/built_in/output.rb', line 44

def failure_message
  "expected block to #{description}, but #{positive_failure_reason}"
end

#failure_message_when_negatedString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


50
51
52
# File 'lib/rspec/matchers/built_in/output.rb', line 50

def failure_message_when_negated
  "expected block to not #{description}, but #{negative_failure_reason}"
end

#matches?(block) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/rspec/matchers/built_in/output.rb', line 17

def matches?(block)
  @block = block
  return false unless Proc === block
  @actual = @stream_capturer.capture(block)
  @expected ? values_match?(@expected, @actual) : captured?
end

#supports_block_expectations?True

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Indicates this matcher matches against a block.

Returns:

  • (True)


73
74
75
# File 'lib/rspec/matchers/built_in/output.rb', line 73

def supports_block_expectations?
  true
end

#to_stderrObject

Tells the matcher to match against stderr.



37
38
39
40
# File 'lib/rspec/matchers/built_in/output.rb', line 37

def to_stderr
  @stream_capturer = CaptureStderr
  self
end

#to_stdoutObject

Tells the matcher to match against stdout.



30
31
32
33
# File 'lib/rspec/matchers/built_in/output.rb', line 30

def to_stdout
  @stream_capturer = CaptureStdout
  self
end