Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Shopify/tapioca
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 068808aa720cab6be801ef1588043e62bc2a1c1b
Choose a base ref
..
head repository: Shopify/tapioca
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cc00fed9c4a47448a94d2d9e3198c0d30d6899fe
Choose a head ref
Showing with 23 additions and 21 deletions.
  1. +1 −1 .github/workflows/ci.yml
  2. +3 −7 lib/ruby_lsp/tapioca/run_gem_rbi_check.rb
  3. +7 −1 spec/helpers/mock_gem.rb
  4. +2 −3 spec/spec_with_project.rb
  5. +10 −9 spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ jobs:
bundler-cache: true
rubygems: ${{ matrix.rubygems }}
- name: Run tests
run: bin/test spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb
run: bin/test
continue-on-error: ${{ !!matrix.experimental }}

buildall:
10 changes: 3 additions & 7 deletions lib/ruby_lsp/tapioca/run_gem_rbi_check.rb
Original file line number Diff line number Diff line change
@@ -27,11 +27,9 @@ def initialize
sig { params(project_path: String).returns(GemRbiCheckResult) }
def run(project_path = ".")
FileUtils.chdir(project_path) do
if git_repo?
lockfile_changed? ? generate_gem_rbis : cleanup_orphaned_rbis
else
log_message("Not a git repository")
end
next log_message("Not a git repository") unless git_repo?

lockfile_changed? ? generate_gem_rbis : cleanup_orphaned_rbis
end

@result
@@ -75,9 +73,7 @@ def generate_gem_rbis
sig { params(gems: T::Array[String]).void }
def execute_tapioca_gem_command(gems)
Bundler.with_unbundled_env do
# 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" },
"bundle",
"exec",
"tapioca",
8 changes: 7 additions & 1 deletion spec/helpers/mock_gem.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ class MockGem < Spoom::Context

# The gem's version string such as "1.0.0" or ">= 2.0.5"
sig { returns(String) }
attr_accessor :version
attr_reader :version

# The dependencies to be added to the gem's gemspec
sig { returns(T::Array[String]) }
@@ -66,5 +66,11 @@ def default_gemspec_contents
end
GEMSPEC
end

sig { params(version: String).void }
def update(version)
@version = version
gemspec(default_gemspec_contents)
end
end
end
5 changes: 2 additions & 3 deletions spec/spec_with_project.rb
Original file line number Diff line number Diff line change
@@ -85,9 +85,8 @@ def mock_gem(name, version, dependencies: [], path: default_gem_path(name), &blo
end

sig { params(gem: MockGem, version: String).returns(MockGem) }
def update_gem(gem, version)
gem.version = version
gem.gemspec(gem.default_gemspec_contents)
def update_mock_gem(gem, version)
gem.update(version)
gem
end

19 changes: 10 additions & 9 deletions spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb
Original file line number Diff line number Diff line change
@@ -12,18 +12,13 @@ module Foo
end
RUBY

before do
before(:all) do
@project = mock_project
end

after do
@project.destroy!
end

describe "without git" do
before do
@project.bundle_install!
@project.tapioca("configure")
end

it "does nothing if there is no git repo" do
@@ -42,14 +37,20 @@ module Foo

describe "with git" do
before do
@project.write!("Gemfile", @project.tapioca_gemfile)
@project.bundle_install!
@project.tapioca("configure")
@project.exec("git init")
@project.exec("git config commit.gpgsign false")
@project.exec("git add .")
@project.exec("git commit -m 'Initial commit'")
end

after do
@project.remove!("sorbet/rbi")
@project.remove!(".git")
@project.remove!("Gemfile")
@project.remove!("Gemfile.lock")
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)
@@ -76,7 +77,7 @@ module Foo
assert_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi")

# Modify the gem
update_gem foo, "0.0.2"
update_mock_gem foo, "0.0.2"
@project.bundle_install!

check.run(@project.absolute_path)