integration test for logging
This commit is contained in:
parent
e32893491b
commit
5f715ca27c
|
@ -26,10 +26,15 @@ class IntegrationTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def display_output(pipe)
|
||||
out = read_output(pipe)
|
||||
$stderr.puts command, out unless out.empty?
|
||||
end
|
||||
|
||||
def read_output(pipe)
|
||||
out = ""
|
||||
loop { out << pipe.read_nonblock(1) }
|
||||
rescue
|
||||
$stderr.puts command, out unless out.empty?
|
||||
out
|
||||
end
|
||||
|
||||
def kill(pid, signal = "TERM")
|
||||
|
@ -41,6 +46,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|||
def with_server
|
||||
pipe = IO.popen(command)
|
||||
error = nil
|
||||
|
||||
Timeout.timeout(120) do
|
||||
begin
|
||||
yield
|
||||
|
@ -50,20 +56,29 @@ class IntegrationTest < Test::Unit::TestCase
|
|||
retry
|
||||
end
|
||||
end
|
||||
|
||||
output = read_output(pipe)
|
||||
kill(pipe.pid) if pipe
|
||||
output
|
||||
rescue Timeout::Error => e
|
||||
display_output pipe
|
||||
kill(pipe.pid, "KILL") if pipe
|
||||
raise error || e
|
||||
end
|
||||
|
||||
def assert_content(url, content)
|
||||
with_server do
|
||||
response = open("http://127.0.0.1:#{port}#{url}")
|
||||
assert_equal response.read, content
|
||||
def get(url)
|
||||
open("http://127.0.0.1:#{port}#{url}").read
|
||||
end
|
||||
|
||||
def assert_content(url, content)
|
||||
with_server { assert_equal get(url), content }
|
||||
end
|
||||
|
||||
it('sets the app_file') { assert_content "/app_file", app_file }
|
||||
it('only extends main') { assert_content "/mainonly", "true" }
|
||||
|
||||
it 'logs once in development mode' do
|
||||
log = with_server { get('/app_file') }
|
||||
assert_equal 1, log.scan('/app_file').count
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue