rubocop / rubocop-capybara

Code style checking for Capybara files.
https://docs.rubocop.org/rubocop-capybara
MIT License
38 stars 7 forks source link

Some `SpecificMatcher` offenses are not being detected #78

Closed tagliala closed 8 months ago

tagliala commented 9 months ago

Hello,

apologies if this is a duplicate. I've searched but I couldn't find anything relevant

In the efforts of adding RuboCop Capybara to activeadmin at activeadmin/activeadmin#8025

we've noticed that some offenses are not being detected

Quoting from: https://github.com/activeadmin/activeadmin/pull/8025#issuecomment-1763293243

Maybe RuboCop Capybara does not flag some offenses:

# Offenses: Capybara/RSpec/HaveSelector, Capybara/SpecificMatcher
have_selector("input[name='title']")

# No offenses detected - Interpolation
have_selector("input[name='#{title}']")
# Offense: Capybara/SpecificMatcher
have_css("input[type=submit]")

# No offenses detected (`value` attribute, should be replaceable with `with`)
have_css("input[type=submit][value='x']")
# Offense: Capybara/SpecificMatcher
have_css("input[name='post_author_attributes__first_name_']")

# No offenses: name with multiple `[]`
have_css("input[name='post[author_attributes][first_name]']")

Don't know if these offenses can be detected, but I thought I should report the above

tagliala commented 8 months ago
# No offenses: name with multiple `[]`
have_css("input[name='post[author_attributes][first_name]']")

CssSelector.attributes detects input[name='foo[bar][baz]'] as a nested hash of attributres

selector
"input[name='foo[bar][baz]']"
(byebug) CssSelector.attributes(selector)
{"name"=>"'foo[bar'", "baz]'"=>nil}
ydah commented 8 months ago
# Offense: Capybara/SpecificMatcher
have_css("input[type=submit]")

# No offenses detected (`value` attribute, should be replaceable with `with`)
have_css("input[type=submit][value='x']")

The "with" option is intended for specifying text content, so it may not be interchangeable with the "value" attribute as they are not equivalent, don't you think?

tagliala commented 8 months ago

The "with" option is intended for specifying text content, so it may not be interchangeable with the "value" attribute as they are not equivalent, don't you think?

Thanks for the clarification, not aware of this difference