Skip to content

False positive for Rails/RedundantActiveRecordAllMethod cop in 2.21.0 #1110

@mkllnk

Description

@mkllnk

The cop is detecting calls to all on any object, not just ActiveRecord models. Using RSpec and Capybara, it can be useful to write code like:

page.all("button").select(&custom_filter).first.click

This is detected by the cop even though all and first do not refer to ActiveRecord methods.


Expected behavior

The cop should only complain about ActiveRecord's all method.

Actual behavior

spec/system/consumer/shopping/shopping_spec.rb:564:20: C: [Correctable] Rails/RedundantActiveRecordAllMethod: Redundant all detected.
              page.all("button", text: increase_quantity_symbol).last.click
                   ^^^

Steps to reproduce the problem

echo '
describe "failing cop", type: :system do
  it "detects Capybara calls" do
    page.all("button").first
  end
end
' > example_spec.rb

rubocop example_spec.rb

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You can see extension cop versions (e.g. rubocop-rails, rubocop-performance, and others) output by rubocop -V,
include them as well. Here's an example:

$ [bundle exec] rubocop -V
1.56.2 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.4) [x86_64-linux]
  - rubocop-rails 2.21.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy