Skip to content

Commit

Permalink
Minor cleaning setting up tests (#1875)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
epergo committed Feb 12, 2023
1 parent baa6bf7 commit f10e571
Show file tree
Hide file tree
Showing 38 changed files with 47 additions and 62 deletions.
25 changes: 8 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
Expand All @@ -54,6 +44,7 @@ namespace :test do
Rake::Task['test'].invoke
end
end
CLEAN.include('coverage')

# Website =============================================================

Expand Down
2 changes: 1 addition & 1 deletion test/asciidoctor_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'asciidoctor'
Expand Down
2 changes: 1 addition & 1 deletion test/base_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class BaseTest < Minitest::Test
describe 'Sinatra::Base subclasses' do
Expand Down
2 changes: 1 addition & 1 deletion test/builder_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'builder'
Expand Down
3 changes: 1 addition & 2 deletions test/compile_test.rb
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion test/delegator_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class DelegatorTest < Minitest::Test
class Mirror
Expand Down
3 changes: 1 addition & 2 deletions test/encoding_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: UTF-8
require File.expand_path('helper', __dir__)
require_relative 'test_helper'
require 'erb'

class BaseTest < Minitest::Test
Expand Down
2 changes: 1 addition & 1 deletion test/erb_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class ERBTest < Minitest::Test
def engine
Expand Down
2 changes: 1 addition & 1 deletion test/extensions_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class ExtensionsTest < Minitest::Test
module FooExtensions
Expand Down
2 changes: 1 addition & 1 deletion test/filter_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/haml_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'haml'
Expand Down
6 changes: 3 additions & 3 deletions test/helpers_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'
require 'date'
require 'json'

Expand Down Expand Up @@ -895,8 +895,8 @@ def send_file_app(opts={})
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'
Expand Down
2 changes: 1 addition & 1 deletion test/integration_async_test.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/integration_test.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/liquid_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'liquid'
Expand Down
2 changes: 1 addition & 1 deletion test/mapped_error_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class FooError < RuntimeError
end
Expand Down
2 changes: 1 addition & 1 deletion test/markaby_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'markaby'
Expand Down
2 changes: 1 addition & 1 deletion test/markdown_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

MarkdownTest = proc do
def markdown_app(&block)
Expand Down
2 changes: 1 addition & 1 deletion test/middleware_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class MiddlewareTest < Minitest::Test
setup do
Expand Down
2 changes: 1 addition & 1 deletion test/nokogiri_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'nokogiri'
Expand Down
2 changes: 1 addition & 1 deletion test/rabl_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'rabl'
Expand Down
2 changes: 1 addition & 1 deletion test/rack_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'
require 'rack'

class RackTest < Minitest::Test
Expand Down
2 changes: 1 addition & 1 deletion test/rdoc_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'rdoc'
Expand Down
4 changes: 2 additions & 2 deletions test/readme_test.rb
Original file line number Diff line number Diff line change
@@ -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!' } }
Expand Down
2 changes: 1 addition & 1 deletion test/request_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'
require 'stringio'

class RequestTest < Minitest::Test
Expand Down
4 changes: 1 addition & 3 deletions test/response_test.rb
Original file line number Diff line number Diff line change
@@ -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' }) }
Expand Down
2 changes: 1 addition & 1 deletion test/result_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class ThirdPartyError < RuntimeError
def http_status; 400 end
Expand Down
2 changes: 1 addition & 1 deletion test/route_added_hook_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

module RouteAddedTest
@routes, @procs = [], []
Expand Down
3 changes: 1 addition & 2 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/server_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'
require 'stringio'

module Rack::Handler
Expand Down
2 changes: 1 addition & 1 deletion test/settings_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class SettingsTest < Minitest::Test
setup do
Expand Down
2 changes: 1 addition & 1 deletion test/sinatra_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/slim_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'slim'
Expand Down
2 changes: 1 addition & 1 deletion test/static_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class StaticTest < Minitest::Test
setup do
Expand Down
2 changes: 1 addition & 1 deletion test/streaming_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

class StreamingTest < Minitest::Test
Stream = Sinatra::Helpers::Stream
Expand Down
3 changes: 1 addition & 2 deletions test/templates_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/yajl_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'yajl'
Expand Down

0 comments on commit f10e571

Please sign in to comment.