Module: CommandExec::SpecHelper
- Defined in:
- lib/command_exec/spec_helper_module.rb
Overview
Helpers for specs
Instance Method Summary collapse
-
#capture_stderr(&block) ⇒ Object
Capture stderr.
-
#capture_stdout(&block) ⇒ Object
Capture stdout.
-
#create_temp_file_with(base_name, content) ⇒ String
Create temporary files for testing (which will be deleted when the ruby process terminates).
-
#environment(env = {}, options = {}) { ... } ⇒ Object
Manipulate environment for the given block.
Instance Method Details
#capture_stderr(&block) ⇒ Object
Capture stderr
10 11 12 13 14 15 16 |
# File 'lib/command_exec/spec_helper_module.rb', line 10 def capture_stderr(&block) previous_stderr, $stderr = $stderr, StringIO.new block.call return $stderr.string ensure $stderr = previous_stderr end |
#capture_stdout(&block) ⇒ Object
Capture stdout
21 22 23 24 25 26 27 |
# File 'lib/command_exec/spec_helper_module.rb', line 21 def capture_stdout(&block) previous_stdout, $stdout = $stdout, StringIO.new block.call return $stdout.string ensure $stdout = previous_stdout end |
#create_temp_file_with(base_name, content) ⇒ String
Create temporary files for testing (which will be deleted when the ruby process terminates)
64 65 66 67 68 69 |
# File 'lib/command_exec/spec_helper_module.rb', line 64 def create_temp_file_with(base_name, content) file = Tempfile.new(base_name) file.write(content) file.close file.path end |
#environment(env = {}, options = {}) { ... } ⇒ Object
Manipulate environment for the given block
42 43 44 45 46 47 48 49 50 |
# File 'lib/command_exec/spec_helper_module.rb', line 42 def environment(env={},={},&block) previous_environment, environment = ENV.to_hash, env ENV.clear if [:clear] == true ENV.update(environment) block.call ensure ENV.clear ENV.update previous_environment end |