-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dd5d4b
commit 6b9f24f
Showing
5 changed files
with
101 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,140 +12,131 @@ module Foo | |
end | ||
RUBY | ||
|
||
# TODO: understand why this fails with `before(:all)` | ||
# before(:all) do | ||
before do | ||
@project.tapioca("configure") | ||
@project = mock_project | ||
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") | ||
@project.destroy! | ||
end | ||
|
||
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 | ||
|
||
it "does nothing if there is no git repo" do | ||
foo = mock_gem("foo", "0.0.1") do | ||
write!("lib/foo.rb", FOO_RB) | ||
describe "without git" do | ||
before do | ||
@project.bundle_install! | ||
@project.tapioca("configure") | ||
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 "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 "creates the RBI for a newly added gem" do | ||
setup_git_repo | ||
@project.bundle_install! | ||
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 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_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
|
||
it "regenerates RBI when a gem version changes" do | ||
setup_git_repo | ||
|
||
foo = mock_gem("foo", "0.0.1") do | ||
write!("lib/foo.rb", FOO_RB) | ||
describe "with git" do | ||
before do | ||
@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 | ||
@project.require_mock_gem(foo) | ||
@project.bundle_install! | ||
|
||
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check.run(@project.absolute_path) | ||
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! | ||
|
||
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) | ||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
@project.require_mock_gem(foo) | ||
@project.bundle_install! | ||
|
||
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]") | ||
end | ||
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check.run(@project.absolute_path) | ||
|
||
it "removes RBI file when a gem is removed" do | ||
setup_git_repo | ||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
|
||
foo = mock_gem("foo", "0.0.1") do | ||
write!("lib/foo.rb", FOO_RB) | ||
end | ||
@project.require_mock_gem(foo) | ||
@project.bundle_install! | ||
# Modify the gem | ||
update_gem foo, "0.0.2" | ||
@project.bundle_install! | ||
|
||
check.run(@project.absolute_path) | ||
|
||
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check.run(@project.absolute_path) | ||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
|
||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
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! | ||
|
||
@project.exec("git add Gemfile.lock") | ||
@project.exec("git commit -m 'Add foo gem'") | ||
check1 = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check1.run(@project.absolute_path) | ||
|
||
@project.write_gemfile!(@project.tapioca_gemfile) | ||
@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 restore Gemfile Gemfile.lock") | ||
|
||
refute_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
check2 = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check2.run(@project.absolute_path) | ||
|
||
it "deletes untracked RBI files" do | ||
setup_git_repo | ||
refute_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
|
||
# Create an untracked RBI file | ||
FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]") | ||
it "deletes untracked RBI files" do | ||
@project.bundle_install! | ||
FileUtils.mkdir_p("#{@project.absolute_path}/sorbet/rbi/gems") | ||
# Create an untracked RBI file | ||
FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]") | ||
|
||
assert_project_file_exist("/sorbet/rbi/gems/[email protected]") | ||
assert_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) | ||
|
||
refute_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
refute_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
|
||
it "restores deleted RBI files" do | ||
setup_git_repo | ||
it "restores deleted RBI files" do | ||
@project.bundle_install! | ||
FileUtils.mkdir_p("#{@project.absolute_path}/sorbet/rbi/gems") | ||
# 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]") | ||
|
||
# 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]") | ||
# Clean-up commit | ||
@project.exec("git reset --hard HEAD^") | ||
end | ||
end | ||
end | ||
end | ||
|