Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleaning setting up tests #1875

Merged
merged 5 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 8 additions & 17 deletions 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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,4 +1,4 @@
require File.expand_path('helper', __dir__)
require_relative 'test_helper'

begin
require 'yajl'
Expand Down