forked from nesquena/gitdocs
/
test_helper.rb
54 lines (51 loc) · 1.52 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
ENV["TEST"] = 'true'
require 'rubygems'
require 'minitest/autorun'
$:.unshift File.expand_path("../../lib")
require 'gitdocs'
require 'fakeweb'
require 'mocha'
FakeWeb.allow_net_connect = false
## Kernel Extensions
require 'stringio'
class MiniTest::Spec
def with_clones(count = 3)
FileUtils.rm_rf("/tmp/gitdocs")
master_path = "/tmp/gitdocs/master"
FileUtils.mkdir_p("/tmp/gitdocs/master")
ShellTools.capture { `git init /tmp/gitdocs/master --bare` }
sub_paths = count.times.map do |c|
ShellTools.capture { `cd /tmp/gitdocs && git clone file://#{master_path} #{c}` }
conf_path = "/tmp/gitdocs/config/#{c}"
FileUtils.mkdir_p(conf_path)
["/tmp/gitdocs/#{c}", conf_path]
end
pids = sub_paths.map do |(path, conf_path)|
fork do
unless ENV['DEBUG']
STDOUT.reopen(File.open("/dev/null", 'w'))
STDERR.reopen(File.open("/dev/null", 'w'))
end
begin
puts "RUNNING!"
Gitdocs.run(conf_path) do |conf|
conf.global.update_attributes(:load_browser_on_startup => false, :start_web_frontend => false)
conf.add_path(path, :polling_interval => 0.1, :notification => false)
end
rescue
puts "RATHER BAD ~~~~~"
puts $!.message
puts $!.backtrace.join("\n ")
end
end
end
begin
sleep 1
yield sub_paths.map{|sp| sp.first}
ensure
pids.each { |pid| Process.kill("INT", pid) rescue nil }
end
ensure
FileUtils.rm_rf("/tmp/gitdocs") unless ENV['DEBUG']
end
end