-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add new Capybara/RSpec/HaveSelector
cop
#63
Conversation
559f3d3
to
5886ef0
Compare
5886ef0
to
4a1b0cf
Compare
This PR add new `Capybara/RSpec/HaveSelector` cop. ```ruby expect(foo).to have_selector(:css, 'bar') expect(foo).to have_css('bar') expect(foo).to have_selector(:xpath, 'bar') expect(foo).to have_xpath('bar') expect(foo).to have_selector('bar') expect(foo).to have_css('bar') expect(foo).to have_selector('bar') expect(foo).to have_xpath('bar') ```
4a1b0cf
to
54069a0
Compare
The first argument of It is passed to
So they work the same but can be written in two ways.
Yes, I think so. |
Please consider this an open discussion, not a request for a change in any way. In my current project, a question for justification for this cop was raised. As it is the default in Capybara, the terms "selector" and "CSS selectors" de facto became synonyms. So why do we have to replace existing From myself - if we now provide a cop to flag the generic page.find(:xpath, './/div[contains(., "bar")]')
page.find('li', text: 'Quox').click_link('Delete') I believe there are many, e.g. In addition to that, there are methods like So what is the actual purpose of the cop? "When looking at a method call, avoid confusing the selector kind". @bquorning @Darhazer I'd love to hear your thoughts on this, too. I don't want to burden the development of this extension, but we are less experienced with Capybara than @ydah. Should we take shifts with code reviews etc? |
I see, The use of
It certainly seems like a good idea to list violations for redundant kind designations since the default_selector should be fixed.
I don't have a strong opinion, but it may be added if necessary. However, it would be added as a separate cop.
the purpose of this cop is to explicitly specify selectors like |
This PR add new
Capybara/RSpec/HaveSelector
cop.The first argument of
have_selector
iskind
, which can be either:css
or:xpath
(if not specified, it works with the default value)https://www.rubydoc.info/gems/capybara/Capybara#configure-class_method
It is passed to
Matchers::HaveSelector
andnew
.https://github.com/teamcapybara/capybara/blob/0b43cb90ae633ce9b2008e07b997c76833fa570e/lib/capybara/rspec/matchers.rb#L19
have_css
andhave_xpath
are passed toMatchers::HaveSelector
as:css
or:xpath
as the first argument, respectively, andnew
is done.https://github.com/teamcapybara/capybara/blob/0b43cb90ae633ce9b2008e07b997c76833fa570e/lib/capybara/rspec/matchers.rb#L50-L53
So they work the same but can be written in two ways.
In the case of
have_selector
, I think it is better to usehave_css
andhave_xpath
because the behavior changes depending on the defaultkind
and it is easier to understand if you specify more details.Before submitting the PR make sure the following are checked:
main
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml
.Enabled: pending
inconfig/default.yml
.VersionAdded: "<<next>>"
indefault/config.yml
.