Skip to content

Commit

Permalink
wip test add logs and change ci yml
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrocha committed Jan 10, 2025
1 parent 3b24432 commit cb7a760
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions lib/ruby_lsp/tapioca/run_gem_rbi_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/mock_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]) }
Expand Down
7 changes: 7 additions & 0 deletions spec/spec_with_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
56 changes: 28 additions & 28 deletions spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Foo

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

Expand All @@ -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 '[email protected]'")
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")
Expand All @@ -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
Expand Down Expand Up @@ -87,9 +88,7 @@ module Foo
assert_project_file_exist("sorbet/rbi/gems/[email protected]")

# 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!

Expand Down Expand Up @@ -122,37 +121,38 @@ module Foo
refute_project_file_exist("sorbet/rbi/gems/[email protected]")
end

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

assert_project_file_exist("/sorbet/rbi/gems/[email protected]")
# 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
# 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]")
end

refute_project_file_exist("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]")

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

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

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

def check_exec(command)
result = command
raise "fail" unless result.status
raise "failing" unless result.status
end
end
end
Expand Down

0 comments on commit cb7a760

Please sign in to comment.