Top Level Namespace

Defined Under Namespace

Modules: Bacon, Hunter2

Constant Summary collapse

AES =
FastAES.new(key)

Instance Method Summary collapse

Instance Method Details

#catch_outputHash

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.

Examples:

out = catch_output do
  puts 'hello'
end

puts out # => {:stdout => "hello\n", :stderr => ""}

Returns:

  • (Hash)

Author:

  • Yorick Peterse



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.

Examples:

obj = stub(:language => 'Ruby')
puts obj.language # => "Ruby"

Parameters:

  • attributes (Hash)

    A hash containing all the attributes to set and

Returns:

  • (Class)

Author:

  • Yorick Peterse



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