class RSpec::Matchers::BuiltIn::Output
@api private Provides the implementation for ‘output`. Not intended to be instantiated directly.
Public Class Methods
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 10 def initialize(expected) @expected = expected @actual = "" @block = nil @stream_capturer = NullCapture end
Public Instance Methods
@api private @return [String]
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 76 def description if @expected "output #{description_of @expected} to #{@stream_capturer.name}" else "output to #{@stream_capturer.name}" end end
@api private @return [Boolean]
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 86 def diffable? true end
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 24 def does_not_match?(block) !matches?(block) && Proc === block end
@api private @return [String]
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 64 def failure_message "expected block to #{description}, but #{positive_failure_reason}" end
@api private @return [String]
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 70 def failure_message_when_negated "expected block to not #{description}, but #{negative_failure_reason}" end
# File rspec-expectations/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
@api private Indicates this matcher matches against a block. @return [True]
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 93 def supports_block_expectations? true end
@api private Indicates this matcher matches against a block only. @return [False]
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 100 def supports_value_expectations? false end
@api public Tells the matcher to match against stderr. Works only when the main Ruby process prints to stderr
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 39 def to_stderr @stream_capturer = CaptureStderr self end
@api public Tells the matcher to match against stderr. Works when subprocesses print to stderr as well. This is significantly (~30x) slower than ‘to_stderr`
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 57 def to_stderr_from_any_process @stream_capturer = CaptureStreamToTempfile.new("stderr", $stderr) self end
@api public Tells the matcher to match against stdout. Works only when the main Ruby process prints to stdout
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 31 def to_stdout @stream_capturer = CaptureStdout self end
@api public Tells the matcher to match against stdout. Works when subprocesses print to stdout as well. This is significantly (~30x) slower than ‘to_stdout`
# File rspec-expectations/lib/rspec/matchers/built_in/output.rb, line 48 def to_stdout_from_any_process @stream_capturer = CaptureStreamToTempfile.new("stdout", $stdout) self end