Permalink
Browse files

integration test for logging

  • Loading branch information...
rkh committed Mar 7, 2012
1 parent e328934 commit 5f715ca27cf06029141dcaac2107103fe1938e09
Showing with 20 additions and 5 deletions.
  1. +20 −5 test/integration_test.rb
View
@@ -26,10 +26,15 @@ def command
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 @@ def kill(pid, signal = "TERM")
def with_server
pipe = IO.popen(command)
error = nil
+
Timeout.timeout(120) do
begin
yield
@@ -50,20 +56,29 @@ def with_server
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 get(url)
+ open("http://127.0.0.1:#{port}#{url}").read
+ end
+
def assert_content(url, content)
- with_server do
- response = open("http://127.0.0.1:#{port}#{url}")
- assert_equal response.read, content
- end
+ 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

0 comments on commit 5f715ca

Please sign in to comment.