Capybara
Capybara/AbsoluteXPathInElementScope
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
|---|---|---|---|---|
Pending |
Yes |
No |
3.1 |
- |
Checks for absolute XPath searches on Capybara elements.
An XPath starting with // searches from the document root, even when
the query is called on an element. Use .// to stay within it.
Direct RSpec let and named subject element definitions are
recognized.
Examples
# bad
page.find('.dialog').find(:xpath, '//button')
dialog = page.find('.dialog')
dialog.find(:xpath, '//button')
RSpec.describe 'dialog' do
let(:dialog) { find('.dialog') }
it { dialog.find(:xpath, '//button') }
end
# good
page.find('.dialog').find(:xpath, './/button')
page.find(:xpath, '//button')
Capybara/AlwaysTrueCountQuery
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
|---|---|---|---|---|
Pending |
Yes |
No |
3.1 |
- |
Checks for positive queries that succeed when there are no matches.
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.
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.
Capybara/ChainedFind
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
|---|---|---|---|---|
Pending |
Yes |
Always |
3.1 |
- |
Avoid chaining find methods and combine selectors.
Combining selectors into a single find call is more efficient than
chaining multiple find calls, as it reduces the number of DOM queries.
Only recognizable Capybara finder chains with string locators are
checked.
Set DefaultSelector to match Capybara.default_selector, or to
null if it varies at runtime. Autocorrection requires css and
literal strings.
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].
Capybara/IgnoredQueryOption
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
|---|---|---|---|---|
Pending |
Yes |
Always |
3.1 |
- |
Checks for query options that have no effect in Capybara.
Count options passed to singular finders are not autocorrected because removing them may conceal the author’s intent.
This cop targets Capybara’s built-in selectors. Set DefaultSelector
to match Capybara.default_selector, or to null if it varies at
runtime. Queries using custom or unknown selectors are skipped.
Examples
# bad
find('.row', count: 3)
find(:css, '.item', exact: true)
find('.item', text: /foo/, exact_text: true)
all(:css, '.item', match: :first)
expect(page).to have_css('.item', count: 3, minimum: 1)
# good
all('.row', count: 3)
find(:css, '.item')
find('.item', text: /foo/)
all(:css, '.item')
expect(page).to have_css('.item', count: 3)
Capybara/ModalMethodWithoutBlock
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
|---|---|---|---|---|
Pending |
Yes |
No |
3.1 |
- |
Checks that modal handling methods are called with a block.
Capybara/NativeAttribute
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
|---|---|---|---|---|
Pending |
Yes |
Always (Unsafe) |
3.1 |
- |
Enforces use of Element#[] instead of native.attribute.
Only calls on Capybara finder chains are checked.
Safety
This cop’s autocorrection is unsafe because attribute values may
differ between the driver API and Capybara’s Element#[].
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.
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.
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')
find(:link, 'Home')
find(:field, 'Name')
find('input[placeholder="Email"]')
find(:css, 'input[type="checkbox"]')
# good
find_by_id('some-id')
find_link('Home')
find_field('Name')
find_field(placeholder: 'Email')
find_field(type: 'checkbox')
Capybara/UnorderedWindowAccess
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
|---|---|---|---|---|
Pending |
Yes |
No |
3.1 |
- |
Checks positional access to Capybara windows, whose order is undefined.
Capybara/VisibilityOption
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
|---|---|---|---|---|
Pending |
Yes |
Always |
3.1 |
- |
Checks for boolean values passed to Capybara’s visible option.
visible: false finds both visible and hidden elements, rather than
only hidden elements. Use :all, :hidden or :visible instead.
Only true is autocorrected, to :visible.
This cop targets Capybara’s built-in selectors. Set DefaultSelector
to match Capybara.default_selector, or to null if it varies at
runtime. Queries using custom or unknown selectors are skipped.