Capybara

Capybara/AmbiguousClick

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

No

2.22

-

Specify the exact target to click on.

In projects where accessibility needs to be considered, it is crucial to specify the click target precisely.

Examples

# bad
click_link_or_button('foo')
click_on('foo')

# good
click_link('foo')
click_button('foo')

Capybara/AssertStyle

Enabled by default Safe Supports autocorrection Version Added Version Changed

Enabled

Yes

Always

2.23

3.0

Checks for usage of deprecated assert style method.

Examples

# bad
page.find(:css, '#first').assert_style(display: 'block')

# good
page.find(:css, '#first').assert_matches_style(display: 'block')

Capybara/FindAllFirst

Enabled by default Safe Supports autocorrection Version Added Version Changed

Enabled

Yes

Always (Unsafe)

2.22

3.0

Enforces use of first instead of all with first or [0].

Safety

This cop’s autocorrection is unsafe because all returns a Capybara::Result (an enumerable collection), while first returns a single Capybara::Node::Element. Replacing all with first may break code that depends on the return value being a collection (e.g. calling .each on the result).

Examples

# bad
all('a').first
all('a')[0]
find('a', match: :first)
all('a', match: :first)

# good
first('a')

Capybara/RedundantWithinFind

Enabled by default Safe Supports autocorrection Version Added Version Changed

Enabled

Yes

Always

2.20

3.0

Checks for redundant within find(…​) calls.

Examples

# bad
within find('foo.bar') do
  # ...
end

# good
within 'foo.bar' do
  # ...
end

# bad
within find_by_id('foo') do
  # ...
end

# good
within '#foo' do
  # ...
end

Capybara/SpecificActions

Enabled by default Safe Supports autocorrection Version Added Version Changed

Enabled

Yes

No

2.14

3.0

Checks for there is a more specific actions offered by Capybara.

Examples

# bad
find('a').click
find('button.cls').click
find('a', exact_text: 'foo').click
find('div button').click

# good
click_link
click_button(class: 'cls')
click_link(exact_text: 'foo')
find('div').click_button

Capybara/SpecificFinders

Enabled by default Safe Supports autocorrection Version Added Version Changed

Enabled

Yes

Always

2.13

3.0

Checks if there is a more specific finder offered by Capybara.

Examples

# bad
find('#some-id')
find('[id=some-id]')
find(:css, '#some-id')
find(:id, 'some-id')

# good
find_by_id('some-id')