From a9af5dc9484159a4deb04597076c119a9e43ad3f Mon Sep 17 00:00:00 2001 From: Matt Brictson Date: Sat, 17 Jan 2026 16:27:35 -0800 Subject: [PATCH] Switch from minitest to megatest --- .rubocop.yml | 13 ++------- Gemfile | 4 +-- Rakefile | 16 +++++------ bin/megatest | 16 +++++++++++ bin/mt | 27 ------------------- test/e2e/rails_setup_deploy_e2e_test.rb | 6 ++--- test/test_helper.rb | 5 ++-- test/tomo/cli/completions_test.rb | 6 ++--- test/tomo/cli_test.rb | 6 ++--- test/tomo/colors_test.rb | 10 +++---- test/tomo/commands/init_test.rb | 6 ++--- test/tomo/configuration_test.rb | 4 +-- test/tomo/console/key_reader_test.rb | 5 ++-- test/tomo/console_test.rb | 3 +-- test/tomo/host_test.rb | 4 +-- test/tomo/path_test.rb | 4 +-- test/tomo/paths_test.rb | 4 +-- test/tomo/plugin/bundler/tasks_test.rb | 3 +-- test/tomo/plugin/core/helpers_test.rb | 5 ++-- test/tomo/plugin/core/tasks_test.rb | 5 ++-- test/tomo/plugin/env/tasks_test.rb | 3 +-- test/tomo/plugin/git/tasks_test.rb | 3 +-- test/tomo/plugin/nodenv/tasks_test.rb | 3 +-- test/tomo/plugin/puma/tasks_test.rb | 5 ++-- test/tomo/plugin/rails/helpers_test.rb | 3 +-- test/tomo/plugin/rails/tasks_test.rb | 3 +-- test/tomo/plugin/rbenv/tasks_test.rb | 3 +-- test/tomo/runtime/execution_plan_test.rb | 4 +-- .../runtime/settings_interpolation_test.rb | 4 +-- test/tomo/runtime_test.rb | 6 ++--- test/tomo/shell_builder_test.rb | 4 +-- test/tomo/task_api_test.rb | 4 +-- 32 files changed, 66 insertions(+), 131 deletions(-) create mode 100755 bin/megatest delete mode 100755 bin/mt diff --git a/.rubocop.yml b/.rubocop.yml index e9b5b101..5dac3e64 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,4 @@ plugins: - - rubocop-minitest - rubocop-packaging - rubocop-performance - rubocop-rake @@ -9,6 +8,8 @@ AllCops: DisplayCopNames: true DisplayStyleGuide: true NewCops: enable + SuggestExtensions: + rubocop-minitest: false TargetRubyVersion: 3.2 Exclude: - "bin/**/*" @@ -75,16 +76,6 @@ Metrics/MethodLength: Metrics/ParameterLists: Max: 6 -Minitest/EmptyLineBeforeAssertionMethods: - Enabled: false - -Minitest/MultipleAssertions: - Max: 5 - -Minitest/TestFileName: - Exclude: - - "**/*.md" - Naming/MemoizedInstanceVariableName: Enabled: false diff --git a/Gemfile b/Gemfile index 8a59958a..7d92908e 100644 --- a/Gemfile +++ b/Gemfile @@ -5,12 +5,10 @@ gemspec gem "concurrent-ruby", "~> 1.1" gem "irb" -gem "mighty_test", "~> 0.4.1" unless RUBY_VERSION < "3.1" -gem "minitest", "~> 5.11" +gem "megatest", "~> 0.6.0" gem "rake", "~> 13.0" gem "rubocop", "1.82.1" gem "rubocop-md", "2.0.3" -gem "rubocop-minitest", "0.38.2" gem "rubocop-packaging", "0.6.0" gem "rubocop-performance", "1.26.1" gem "rubocop-rake", "0.7.1" diff --git a/Rakefile b/Rakefile index fbd5b1f6..817ec59f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # frozen_string_literal: true require "bundler/gem_tasks" -require "rake/testtask" +require "megatest/test_task" require "rubocop/rake_task" task default: %i[test rubocop] @@ -10,16 +10,14 @@ task test: %w[test:unit] RuboCop::RakeTask.new -Rake::TestTask.new("test:unit") do |t| - t.libs << "test" - t.libs << "lib" - t.test_files = FileList["test/**/*_test.rb"] - FileList["test/**/*_e2e_test.rb"] +Megatest::TestTask.create("test:unit") do |t| + t.command = "bin/megatest" + t.tests = FileList["test/**/*_test.rb"] - FileList["test/**/*_e2e_test.rb"] end -Rake::TestTask.new("test:e2e") do |t| - t.libs << "test" - t.libs << "lib" - t.test_files = FileList["test/**/*_e2e_test.rb"] +Megatest::TestTask.create("test:e2e") do |t| + t.command = "bin/megatest" + t.tests = FileList["test/**/*_e2e_test.rb"] end # == "rake release" enhancements ============================================== diff --git a/bin/megatest b/bin/megatest new file mode 100755 index 00000000..c0f62b37 --- /dev/null +++ b/bin/megatest @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'megatest' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("megatest", "megatest") diff --git a/bin/mt b/bin/mt deleted file mode 100755 index 3911e1c4..00000000 --- a/bin/mt +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'mt' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) - -bundle_binstub = File.expand_path("bundle", __dir__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("mighty_test", "mt") diff --git a/test/e2e/rails_setup_deploy_e2e_test.rb b/test/e2e/rails_setup_deploy_e2e_test.rb index 4dfbadb9..844813c3 100644 --- a/test/e2e/rails_setup_deploy_e2e_test.rb +++ b/test/e2e/rails_setup_deploy_e2e_test.rb @@ -1,14 +1,12 @@ # frozen_string_literal: true -require "test_helper" - require "net/http" require "securerandom" -class RailsSetupDeployE2ETest < Minitest::Test +class RailsSetupDeployE2ETest < TomoTest include Tomo::Testing::Local - def setup + setup do @docker = Tomo::Testing::DockerImage.new @docker.build_and_run end diff --git a/test/test_helper.rb b/test/test_helper.rb index b72efaeb..20052527 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "tomo/testing" -require "minitest/autorun" -require "minitest/rg" +class TomoTest < Megatest::Test +end diff --git a/test/tomo/cli/completions_test.rb b/test/tomo/cli/completions_test.rb index 734c6f9f..358c5512 100644 --- a/test/tomo/cli/completions_test.rb +++ b/test/tomo/cli/completions_test.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::CLI::CompletionsTest < Minitest::Test - def setup +class Tomo::CLI::CompletionsTest < TomoTest + setup do @tester = Tomo::Testing::CLITester.new end diff --git a/test/tomo/cli_test.rb b/test/tomo/cli_test.rb index a23b6d97..09535705 100644 --- a/test/tomo/cli_test.rb +++ b/test/tomo/cli_test.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::CLITest < Minitest::Test - def setup +class Tomo::CLITest < TomoTest + setup do @tester = Tomo::Testing::CLITester.new end diff --git a/test/tomo/colors_test.rb b/test/tomo/colors_test.rb index a0922d95..5b3f21b1 100644 --- a/test/tomo/colors_test.rb +++ b/test/tomo/colors_test.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::ColorsTest < Minitest::Test - def setup +class Tomo::ColorsTest < TomoTest + setup do # This forces color support detection to happen again Tomo::Colors.remove_instance_variable(:@enabled) end @@ -55,10 +53,10 @@ def test_disabled_by_dumb_term private def with_tty(tty, &block) - $stdout.stub(:tty?, tty) { $stderr.stub(:tty?, tty, &block) } + stub($stdout, :tty?, -> { tty }) { stub($stderr, :tty?, -> { tty }, &block) } end def with_env(env, &) - ENV.stub(:[], ->(name) { env[name] }, &) + stub(ENV, :[], ->(name) { env[name] }, &) end end diff --git a/test/tomo/commands/init_test.rb b/test/tomo/commands/init_test.rb index b620ea64..761b193e 100644 --- a/test/tomo/commands/init_test.rb +++ b/test/tomo/commands/init_test.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::Commands::InitTest < Minitest::Test - def setup +class Tomo::Commands::InitTest < TomoTest + setup do @tester = Tomo::Testing::CLITester.new end diff --git a/test/tomo/configuration_test.rb b/test/tomo/configuration_test.rb index 6da50b1a..06e8f181 100644 --- a/test/tomo/configuration_test.rb +++ b/test/tomo/configuration_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::ConfigurationTest < Minitest::Test +class Tomo::ConfigurationTest < TomoTest include Tomo::Testing::Local def test_parses_a_config_file_that_contains_frozen_string_literals diff --git a/test/tomo/console/key_reader_test.rb b/test/tomo/console/key_reader_test.rb index cfdbbc5a..3586b66b 100644 --- a/test/tomo/console/key_reader_test.rb +++ b/test/tomo/console/key_reader_test.rb @@ -1,11 +1,10 @@ # frozen_string_literal: true -require "test_helper" require "stringio" class Tomo::Console - class KeyReaderTest < Minitest::Test - def setup + class KeyReaderTest < TomoTest + setup do @input = StringIO.new @input.define_singleton_method(:raw) do |&block| block.call diff --git a/test/tomo/console_test.rb b/test/tomo/console_test.rb index c971a117..d3cc78c9 100644 --- a/test/tomo/console_test.rb +++ b/test/tomo/console_test.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require "test_helper" require "stringio" -class Tomo::ConsoleTest < Minitest::Test +class Tomo::ConsoleTest < TomoTest def test_interactive_is_true_for_tty assert_predicate Tomo::Console.new({}, tty), :interactive? end diff --git a/test/tomo/host_test.rb b/test/tomo/host_test.rb index 268993b8..02bd5991 100644 --- a/test/tomo/host_test.rb +++ b/test/tomo/host_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::HostTest < Minitest::Test +class Tomo::HostTest < TomoTest def test_parse_hostname host = Tomo::Host.parse("app.example.com") assert_equal("app.example.com", host.address) diff --git a/test/tomo/path_test.rb b/test/tomo/path_test.rb index 652c2f05..c74aa3a7 100644 --- a/test/tomo/path_test.rb +++ b/test/tomo/path_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::PathTest < Minitest::Test +class Tomo::PathTest < TomoTest def test_join path = Tomo::Path.new("/some/path").join("tmp/file.txt") diff --git a/test/tomo/paths_test.rb b/test/tomo/paths_test.rb index 538ab19f..ad465311 100644 --- a/test/tomo/paths_test.rb +++ b/test/tomo/paths_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::PathsTest < Minitest::Test +class Tomo::PathsTest < TomoTest def test_raises_if_setting_does_not_exist paths = Tomo::Paths.new({}) assert_raises(NoMethodError) { paths.storage } diff --git a/test/tomo/plugin/bundler/tasks_test.rb b/test/tomo/plugin/bundler/tasks_test.rb index 303181b9..38bd48e6 100644 --- a/test/tomo/plugin/bundler/tasks_test.rb +++ b/test/tomo/plugin/bundler/tasks_test.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/bundler" -class Tomo::Plugin::Bundler::TasksTest < Minitest::Test +class Tomo::Plugin::Bundler::TasksTest < TomoTest def test_install tester = configure(release_path: "/app/release") tester.mock_script_result(/bundle check/, exit_status: 1) diff --git a/test/tomo/plugin/core/helpers_test.rb b/test/tomo/plugin/core/helpers_test.rb index e6995e4b..a60bd3fe 100644 --- a/test/tomo/plugin/core/helpers_test.rb +++ b/test/tomo/plugin/core/helpers_test.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/core" -class Tomo::Plugin::Core::HelpersTest < Minitest::Test - def setup +class Tomo::Plugin::Core::HelpersTest < TomoTest + setup do @tester = Tomo::Testing::MockPluginTester.new( settings: { application: "test" } ) diff --git a/test/tomo/plugin/core/tasks_test.rb b/test/tomo/plugin/core/tasks_test.rb index 7619e7ca..0fe481ef 100644 --- a/test/tomo/plugin/core/tasks_test.rb +++ b/test/tomo/plugin/core/tasks_test.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/core" require "shellwords" require "time" -class Tomo::Plugin::Core::TasksTest < Minitest::Test - def setup +class Tomo::Plugin::Core::TasksTest < TomoTest + setup do configure end diff --git a/test/tomo/plugin/env/tasks_test.rb b/test/tomo/plugin/env/tasks_test.rb index 230710f5..3194af2c 100644 --- a/test/tomo/plugin/env/tasks_test.rb +++ b/test/tomo/plugin/env/tasks_test.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/env" -class Tomo::Plugin::Env::TasksTest < Minitest::Test +class Tomo::Plugin::Env::TasksTest < TomoTest def test_setup_allows_integer_value tester = Tomo::Testing::MockPluginTester.new( "env", diff --git a/test/tomo/plugin/git/tasks_test.rb b/test/tomo/plugin/git/tasks_test.rb index afdf7504..ce6f1a44 100644 --- a/test/tomo/plugin/git/tasks_test.rb +++ b/test/tomo/plugin/git/tasks_test.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/git" -class Tomo::Plugin::Git::TasksTest < Minitest::Test +class Tomo::Plugin::Git::TasksTest < TomoTest def test_config_sets_name_and_email_with_user_by_default tester = configure tester.run_task("git:config") diff --git a/test/tomo/plugin/nodenv/tasks_test.rb b/test/tomo/plugin/nodenv/tasks_test.rb index e2d761a1..f4c582e5 100644 --- a/test/tomo/plugin/nodenv/tasks_test.rb +++ b/test/tomo/plugin/nodenv/tasks_test.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/nodenv" -class Tomo::Plugin::Nodenv::TasksTest < Minitest::Test +class Tomo::Plugin::Nodenv::TasksTest < TomoTest def test_install_modifies_bashrc bashrc = <<~SH # example bashrc diff --git a/test/tomo/plugin/puma/tasks_test.rb b/test/tomo/plugin/puma/tasks_test.rb index f0aaa208..cc455999 100644 --- a/test/tomo/plugin/puma/tasks_test.rb +++ b/test/tomo/plugin/puma/tasks_test.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/puma" -class Tomo::Plugin::Puma::TasksTest < Minitest::Test - def setup +class Tomo::Plugin::Puma::TasksTest < TomoTest + setup do configure end diff --git a/test/tomo/plugin/rails/helpers_test.rb b/test/tomo/plugin/rails/helpers_test.rb index 9e96f126..7aa83416 100644 --- a/test/tomo/plugin/rails/helpers_test.rb +++ b/test/tomo/plugin/rails/helpers_test.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/rails" -class Tomo::Plugin::Rails::HelpersTest < Minitest::Test +class Tomo::Plugin::Rails::HelpersTest < TomoTest def test_rake_runs_bundle_exec_rake_in_current_path tester = Tomo::Testing::MockPluginTester.new("bundler", "rails", settings: { current_path: "/app/current" }) tester.call_helper(:rake, "db:migrate") diff --git a/test/tomo/plugin/rails/tasks_test.rb b/test/tomo/plugin/rails/tasks_test.rb index 9860b930..3bf2ea4a 100644 --- a/test/tomo/plugin/rails/tasks_test.rb +++ b/test/tomo/plugin/rails/tasks_test.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/rails" -class Tomo::Plugin::Rails::TasksTest < Minitest::Test +class Tomo::Plugin::Rails::TasksTest < TomoTest def test_db_console tester = Tomo::Testing::MockPluginTester.new( "bundler", "rails", settings: { current_path: "/app/current" } diff --git a/test/tomo/plugin/rbenv/tasks_test.rb b/test/tomo/plugin/rbenv/tasks_test.rb index 25b475b2..dea2a2f3 100644 --- a/test/tomo/plugin/rbenv/tasks_test.rb +++ b/test/tomo/plugin/rbenv/tasks_test.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require "test_helper" require "tomo/plugin/rbenv" -class Tomo::Plugin::Rbenv::TasksTest < Minitest::Test +class Tomo::Plugin::Rbenv::TasksTest < TomoTest def test_install_uses_ruby_version_file_for_ruby_version tester = configure(release_path: "/tmp/tomo/20201027184921") tester.mock_script_result("cat /tmp/tomo/20201027184921/.ruby-version", stdout: "2.7.1\n") diff --git a/test/tomo/runtime/execution_plan_test.rb b/test/tomo/runtime/execution_plan_test.rb index 1140677f..4921564a 100644 --- a/test/tomo/runtime/execution_plan_test.rb +++ b/test/tomo/runtime/execution_plan_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::Runtime::ExecutionPlanTest < Minitest::Test +class Tomo::Runtime::ExecutionPlanTest < TomoTest def test_single_host_run_plan runtime = single_host_config.build_runtime plan = runtime.execution_plan_for(["core:clean_releases"]) diff --git a/test/tomo/runtime/settings_interpolation_test.rb b/test/tomo/runtime/settings_interpolation_test.rb index f9726984..5210eae7 100644 --- a/test/tomo/runtime/settings_interpolation_test.rb +++ b/test/tomo/runtime/settings_interpolation_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::Runtime::SettingsInterpolationTest < Minitest::Test +class Tomo::Runtime::SettingsInterpolationTest < TomoTest def test_interpolates_settings interpolated = interpolate( application: "test", diff --git a/test/tomo/runtime_test.rb b/test/tomo/runtime_test.rb index ed401e15..7c92c3b9 100644 --- a/test/tomo/runtime_test.rb +++ b/test/tomo/runtime_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::RuntimeTest < Minitest::Test +class Tomo::RuntimeTest < TomoTest def test_deploy_raises_if_no_deploy_tasks runtime = Tomo::Configuration.new.build_runtime assert_raises(Tomo::Runtime::NoTasksError) do @@ -67,6 +65,6 @@ def with_env(mock_env) def with_whoami_mock(result, &) result_callable = ->(*) { result.is_a?(Exception) ? raise(result) : result } - Tomo::Runtime.stub(:`, result_callable, &) + stub(Tomo::Runtime, :`, result_callable, &) end end diff --git a/test/tomo/shell_builder_test.rb b/test/tomo/shell_builder_test.rb index 59223013..9c12c68d 100644 --- a/test/tomo/shell_builder_test.rb +++ b/test/tomo/shell_builder_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::ShellBuilderTest < Minitest::Test +class Tomo::ShellBuilderTest < TomoTest def test_raw_preserves_string_when_shellescaped raw_string = Tomo::ShellBuilder.raw("$HOME") assert_equal("$HOME", raw_string.shellescape) diff --git a/test/tomo/task_api_test.rb b/test/tomo/task_api_test.rb index 1156abfb..4da63200 100644 --- a/test/tomo/task_api_test.rb +++ b/test/tomo/task_api_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "test_helper" - -class Tomo::TaskAPITest < Minitest::Test +class Tomo::TaskAPITest < TomoTest Subject = Struct.new(:context) Subject.include Tomo::TaskAPI