-
-
Notifications
You must be signed in to change notification settings - Fork 11
Add new Capybara/RSpec/HaveContent cop
#160
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
Conversation
cc8046b to
4969493
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.
I believe it is beneficial to provide a cop that unifies multiple approaches yielding the same result into one. Such cops have been provided by this gem in the past as well. Therefore, I personally think that this kind of cop is acceptable.
The points that I was interested in are as follows:
- You should explain the clear reason why
have_textis always better thanhave_contentin the doc comments. For example, the fact that it's shorter, how good short code is, or that Capybara's official documentation recommends it, or some performance reason, etc. If no special reason can be shown and it's merely a matter of preference, then preferences should be switchable byEnforcedStyle. - If a clear reason can be shown as mentioned above, how about
Capyabara/HaveContent(orCapybara/RSpec/HaveContent) as the cop name? I believe there are various opinions regarding cop naming conventions, but I personally prefer names that represent bad styles. Therefore, in cases where there is a binary choice, with one option being inherently bad, I prefer a cop likeHaveContent. This makes it easier to understand that "have_content" is not good. - Some cops in this gem are included in the department
Capybara/RSpec, but what criteria are used to decide whether a particular cop should be included in this department? Are all existing cops following some specific criteria, or is there no consistency? Furthermore, should this cop be included there this time?
Capybara/TextMatcherStyle cop
@ydah I believe you are knowledgeable about There is a possibility that this pr might conflict with your pr. Do you have any opinions about this cop? |
|
hi @r7kamura thanks for the feedback 😄
It makes it clearer using Capybara also supports
|
Capybara/TextMatcherStyle copCapybara/HaveContent cop
|
Nice! I'm all for adding this cop with this implementation. I believe the final decision on whether to use Capybara/RSpec/HaveContent or just Capybara/HaveContent will depend on the outcome of the following PR, so please wait a little longer for that decision: @rubocop/rubocop-rspec Please let us know if you have any other opinions about this cop. |
|
Agreed! I think |
|
@ydah sure thing, I'll update it, then squash my commits down to one commit too 😄 |
7b6a9ef to
4db66f0
Compare
Capybara/HaveContent copCapybara/RSpec/HaveContent cop
lib/rubocop/cop/capybara_cops.rb
Outdated
| require_relative 'capybara/click_link_or_button_style' | ||
| require_relative 'capybara/current_path_expectation' | ||
| require_relative 'capybara/find_all_first' | ||
|
|
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.
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.
Removed and squashed 😄
|
It's a minor thing, but there's an unnecessary line break, so please remove it and squash it. Other than that, it's perfect! I plan to merge it once that's fixed. |
fac2c15 to
729cede
Compare
|
Thank you for your contribution! |
Addresses issue:
Capybara supports both methods, but as the former is more concise, this cop standardises on using
have_textandhave_no_textoverhave_contentorhave_no_content, which will help with consistency in codebases using them.It makes it clearer using have_text because the matcher is checking visible text rather than content in a broader sense, and have_content is just an alias for the method. As far as I know there's no functional advantage to using have_content so standardising on one seems sensible?
Capybara also supports assert_text - so I think that's another important reason to support have_text, just having that consistent naming across the RSpec and minitest options is helpful when using them in a codebase.
Before submitting the PR make sure the following are checked:
main(if not - rebase it).CHANGELOG.mdif the new code introduces user-observable changes.bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml.Enabled: pendinginconfig/default.yml.VersionAdded: "<<next>>"indefault/config.yml.If you have modified an existing cop's configuration options:
VersionChanged: "<<next>>"inconfig/default.yml.