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 ‘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
Instance Method Summary
- #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. |
#assert_ivars, | |
#present_ivars | :nocov: |
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. |
BaseMatcher::HashFormatting
- Included
#improve_hash_formatting | ‘{ |
::RSpec::Matchers::Composable
- Included
#& | Alias for Composable#and. |
#=== | Delegates to ‘#matches?`. |
#and | Creates a compound ‘and` expectation. |
#description_of | Returns the description of the given object in a way that is aware of composed matchers. |
#or | Creates a compound ‘or` expectation. |
#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 ‘#inspect` is called on it, will provide descriptions of any contained matchers rather than the normal |
#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 106
def captured? @actual.length > 0 end
#diffable? ⇒ Boolean
(readonly)
# File 'rspec-expectations/lib/rspec/matchers/built_in/output.rb', line 86
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 93
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 100
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 121
def actual_output_description return "nothing" unless captured? actual_formatted end
#description ⇒ 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
#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 64
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 70
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 116
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 110
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 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 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