Skip to content

Commit

Permalink
spring command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexevanczuk committed Nov 10, 2021
1 parent 2678be4 commit 3b968e6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/packwerk/spring_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
# typed: false

require "spring/commands"

module Packwerk
class SpringCommand
def env(*)
# Packwerk needs to run in a test environment, which has a set of autoload paths that are
# often a superset of the dev/prod paths (for example, test/support/helpers)
"test"
end

def exec_name
"packwerk"
end

def gem_name
"packwerk"
end

def call
load(Gem.bin_path(gem_name, exec_name))
end
end

Spring.register_command("packwerk", SpringCommand.new)
end
20 changes: 20 additions & 0 deletions test/unit/spring_command_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# typed: ignore
# frozen_string_literal: true

require "test_helper"
require "spring/commands"

module Packwerk
class SpringCommandTest < Minitest::Test
test "registers command with Spring when loaded" do
require "packwerk/spring_command"

command = Spring.command("packwerk")

assert_not_nil(command, message: "packwerk command not registered with Spring")
assert_equal("packwerk", command.exec_name)
assert_equal("packwerk", command.gem_name)
assert_equal("test", command.env(nil))
end
end
end

0 comments on commit 3b968e6

Please sign in to comment.