Module: RSpec::Helpers
- Extended by:
- Helpers
- Included in:
- Helpers
- Defined in:
- lib/rspec/helpers.rb,
lib/rspec/helpers/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"1.2.0"
Instance Method Summary collapse
-
#capture_io(&block) ⇒ Object
———————————————————————— Wrap around `silence_io` making it easy to capture IO.
-
#silence_io(capture: false) ⇒ Object
———————————————————————— Silence the output of any method or command being ran.
Instance Method Details
#capture_io(&block) ⇒ Object
Wrap around `silence_io` making it easy to capture IO.
41 42 43 |
# File 'lib/rspec/helpers.rb', line 41 def capture_io(&block) silence_io(:capture => true, &block) end |
#silence_io(capture: false) ⇒ Object
Silence the output of any method or command being ran.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rspec/helpers.rb', line 17 def silence_io(capture: false) _stdout = $stdout # OG _stderr = $stderr # OG $stdout = StringIO.new $stderr = StringIO.new if !capture yield else yield return { :stderr => $stderr.string, :stdout => $stdout.string } end ensure $stdout = _stdout $stderr = _stderr end |