-
Notifications
You must be signed in to change notification settings - Fork 17
/
test_helper.rb
67 lines (59 loc) · 1.34 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'rubygems'
require 'tempfile'
require 'minitest/autorun'
require 'mocha'
$:.unshift File.expand_path("../../lib")
require 'dante'
## Kernel Extensions
require 'stringio'
module Kernel
# Redirect standard out, standard error and the buffered logger for sprinkle to StringIO
# capture_stdout { any_commands; you_want } => "all output from the commands"
def capture_stdout
return yield if ENV['DEBUG'] # Skip if debug mode
out = StringIO.new
$stdout = out
$stderr = out
yield
return out.string
ensure
$stdout = STDOUT
$stderr = STDERR
end
end
# Process fixture
class TestingProcess
attr_reader :tmp_path
def initialize(name)
@tmp_path = "/tmp/dante-#{name}.log"
end # initialize
def run_a!(data=nil)
@tmp = File.new(@tmp_path, 'w')
@tmp.puts("Started")
@tmp.puts "Data is: #{data}" if data
@tmp.close
end # run_a!
def run_b!(port=9090)
begin
@tmp = File.new(@tmp_path, 'w')
@tmp.print "Started on #{port}!!"
sleep(100)
rescue Interrupt
@tmp.print "Interrupt!!"
exit
ensure
@tmp.print "Closing!!"
@tmp.close
end
end # run_b!
# For logging test
def run_c!(port=9091)
puts "Started on #{port}!!"
sleep(100)
rescue Interrupt
puts "Interrupt!!"
exit
ensure
puts "Closing!!"
end
end # TestingProcess