类: RSpec::Matchers::BuiltIn::Output 私有
- 继承
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::Matchers::BuiltIn::Output
- 定义在
- lib/rspec/matchers/built_in/output.rb
概述
此类是私有 API 的一部分。 应尽量避免使用此类,因为它可能会在将来被删除或更改。
提供 output
的实现。不打算直接实例化。
常量摘要
从 BaseMatcher 继承的常量
实例方法摘要 收起
- #description ⇒ String 私有
- #diffable? ⇒ Boolean 私有
- #does_not_match?(block) ⇒ Boolean 私有
- #failure_message ⇒ String 私有
- #failure_message_when_negated ⇒ String 私有
-
#initialize(expected) ⇒ Output 构造函数 私有
一个新的 Output 实例。
- #matches?(block) ⇒ Boolean 私有
-
#supports_block_expectations? ⇒ True 私有
表示此匹配器匹配块。
-
#supports_value_expectations? ⇒ False 私有
表示此匹配器只匹配块。
-
#to_stderr ⇒ Object
告诉匹配器匹配 stderr。
-
#to_stderr_from_any_process ⇒ Object
告诉匹配器匹配 stderr。
-
#to_stdout ⇒ Object
告诉匹配器匹配 stdout。
-
#to_stdout_from_any_process ⇒ Object
告诉匹配器匹配 stdout。
从 BaseMatcher 继承的方法
#expects_call_stack_jump?, #match_unless_raises
从 Composable 包含的方法
#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?
构造函数详细信息
#initialize(expected) ⇒Output
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
返回一个新的 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 |
实例方法详细信息
#description ⇒String
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
76 77 78 79 80 81 82 |
# File '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 |
#diffable? ⇒Boolean
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
86 87 88 |
# File 'lib/rspec/matchers/built_in/output.rb', line 86 def diffable? true end |
#does_not_match?(block) ⇒Boolean
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
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
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
64 65 66 |
# File 'lib/rspec/matchers/built_in/output.rb', line 64 def "expected block to #{description}, but #{positive_failure_reason}" end |
#failure_message_when_negated ⇒String
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
70 71 72 |
# File 'lib/rspec/matchers/built_in/output.rb', line 70 def "expected block to not #{description}, but #{negative_failure_reason}" end |
#matches?(block) ⇒Boolean
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
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
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
表示此匹配器匹配块。
93 94 95 |
# File 'lib/rspec/matchers/built_in/output.rb', line 93 def supports_block_expectations? true end |
#supports_value_expectations? ⇒False
此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被删除或更改。
表示此匹配器只匹配块。
100 101 102 |
# File 'lib/rspec/matchers/built_in/output.rb', line 100 def supports_value_expectations? false end |
#to_stderr ⇒Object
告诉匹配器匹配 stderr。仅当主 Ruby 进程打印到 stderr 时才有效
39 40 41 42 |
# File 'lib/rspec/matchers/built_in/output.rb', line 39 def to_stderr @stream_capturer = CaptureStderr self end |
#to_stderr_from_any_process ⇒Object
告诉匹配器匹配 stderr。当子进程也打印到 stderr 时有效。这比 to_stderr
慢得多 (~30x)
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
告诉匹配器匹配 stdout。仅当主 Ruby 进程打印到 stdout 时才有效
31 32 33 34 |
# File 'lib/rspec/matchers/built_in/output.rb', line 31 def to_stdout @stream_capturer = CaptureStdout self end |
#to_stdout_from_any_process ⇒Object
告诉匹配器匹配 stdout。当子进程也打印到 stdout 时有效。这比 to_stdout
慢得多 (~30x)
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 |