1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test/test_helper.rb
Fumiaki MATSUSHIMA 0b3424a7d6 Fix test error
We got following error on travis now:

https://travis-ci.org/puma/puma/jobs/207434226

```
1) Error:
WebServerTest#test_simple_server:
NameError: uninitialized constant Net
    /home/travis/build/puma/puma/test/test_helper.rb:24:in `block in hit'
    /home/travis/build/puma/puma/test/test_helper.rb:20:in `each'
    /home/travis/build/puma/puma/test/test_helper.rb:20:in `hit'
    /home/travis/build/puma/puma/test/test_web_server.rb:36:in `test_simple_server'
```

I confirmed test passed with bundler 1.14.4 but errored with 1.14.5.

https://github.com/bundler/bundler/compare/v1.14.4...v1.14.5

The cause is 984f64d8a5
because `rubygems/spec_fetcher` requires `net/http` internally but is deferred now.

I think we should require stdlibs explicitly.
2017-03-09 00:56:07 +09:00

56 lines
1.1 KiB
Ruby

# Copyright (c) 2011 Evan Phoenix
# Copyright (c) 2005 Zed A. Shaw
begin
require "bundler/setup"
rescue LoadError
end
require "net/http"
require "timeout"
require "minitest/autorun"
require "minitest/pride"
require "puma"
require "puma/detect"
# Either takes a string to do a get request against, or a tuple of [URI, HTTP] where
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
def hit(uris)
results = []
uris.each do |u|
res = nil
if u.kind_of? String
res = Net::HTTP.get(URI.parse(u))
else
url = URI.parse(u[0])
res = Net::HTTP.new(url.host, url.port).start {|h| h.request(u[1]) }
end
assert res != nil, "Didn't get a response: #{u}"
results << res
end
return results
end
module TimeoutEveryTestCase
def run(*)
if !!ENV['CI']
::Timeout.timeout(60) { super }
else
super
end
end
end
Minitest::Test.prepend TimeoutEveryTestCase
module SkipTestsBasedOnRubyEngine
def skip_on_jruby
skip "Skipped on JRuby" if Puma.jruby?
end
end
Minitest::Test.include SkipTestsBasedOnRubyEngine