Skip to content

Commit

Permalink
Handle missing gems gracefully in tapioca gem command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrocha committed Dec 10, 2024
1 parent 712ede4 commit 49d97aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tapioca/commands/abstract_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def gems_to_generate(gem_names)
gem = @bundle.gem(gem_name)

if gem.nil?
next say("Warning: Cannot find gem '#{gem_name}', skipping", :yellow) if @lsp_addon

raise Thor::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
end

Expand Down
16 changes: 16 additions & 0 deletions spec/tapioca/cli/gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,22 @@ class Secret; end
assert_success_status(result)
end

it "skips missing gems and continues with warning when --lsp_addon is used" do
result = @project.tapioca("gem non_existent_gem --lsp_addon")

assert_stdout_includes(result, "Warning: Cannot find gem 'non_existent_gem', skipping")

assert_empty_stderr(result)
assert_success_status(result)
end

it "fails with error when gem cannot be found" do
result = @project.tapioca("gem non_existent_gem")

assert_stderr_includes(result, "Error: Cannot find gem 'non_existent_gem'")
refute_success_status(result)
end

it "does not crash when the extras gem is loaded" do
foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
Expand Down

0 comments on commit 49d97aa

Please sign in to comment.