From 7c3329b7aa7fdf4945998cdf8962a289a8117c3a Mon Sep 17 00:00:00 2001 From: 3v0k4 Date: Fri, 9 Jan 2026 11:33:37 +0100 Subject: [PATCH 1/2] fix: minitest spec with oneword dynamic class --- lib/knapsack_pro/adapters/minitest_adapter.rb | 13 ++++--- rails-app-with-knapsack_pro/Gemfile.lock | 2 +- .../test/minitest/meme_spec_test.rb | 35 ------------------- .../test/minitest/minitest_spec_test.rb | 35 +++++++++++++++++++ 4 files changed, 44 insertions(+), 41 deletions(-) delete mode 100644 rails-app-with-knapsack_pro/test/minitest/meme_spec_test.rb create mode 100644 rails-app-with-knapsack_pro/test/minitest/minitest_spec_test.rb diff --git a/lib/knapsack_pro/adapters/minitest_adapter.rb b/lib/knapsack_pro/adapters/minitest_adapter.rb index cec9d97a..19249666 100644 --- a/lib/knapsack_pro/adapters/minitest_adapter.rb +++ b/lib/knapsack_pro/adapters/minitest_adapter.rb @@ -10,15 +10,18 @@ def self.test_path(obj) path, _line = begin Object.const_source_location(obj.class.to_s) - rescue NameError - test_method_name = obj.class.runnable_methods.first - obj.method(test_method_name).source_location + rescue NameError # Dynamically defined class (Minitest::Spec `describe "more words"`) + nil end + + if path.nil? # Dynamically defined class (Minitest::Spec `describe "oneword"`) + test_method_name = obj.class.runnable_methods.first + path, _line = obj.method(test_method_name).source_location + end + path.gsub(Regexp.new("^#{@@parent_of_test_dir}"), '.') end - # See how to write hooks and plugins - # https://github.com/seattlerb/minitest/blob/master/lib/minitest/test.rb module BindTimeTrackerMinitestPlugin def before_setup super diff --git a/rails-app-with-knapsack_pro/Gemfile.lock b/rails-app-with-knapsack_pro/Gemfile.lock index c0173464..bd1c0ca1 100644 --- a/rails-app-with-knapsack_pro/Gemfile.lock +++ b/rails-app-with-knapsack_pro/Gemfile.lock @@ -103,7 +103,7 @@ GIT PATH remote: .. specs: - knapsack_pro (9.1.0) + knapsack_pro (9.2.0) rake GEM diff --git a/rails-app-with-knapsack_pro/test/minitest/meme_spec_test.rb b/rails-app-with-knapsack_pro/test/minitest/meme_spec_test.rb deleted file mode 100644 index 95a7e334..00000000 --- a/rails-app-with-knapsack_pro/test/minitest/meme_spec_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'test_helper' - -class MemeTest < ActiveSupport::TestCase - before do - @meme = Meme.new - end - - # test inside of describe won't be run when rspec is loaded, due to conflict: - # https://stackoverflow.com/questions/23683009/minitest-not-picking-up-describe-blocks - # To fix it we need to ensure rspec is not loaded when running minitest. - # See if statement for KNAPSACK_PRO_RSPEC_DISABLED in Gemfile. - describe "when asked about cheeseburgers" do - it "must respond positively" do - _(@meme.i_can_has_cheezburger?).must_equal "OHAI!" - end - end - - describe "when asked about blending possibilities" do - context 'example context in describe' do - it "won't say no" do - _(@meme.will_it_blend?).wont_match /^no/i - end - end - end - - context 'example context' do - it "won't say no" do - _(@meme.will_it_blend?).wont_match /^no/i - end - end - - it "outside of describe and context" do - _(@meme.will_it_blend?).wont_match /^no/i - end -end diff --git a/rails-app-with-knapsack_pro/test/minitest/minitest_spec_test.rb b/rails-app-with-knapsack_pro/test/minitest/minitest_spec_test.rb new file mode 100644 index 00000000..084366f9 --- /dev/null +++ b/rails-app-with-knapsack_pro/test/minitest/minitest_spec_test.rb @@ -0,0 +1,35 @@ +require "test_helper" + +class MinitestSpecTest < ActiveSupport::TestCase + describe "oneword" do + it "works" do + _(1).must_equal 1 + end + end + + describe "two words" do + it "really works" do + _(1).must_equal 1 + end + end + + context "with nested" do + describe "described in context" do + it "works" do + _(1).must_equal 1 + end + end + end + + describe "with nested" do + context "context in describe" do + it "works" do + _(1).must_equal 1 + end + end + end + + it "top level it" do + _(1).must_equal 1 + end +end From 4c4a2c96147d5fb3425902cf6dc61c2c6798f11c Mon Sep 17 00:00:00 2001 From: 3v0k4 Date: Fri, 9 Jan 2026 11:41:07 +0100 Subject: [PATCH 2/2] chore: update changelog [skip ci] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8612698..d2545775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### Unreleased +### 9.2.1 + +* Minitest: Fix for `Minitest::Spec` with oneword dynamic classes (`describe "oneword"`) (https://github.com/KnapsackPro/knapsack_pro-ruby/pull/324). + ### 9.2.0 * RSpec: Allow initializing the test queue for Queue Mode with `rake knapsack_pro:queue:rspec:initialize` (https://github.com/KnapsackPro/knapsack_pro-ruby/pull/322).