-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include excluded gems in verify logic #1058
Conversation
lib/tapioca/commands/gem.rb
Outdated
diff = {} | ||
|
||
removed_rbis.each do |gem_name| | ||
filename = existing_rbi(gem_name) | ||
diff[filename] = :removed | ||
unless exclude.include?(gem_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do the same in the loop below for added_rbis
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exclude
prevents the creation of an RBI for the excluded gem and if one exists, deletes it so my understanding is that there really shouldn't be a case where an excluded RBI ends up in theadded_rbis
array
@@ -1604,30 +1604,23 @@ class User; end | |||
assert_success_status(result) | |||
end | |||
|
|||
it "advises of removed file(s) and returns exit_status 1" do | |||
it "is aware of exclude option and does not error due to removed files" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the previous test has value. Can we add a new example instead of modifying the existing one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I can do that! I am a bit confused though because this code change means there won't be a warning of removed file(s) & won't return exist_status 1
with gem --verify --exclude foo bar
so I'm not sure how to leave this test unmodified since what it is testing is no longer the expected behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test was probably using exclude
to simplify the setup, but the scenario is still valid. We should still warn users of removed gems and exit with status 1.
Instead of running Tapioca with the exclude flag, you'll need to somehow remove the fake foo or bar gems from @project
and then see that the RBI is removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we already have a test for that scenario here:
tapioca/spec/tapioca/cli/gem_spec.rb
Lines 1609 to 1642 in 67f9504
it "advises of added/removed/changed file(s) and returns exit_status 1" do | |
@project.tapioca("gem") | |
@project.remove("sorbet/rbi/gems/foo@0.0.1.rbi") | |
@project.write("sorbet/rbi/gems/outdated@5.0.0.rbi") | |
@project.move("sorbet/rbi/gems/bar@0.3.0.rbi", "sorbet/rbi/gems/bar@0.2.0.rbi") | |
result = @project.tapioca("gem --verify") | |
assert_equal(<<~OUT, result.out) | |
Checking for out-of-date RBIs... | |
RBI files are out-of-date. In your development environment, please run: | |
`bin/tapioca gem` | |
Once it is complete, be sure to commit and push any changes | |
Reason: | |
File(s) added: | |
- sorbet/rbi/gems/foo@0.0.1.rbi | |
File(s) changed: | |
- sorbet/rbi/gems/bar@0.3.0.rbi | |
File(s) removed: | |
- sorbet/rbi/gems/outdated@5.0.0.rbi | |
OUT | |
# Does not actually modify anything | |
refute_project_file_exist("sorbet/rbi/gems/foo@0.0.1.rbi") | |
assert_project_file_exist("sorbet/rbi/gems/outdated@5.0.0.rbi") | |
assert_project_file_exist("sorbet/rbi/gems/bar@0.2.0.rbi") | |
assert_empty_stderr(result) | |
refute_success_status(result) | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay. In that case, I think we're covered. Thanks for looking into it!
lib/tapioca/commands/gem.rb
Outdated
diff = {} | ||
|
||
removed_rbis.each do |gem_name| | ||
filename = existing_rbi(gem_name) | ||
diff[filename] = :removed | ||
unless exclude.include?(gem_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead do:
unless exclude.include?(gem_name) | |
next if exclude.include?(gem_name) |
so that the code is easier to read and not deeply nested?
a7692db
to
3a148e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should spec/tapioca/.DS_Store
be added?
@stanjdev no LOL that was a mistake 🤣 I'm googling how to remove it |
3a148e9
to
aa2c443
Compare
Motivation
Closes #658
Excluded gems shouldn't be verified.
Implementation
I went into the
verify
implementation and added in some logic to skip over anyexcluded
gems so that it doesn't error due to them being removed.Tests
I updated the related test and all local tests passed.
Additionally, I spun up an instance of
Shopify/shopify
and added a random gem (colorize
) to the list of excluded gems thenbin/tapioca gem
to remove thecolorize
gem andbin/tapioca --verify
which caused no errors. Once I removedcolorize
from the excluded list,bin/tapioca --verify
errored as expected.