-
Notifications
You must be signed in to change notification settings - Fork 134
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
b0ab3d6
commit 17d6c89
Showing
2 changed files
with
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,140 +12,141 @@ module Foo | |
end | ||
RUBY | ||
|
||
# TODO: understand why this fails with `before(:all)` | ||
# before(:all) do | ||
before do | ||
@project.tapioca("configure") | ||
end | ||
describe "without git" do | ||
before do | ||
@project.tapioca("configure") | ||
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") | ||
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) | ||
|
||
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 | ||
@project.bundle_install! | ||
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check.run(@project.absolute_path) | ||
|
||
it "does nothing if there is no git repo" do | ||
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 check.result.stdout.include?("Not a git repository") | ||
end | ||
|
||
it "creates the RBI for a newly added gem" do | ||
setup_git_repo | ||
|
||
foo = mock_gem("foo", "0.0.1") do | ||
write!("lib/foo.rb", FOO_RB) | ||
describe "with git" do | ||
# TODO: understand why this fails with `before(:all)` | ||
# before(:all) do | ||
before do | ||
@project.tapioca("configure") | ||
@project.exec("git init") | ||
@project.exec("git config user.email '[email protected]'") | ||
@project.exec("git config user.name 'Test User'") | ||
@project.bundle_install! | ||
FileUtils.mkdir_p("#{@project.absolute_path}/sorbet/rbi/gems") | ||
@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) | ||
after do | ||
ENV["BUNDLE_GEMFILE"] = nil | ||
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") | ||
project.remove!(".bundle") | ||
project.remove!("Gemfile.lock") | ||
ensure | ||
@project.remove!("output") | ||
end | ||
|
||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
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) | ||
end | ||
@project.require_mock_gem(foo) | ||
@project.bundle_install! | ||
|
||
it "regenerates RBI when a gem version changes" do | ||
setup_git_repo | ||
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_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
@project.require_mock_gem(foo) | ||
@project.bundle_install! | ||
|
||
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
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]") | ||
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) | ||
end | ||
@project.require_mock_gem(foo) | ||
@project.bundle_install! | ||
|
||
check.run(@project.absolute_path) | ||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
|
||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
# Modify the gem | ||
foo = mock_gem("foo", "0.0.2") do | ||
write!("lib/foo.rb", FOO_RB) | ||
end | ||
@project.require_mock_gem(foo) | ||
@project.bundle_install! | ||
|
||
it "removes RBI file when a gem is removed" do | ||
setup_git_repo | ||
check.run(@project.absolute_path) | ||
|
||
foo = mock_gem("foo", "0.0.1") 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 = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check.run(@project.absolute_path) | ||
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! | ||
|
||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check.run(@project.absolute_path) | ||
|
||
@project.exec("git add Gemfile.lock") | ||
@project.exec("git commit -m 'Add foo gem'") | ||
assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
|
||
@project.write_gemfile!(@project.tapioca_gemfile) | ||
@project.bundle_install! | ||
@project.exec("git add Gemfile.lock") | ||
@project.exec("git commit -m 'Add foo gem'") | ||
|
||
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check.run(@project.absolute_path) | ||
|
||
refute_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
@project.write_gemfile!(@project.tapioca_gemfile) | ||
@project.bundle_install! | ||
|
||
it "deletes untracked RBI files" do | ||
setup_git_repo | ||
check = ::RubyLsp::Tapioca::RunGemRbiCheck.new | ||
check.run(@project.absolute_path) | ||
|
||
# Create an untracked RBI file | ||
FileUtils.touch("#{@project.absolute_path}/sorbet/rbi/gems/[email protected]") | ||
refute_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
|
||
assert_project_file_exist("/sorbet/rbi/gems/[email protected]") | ||
it "deletes untracked RBI files" do | ||
# 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 | ||
setup_git_repo | ||
refute_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
end | ||
|
||
# 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]") | ||
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]") | ||
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]") | ||
end | ||
end | ||
end | ||
end | ||
|