diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-01-27 13:47:14 -0800 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-01-27 19:30:54 -0800 |
commit | 68dde7b79b30dd1a721eaf503e20ace8e162b980 (patch) | |
tree | 82696af7fc3b1af32884ef12b4503415b439e9ad | |
parent | 30f818b2e6a00543b3b5910daa7c8ee39887544c (diff) | |
download | rack-68dde7b79b30dd1a721eaf503e20ace8e162b980.tar.gz |
DRY up tests using the test helper
For some reason, the test helper was only used by a single spec file.
This uses it for all spec files. While here, rely on autoload
loading the libraries instead of loading everything manually.
50 files changed, 57 insertions, 189 deletions
diff --git a/test/helper.rb b/test/helper.rb index 38f7df40..7e43aa8a 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true +$:.unshift(File.expand_path('../lib', __dir__)) +require_relative '../lib/rack' require 'minitest/global_expectations/autorun' - -module Rack - class TestCase < Minitest::Test - end -end +require 'stringio' diff --git a/test/spec_auth_basic.rb b/test/spec_auth_basic.rb index 79d034b8..7d39b195 100644 --- a/test/spec_auth_basic.rb +++ b/test/spec_auth_basic.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/auth/basic' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::Auth::Basic do def realm diff --git a/test/spec_auth_digest.rb b/test/spec_auth_digest.rb index cc205aa9..f0fec5fc 100644 --- a/test/spec_auth_digest.rb +++ b/test/spec_auth_digest.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/auth/digest/md5' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::Auth::Digest::MD5 do def realm diff --git a/test/spec_body_proxy.rb b/test/spec_body_proxy.rb index d3853e1e..978af7bc 100644 --- a/test/spec_body_proxy.rb +++ b/test/spec_body_proxy.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/body_proxy' -require 'stringio' +require_relative 'helper' describe Rack::BodyProxy do it 'call each on the wrapped body' do diff --git a/test/spec_builder.rb b/test/spec_builder.rb index 3be3aa5b..9fc492bd 100644 --- a/test/spec_builder.rb +++ b/test/spec_builder.rb @@ -1,11 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/builder' -require 'rack/lint' -require 'rack/mock' -require 'rack/show_exceptions' -require 'rack/urlmap' +require_relative 'helper' class NothingMiddleware def initialize(app, **) diff --git a/test/spec_cascade.rb b/test/spec_cascade.rb index b372a56d..eb14ece0 100644 --- a/test/spec_cascade.rb +++ b/test/spec_cascade.rb @@ -1,12 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack' -require 'rack/cascade' -require 'rack/files' -require 'rack/lint' -require 'rack/urlmap' -require 'rack/mock' +require_relative 'helper' describe Rack::Cascade do def cascade(*args) diff --git a/test/spec_chunked.rb b/test/spec_chunked.rb index 23f640a5..b43803db 100644 --- a/test/spec_chunked.rb +++ b/test/spec_chunked.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/chunked' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::Chunked do def chunked(app) diff --git a/test/spec_common_logger.rb b/test/spec_common_logger.rb index b88ef009..dd55c2f8 100644 --- a/test/spec_common_logger.rb +++ b/test/spec_common_logger.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/common_logger' -require 'rack/lint' -require 'rack/mock' - +require_relative 'helper' require 'logger' describe Rack::CommonLogger do diff --git a/test/spec_conditional_get.rb b/test/spec_conditional_get.rb index 8402f04e..f64faf41 100644 --- a/test/spec_conditional_get.rb +++ b/test/spec_conditional_get.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' +require_relative 'helper' require 'time' -require 'rack/conditional_get' -require 'rack/mock' describe Rack::ConditionalGet do def conditional_get(app) diff --git a/test/spec_config.rb b/test/spec_config.rb index d97107b6..304ef8bf 100644 --- a/test/spec_config.rb +++ b/test/spec_config.rb @@ -1,11 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/builder' -require 'rack/config' -require 'rack/content_length' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::Config do it "accept a block that modifies the environment" do diff --git a/test/spec_content_length.rb b/test/spec_content_length.rb index 2710f353..07a4c56e 100644 --- a/test/spec_content_length.rb +++ b/test/spec_content_length.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/content_length' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::ContentLength do def content_length(app) diff --git a/test/spec_content_type.rb b/test/spec_content_type.rb index 53f1d172..4cfc3223 100644 --- a/test/spec_content_type.rb +++ b/test/spec_content_type.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/content_type' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::ContentType do def content_type(app, *args) diff --git a/test/spec_deflater.rb b/test/spec_deflater.rb index f903c012..ed9cffec 100644 --- a/test/spec_deflater.rb +++ b/test/spec_deflater.rb @@ -1,11 +1,7 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'stringio' +require_relative 'helper' require 'time' # for Time#httpdate -require 'rack/deflater' -require 'rack/lint' -require 'rack/mock' require 'zlib' describe Rack::Deflater do diff --git a/test/spec_directory.rb b/test/spec_directory.rb index 774a50c4..e61a2a7c 100644 --- a/test/spec_directory.rb +++ b/test/spec_directory.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/directory' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' require 'tempfile' require 'fileutils' diff --git a/test/spec_etag.rb b/test/spec_etag.rb index 63e64d43..311ad803 100644 --- a/test/spec_etag.rb +++ b/test/spec_etag.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/etag' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' require 'time' describe Rack::ETag do diff --git a/test/spec_events.rb b/test/spec_events.rb index 8c079361..6ba6968f 100644 --- a/test/spec_events.rb +++ b/test/spec_events.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true -require 'helper' -require 'rack/events' +require_relative 'helper' module Rack - class TestEvents < Rack::TestCase + class TestEvents < Minitest::Test class EventMiddleware attr_reader :events diff --git a/test/spec_files.rb b/test/spec_files.rb index 0caef90d..8ee3c2c9 100644 --- a/test/spec_files.rb +++ b/test/spec_files.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/files' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::Files do DOCROOT = File.expand_path(File.dirname(__FILE__)) unless defined? DOCROOT diff --git a/test/spec_handler.rb b/test/spec_handler.rb index 5746dc22..d6d9ccce 100644 --- a/test/spec_handler.rb +++ b/test/spec_handler.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/handler' +require_relative 'helper' class Rack::Handler::Lobster; end class RockLobster; end diff --git a/test/spec_head.rb b/test/spec_head.rb index f6f41a5d..d2dedd28 100644 --- a/test/spec_head.rb +++ b/test/spec_head.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/head' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::Head do diff --git a/test/spec_lint.rb b/test/spec_lint.rb index b71fa779..f79de53a 100644 --- a/test/spec_lint.rb +++ b/test/spec_lint.rb @@ -1,10 +1,7 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'stringio' +require_relative 'helper' require 'tempfile' -require 'rack/lint' -require 'rack/mock' describe Rack::Lint do def env(*args) diff --git a/test/spec_lobster.rb b/test/spec_lobster.rb index 9f3b9a89..ac3f1193 100644 --- a/test/spec_lobster.rb +++ b/test/spec_lobster.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' +require_relative 'helper' require 'rack/lobster' -require 'rack/lint' -require 'rack/mock' module LobsterHelpers def lobster diff --git a/test/spec_lock.rb b/test/spec_lock.rb index cd9e1230..89570498 100644 --- a/test/spec_lock.rb +++ b/test/spec_lock.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/lint' -require 'rack/lock' -require 'rack/mock' +require_relative 'helper' class Lock attr_reader :synchronized diff --git a/test/spec_logger.rb b/test/spec_logger.rb index f453b14d..8355fc82 100644 --- a/test/spec_logger.rb +++ b/test/spec_logger.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'stringio' -require 'rack/lint' -require 'rack/logger' -require 'rack/mock' +require_relative 'helper' describe Rack::Logger do app = lambda { |env| diff --git a/test/spec_media_type.rb b/test/spec_media_type.rb index 7d52b4d4..a00a767e 100644 --- a/test/spec_media_type.rb +++ b/test/spec_media_type.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/media_type' +require_relative 'helper' describe Rack::MediaType do before { @empty_hash = {} } diff --git a/test/spec_method_override.rb b/test/spec_method_override.rb index 6b01f7c9..5909907b 100644 --- a/test/spec_method_override.rb +++ b/test/spec_method_override.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'stringio' -require 'rack/method_override' -require 'rack/mock' +require_relative 'helper' describe Rack::MethodOverride do def app diff --git a/test/spec_mime.rb b/test/spec_mime.rb index 8d1ca256..65a77f6f 100644 --- a/test/spec_mime.rb +++ b/test/spec_mime.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/mime' +require_relative 'helper' describe Rack::Mime do diff --git a/test/spec_mock.rb b/test/spec_mock.rb index 47408474..c639436d 100644 --- a/test/spec_mock.rb +++ b/test/spec_mock.rb @@ -1,10 +1,7 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' +require_relative 'helper' require 'yaml' -require 'rack/lint' -require 'rack/mock' -require 'stringio' app = Rack::Lint.new(lambda { |env| req = Rack::Request.new(env) diff --git a/test/spec_multipart.rb b/test/spec_multipart.rb index 946e52c3..8cd3664f 100644 --- a/test/spec_multipart.rb +++ b/test/spec_multipart.rb @@ -1,11 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack' -require 'rack/multipart' -require 'rack/multipart/parser' -require 'rack/utils' -require 'rack/mock' +require_relative 'helper' require 'timeout' describe Rack::Multipart do diff --git a/test/spec_null_logger.rb b/test/spec_null_logger.rb index 1037c9fa..435d051e 100644 --- a/test/spec_null_logger.rb +++ b/test/spec_null_logger.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/lint' -require 'rack/mock' -require 'rack/null_logger' +require_relative 'helper' describe Rack::NullLogger do it "act as a noop logger" do diff --git a/test/spec_recursive.rb b/test/spec_recursive.rb index e77d966d..62e3a4f1 100644 --- a/test/spec_recursive.rb +++ b/test/spec_recursive.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/lint' -require 'rack/recursive' -require 'rack/mock' +require_relative 'helper' describe Rack::Recursive do before do diff --git a/test/spec_request.rb b/test/spec_request.rb index 77921867..81092f75 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -1,11 +1,8 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'stringio' +require_relative 'helper' require 'cgi' -require 'rack/request' -require 'rack/mock' -require 'rack/multipart' +require 'forwardable' require 'securerandom' class RackRequestTest < Minitest::Spec diff --git a/test/spec_response.rb b/test/spec_response.rb index 0d94d92c..425407bf 100644 --- a/test/spec_response.rb +++ b/test/spec_response.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack' -require 'rack/response' -require 'stringio' +require_relative 'helper' describe Rack::Response do it 'has standard constructor' do diff --git a/test/spec_rewindable_input.rb b/test/spec_rewindable_input.rb index 6bb5f5cf..64d56673 100644 --- a/test/spec_rewindable_input.rb +++ b/test/spec_rewindable_input.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'stringio' -require 'rack/rewindable_input' +require_relative 'helper' module RewindableTest extend Minitest::Spec::DSL diff --git a/test/spec_runtime.rb b/test/spec_runtime.rb index 10e561de..10c0c382 100644 --- a/test/spec_runtime.rb +++ b/test/spec_runtime.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/lint' -require 'rack/mock' -require 'rack/runtime' +require_relative 'helper' describe Rack::Runtime do def runtime_app(app, *args) diff --git a/test/spec_sendfile.rb b/test/spec_sendfile.rb index cbed8db3..a20aacf5 100644 --- a/test/spec_sendfile.rb +++ b/test/spec_sendfile.rb @@ -1,10 +1,7 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' +require_relative 'helper' require 'fileutils' -require 'rack/lint' -require 'rack/sendfile' -require 'rack/mock' require 'tmpdir' describe Rack::Sendfile do diff --git a/test/spec_server.rb b/test/spec_server.rb index dc334528..ed7d435b 100644 --- a/test/spec_server.rb +++ b/test/spec_server.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack' -require 'rack/server' +require_relative 'helper' require 'tempfile' require 'socket' +require 'webrick' require 'open-uri' require 'net/http' require 'net/https' diff --git a/test/spec_session_abstract_id.rb b/test/spec_session_abstract_id.rb index 3591a3de..2f783df6 100644 --- a/test/spec_session_abstract_id.rb +++ b/test/spec_session_abstract_id.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' +require_relative 'helper' ### WARNING: there be hax in this file. require 'rack/session/abstract/id' diff --git a/test/spec_session_abstract_session_hash.rb b/test/spec_session_abstract_session_hash.rb index 60665ae0..c55c97d2 100644 --- a/test/spec_session_abstract_session_hash.rb +++ b/test/spec_session_abstract_session_hash.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' +require_relative 'helper' require 'rack/session/abstract/id' describe Rack::Session::Abstract::SessionHash do diff --git a/test/spec_session_cookie.rb b/test/spec_session_cookie.rb index 57850239..0a240b9f 100644 --- a/test/spec_session_cookie.rb +++ b/test/spec_session_cookie.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/session/cookie' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::Session::Cookie do incrementor = lambda do |env| diff --git a/test/spec_session_persisted_secure_secure_session_hash.rb b/test/spec_session_persisted_secure_secure_session_hash.rb index 00d5401d..1a007eb4 100644 --- a/test/spec_session_persisted_secure_secure_session_hash.rb +++ b/test/spec_session_persisted_secure_secure_session_hash.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' +require_relative 'helper' require 'rack/session/abstract/id' describe Rack::Session::Abstract::PersistedSecure::SecureSessionHash do diff --git a/test/spec_session_pool.rb b/test/spec_session_pool.rb index e5e7e214..ac7522b5 100644 --- a/test/spec_session_pool.rb +++ b/test/spec_session_pool.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'thread' -require 'rack/lint' -require 'rack/mock' -require 'rack/session/pool' +require_relative 'helper' describe Rack::Session::Pool do session_key = Rack::Session::Pool::DEFAULT_OPTIONS[:key] diff --git a/test/spec_show_exceptions.rb b/test/spec_show_exceptions.rb index 73a0536f..82924391 100644 --- a/test/spec_show_exceptions.rb +++ b/test/spec_show_exceptions.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/show_exceptions' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::ShowExceptions do def show_exceptions(app) diff --git a/test/spec_show_status.rb b/test/spec_show_status.rb index ca23134e..2c6a2244 100644 --- a/test/spec_show_status.rb +++ b/test/spec_show_status.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/show_status' -require 'rack/lint' -require 'rack/mock' -require 'rack/utils' +require_relative 'helper' describe Rack::ShowStatus do def show_status(app) diff --git a/test/spec_static.rb b/test/spec_static.rb index fabce2a6..1f3ece9c 100644 --- a/test/spec_static.rb +++ b/test/spec_static.rb @@ -1,11 +1,7 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/static' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' require 'zlib' -require 'stringio' class DummyApp def call(env) diff --git a/test/spec_tempfile_reaper.rb b/test/spec_tempfile_reaper.rb index 0e7de841..063687a0 100644 --- a/test/spec_tempfile_reaper.rb +++ b/test/spec_tempfile_reaper.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/tempfile_reaper' -require 'rack/lint' -require 'rack/mock' +require_relative 'helper' describe Rack::TempfileReaper do class MockTempfile diff --git a/test/spec_thin.rb b/test/spec_thin.rb index 0729c3f3..f7a12110 100644 --- a/test/spec_thin.rb +++ b/test/spec_thin.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' +require_relative 'helper' begin require 'rack/handler/thin' -require File.expand_path('../testrequest', __FILE__) +require_relative 'testrequest' require 'timeout' describe Rack::Handler::Thin do diff --git a/test/spec_urlmap.rb b/test/spec_urlmap.rb index 9ce38298..b29b829b 100644 --- a/test/spec_urlmap.rb +++ b/test/spec_urlmap.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/urlmap' -require 'rack/mock' +require_relative 'helper' describe Rack::URLMap do it "dispatches paths correctly" do diff --git a/test/spec_utils.rb b/test/spec_utils.rb index 41602991..88ad64f5 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/utils' -require 'rack/mock' +require_relative 'helper' require 'timeout' describe Rack::Utils do diff --git a/test/spec_version.rb b/test/spec_version.rb index d4191aa4..68c4b4c7 100644 --- a/test/spec_version.rb +++ b/test/spec_version.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack' +require_relative 'helper' describe Rack do describe 'version' do diff --git a/test/spec_webrick.rb b/test/spec_webrick.rb index 0923c2cd..a3c324a9 100644 --- a/test/spec_webrick.rb +++ b/test/spec_webrick.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require 'minitest/global_expectations/autorun' -require 'rack/mock' +require_relative 'helper' require 'thread' -require File.expand_path('../testrequest', __FILE__) +require_relative 'testrequest' Thread.abort_on_exception = true |