Class: RSpec::Risky::Minitest::Plugin::OutputCapture
- Inherits:
-
Object
- Object
- RSpec::Risky::Minitest::Plugin::OutputCapture
show all
- Defined in:
- lib/rspec/risky/minitest/output_capture.rb
Defined Under Namespace
Modules: KernelWarnPatch
Classes: State, Stream
Constant Summary
collapse
- ALLOW_WARN_KEY =
:__rspec_risky_minitest_allow_warn
- SUPPRESS_KEY =
:__rspec_risky_minitest_output_suppressed
Class Method Summary
collapse
Class Method Details
.allow_warn? ⇒ Boolean
96
97
98
|
# File 'lib/rspec/risky/minitest/output_capture.rb', line 96
def self.allow_warn?
Thread.current[ALLOW_WARN_KEY]
end
|
.finish(state) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/rspec/risky/minitest/output_capture.rb', line 87
def self.finish(state)
return unless state
$stdout = state.original_stdout if $stdout.equal?(state.stdout_proxy)
$stderr = state.original_stderr if $stderr.equal?(state.stderr_proxy)
Thread.current[ALLOW_WARN_KEY] = false
state.report
end
|
.install ⇒ Object
69
70
71
72
73
74
|
# File 'lib/rspec/risky/minitest/output_capture.rb', line 69
def self.install
return if @installed
::Kernel.prepend(KernelWarnPatch)
@installed = true
end
|
.start(allow_warn: false) ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/rspec/risky/minitest/output_capture.rb', line 76
def self.start(allow_warn: false)
report = Probe::OutputProbe::Report.new
state = State.new(original_stderr: $stderr, original_stdout: $stdout, report: report)
state.stdout_proxy = Stream.new(:stdout, $stdout, report)
state.stderr_proxy = Stream.new(:stderr, $stderr, report)
$stdout = state.stdout_proxy
$stderr = state.stderr_proxy
Thread.current[ALLOW_WARN_KEY] = allow_warn
state
end
|
.suppressed? ⇒ Boolean
100
101
102
|
# File 'lib/rspec/risky/minitest/output_capture.rb', line 100
def self.suppressed?
Thread.current[SUPPRESS_KEY].to_i.positive?
end
|
.with_suppressed ⇒ Object
104
105
106
107
108
109
|
# File 'lib/rspec/risky/minitest/output_capture.rb', line 104
def self.with_suppressed
Thread.current[SUPPRESS_KEY] = Thread.current[SUPPRESS_KEY].to_i + 1
yield
ensure
Thread.current[SUPPRESS_KEY] -= 1
end
|