From f10e571f4d9d670ec7992b7a122cae6780ce5474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20P=C3=A9rez?= Date: Sun, 12 Feb 2023 19:09:35 +0100 Subject: [PATCH] Minor cleaning setting up tests (#1875) We use minitest for Sinatra's test suite but we weren't using its rake task. I've updated the Rakefile to require and use Minitest default rake task to simplify. Another change is to rename the `helper.rb` file to `test_helper.rb` because I think that name is used more in the community and require it directly without calling `File.expand_path` --- Rakefile | 25 ++++++++----------------- test/asciidoctor_test.rb | 2 +- test/base_test.rb | 2 +- test/builder_test.rb | 2 +- test/compile_test.rb | 3 +-- test/delegator_test.rb | 2 +- test/encoding_test.rb | 3 +-- test/erb_test.rb | 2 +- test/extensions_test.rb | 2 +- test/filter_test.rb | 2 +- test/haml_test.rb | 2 +- test/helpers_test.rb | 6 +++--- test/integration_async_test.rb | 2 +- test/integration_test.rb | 2 +- test/liquid_test.rb | 2 +- test/mapped_error_test.rb | 2 +- test/markaby_test.rb | 2 +- test/markdown_test.rb | 2 +- test/middleware_test.rb | 2 +- test/nokogiri_test.rb | 2 +- test/rabl_test.rb | 2 +- test/rack_test.rb | 2 +- test/rdoc_test.rb | 2 +- test/readme_test.rb | 4 ++-- test/request_test.rb | 2 +- test/response_test.rb | 4 +--- test/result_test.rb | 2 +- test/route_added_hook_test.rb | 2 +- test/routing_test.rb | 3 +-- test/server_test.rb | 2 +- test/settings_test.rb | 2 +- test/sinatra_test.rb | 2 +- test/slim_test.rb | 2 +- test/static_test.rb | 2 +- test/streaming_test.rb | 2 +- test/templates_test.rb | 3 +-- test/{helper.rb => test_helper.rb} | 0 test/yajl_test.rb | 2 +- 38 files changed, 47 insertions(+), 62 deletions(-) rename test/{helper.rb => test_helper.rb} (100%) diff --git a/Rakefile b/Rakefile index 7bbd08ca..732cfc84 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,11 @@ # frozen_string_literal: true require 'rake/clean' -require 'rake/testtask' +require 'minitest/test_task' require 'fileutils' require 'date' task default: :test -task spec: :test - -CLEAN.include '**/*.rbc' def source_version @source_version ||= File.read(File.expand_path('VERSION', __dir__)).strip @@ -24,27 +21,20 @@ def prev_version source_version.gsub(/\d+$/) { |s| s.to_i - 1 } end -# SPECS =============================================================== +# Tests =============================================================== -Rake::TestTask.new(:test) do |t| - t.test_files = FileList['test/*_test.rb'] - t.ruby_opts = ['-r rubygems'] if defined? Gem +Minitest::TestTask.create # Default `test` task +Minitest::TestTask.create(:'test:core') do |t| t.warning = true -end - -Rake::TestTask.new(:'test:core') do |t| - core_tests = %w[ + t.test_globs = %w[ base delegator encoding extensions filter helpers mapped_error middleware rdoc readme request response result route_added_hook routing server settings sinatra static templates - ] - t.test_files = core_tests.map { |n| "test/#{n}_test.rb" } - t.ruby_opts = ['-r rubygems'] if defined? Gem - t.warning = true + ].map { |n| "test/#{n}_test.rb" } end -# Rcov ================================================================ +# Test code coverage ================================================== namespace :test do desc 'Measures test coverage' @@ -54,6 +44,7 @@ namespace :test do Rake::Task['test'].invoke end end +CLEAN.include('coverage') # Website ============================================================= diff --git a/test/asciidoctor_test.rb b/test/asciidoctor_test.rb index 9a296f46..fd0def74 100644 --- a/test/asciidoctor_test.rb +++ b/test/asciidoctor_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'asciidoctor' diff --git a/test/base_test.rb b/test/base_test.rb index 00ca61cf..2bccf2e9 100644 --- a/test/base_test.rb +++ b/test/base_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class BaseTest < Minitest::Test describe 'Sinatra::Base subclasses' do diff --git a/test/builder_test.rb b/test/builder_test.rb index 0729537c..ef1c95aa 100644 --- a/test/builder_test.rb +++ b/test/builder_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'builder' diff --git a/test/compile_test.rb b/test/compile_test.rb index 794f2846..6bbadd24 100644 --- a/test/compile_test.rb +++ b/test/compile_test.rb @@ -1,5 +1,4 @@ -# I like coding: UTF-8 -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class CompileTest < Minitest::Test def self.parses pattern, example, expected_params, mtype = :sinatra, mopts = {} diff --git a/test/delegator_test.rb b/test/delegator_test.rb index 52ce1594..da2b5d99 100644 --- a/test/delegator_test.rb +++ b/test/delegator_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class DelegatorTest < Minitest::Test class Mirror diff --git a/test/encoding_test.rb b/test/encoding_test.rb index 28ead0a0..fce8f316 100644 --- a/test/encoding_test.rb +++ b/test/encoding_test.rb @@ -1,5 +1,4 @@ -# encoding: UTF-8 -require File.expand_path('helper', __dir__) +require_relative 'test_helper' require 'erb' class BaseTest < Minitest::Test diff --git a/test/erb_test.rb b/test/erb_test.rb index f306ae8e..646576f3 100644 --- a/test/erb_test.rb +++ b/test/erb_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class ERBTest < Minitest::Test def engine diff --git a/test/extensions_test.rb b/test/extensions_test.rb index bb58e966..cff43e3d 100644 --- a/test/extensions_test.rb +++ b/test/extensions_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class ExtensionsTest < Minitest::Test module FooExtensions diff --git a/test/filter_test.rb b/test/filter_test.rb index 3af2cadd..53249690 100644 --- a/test/filter_test.rb +++ b/test/filter_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class BeforeFilterTest < Minitest::Test it "executes filters in the order defined" do diff --git a/test/haml_test.rb b/test/haml_test.rb index ae13ae10..766d3d95 100644 --- a/test/haml_test.rb +++ b/test/haml_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'haml' diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 71b42a8f..50ee6778 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' require 'date' require 'json' @@ -895,8 +895,8 @@ class HelpersTest < Minitest::Test send_file_app :disposition => 'inline'.freeze get '/file.txt' assert_equal 'inline; filename="file.txt"', response['Content-Disposition'] - end - + end + it "sets the Content-Disposition header when :filename provided" do send_file_app :filename => 'foo.txt' get '/file.txt' diff --git a/test/integration_async_test.rb b/test/integration_async_test.rb index cd283692..614f93fc 100644 --- a/test/integration_async_test.rb +++ b/test/integration_async_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' require File.expand_path('integration_async_helper', __dir__) # These tests are like integration_test, but they test asynchronous streaming. diff --git a/test/integration_test.rb b/test/integration_test.rb index f7069d51..22d51634 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' require File.expand_path('integration_helper', __dir__) # These tests start a real server and talk to it over TCP. diff --git a/test/liquid_test.rb b/test/liquid_test.rb index ecbceac2..747d539e 100644 --- a/test/liquid_test.rb +++ b/test/liquid_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'liquid' diff --git a/test/mapped_error_test.rb b/test/mapped_error_test.rb index 60d6a90a..0ea2019f 100644 --- a/test/mapped_error_test.rb +++ b/test/mapped_error_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class FooError < RuntimeError end diff --git a/test/markaby_test.rb b/test/markaby_test.rb index 32dff219..26d54af2 100644 --- a/test/markaby_test.rb +++ b/test/markaby_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'markaby' diff --git a/test/markdown_test.rb b/test/markdown_test.rb index 6e38fcc3..642391c0 100644 --- a/test/markdown_test.rb +++ b/test/markdown_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' MarkdownTest = proc do def markdown_app(&block) diff --git a/test/middleware_test.rb b/test/middleware_test.rb index 3901b7b5..aa6fcdb9 100644 --- a/test/middleware_test.rb +++ b/test/middleware_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class MiddlewareTest < Minitest::Test setup do diff --git a/test/nokogiri_test.rb b/test/nokogiri_test.rb index 99461bfd..0801fbdd 100644 --- a/test/nokogiri_test.rb +++ b/test/nokogiri_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'nokogiri' diff --git a/test/rabl_test.rb b/test/rabl_test.rb index f72caef0..781569f1 100644 --- a/test/rabl_test.rb +++ b/test/rabl_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'rabl' diff --git a/test/rack_test.rb b/test/rack_test.rb index e20d0f63..c7b3eae3 100644 --- a/test/rack_test.rb +++ b/test/rack_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' require 'rack' class RackTest < Minitest::Test diff --git a/test/rdoc_test.rb b/test/rdoc_test.rb index f13cea01..33e74798 100644 --- a/test/rdoc_test.rb +++ b/test/rdoc_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'rdoc' diff --git a/test/readme_test.rb b/test/readme_test.rb index eaa37924..e77e4ea8 100644 --- a/test/readme_test.rb +++ b/test/readme_test.rb @@ -1,6 +1,6 @@ -# Tests to check if all the README examples work. -require File.expand_path('helper', __dir__) +require_relative 'test_helper' +# Tests to check if all the README examples work. class ReadmeTest < Minitest::Test example do mock_app { get('/') { 'Hello world!' } } diff --git a/test/request_test.rb b/test/request_test.rb index d405205b..78663b9b 100644 --- a/test/request_test.rb +++ b/test/request_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' require 'stringio' class RequestTest < Minitest::Test diff --git a/test/response_test.rb b/test/response_test.rb index d713bd08..5c1e6057 100644 --- a/test/response_test.rb +++ b/test/response_test.rb @@ -1,6 +1,4 @@ -# encoding: utf-8 - -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class ResponseTest < Minitest::Test setup { @response = Sinatra::Response.new([], 200, { 'Content-Type' => 'text/html' }) } diff --git a/test/result_test.rb b/test/result_test.rb index 28c4a1e2..293680bd 100644 --- a/test/result_test.rb +++ b/test/result_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class ThirdPartyError < RuntimeError def http_status; 400 end diff --git a/test/route_added_hook_test.rb b/test/route_added_hook_test.rb index db3edbbf..91a0c70b 100644 --- a/test/route_added_hook_test.rb +++ b/test/route_added_hook_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' module RouteAddedTest @routes, @procs = [], [] diff --git a/test/routing_test.rb b/test/routing_test.rb index 73c5c92e..88c7532a 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -1,5 +1,4 @@ -# I like coding: UTF-8 -require File.expand_path('helper', __dir__) +require_relative 'test_helper' # Helper method for easy route pattern matching testing def route_def(pattern) diff --git a/test/server_test.rb b/test/server_test.rb index efacddb1..764295b8 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' require 'stringio' module Rack::Handler diff --git a/test/settings_test.rb b/test/settings_test.rb index 51770986..c1aa02c9 100644 --- a/test/settings_test.rb +++ b/test/settings_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class SettingsTest < Minitest::Test setup do diff --git a/test/sinatra_test.rb b/test/sinatra_test.rb index f903825f..92a30809 100644 --- a/test/sinatra_test.rb +++ b/test/sinatra_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class SinatraTest < Minitest::Test it 'creates a new Sinatra::Base subclass on new' do diff --git a/test/slim_test.rb b/test/slim_test.rb index dd304000..7eea7306 100644 --- a/test/slim_test.rb +++ b/test/slim_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'slim' diff --git a/test/static_test.rb b/test/static_test.rb index 0022f088..4d8cffb1 100644 --- a/test/static_test.rb +++ b/test/static_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class StaticTest < Minitest::Test setup do diff --git a/test/streaming_test.rb b/test/streaming_test.rb index 83b3bd0b..cdb10c2b 100644 --- a/test/streaming_test.rb +++ b/test/streaming_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' class StreamingTest < Minitest::Test Stream = Sinatra::Helpers::Stream diff --git a/test/templates_test.rb b/test/templates_test.rb index 76284400..dc22666a 100644 --- a/test/templates_test.rb +++ b/test/templates_test.rb @@ -1,5 +1,4 @@ -# encoding: UTF-8 -require File.expand_path('helper', __dir__) +require_relative 'test_helper' File.delete(__dir__ + '/views/layout.test') rescue nil class TestTemplate < Tilt::Template diff --git a/test/helper.rb b/test/test_helper.rb similarity index 100% rename from test/helper.rb rename to test/test_helper.rb diff --git a/test/yajl_test.rb b/test/yajl_test.rb index 6da0daed..8df06a73 100644 --- a/test/yajl_test.rb +++ b/test/yajl_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('helper', __dir__) +require_relative 'test_helper' begin require 'yajl'