Class: RSpec::Matchers::BuiltIn::Output Private
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
BaseMatcher
|
|
Instance Chain:
|
|
Inherits: |
RSpec::Matchers::BuiltIn::BaseMatcher
|
Defined in: | rspec-expectations/lib/rspec/matchers/built_in/output.rb |
Overview
Provides the implementation for RSpec::Matchers#output. Not intended to be instantiated directly.
Constant Summary
BaseMatcher
- Inherited
Class Method Summary
- .new(expected) ⇒ Output constructor Internal use only
BaseMatcher
- Inherited
.matcher_name, .new, | |
.underscore | Borrowed from ActiveSupport. |
Instance Attribute Summary
- #diffable? ⇒ Boolean readonly Internal use only
-
#supports_block_expectations? ⇒ True
readonly
Internal use only
Indicates this matcher matches against a block.
-
#supports_value_expectations? ⇒ False
readonly
Internal use only
Indicates this matcher matches against a block only.
- #captured? ⇒ Boolean readonly private Internal use only
BaseMatcher
- Inherited
#actual, | |
#diffable? |
|
#expected, #expects_call_stack_jump?, #matcher_name, #matcher_name=, #rescued_exception, | |
#supports_block_expectations? | Most matchers are value matchers (i.e. meant to work with ‘expect(value)`) rather than block matchers (i.e. meant to work with `expect { }`), so this defaults to false. |
#supports_value_expectations? |
BaseMatcher::StringEncodingFormatting
- Included
#string_encoding_differs? | :nocov: |
Instance Method Summary
-
#as_not_tty
Tells the matcher to simulate the output stream not being a TTY.
-
#as_tty
Tells the matcher to simulate the output stream being a TTY.
- #description ⇒ String Internal use only
- #does_not_match?(block) ⇒ Boolean Internal use only
- #failure_message ⇒ String Internal use only
- #failure_message_when_negated ⇒ String Internal use only
- #matches?(block) ⇒ Boolean Internal use only
-
#to_stderr
Tells the matcher to match against stderr.
-
#to_stderr_from_any_process
Tells the matcher to match against stderr.
-
#to_stdout
Tells the matcher to match against stdout.
-
#to_stdout_from_any_process
Tells the matcher to match against stdout.
- #actual_output_description private Internal use only
- #negative_failure_reason private Internal use only
- #positive_failure_reason private Internal use only
BaseMatcher
- Inherited
#actual_formatted, | |
#description | Generates a description using |
#expected_formatted, | |
#match_unless_raises | Used to wrap a block of code that will indicate failure by raising one of the named exceptions. |
#matches? | Indicates if the match is successful. |
BaseMatcher::DefaultFailureMessages
- Included
#failure_message | Provides a good generic failure message. |
#failure_message_when_negated | Provides a good generic negative failure message. |
BaseMatcher::StringEncodingFormatting
- Included
#format_encoding | Formats a String’s encoding as a human readable string :nocov: |
BaseMatcher::HashFormatting
- Included
#improve_hash_formatting | ‘{ |
::RSpec::Matchers::Composable
- Included
#& | Alias for Composable#and. |
#=== | Delegates to #matches?. |
#and | Creates a compound |
#description_of | Returns the description of the given object in a way that is aware of composed matchers. |
#or | Creates a compound |
#values_match? | This provides a generic way to fuzzy-match an expected value against an actual value. |
#| | Alias for Composable#or. |
#should_enumerate? | We should enumerate arrays as long as they are not recursive. |
#surface_descriptions_in | Transforms the given data structure (typically a hash or array) into a new data structure that, when |
#unreadable_io?, | |
#with_matchers_cloned | Historically, a single matcher instance was only checked against a single value. |
Instance Attribute Details
#captured? ⇒ Boolean
(readonly, private)
# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 127
def captured? @actual.length > 0 end
#diffable? ⇒ Boolean
(readonly)
# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 107
def diffable? true end
#supports_block_expectations? ⇒ True
(readonly)
Indicates this matcher matches against a block.
# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 114
def supports_block_expectations? true end
#supports_value_expectations? ⇒ False
(readonly)
Indicates this matcher matches against a block only.
# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 121
def supports_value_expectations? false end
Instance Method Details
#actual_output_description (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 142
def actual_output_description return "nothing" unless captured? actual_formatted end
#as_not_tty
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).
# File 'rspec-expectations/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
Tells the matcher to simulate the output stream being a TTY. This is useful to test code like ‘puts ’…‘ if $stdout.tty?`.
# File 'rspec-expectations/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
# File 'rspec-expectations/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
#does_not_match?(block) ⇒ Boolean
# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 24
def does_not_match?(block) !matches?(block) && Proc === block end
#failure_message ⇒ String
# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 85
def "expected block to #{description}, but #{positive_failure_reason}" end
#failure_message_when_negated ⇒ String
# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 91
def "expected block to not #{description}, but #{negative_failure_reason}" end
#matches?(block) ⇒ Boolean
# 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
#negative_failure_reason (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 137
def negative_failure_reason return "was not a block" unless Proc === @block "output #{actual_output_description}" end
#positive_failure_reason (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 131
def positive_failure_reason return "was not a block" unless Proc === @block return "output #{actual_output_description}" if @expected "did not" end
#to_stderr
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.new self end
#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`
# 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
#to_stdout
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.new self end
#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`
# 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