Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/super_slim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "minitest/autorun"
require "stringio"
require "fileutils"
require "open3"
require "tmpdir"
require "super_slim/cli"

Expand Down Expand Up @@ -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)
Expand Down
Loading