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

Fix an offense message for Capybara/SpecificFinders #32

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Edge (Unreleased)

- Fix an offense message for `Capybara/SpecificFinders`. ([@ydah])

## 2.17.1 (2023-02-13)

- Fix an incorrect autocorrect for `Capybara/CurrentPathExpectation`. ([@ydah])
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/capybara/specific_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SpecificFinders < ::RuboCop::Cop::Base

include RangeHelp

MSG = 'Prefer `find_by` over `find`.'
MSG = 'Prefer `find_by_id` over `find`.'
RESTRICT_ON_SEND = %i[find].freeze

# @!method find_argument(node)
Expand Down
40 changes: 20 additions & 20 deletions spec/rubocop/cop/capybara/specific_finders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
it 'registers an offense when using `find`' do
expect_offense(<<~RUBY)
find('#some-id')
^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -15,7 +15,7 @@
it 'registers an offense when using `find` with no parentheses' do
expect_offense(<<~RUBY)
find "#some-id"
^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -26,7 +26,7 @@
it 'registers an offense when using `find` with id and class' do
expect_offense(<<~RUBY)
find('#some-id.some-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -37,15 +37,15 @@
it 'registers an offense when using `find` with id include `\.`' do
expect_offense(<<~RUBY)
find('#some-id\\.some-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
find('#some-id\\>some-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
find('#some-id\\,some-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
find('#some-id\\+some-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
find('#some-id\\~some-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -60,7 +60,7 @@
it 'registers an offense when using `find` with multiple classes' do
expect_offense(<<~RUBY)
find('#some-id.some-cls.other-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -72,7 +72,7 @@
"and class: 'other-cls'" do
expect_offense(<<~RUBY)
find('#some-id.some-cls', class: 'other-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -84,7 +84,7 @@
"and class: ['other-cls1', 'other-cls2']" do
expect_offense(<<~RUBY)
find('#some-id.some-cls', class: ['other-cls1', 'other-cls2'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -96,7 +96,7 @@
"and exact_text: 'foo', class: 'other-cls'" do
expect_offense(<<~RUBY)
find('#some-id.some-cls', exact_text: 'foo', class: 'other-cls')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -107,7 +107,7 @@
it 'registers an offense when using `find` and other args' do
expect_offense(<<~RUBY)
find('#some-id', exact_text: 'foo')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -119,7 +119,7 @@
'with no parentheses' do
expect_offense(<<~RUBY)
find '#some-id', exact_text: 'foo'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -130,9 +130,9 @@
it 'registers an offense when using `find` with method chain' do
expect_offense(<<~RUBY)
find('#some-id').find('#other-id').find('#another-id')
^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -144,7 +144,7 @@
'with argument is attribute specified id' do
expect_offense(<<~RUBY)
find('[id=some-id]')
^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -156,9 +156,9 @@
'with argument is attribute specified id surrounded by quotation' do
expect_offense(<<~RUBY)
find('[id="foo"]')
^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
find('[id="foo[bar]"]')
^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by_id` over `find`.
RUBY

expect_correction(<<~RUBY)
Expand Down