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

- (Output) initialize(expected)

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



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

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

Instance Method Details

- (String) description

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)


77
78
79
80
81
82
83
# File 'lib/rspec/matchers/built_in/output.rb', line 77

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

- (Boolean) diffable?

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)


87
88
89
# File 'lib/rspec/matchers/built_in/output.rb', line 87

def diffable?
  true
end

- (Boolean) does_not_match?(block)

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)


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

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

- (String) failure_message

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)


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

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

- (String) failure_message_when_negated

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)


71
72
73
# File 'lib/rspec/matchers/built_in/output.rb', line 71

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

- (Boolean) matches?(block)

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)


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

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

- (True) supports_block_expectations?

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)


94
95
96
# File 'lib/rspec/matchers/built_in/output.rb', line 94

def supports_block_expectations?
  true
end

- (Object) to_stderr

Tells the matcher to match against stderr. Works only when the main Ruby process prints to stderr



40
41
42
43
# File 'lib/rspec/matchers/built_in/output.rb', line 40

def to_stderr
  @stream_capturer = CaptureStderr
  self
end

- (Object) to_stderr_from_any_process

Tells the matcher to match against stderr. Works when subprocesses print to stderr as well. This is significantly (~30x) slower than to_stderr



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

def to_stderr_from_any_process
  @stream_capturer = CaptureStreamToTempfile.new("stderr", $stderr)
  self
end

- (Object) to_stdout

Tells the matcher to match against stdout. Works only when the main Ruby process prints to stdout



32
33
34
35
# File 'lib/rspec/matchers/built_in/output.rb', line 32

def to_stdout
  @stream_capturer = CaptureStdout
  self
end

- (Object) to_stdout_from_any_process

Tells the matcher to match against stdout. Works when subprocesses print to stdout as well. This is significantly (~30x) slower than to_stdout



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

def to_stdout_from_any_process
  @stream_capturer = CaptureStreamToTempfile.new("stdout", $stdout)
  self
end