class RSpec::Matchers::BuiltIn::Output

@api private Provides the implementation for `output`. Not intended to be instantiated directly.

Public Class Methods

new(expected) click to toggle source
# File lib/rspec/matchers/built_in/output.rb, line 10
def initialize(expected)
  @expected = expected
  @stream_capturer = NullCapture
end

Public Instance Methods

description() click to toggle source

@api private @return [String]

# File lib/rspec/matchers/built_in/output.rb, line 54
def description
  if @expected
    "output #{description_of @expected} to #{@stream_capturer.name}"
  else
    "output to #{@stream_capturer.name}"
  end
end
diffable?() click to toggle source

@api private @return [Boolean]

# File lib/rspec/matchers/built_in/output.rb, line 64
def diffable?
  true
end
does_not_match?(block) click to toggle source
# File lib/rspec/matchers/built_in/output.rb, line 22
def does_not_match?(block)
  !matches?(block) && Proc === block
end
failure_message() click to toggle source

@api private @return [String]

# File lib/rspec/matchers/built_in/output.rb, line 42
def failure_message
  "expected block to #{description}, but #{positive_failure_reason}"
end
failure_message_when_negated() click to toggle source

@api private @return [String]

# File lib/rspec/matchers/built_in/output.rb, line 48
def failure_message_when_negated
  "expected block to not #{description}, but #{negative_failure_reason}"
end
matches?(block) click to toggle source
# File lib/rspec/matchers/built_in/output.rb, line 15
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?() click to toggle source

@api private Indicates this matcher matches against a block. @return [True]

# File lib/rspec/matchers/built_in/output.rb, line 71
def supports_block_expectations?
  true
end
to_stderr() click to toggle source

@api public Tells the matcher to match against stderr.

# File lib/rspec/matchers/built_in/output.rb, line 35
def to_stderr
  @stream_capturer = CaptureStderr
  self
end
to_stdout() click to toggle source

@api public Tells the matcher to match against stdout.

# File lib/rspec/matchers/built_in/output.rb, line 28
def to_stdout
  @stream_capturer = CaptureStdout
  self
end

Private Instance Methods

actual_output_description() click to toggle source
# File lib/rspec/matchers/built_in/output.rb, line 92
def actual_output_description
  return "nothing" unless captured?
  @actual.inspect
end
captured?() click to toggle source
# File lib/rspec/matchers/built_in/output.rb, line 77
def captured?
  @actual.length > 0
end
negative_failure_reason() click to toggle source
# File lib/rspec/matchers/built_in/output.rb, line 87
def negative_failure_reason
  return "was not a block" unless Proc === @block
  "output #{actual_output_description}"
end
positive_failure_reason() click to toggle source
# File lib/rspec/matchers/built_in/output.rb, line 81
def positive_failure_reason
  return "was not a block" unless Proc === @block
  return "output #{actual_output_description}" if @expected
  "did not"
end