Skip to content

Commit

Permalink
wip test fix against CI
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrocha committed Jan 9, 2025
1 parent b0ab3d6 commit 17d6c89
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 101 deletions.
4 changes: 3 additions & 1 deletion lib/ruby_lsp/tapioca/run_gem_rbi_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def execute_tapioca_gem_command(gems)
# Resetting BUNDLE_GEMFILE to root folder to use the project's Gemfile instead of Ruby LSP's composed Gemfile
stdout, stderr, status = T.unsafe(Open3).capture3(
{ "BUNDLE_GEMFILE" => "Gemfile" },
"bin/tapioca",
"bundle",
"exec",
"tapioca",
"gem",
"--lsp_addon",
*gems,
Expand Down
201 changes: 101 additions & 100 deletions spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,140 +12,141 @@ module Foo
end
RUBY

# TODO: understand why this fails with `before(:all)`
# before(:all) do
before do
@project.tapioca("configure")
end
describe "without git" do
before do
@project.tapioca("configure")
end

after do
project.write_gemfile!(project.tapioca_gemfile)
@project.require_default_gems
project.remove!("sorbet/rbi")
project.remove!("../gems")
project.remove!(".git")
project.remove!("sorbet/tapioca/require.rb")
project.remove!("config/application.rb")
ensure
@project.remove!("output")
end
it "does nothing if there is no git repo" do
foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
end
@project.require_mock_gem(foo)

def setup_git_repo
@project.exec("git init")
@project.exec("touch Gemfile.lock")
FileUtils.mkdir_p("#{@project.absolute_path}/sorbet/rbi/gems")
@project.exec("git add . && git commit -m 'Initial commit'")
end
@project.bundle_install!
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

it "does nothing if there is no git repo" do
foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
assert check.result.stdout.include?("Not a git repository")
end
@project.require_mock_gem(foo)

@project.bundle_install!
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

assert check.result.stdout.include?("Not a git repository")
end

it "creates the RBI for a newly added gem" do
setup_git_repo

foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
describe "with git" do
# TODO: understand why this fails with `before(:all)`
# before(:all) do
before do
@project.tapioca("configure")
@project.exec("git init")
@project.exec("git config user.email '[email protected]'")
@project.exec("git config user.name 'Test User'")
@project.bundle_install!
FileUtils.mkdir_p("#{@project.absolute_path}/sorbet/rbi/gems")
@project.exec("git add .")
@project.exec("git commit -m 'Initial commit'")
end
@project.require_mock_gem(foo)
@project.bundle_install!

check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)
after do
ENV["BUNDLE_GEMFILE"] = nil
project.write_gemfile!(project.tapioca_gemfile)
@project.require_default_gems
project.remove!("sorbet/rbi")
project.remove!("../gems")
project.remove!(".git")
project.remove!("sorbet/tapioca/require.rb")
project.remove!("config/application.rb")
project.remove!(".bundle")
project.remove!("Gemfile.lock")
ensure
@project.remove!("output")
end

assert_project_file_exist("sorbet/rbi/gems/[email protected]")
end
it "creates the RBI for a newly added gem" do
foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
end
@project.require_mock_gem(foo)
@project.bundle_install!

it "regenerates RBI when a gem version changes" do
setup_git_repo
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
assert_project_file_exist("sorbet/rbi/gems/[email protected]")
end
@project.require_mock_gem(foo)
@project.bundle_install!

check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)
it "regenerates RBI when a gem version changes" do
foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
end
@project.require_mock_gem(foo)
@project.bundle_install!

assert_project_file_exist("sorbet/rbi/gems/[email protected]")
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

# Modify the gem
foo = mock_gem("foo", "0.0.2") do
write!("lib/foo.rb", FOO_RB)
end
@project.require_mock_gem(foo)
@project.bundle_install!

check.run(@project.absolute_path)
assert_project_file_exist("sorbet/rbi/gems/[email protected]")

assert_project_file_exist("sorbet/rbi/gems/[email protected]")
end
# Modify the gem
foo = mock_gem("foo", "0.0.2") do
write!("lib/foo.rb", FOO_RB)
end
@project.require_mock_gem(foo)
@project.bundle_install!

it "removes RBI file when a gem is removed" do
setup_git_repo
check.run(@project.absolute_path)

foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
assert_project_file_exist("sorbet/rbi/gems/[email protected]")
end
@project.require_mock_gem(foo)
@project.bundle_install!

check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)
it "removes RBI file when a gem is removed" do
foo = mock_gem("foo", "0.0.1") do
write!("lib/foo.rb", FOO_RB)
end
@project.require_mock_gem(foo)
@project.bundle_install!

assert_project_file_exist("sorbet/rbi/gems/[email protected]")
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

@project.exec("git add Gemfile.lock")
@project.exec("git commit -m 'Add foo gem'")
assert_project_file_exist("sorbet/rbi/gems/[email protected]")

@project.write_gemfile!(@project.tapioca_gemfile)
@project.bundle_install!
@project.exec("git add Gemfile.lock")
@project.exec("git commit -m 'Add foo gem'")

check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

refute_project_file_exist("sorbet/rbi/gems/[email protected]")
end
@project.write_gemfile!(@project.tapioca_gemfile)
@project.bundle_install!

it "deletes untracked RBI files" do
setup_git_repo
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

# Create an untracked RBI file
FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]")
refute_project_file_exist("sorbet/rbi/gems/[email protected]")
end

assert_project_file_exist("/sorbet/rbi/gems/[email protected]")
it "deletes untracked RBI files" do
# Create an untracked RBI file
FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]")

check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)
assert_project_file_exist("/sorbet/rbi/gems/[email protected]")

refute_project_file_exist("sorbet/rbi/gems/[email protected]")
end
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

it "restores deleted RBI files" do
setup_git_repo
refute_project_file_exist("sorbet/rbi/gems/[email protected]")
end

# Create and delete a tracked RBI file
FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]")
@project.exec("git add sorbet/rbi/gems/[email protected]")
@project.exec("git commit -m 'Add foo RBI'")
FileUtils.rm("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]")
it "restores deleted RBI files" do
# Create and delete a tracked RBI file
FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]")
@project.exec("git add sorbet/rbi/gems/[email protected]")
@project.exec("git commit -m 'Add foo RBI'")
FileUtils.rm("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]")

refute_project_file_exist("sorbet/rbi/gems/[email protected]")
refute_project_file_exist("sorbet/rbi/gems/[email protected]")

check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new
check.run(@project.absolute_path)

assert_project_file_exist("sorbet/rbi/gems/[email protected]")
assert_project_file_exist("sorbet/rbi/gems/[email protected]")
end
end
end
end
Expand Down

0 comments on commit 17d6c89

Please sign in to comment.