1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Merge pull request #671 from patriciomacadden/fix-integration-tests

Fix integration tests for Net HTTP Server.
This commit is contained in:
Konstantin Haase 2013-03-12 02:49:14 -07:00
commit 9fbb92fea7
4 changed files with 18 additions and 9 deletions

View file

@ -75,12 +75,9 @@ if RUBY_ENGINE != 'jruby' or not ENV['TRAVIS']
end end
gem 'RedCloth' unless RUBY_ENGINE == "macruby" gem 'RedCloth' unless RUBY_ENGINE == "macruby"
gem 'puma' gem 'puma'
## bluecloth is broken
#gem 'bluecloth'
end end
gem 'net-http-server' gem 'net-http-server' unless RUBY_VERSION == '1.8.7' || RUBY_ENGINE =~ /jruby|rbx/
platforms :ruby_18, :jruby do platforms :ruby_18, :jruby do
gem 'json' unless RUBY_VERSION > '1.9' # is there a jruby but 1.8 only selector? gem 'json' unless RUBY_VERSION > '1.9' # is there a jruby but 1.8 only selector?

View file

@ -1755,7 +1755,7 @@ module Sinatra
set :run, false # start server via at-exit hook? set :run, false # start server via at-exit hook?
set :running, false # is the built-in server running now? set :running, false # is the built-in server running now?
set :server, %w[http webrick] set :server, %w[HTTP webrick]
set :bind, Proc.new { development? ? 'localhost' : '0.0.0.0' } set :bind, Proc.new { development? ? 'localhost' : '0.0.0.0' }
set :port, Integer(ENV['PORT'] || 4567) set :port, Integer(ENV['PORT'] || 4567)

View file

@ -86,7 +86,8 @@ module IntegrationHelper
def installed? def installed?
return @installed unless @installed.nil? return @installed unless @installed.nil?
require server s = server == 'HTTP' ? 'net/http/server' : server
require s
@installed = true @installed = true
rescue LoadError rescue LoadError
warn "#{server} is not installed, skipping integration tests" warn "#{server} is not installed, skipping integration tests"
@ -102,7 +103,7 @@ module IntegrationHelper
file, dir = RbConfig::CONFIG.values_at('ruby_install_name', 'bindir') file, dir = RbConfig::CONFIG.values_at('ruby_install_name', 'bindir')
cmd << File.expand_path(file, dir).inspect cmd << File.expand_path(file, dir).inspect
end end
cmd << "-w" unless thin? cmd << "-w" unless thin? || net_http_server?
cmd << "-I" << File.expand_path('../../lib', __FILE__).inspect cmd << "-I" << File.expand_path('../../lib', __FILE__).inspect
cmd << app_file.inspect << '-s' << server << '-o' << '127.0.0.1' << '-p' << port cmd << app_file.inspect << '-s' << server << '-o' << '127.0.0.1' << '-p' << port
cmd << "-e" << environment.to_s << '2>&1' cmd << "-e" << environment.to_s << '2>&1'
@ -134,6 +135,10 @@ module IntegrationHelper
name.to_s == "trinidad" name.to_s == "trinidad"
end end
def net_http_server?
name.to_s == 'HTTP'
end
def warnings def warnings
log.scan(%r[(?:\(eval|lib/sinatra).*warning:.*$]) log.scan(%r[(?:\(eval|lib/sinatra).*warning:.*$])
end end

View file

@ -17,7 +17,13 @@ class IntegrationTest < Test::Unit::TestCase
random = "%064x" % Kernel.rand(2**256-1) random = "%064x" % Kernel.rand(2**256-1)
server.get "/ping?x=#{random}" server.get "/ping?x=#{random}"
count = server.log.scan("GET /ping?x=#{random}").count count = server.log.scan("GET /ping?x=#{random}").count
server.webrick? ? assert(count > 0) : assert_equal(1, count) if server.net_http_server?
assert_equal 0, count
elsif server.webrick?
assert(count > 0)
else
assert_equal(1, count)
end
end end
it 'streams' do it 'streams' do
@ -76,7 +82,8 @@ class IntegrationTest < Test::Unit::TestCase
with\sbackup\sfrom\s#{server} with\sbackup\sfrom\s#{server}
}ix }ix
assert_match exp, server.log # because Net HTTP Server logs to $stderr by default
assert_match exp, server.log unless server.net_http_server?
end end
it 'does not generate warnings' do it 'does not generate warnings' do