diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8328f7d4..a55935403 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: bundler-cache: true rubygems: ${{ matrix.rubygems }} - name: Run tests - run: bin/test + run: bin/test spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb continue-on-error: ${{ !!matrix.experimental }} buildall: diff --git a/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb b/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb index 8a503a5bd..460f664dd 100644 --- a/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +++ b/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb @@ -27,6 +27,7 @@ def initialize sig { params(project_path: String).returns(GemRbiCheckResult) } def run(project_path = ".") FileUtils.chdir(project_path) do + $stderr.puts "Inside Run Method" if git_repo? lockfile_changed? ? generate_gem_rbis : cleanup_orphaned_rbis else @@ -119,6 +120,7 @@ def restore_files(files, message) sig { params(message: String).void } def log_message(message) + $stderr.puts message @result.stdout += "#{message}\n" end end diff --git a/spec/helpers/mock_gem.rb b/spec/helpers/mock_gem.rb index 1aa278fdd..d26ad94ed 100644 --- a/spec/helpers/mock_gem.rb +++ b/spec/helpers/mock_gem.rb @@ -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_reader :version + attr_accessor :version # The dependencies to be added to the gem's gemspec sig { returns(T::Array[String]) } diff --git a/spec/spec_with_project.rb b/spec/spec_with_project.rb index 3413914a5..be06a01b6 100644 --- a/spec/spec_with_project.rb +++ b/spec/spec_with_project.rb @@ -84,6 +84,13 @@ def mock_gem(name, version, dependencies: [], path: default_gem_path(name), &blo gem end + sig { params(gem: MockGem, version: String).returns(MockGem) } + def update_gem(gem, version) + gem.version = version + gem.gemspec(gem.default_gemspec_contents) + gem + end + # Spec assertions # Assert that the contents of `path` inside `@project` is equals to `expected` diff --git a/spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb b/spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb index 7811596a8..cb6e8387c 100644 --- a/spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb +++ b/spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb @@ -14,6 +14,7 @@ module Foo describe "without git" do before do + @project.bundle_install! @project.tapioca("configure") end @@ -35,19 +36,19 @@ module Foo # TODO: understand why this fails with `before(:all)` # before(:all) do before do + # @project.require_default_gems + @project.bundle_install! @project.tapioca("configure") check_exec @project.exec("git init") check_exec @project.exec("git config user.email 'test@example.com'") check_exec @project.exec("git config user.name 'Test User'") - @project.bundle_install! + check_exec @project.exec("git config commit.gpgsign false") FileUtils.mkdir_p("#{@project.absolute_path}/sorbet/rbi/gems") check_exec @project.exec("git add .") check_exec @project.exec("git commit -m 'Initial commit'") - $stdout.puts %x(cd #{@project.absolute_path} && git status) end after do - ENV["BUNDLE_GEMFILE"] = nil @project.write_gemfile!(project.tapioca_gemfile) @project.require_default_gems @project.remove!("sorbet/rbi") @@ -57,8 +58,8 @@ module Foo @project.remove!("config/application.rb") @project.remove!(".bundle") @project.remove!("Gemfile.lock") - ensure - @project.remove!("output") + ensure + @project.remove!("output") end it "creates the RBI for a newly added gem" do @@ -87,9 +88,7 @@ module Foo assert_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi") # Modify the gem - foo = mock_gem("foo", "0.0.2") do - write!("lib/foo.rb", FOO_RB) - end + update_gem foo, "0.0.2" @project.require_mock_gem(foo) @project.bundle_install! @@ -122,37 +121,38 @@ module Foo refute_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi") end - it "deletes untracked RBI files" do - # Create an untracked RBI file - FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/bar@0.0.1.rbi") + it "deletes untracked RBI files" do - assert_project_file_exist("/sorbet/rbi/gems/bar@0.0.1.rbi") + # Create an untracked RBI file + FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/bar@0.0.1.rbi") - check = ::RubyLsp::Tapioca::RunGemRbiCheck.new - check.run(@project.absolute_path) + assert_project_file_exist("/sorbet/rbi/gems/bar@0.0.1.rbi") - refute_project_file_exist("sorbet/rbi/gems/bar@0.0.1.rbi") - end + check = ::RubyLsp::Tapioca::RunGemRbiCheck.new + check.run(@project.absolute_path) - it "restores deleted RBI files" do - # Create and delete a tracked RBI file - FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/foo@0.0.1.rbi") - @project.exec("git add sorbet/rbi/gems/foo@0.0.1.rbi") - @project.exec("git commit -m 'Add foo RBI'") - FileUtils.rm("#{@project.absolute_path}/sorbet/rbi/gems/foo@0.0.1.rbi") + refute_project_file_exist("sorbet/rbi/gems/bar@0.0.1.rbi") + end - refute_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi") + it "restores deleted RBI files" do + # Create and delete a tracked RBI file + FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/foo@0.0.1.rbi") + @project.exec("git add sorbet/rbi/gems/foo@0.0.1.rbi") + @project.exec("git commit -m 'Add foo RBI'") + FileUtils.rm("#{@project.absolute_path}/sorbet/rbi/gems/foo@0.0.1.rbi") - check = ::RubyLsp::Tapioca::RunGemRbiCheck.new - check.run(@project.absolute_path) + refute_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi") - assert_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi") - end + check = ::RubyLsp::Tapioca::RunGemRbiCheck.new + check.run(@project.absolute_path) + + assert_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi") + end end def check_exec(command) result = command - raise "fail" unless result.status + raise "failing" unless result.status end end end