2011-10-31 17:40:22 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
|
|
|
require 'rbconfig'
|
|
|
|
require 'open-uri'
|
2011-10-31 17:50:40 -04:00
|
|
|
require 'timeout'
|
2011-10-31 17:40:22 -04:00
|
|
|
|
|
|
|
class IntegrationTest < Test::Unit::TestCase
|
2011-10-31 17:59:09 -04:00
|
|
|
def app_file
|
|
|
|
File.expand_path('../integration/app.rb', __FILE__)
|
|
|
|
end
|
|
|
|
|
2011-10-31 18:58:04 -04:00
|
|
|
def port
|
2011-10-31 19:19:22 -04:00
|
|
|
5000 + (Process.pid % 1000)
|
2011-10-31 18:58:04 -04:00
|
|
|
end
|
|
|
|
|
2011-10-31 17:59:09 -04:00
|
|
|
def command
|
2011-11-14 13:16:59 -05:00
|
|
|
cmd = ['exec']
|
2011-10-31 17:40:22 -04:00
|
|
|
if RbConfig.respond_to? :ruby
|
|
|
|
cmd << RbConfig.ruby.inspect
|
|
|
|
else
|
|
|
|
file, dir = RbConfig::CONFIG.values_at('ruby_install_name', 'bindir')
|
|
|
|
cmd << File.expand_path(file, dir).inspect
|
|
|
|
end
|
|
|
|
cmd << "-I" << File.expand_path('../../lib', __FILE__).inspect
|
2011-10-31 18:58:04 -04:00
|
|
|
cmd << app_file.inspect << '-p' << port << '2>&1'
|
2011-10-31 17:59:09 -04:00
|
|
|
cmd.join(" ")
|
|
|
|
end
|
|
|
|
|
2011-11-06 07:17:42 -05:00
|
|
|
def display_output(pipe)
|
|
|
|
out = ""
|
|
|
|
loop { out << pipe.read_nonblock(1) }
|
|
|
|
rescue
|
|
|
|
$stderr.puts command, out unless out.empty?
|
|
|
|
end
|
|
|
|
|
2011-11-06 08:04:15 -05:00
|
|
|
def kill(pid, signal = "TERM")
|
|
|
|
Process.kill(signal, pid)
|
|
|
|
rescue NotImplementedError
|
|
|
|
system "kill -s #{signal} #{pid}"
|
|
|
|
end
|
|
|
|
|
2011-10-31 17:59:09 -04:00
|
|
|
def with_server
|
|
|
|
pipe = IO.popen(command)
|
2011-10-31 18:58:04 -04:00
|
|
|
error = nil
|
2011-11-06 07:18:07 -05:00
|
|
|
Timeout.timeout(120) do
|
2011-10-31 17:50:40 -04:00
|
|
|
begin
|
2011-10-31 17:59:09 -04:00
|
|
|
yield
|
2011-10-31 18:58:04 -04:00
|
|
|
rescue Errno::ECONNREFUSED => e
|
|
|
|
error = e
|
2011-10-31 17:50:40 -04:00
|
|
|
sleep 0.1
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
end
|
2011-11-06 08:04:15 -05:00
|
|
|
kill(pipe.pid) if pipe
|
2011-10-31 18:58:04 -04:00
|
|
|
rescue Timeout::Error => e
|
2011-11-06 07:17:42 -05:00
|
|
|
display_output pipe
|
2011-11-06 08:04:15 -05:00
|
|
|
kill(pipe.pid, "KILL") if pipe
|
2011-10-31 18:58:04 -04:00
|
|
|
raise error || e
|
2011-10-31 17:40:22 -04:00
|
|
|
end
|
2011-10-31 17:59:09 -04:00
|
|
|
|
2011-11-05 09:46:14 -04:00
|
|
|
def assert_content(url, content)
|
2011-10-31 17:59:09 -04:00
|
|
|
with_server do
|
2011-11-05 09:46:14 -04:00
|
|
|
response = open("http://127.0.0.1:#{port}#{url}")
|
|
|
|
assert_equal response.read, content
|
2011-10-31 17:59:09 -04:00
|
|
|
end
|
|
|
|
end
|
2011-11-05 09:46:14 -04:00
|
|
|
|
|
|
|
it('sets the app_file') { assert_content "/app_file", app_file }
|
|
|
|
it('only extends main') { assert_content "/mainonly", "true" }
|
2011-10-31 17:40:22 -04:00
|
|
|
end
|