Class: RSpec::Matchers::BuiltIn::CaptureStreamToTempfile
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/output.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#stream ⇒ Object
Returns the value of attribute stream.
Instance Method Summary collapse
Methods inherited from Struct
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
179 180 181 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/output.rb', line 179 def name @name end |
#stream ⇒ Object
Returns the value of attribute stream
179 180 181 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/output.rb', line 179 def stream @stream end |
Instance Method Details
#capture(block) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/output.rb', line 180 def capture(block) # We delay loading tempfile until it is actually needed because # we want to minimize stdlibs loaded so that users who use a # portion of the stdlib can't have passing specs while forgetting # to load it themselves. `CaptureStreamToTempfile` is rarely used # and `tempfile` pulls in a bunch of things (delegate, tmpdir, # thread, fileutils, etc), so it's worth delaying it until this point. require 'tempfile' original_stream = stream.clone captured_stream = Tempfile.new(name) begin captured_stream.sync = true stream.reopen(captured_stream) block.call captured_stream.rewind captured_stream.read ensure stream.reopen(original_stream) captured_stream.close captured_stream.unlink end end |