Class: RSpec::Matchers::BuiltIn::Output Private
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::Matchers::BuiltIn::Output
- 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
Constants inherited from BaseMatcher
Instance Method Summary collapse
-
#as_not_tty ⇒ Object
Tells the matcher to simulate the output stream not being a TTY.
-
#as_tty ⇒ Object
Tells the matcher to simulate the output stream being a TTY.
- #description ⇒ String private
- #diffable? ⇒ Boolean private
- #does_not_match?(block) ⇒ Boolean private
- #failure_message ⇒ String private
- #failure_message_when_negated ⇒ String private
-
#initialize(expected) ⇒ Output
constructor
private
A new instance of Output.
- #matches?(block) ⇒ Boolean private
-
#supports_block_expectations? ⇒ True
private
Indicates this matcher matches against a block.
-
#supports_value_expectations? ⇒ False
private
Indicates this matcher matches against a block only.
-
#to_stderr ⇒ Object
Tells the matcher to match against stderr.
-
#to_stderr_from_any_process ⇒ Object
Tells the matcher to match against stderr.
-
#to_stdout ⇒ Object
Tells the matcher to match against stdout.
-
#to_stdout_from_any_process ⇒ Object
Tells the matcher to match against stdout.
Methods inherited from BaseMatcher
#expects_call_stack_jump?, #match_unless_raises
Methods included from Composable
#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?
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
#as_not_tty ⇒ Object
Tells the matcher to simulate the output stream not being a TTY.
Note that that's the default behaviour if you don't call as_tty
(since StringIO
is not a TTY).
76 77 78 79 80 81 |
# File 'lib/rspec/matchers/built_in/output.rb', line 76 def as_not_tty raise ArgumentError, '`as_not_tty` can only be used after `to_stdout` or `to_stderr`' unless @stream_capturer.respond_to?(:as_tty=) @stream_capturer.as_tty = false self end |
#as_tty ⇒ Object
Tells the matcher to simulate the output stream being a TTY.
This is useful to test code like puts '...' if $stdout.tty?
.
65 66 67 68 69 70 |
# File 'lib/rspec/matchers/built_in/output.rb', line 65 def as_tty raise ArgumentError, '`as_tty` can only be used after `to_stdout` or `to_stderr`' unless @stream_capturer.respond_to?(:as_tty=) @stream_capturer.as_tty = true self end |
#description ⇒ String
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.
97 98 99 100 101 102 103 |
# File 'lib/rspec/matchers/built_in/output.rb', line 97 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.
107 108 109 |
# File 'lib/rspec/matchers/built_in/output.rb', line 107 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.
24 25 26 |
# File 'lib/rspec/matchers/built_in/output.rb', line 24 def does_not_match?(block) !matches?(block) && Proc === block end |
#failure_message ⇒ String
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.
85 86 87 |
# File 'lib/rspec/matchers/built_in/output.rb', line 85 def "expected block to #{description}, but #{positive_failure_reason}" end |
#failure_message_when_negated ⇒ String
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.
91 92 93 |
# File 'lib/rspec/matchers/built_in/output.rb', line 91 def "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.
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.
114 115 116 |
# File 'lib/rspec/matchers/built_in/output.rb', line 114 def supports_block_expectations? true end |
#supports_value_expectations? ⇒ False
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 only.
121 122 123 |
# File 'lib/rspec/matchers/built_in/output.rb', line 121 def supports_value_expectations? false end |
#to_stderr ⇒ Object
Tells the matcher to match against stderr. Works only when the main Ruby process prints to stderr
39 40 41 42 |
# File 'lib/rspec/matchers/built_in/output.rb', line 39 def to_stderr @stream_capturer = CaptureStderr.new self end |
#to_stderr_from_any_process ⇒ Object
Tells the matcher to match against stderr.
Works when subprocesses print to stderr as well.
This is significantly (~30x) slower than to_stderr
57 58 59 60 |
# File 'lib/rspec/matchers/built_in/output.rb', line 57 def to_stderr_from_any_process @stream_capturer = CaptureStreamToTempfile.new("stderr", $stderr) self end |
#to_stdout ⇒ Object
Tells the matcher to match against stdout. Works only when the main Ruby process prints to stdout
31 32 33 34 |
# File 'lib/rspec/matchers/built_in/output.rb', line 31 def to_stdout @stream_capturer = CaptureStdout.new self end |
#to_stdout_from_any_process ⇒ Object
Tells the matcher to match against stdout.
Works when subprocesses print to stdout as well.
This is significantly (~30x) slower than to_stdout
48 49 50 51 |
# File 'lib/rspec/matchers/built_in/output.rb', line 48 def to_stdout_from_any_process @stream_capturer = CaptureStreamToTempfile.new("stdout", $stdout) self end |