Skip to content

Commit

Permalink
Merge pull request #135 from rubocop/docs
Browse files Browse the repository at this point in the history
Update references and examples for Capybara cops in documentation
  • Loading branch information
ydah authored Oct 17, 2024
2 parents d307446 + a29d39c commit 88eb2ba
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/modules/ROOT/pages/cops_capybara.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
= Capybara
[#capybaraambiguousclick]
== Capybara/AmbiguousClick
|===
Expand All @@ -23,6 +24,7 @@ Specify the exact target to click on.
In projects where accessibility needs to be considered,
it is crucial to specify the click target precisely.
[#examples-capybaraambiguousclick]
=== Examples
[source,ruby]
Expand All @@ -36,10 +38,12 @@ click_link('foo')
click_button('foo')
----
[#references-capybaraambiguousclick]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/AmbiguousClick
[#capybaraclicklinkorbuttonstyle]
== Capybara/ClickLinkOrButtonStyle
|===
Expand Down Expand Up @@ -69,8 +73,10 @@ allowing for a more faithful reflection of how the user behaves.
You can set `EnforcedStyle: strict` to prefer the use of
`click_link` and `click_button`, but this is a deprecated setting.
[#examples-capybaraclicklinkorbuttonstyle]
=== Examples
[#enforcedstyle_-link_or_button-_default_-capybaraclicklinkorbuttonstyle]
==== EnforcedStyle: link_or_button (default)
[source,ruby]
Expand All @@ -84,6 +90,7 @@ click_link_or_button('foo')
click_on('foo')
----
[#enforcedstyle_-strict-capybaraclicklinkorbuttonstyle]
==== EnforcedStyle: strict
[source,ruby]
Expand All @@ -97,6 +104,7 @@ click_link('foo')
click_button('foo')
----
[#configurable-attributes-capybaraclicklinkorbuttonstyle]
=== Configurable attributes
|===
Expand All @@ -107,10 +115,12 @@ click_button('foo')
| `link_or_button`, `strict`
|===
[#references-capybaraclicklinkorbuttonstyle]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/ClickLinkOrButtonStyle
[#capybaracurrentpathexpectation]
== Capybara/CurrentPathExpectation
|===
Expand All @@ -135,6 +145,7 @@ completed.
This cop does not support autocorrection in some cases.
[#examples-capybaracurrentpathexpectation]
=== Examples
[source,ruby]
Expand All @@ -150,10 +161,12 @@ expect(page).to have_current_path('/callback', ignore_query: true)
expect(page).to match(variable)
----
[#references-capybaracurrentpathexpectation]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/CurrentPathExpectation
[#capybarafindallfirst]
== Capybara/FindAllFirst
|===
Expand All @@ -168,6 +181,7 @@ expect(page).to match(variable)
Enforces use of `first` instead of `all` with `first` or `[0]`.
[#examples-capybarafindallfirst]
=== Examples
[source,ruby]
Expand All @@ -182,10 +196,12 @@ all('a', match: :first)
first('a')
----
[#references-capybarafindallfirst]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/FindAllFirst
[#capybaramatchstyle]
== Capybara/MatchStyle
|===
Expand All @@ -200,8 +216,10 @@ first('a')
Checks for usage of deprecated style methods.
[#examples-capybaramatchstyle]
=== Examples
[#when-using-_assert_style_-capybaramatchstyle]
==== when using `assert_style`
[source,ruby]
Expand All @@ -213,6 +231,7 @@ page.find(:css, '#first').assert_style(display: 'block')
page.find(:css, '#first').assert_matches_style(display: 'block')
----
[#when-using-_has_style__-capybaramatchstyle]
==== when using `has_style?`
[source,ruby]
Expand All @@ -226,6 +245,7 @@ expect(page.find(:css, 'first')
.matches_style?(display: 'block')).to be true
----
[#when-using-_have_style_-capybaramatchstyle]
==== when using `have_style`
[source,ruby]
Expand All @@ -237,10 +257,12 @@ expect(page).to have_style(display: 'block')
expect(page).to match_style(display: 'block')
----
[#references-capybaramatchstyle]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/MatchStyle
[#capybaranegationmatcher]
== Capybara/NegationMatcher
|===
Expand All @@ -255,8 +277,10 @@ expect(page).to match_style(display: 'block')
Enforces use of `have_no_*` or `not_to` for negated expectations.
[#examples-capybaranegationmatcher]
=== Examples
[#enforcedstyle_-have_no-_default_-capybaranegationmatcher]
==== EnforcedStyle: have_no (default)
[source,ruby]
Expand All @@ -270,6 +294,7 @@ expect(page).to have_no_selector 'a'
expect(page).to have_no_css('a')
----
[#enforcedstyle_-not_to-capybaranegationmatcher]
==== EnforcedStyle: not_to
[source,ruby]
Expand All @@ -283,6 +308,7 @@ expect(page).not_to have_selector 'a'
expect(page).not_to have_css('a')
----
[#configurable-attributes-capybaranegationmatcher]
=== Configurable attributes
|===
Expand All @@ -293,10 +319,12 @@ expect(page).not_to have_css('a')
| `have_no`, `not_to`
|===
[#references-capybaranegationmatcher]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/NegationMatcher
[#capybararedundantwithinfind]
== Capybara/RedundantWithinFind
|===
Expand All @@ -311,6 +339,7 @@ expect(page).not_to have_css('a')
Checks for redundant `within find(...)` calls.
[#examples-capybararedundantwithinfind]
=== Examples
[source,ruby]
Expand All @@ -336,10 +365,12 @@ within '#foo' do
end
----
[#references-capybararedundantwithinfind]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RedundantWithinFind
[#capybaraspecificactions]
== Capybara/SpecificActions
|===
Expand All @@ -354,6 +385,7 @@ end
Checks for there is a more specific actions offered by Capybara.
[#examples-capybaraspecificactions]
=== Examples
[source,ruby]
Expand All @@ -371,10 +403,12 @@ click_link(exact_text: 'foo')
find('div').click_button
----
[#references-capybaraspecificactions]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/SpecificActions
[#capybaraspecificfinders]
== Capybara/SpecificFinders
|===
Expand All @@ -389,6 +423,7 @@ find('div').click_button
Checks if there is a more specific finder offered by Capybara.
[#examples-capybaraspecificfinders]
=== Examples
[source,ruby]
Expand All @@ -403,10 +438,12 @@ find(:id, 'some-id')
find_by_id('some-id')
----
[#references-capybaraspecificfinders]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/SpecificFinders
[#capybaraspecificmatcher]
== Capybara/SpecificMatcher
|===
Expand All @@ -421,6 +458,7 @@ find_by_id('some-id')
Checks for there is a more specific matcher offered by Capybara.
[#examples-capybaraspecificmatcher]
=== Examples
[source,ruby]
Expand All @@ -444,10 +482,12 @@ expect(page).to have_select
expect(page).to have_field(with: 'foo')
----
[#references-capybaraspecificmatcher]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/SpecificMatcher
[#capybaravisibilitymatcher]
== Capybara/VisibilityMatcher
|===
Expand All @@ -471,6 +511,7 @@ symbol values, `:all`, `:hidden` or `:visible`.
Read more in
https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
[#examples-capybaravisibilitymatcher]
=== Examples
[source,ruby]
Expand All @@ -486,6 +527,7 @@ expect(page).to have_css('.foo', visible: :all)
expect(page).to have_link('my link', visible: :hidden)
----
[#references-capybaravisibilitymatcher]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/VisibilityMatcher
14 changes: 14 additions & 0 deletions docs/modules/ROOT/pages/cops_capybara_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
= Capybara/RSpec
[#capybararspechaveselector]
== Capybara/RSpec/HaveSelector
|===
Expand All @@ -20,6 +21,7 @@
Use `have_css` or `have_xpath` instead of `have_selector`.
[#examples-capybararspechaveselector]
=== Examples
[source,ruby]
Expand All @@ -37,6 +39,7 @@ expect(foo).to have_selector(:xpath, 'bar')
expect(foo).to have_xpath('bar')
----
[#defaultselector_-css-_default_-capybararspechaveselector]
==== DefaultSelector: css (default)
[source,ruby]
Expand All @@ -48,6 +51,7 @@ expect(foo).to have_selector('bar')
expect(foo).to have_css('bar')
----
[#defaultselector_-xpath-capybararspechaveselector]
==== DefaultSelector: xpath
[source,ruby]
Expand All @@ -59,6 +63,7 @@ expect(foo).to have_selector('bar')
expect(foo).to have_xpath('bar')
----
[#configurable-attributes-capybararspechaveselector]
=== Configurable attributes
|===
Expand All @@ -69,10 +74,12 @@ expect(foo).to have_xpath('bar')
| String
|===
[#references-capybararspechaveselector]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RSpec/HaveSelector
[#capybararspecpredicatematcher]
== Capybara/RSpec/PredicateMatcher
|===
Expand All @@ -91,8 +98,10 @@ Capybara defines magic matchers for predicate methods.
This cop recommends to use the predicate matcher instead of using
predicate method directly.
[#examples-capybararspecpredicatematcher]
=== Examples
[#strict_-true_-enforcedstyle_-inflected-_default_-capybararspecpredicatematcher]
==== Strict: true, EnforcedStyle: inflected (default)
[source,ruby]
Expand All @@ -113,6 +122,7 @@ expect(foo).to match_xpath(bar: 'baz')
expect(foo.matches_style?(bar: 'baz')).to be(true)
----
[#strict_-false_-enforcedstyle_-inflected-capybararspecpredicatematcher]
==== Strict: false, EnforcedStyle: inflected
[source,ruby]
Expand All @@ -125,6 +135,7 @@ expect(foo.matches_style?(bar: 'baz')).to be(true)
expect(foo).to match_style(bar: 'baz')
----
[#strict_-true_-enforcedstyle_-explicit-capybararspecpredicatematcher]
==== Strict: true, EnforcedStyle: explicit
[source,ruby]
Expand All @@ -136,6 +147,7 @@ expect(foo).to match_style(bar: 'baz')
expect(foo.matches_style?(bar: 'baz')).to be(true)
----
[#strict_-false_-enforcedstyle_-explicit-capybararspecpredicatematcher]
==== Strict: false, EnforcedStyle: explicit
[source,ruby]
Expand All @@ -147,6 +159,7 @@ expect(foo).to match_style(bar: 'baz')
expect(foo.matches_style?(bar: 'baz')).to be_truthy
----
[#configurable-attributes-capybararspecpredicatematcher]
=== Configurable attributes
|===
Expand All @@ -165,6 +178,7 @@ expect(foo.matches_style?(bar: 'baz')).to be_truthy
| Array
|===
[#references-capybararspecpredicatematcher]
=== References
* https://www.rubydoc.info/gems/rubocop-capybara/RuboCop/Cop/Capybara/RSpec/PredicateMatcher

0 comments on commit 88eb2ba

Please sign in to comment.