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
|
module TestUtil
# MT-unsafe
def self.require(dir, *features)
begin
# avoid 'already initialized constant FizzBuzz' warning
silent do
Dir.chdir(dir) do
features.each do |feature|
Kernel.require feature
end
end
end
ensure
features.each do |feature|
$".delete(feature)
end
end
end
# MT-unsafe
def self.silent
if $DEBUG
yield
else
back = $VERBOSE
$VERBOSE = nil
begin
yield
ensure
$VERBOSE = back
end
end
end
def self.filecompare(expectedfile, actualfile)
expected = loadfile(expectedfile)
actual = loadfile(actualfile)
if expected != actual
raise "#{File.basename(actualfile)} is different from #{File.basename(expectedfile)}"
end
end
def self.loadfile(file)
File.open(file) { |f| f.read }
end
def self.start_server_thread(server)
t = Thread.new {
Thread.current.abort_on_exception = true
server.start
}
t
end
end
|