Skip to content

Commit

Permalink
Fix obsoletion errors by only enlisting the new cop
Browse files Browse the repository at this point in the history
...and soft-aliasing the old one with a constant pointing to a class
  • Loading branch information
pirj committed Jan 8, 2023
1 parent eaa2e36 commit 1f3cc3d
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 172 deletions.
13 changes: 7 additions & 6 deletions docs/modules/ROOT/pages/cops_rspec_capybara.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,13 @@ expect(page).to have_field('foo')

Checks for boolean visibility in Capybara finders.

Capybara lets you find elements that match a certain visibility using
the `:visible` option. `:visible` accepts both boolean and symbols as
values, however using booleans can have unwanted effects. `visible:
false` does not find just invisible elements, but both visible and
invisible elements. For expressiveness and clarity, use one of the
symbol values, `:all`, `:hidden` or `:visible`.
Capybara lets you find elements that match a certain visibility
using the `:visible` option. `:visible` accepts both boolean and
symbols as values, however using booleans can have unwanted
effects. `visible: false` does not find just invisible elements,
but both visible and invisible elements. For expressiveness and
clarity, use one of the # symbol values, `:all`, `:hidden` or
`:visible`.
Read more in
https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].

Expand Down
56 changes: 28 additions & 28 deletions lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ module RuboCop
module Cop
module RSpec
module Capybara
# Checks that no expectations are set on Capybara's `current_path`.
#
# The
# https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
# should be used on `page` to set expectations on Capybara's
# current path, since it uses
# https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
# which ensures that preceding actions (like `click_link`) have
# completed.
#
# This cop does not support autocorrection in some cases.
#
# @example
# # bad
# expect(current_path).to eq('/callback')
#
# # good
# expect(page).to have_current_path('/callback')
#
# # bad (does not support autocorrection)
# expect(page.current_path).to match(variable)
#
# # good
# expect(page).to have_current_path('/callback')
#
# @!parse class CurrentPathExpectation < ::RuboCop::Cop::Base; end
class CurrentPathExpectation <
# @!parse
# # Checks that no expectations are set on Capybara's `current_path`.
# #
# # The
# # https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
# # should be used on `page` to set expectations on Capybara's
# # current path, since it uses
# # https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
# # which ensures that preceding actions (like `click_link`) have
# # completed.
# #
# # This cop does not support autocorrection in some cases.
# #
# # @example
# # # bad
# # expect(current_path).to eq('/callback')
# #
# # # good
# # expect(page).to have_current_path('/callback')
# #
# # # bad (does not support autocorrection)
# # expect(page.current_path).to match(variable)
# #
# # # good
# # expect(page).to have_current_path('/callback')
# #
# class CurrentPathExpectation < ::RuboCop::Cop::Base; end
CurrentPathExpectation =
::RuboCop::Cop::Capybara::CurrentPathExpectation
end
end
end
end
Expand Down
56 changes: 28 additions & 28 deletions lib/rubocop/cop/rspec/capybara/match_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ module RuboCop
module Cop
module RSpec
module Capybara
# Checks for usage of deprecated style methods.
#
# @example when using `assert_style`
# # bad
# page.find(:css, '#first').assert_style(display: 'block')
#
# # good
# page.find(:css, '#first').assert_matches_style(display: 'block')
#
# @example when using `has_style?`
# # bad
# expect(page.find(:css, 'first')
# .has_style?(display: 'block')).to be true
#
# # good
# expect(page.find(:css, 'first')
# .matches_style?(display: 'block')).to be true
#
# @example when using `have_style`
# # bad
# expect(page).to have_style(display: 'block')
#
# # good
# expect(page).to match_style(display: 'block')
#
# @!parse class MatchStyle < ::RuboCop::Cop::Base; end
class MatchStyle < ::RuboCop::Cop::Capybara::MatchStyle
end
# @!parse
# # Checks for usage of deprecated style methods.
# #
# # @example when using `assert_style`
# # # bad
# # page.find(:css, '#first').assert_style(display: 'block')
# #
# # # good
# # page.find(:css, '#first').assert_matches_style(display: 'block')
# #
# # @example when using `has_style?`
# # # bad
# # expect(page.find(:css, 'first')
# # .has_style?(display: 'block')).to be true
# #
# # # good
# # expect(page.find(:css, 'first')
# # .matches_style?(display: 'block')).to be true
# #
# # @example when using `have_style`
# # # bad
# # expect(page).to have_style(display: 'block')
# #
# # # good
# # expect(page).to match_style(display: 'block')
# #
# class MatchStyle < ::RuboCop::Cop::Base; end
MatchStyle = ::RuboCop::Cop::Capybara::MatchStyle
end
end
end
Expand Down
46 changes: 23 additions & 23 deletions lib/rubocop/cop/rspec/capybara/negation_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ module RuboCop
module Cop
module RSpec
module Capybara
# Enforces use of `have_no_*` or `not_to` for negated expectations.
#
# @example EnforcedStyle: not_to (default)
# # bad
# expect(page).to have_no_selector
# expect(page).to have_no_css('a')
#
# # good
# expect(page).not_to have_selector
# expect(page).not_to have_css('a')
#
# @example EnforcedStyle: have_no
# # bad
# expect(page).not_to have_selector
# expect(page).not_to have_css('a')
#
# # good
# expect(page).to have_no_selector
# expect(page).to have_no_css('a')
#
# @!parse class NegationMatcher < ::RuboCop::Cop::Base; end
class NegationMatcher < ::RuboCop::Cop::Capybara::NegationMatcher
end
# @!parse
# # Enforces use of `have_no_*` or `not_to` for negated expectations.
# #
# # @example EnforcedStyle: not_to (default)
# # # bad
# # expect(page).to have_no_selector
# # expect(page).to have_no_css('a')
# #
# # # good
# # expect(page).not_to have_selector
# # expect(page).not_to have_css('a')
# #
# # @example EnforcedStyle: have_no
# # # bad
# # expect(page).not_to have_selector
# # expect(page).not_to have_css('a')
# #
# # # good
# # expect(page).to have_no_selector
# # expect(page).to have_no_css('a')
# #
# class NegationMatcher < ::RuboCop::Cop::Base; end
NegationMatcher = ::RuboCop::Cop::Capybara::NegationMatcher
end
end
end
Expand Down
38 changes: 19 additions & 19 deletions lib/rubocop/cop/rspec/capybara/specific_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ module RuboCop
module Cop
module RSpec
module Capybara
# Checks for there is a more specific actions offered by Capybara.
#
# @example
#
# # bad
# find('a').click
# find('button.cls').click
# find('a', exact_text: 'foo').click
# find('div button').click
#
# # good
# click_link
# click_button(class: 'cls')
# click_link(exact_text: 'foo')
# find('div').click_button
#
# @!parse class SpecificActions < ::RuboCop::Cop::Base; end
class SpecificActions < ::RuboCop::Cop::Capybara::SpecificActions
end
# @!parse
# # Checks for there is a more specific actions offered by Capybara.
# #
# # @example
# #
# # # bad
# # find('a').click
# # find('button.cls').click
# # find('a', exact_text: 'foo').click
# # find('div button').click
# #
# # # good
# # click_link
# # click_button(class: 'cls')
# # click_link(exact_text: 'foo')
# # find('div').click_button
# #
# class SpecificActions < ::RuboCop::Cop::Base; end
SpecificActions = ::RuboCop::Cop::Capybara::SpecificActions
end
end
end
Expand Down
28 changes: 14 additions & 14 deletions lib/rubocop/cop/rspec/capybara/specific_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ module RuboCop
module Cop
module RSpec
module Capybara
# Checks if there is a more specific finder offered by Capybara.
#
# @example
# # bad
# find('#some-id')
# find('[visible][id=some-id]')
#
# # good
# find_by_id('some-id')
# find_by_id('some-id', visible: true)
#
# @!parse class SpecificFinders < ::RuboCop::Cop::Base; end
class SpecificFinders < ::RuboCop::Cop::Capybara::SpecificFinders
end
# @!parse
# # Checks if there is a more specific finder offered by Capybara.
# #
# # @example
# # # bad
# # find('#some-id')
# # find('[visible][id=some-id]')
# #
# # # good
# # find_by_id('some-id')
# # find_by_id('some-id', visible: true)
# #
# class SpecificFinders < ::RuboCop::Cop::Base; end
SpecificFinders = ::RuboCop::Cop::Capybara::SpecificFinders
end
end
end
Expand Down
50 changes: 25 additions & 25 deletions lib/rubocop/cop/rspec/capybara/specific_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ module RuboCop
module Cop
module RSpec
module Capybara
# Checks for there is a more specific matcher offered by Capybara.
#
# @example
#
# # bad
# expect(page).to have_selector('button')
# expect(page).to have_no_selector('button.cls')
# expect(page).to have_css('button')
# expect(page).to have_no_css('a.cls', href: 'http://example.com')
# expect(page).to have_css('table.cls')
# expect(page).to have_css('select')
# expect(page).to have_css('input', exact_text: 'foo')
#
# # good
# expect(page).to have_button
# expect(page).to have_no_button(class: 'cls')
# expect(page).to have_button
# expect(page).to have_no_link('foo', class: 'cls', href: 'http://example.com')
# expect(page).to have_table(class: 'cls')
# expect(page).to have_select
# expect(page).to have_field('foo')
#
# @!parse class SpecificMatcher < ::RuboCop::Cop::Base; end
class SpecificMatcher < ::RuboCop::Cop::Capybara::SpecificMatcher
end
# @!parse
# # Checks for there is a more specific matcher offered by Capybara.
# #
# # @example
# #
# # # bad
# # expect(page).to have_selector('button')
# # expect(page).to have_no_selector('button.cls')
# # expect(page).to have_css('button')
# # expect(page).to have_no_css('a.cls', href: 'http://example.com')
# # expect(page).to have_css('table.cls')
# # expect(page).to have_css('select')
# # expect(page).to have_css('input', exact_text: 'foo')
# #
# # # good
# # expect(page).to have_button
# # expect(page).to have_no_button(class: 'cls')
# # expect(page).to have_button
# # expect(page).to have_no_link('foo', class: 'cls', href: 'http://example.com')
# # expect(page).to have_table(class: 'cls')
# # expect(page).to have_select
# # expect(page).to have_field('foo')
# #
# class SpecificMatcher < ::RuboCop::Cop::Base; end
SpecificMatcher = ::RuboCop::Cop::Capybara::SpecificMatcher
end
end
end
Expand Down
51 changes: 26 additions & 25 deletions lib/rubocop/cop/rspec/capybara/visibility_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ module RuboCop
module Cop
module RSpec
module Capybara
# Checks for boolean visibility in Capybara finders.
#
# Capybara lets you find elements that match a certain visibility using
# the `:visible` option. `:visible` accepts both boolean and symbols as
# values, however using booleans can have unwanted effects. `visible:
# false` does not find just invisible elements, but both visible and
# invisible elements. For expressiveness and clarity, use one of the
# symbol values, `:all`, `:hidden` or `:visible`.
# Read more in
# https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
#
# @example
# # bad
# expect(page).to have_selector('.foo', visible: false)
# expect(page).to have_css('.foo', visible: true)
# expect(page).to have_link('my link', visible: false)
#
# # good
# expect(page).to have_selector('.foo', visible: :visible)
# expect(page).to have_css('.foo', visible: :all)
# expect(page).to have_link('my link', visible: :hidden)
#
# @!parse class VisibilityMatcher < ::RuboCop::Cop::Base; end
class VisibilityMatcher < ::RuboCop::Cop::Capybara::VisibilityMatcher
end
# @!parse
# # Checks for boolean visibility in Capybara finders.
# #
# # Capybara lets you find elements that match a certain visibility
# # using the `:visible` option. `:visible` accepts both boolean and
# # symbols as values, however using booleans can have unwanted
# # effects. `visible: false` does not find just invisible elements,
# # but both visible and invisible elements. For expressiveness and
# # clarity, use one of the # symbol values, `:all`, `:hidden` or
# # `:visible`.
# # Read more in
# # https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
# #
# # @example
# # # bad
# # expect(page).to have_selector('.foo', visible: false)
# # expect(page).to have_css('.foo', visible: true)
# # expect(page).to have_link('my link', visible: false)
# #
# # # good
# # expect(page).to have_selector('.foo', visible: :visible)
# # expect(page).to have_css('.foo', visible: :all)
# # expect(page).to have_link('my link', visible: :hidden)
# #
# class VisibilityMatcher < ::RuboCop::Cop::Base; end
VisibilityMatcher = ::RuboCop::Cop::Capybara::VisibilityMatcher
end
end
end
Expand Down

0 comments on commit 1f3cc3d

Please sign in to comment.