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 4 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
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 'test_helper'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do require_relative 'test_helper' instead?

Copy link
Member Author

@epergo epergo Feb 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used require because it's the one I've found in other projects (Rails, Pay) and because is what rubygems use when creating a new gem.

The only issue I could think of is that running tests manually from inside the test folder (or any other place different from the root path) won't work, as it won't find the file.

Do you foresee any other issue for not using require_relative?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were the issues I was thinking about. The code before could handle those scenarios, right?

I also recall reading relative being faster.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enough arguments 😄 updated to use require_relative instead


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 '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 '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 '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 '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 '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 '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 '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 '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 'test_helper'

begin
require 'haml'
Expand Down
2 changes: 1 addition & 1 deletion 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 'test_helper'
require 'date'
require 'json'

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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 '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 'test_helper'

begin
require 'yajl'
Expand Down