Top Level Namespace
Defined Under Namespace
Constant Summary collapse
- AES =
FastAES.new(key)
Instance Method Summary collapse
-
#catch_output ⇒ Hash
Runs the block in a new thread and redirects $stdout and $stderr.
-
#stub(attributes) ⇒ Class
Allows developers to create stubbed objects similar to Mocha’s stub() method.
Instance Method Details
#catch_output ⇒ Hash
Runs the block in a new thread and redirects $stdout and $stderr. The output normally stored in these variables is stored in an instance of StringIO which is returned as a hash.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hunter2/spec/helper.rb', line 23 def catch_output data = { :stdout => nil, :stderr => nil } Thread.new do $stdout, $stderr = StringIO.new, StringIO.new yield $stdout.rewind $stderr.rewind data[:stdout], data[:stderr] = $stdout.read, $stderr.read $stdout, $stderr = STDOUT, STDERR end.join return data end |
#stub(attributes) ⇒ Class
Allows developers to create stubbed objects similar to Mocha’s stub() method.
their values.
57 58 59 60 61 62 63 64 65 |
# File 'lib/hunter2/spec/helper.rb', line 57 def stub(attributes) obj = Struct.new(*attributes.keys).new attributes.each do |k, v| obj.send("#{k}=", v) end return obj end |