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