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 ee8b822
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 52 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
1 change: 1 addition & 0 deletions spec/helpers/mock_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def require_real_gem(name, version = nil, require: nil)
def require_default_gems
require_real_gem("ostruct")
require_real_gem("logger")
require_real_gem("erubi")
end

# Default Gemfile contents requiring only Tapioca
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
99 changes: 49 additions & 50 deletions spec/tapioca/ruby_lsp/run_gem_rbi_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,53 @@ module Foo
end
RUBY

describe "without git" do
before do
@project.tapioca("configure")
end
# describe "without git" do
# before do
# @project.tapioca("configure")
# 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)
# 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)

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

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

describe "with git" do
# 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.write_gemfile!(project.tapioca_gemfile)
# @project.require_default_gems
@project.remove!("sorbet/rbi")
@project.remove!("../gems")
# @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")
# @project.remove!("sorbet/tapioca/require.rb")
# @project.remove!("config/application.rb")
# @project.remove!(".bundle")
# @project.remove!("Gemfile.lock")
# ensure
# @project.remove!("output")
end

it "creates the RBI for a newly added gem" do
Expand Down Expand Up @@ -87,9 +87,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 +120,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 ee8b822

Please sign in to comment.