From 81bbba206b0067eccc8dede456dbb6625a22adb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Joubert?= <14306+czj@users.noreply.github.com> Date: Wed, 11 Nov 2026 10:49:30 +0100 Subject: [PATCH] The formatter loads from the same copy of the gem as the rest Formatter and RuboCop were autoloaded by a name Ruby looks up on the load path: loaded by its path, as exe/super-slim does in a checkout, SuperSlim formatted with whichever copy of the gem came first there. They are autoloaded by their full path. Assisted-by: Claude Fable 5 [Claude Code] --- lib/super_slim.rb | 6 ++++-- test/cli_test.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/super_slim.rb b/lib/super_slim.rb index 083e552..669e7ec 100644 --- a/lib/super_slim.rb +++ b/lib/super_slim.rb @@ -8,8 +8,10 @@ require_relative "super_slim/runtime" module SuperSlim - autoload :Formatter, "super_slim/formatter" - autoload :RuboCop, "super_slim/rubocop" + # By their full path: a bare "super_slim/formatter" is the first one on the load path, which is another copy of the + # gem when this one was loaded by its path, as `exe/super-slim` does in a checkout. + autoload :Formatter, File.join(__dir__, "super_slim/formatter") + autoload :RuboCop, File.join(__dir__, "super_slim/rubocop") class Error < StandardError; end class InvalidAttributeNameError < Error; end diff --git a/test/cli_test.rb b/test/cli_test.rb index 708065b..016839d 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -3,6 +3,7 @@ require "minitest/autorun" require "stringio" require "fileutils" +require "open3" require "tmpdir" require "super_slim/cli" @@ -164,6 +165,20 @@ def test_control_characters_are_escaped_in_what_lint_prints end end + # `exe/super-slim` loads the checkout it sits in by path: with the gem installed too, a formatter looked up on + # the load path would be the installed one. + def test_the_formatter_comes_from_the_copy_of_the_gem_that_was_loaded + Dir.mktmpdir do |directory| + FileUtils.mkdir_p(File.join(directory, "super_slim")) + File.write(File.join(directory, "super_slim/formatter.rb"), "raise 'the formatter of another copy of the gem'\n") + script = "require #{File.expand_path("../lib/super_slim", __dir__).dump}; print SuperSlim::Formatter.call(%(p\\n | Hello\\n))" + output, status = Open3.capture2e(RbConfig.ruby, "-I", directory, "-e", script) + + assert_predicate status, :success?, output + assert_equal "p\n | Hello\n", output + end + end + private def template_name(number) = format("template_%03d.html.slim", number)