Skip to content
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

rubocops/text: improve test descriptions #10332

Merged
merged 2 commits into from
Jan 18, 2021

Conversation

SeekingMeaning
Copy link
Contributor

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?
  • Have you successfully run brew man locally and committed any changes?

Continuation of #10124

This PR improves the test descriptions of text_spec.rb so that the error messages are more coherent.

Before:
RuboCop::Cop::FormulaAudit::Text When auditing formula text with `require "formula"` is present

After:
RuboCop::Cop::FormulaAudit::Text when auditing formula text reports an offense if `require "formula"` is present

(I'm not sure if my extensive use of single quotes ['] and percent literals [%Q(...)] is recommended; please tell me if it isn't)

@BrewTestBot
Copy link
Member

Review period will end on 2021-01-18 at 02:18:16 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 15, 2021
Copy link
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for the most part. Thanks, @SeekingMeaning!

I'm not at all opposed to using single-quotes.

I think the %Q() should be avoided if possible because it's a little less clean (and can be confusing to people who aren't as familiar with ruby). I think all the instances in this PR can be replaced with single-quotes without any issues. I could very well be missing something, though.

Library/Homebrew/test/rubocops/text_spec.rb Outdated Show resolved Hide resolved
Library/Homebrew/test/rubocops/text_spec.rb Outdated Show resolved Hide resolved
@@ -307,7 +303,7 @@ class Foo < Formula
RUBY
end

it "when `\#{share}/foo` is used instead of `\#{pkgshare}`" do
it %Q(reports an offense if "\#{share}/<formula name>" is present) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not work? Single quotes won't do string interpolation

Suggested change
it %Q(reports an offense if "\#{share}/<formula name>" is present) do
it 'reports an offense if "#{share}/<formula name>" is present' do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't work as it's seen as broken interpolation, i.e. we have to explicitly escape the #

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? When I test it out in brew irb it seems to work fine...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a quick test ruby script:

puts 'reports an offense if "#{share}/<formula name>" is present'

And then ran brew ruby test.rb:

$ brew ruby test.rb
reports an offense if "#{share}/<formula name>" is present

Copy link
Contributor Author

@SeekingMeaning SeekingMeaning Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant that it works, but brew style sees it as "broken"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Library/Homebrew/test/rubocops/text_spec.rb:304:8: W: [Correctable] Interpolation in single quoted string detected. Use double quoted strings if you need interpolation.
    it 'reports an offense if "#{share}/<formula name>" is present' do
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense auto-correctable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. That's interesting... If it were up to me I'd say let's disable that cop and allow it. But I don't feel strongly about that, so I think %Q is fine. Although, if we use %q instead no need to escape the #:

Suggested change
it %Q(reports an offense if "\#{share}/<formula name>" is present) do
it %q(reports an offense if "#{share}/<formula name>" is present) do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same error:

Library/Homebrew/test/rubocops/text_spec.rb:304:8: W: [Correctable] Interpolation in single quoted string detected. Use double quoted strings if you need interpolation.
    it %q(reports an offense if "#{share}/<formula name>" is present) do
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah well, that's unfortunate. I agree, then, this is the best option.

Library/Homebrew/test/rubocops/text_spec.rb Show resolved Hide resolved
Library/Homebrew/test/rubocops/text_spec.rb Show resolved Hide resolved
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 18, 2021
@BrewTestBot
Copy link
Member

Review period ended.

@SeekingMeaning SeekingMeaning merged commit 32ba87d into Homebrew:master Jan 18, 2021
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Feb 18, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Feb 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants