Skip to content
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

[Capybara/SpecificMatcher] False-positive when using regex #82

Closed
boris-petrov opened this issue Nov 7, 2023 · 5 comments · Fixed by #87
Closed

[Capybara/SpecificMatcher] False-positive when using regex #82

boris-petrov opened this issue Nov 7, 2023 · 5 comments · Fixed by #87

Comments

@boris-petrov
Copy link
Contributor

expect(page).to have_css('button', exact_text: /my regex+/)

This should not trigger the Capybara/SpecificMatcher because there is no way to write this with have_button. Same applies for text with regex in addition to exact_text.

@svegaca
Copy link

svegaca commented Nov 14, 2023

It also has false-positive issues in expectations that include CSS class names. It seems that have_field, have_link, and have_button don't currently support the class option.

@boris-petrov
Copy link
Contributor Author

@svegaca - hm, I have to following in my tests:

expect(page).to have_button(class: 'btn-close')

Are you saying that this doesn't work? It seems to pass. 😄

@svegaca
Copy link

svegaca commented Nov 14, 2023

Yes, it fails for me using capybara (2.4.4) and rubocop-capybara (2.17.0). Maybe I should upgrade capybara 😅 but looking at the current code I don't find where it accepts the class option 🤔

@boris-petrov
Copy link
Contributor Author

Well, it passes options to has_selector? which does work with class: so it should be fine. :)

@svegaca
Copy link

svegaca commented Nov 14, 2023

Ah! I'm sorry, it works and supports class as expected. I was writing the test with one of the expected classes but it failed because check if the given value is identical to the whole value of the class attribute, I've fixed with a regexp 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants