diff --git a/.rubocop.yml b/.rubocop.yml index 863f5c5f2..2d1e300fc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -132,6 +132,10 @@ Naming/PredicateName: Exclude: - '**/*/*matchers.rb' +Naming/BlockForwarding: + Exclude: + - 'lib/capybara/node/matchers.rb' + - 'lib/capybara/node/finders.rb' #################### Performance #################### Performance/MethodObjectAsBlock: diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index a7a0f452f..ad7ed2624 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -48,12 +48,12 @@ def match_selector(...) end %i[css xpath].each do |selector| - define_method "have_#{selector}" do |expr, **options, &optional_filter_block| - Matchers::HaveSelector.new(selector, expr, **options, &optional_filter_block) + define_method "have_#{selector}" do |expr, **options, &| + Matchers::HaveSelector.new(selector, expr, **options, &) end - define_method "match_#{selector}" do |expr, **options, &optional_filter_block| - Matchers::MatchSelector.new(selector, expr, **options, &optional_filter_block) + define_method "match_#{selector}" do |expr, **options, &| + Matchers::MatchSelector.new(selector, expr, **options, &) end end @@ -78,8 +78,8 @@ def match_selector(...) # @see Capybara::Node::Matchers#matches_css? %i[link button field select table element].each do |selector| - define_method "have_#{selector}" do |locator = nil, **options, &optional_filter_block| - Matchers::HaveSelector.new(selector, locator, **options, &optional_filter_block) + define_method "have_#{selector}" do |locator = nil, **options, &| + Matchers::HaveSelector.new(selector, locator, **options, &) end end @@ -114,8 +114,8 @@ def match_selector(...) # @see Capybara::Node::Matchers#has_table? %i[checked unchecked].each do |state| - define_method "have_#{state}_field" do |locator = nil, **options, &optional_filter_block| - Matchers::HaveSelector.new(:field, locator, **options.merge(state => true), &optional_filter_block) + define_method "have_#{state}_field" do |locator = nil, **options, &| + Matchers::HaveSelector.new(:field, locator, **options.merge(state => true), &) end end @@ -144,8 +144,8 @@ def have_title(title, **options) # RSpec matcher for the current path. # # @see Capybara::SessionMatchers#assert_current_path - def have_current_path(path, **options, &optional_filter_block) - Matchers::HaveCurrentPath.new(path, **options, &optional_filter_block) + def have_current_path(path, **options, &) + Matchers::HaveCurrentPath.new(path, **options, &) end # RSpec matcher for element style. @@ -167,15 +167,15 @@ def have_style(styles = nil, **options) %w[selector css xpath text title current_path link button field checked_field unchecked_field select table sibling ancestor element].each do |matcher_type| - define_method "have_no_#{matcher_type}" do |*args, **kw_args, &optional_filter_block| - Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, **kw_args, &optional_filter_block)) + define_method "have_no_#{matcher_type}" do |*args, **kw_args, &| + Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, **kw_args, &)) end end alias_method :have_no_content, :have_no_text %w[selector css xpath].each do |matcher_type| - define_method "not_match_#{matcher_type}" do |*args, **kw_args, &optional_filter_block| - Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, **kw_args, &optional_filter_block)) + define_method "not_match_#{matcher_type}" do |*args, **kw_args, &| + Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, **kw_args, &)) end end diff --git a/lib/capybara/rspec/matchers/base.rb b/lib/capybara/rspec/matchers/base.rb index dc56205ac..32cd7f5b3 100644 --- a/lib/capybara/rspec/matchers/base.rb +++ b/lib/capybara/rspec/matchers/base.rb @@ -88,12 +88,12 @@ def initialize(matcher) @matcher = matcher end - def matches?(actual, &filter_block) - @matcher.does_not_match?(actual, &filter_block) + def matches?(actual, &) + @matcher.does_not_match?(actual, &) end - def does_not_match?(actual, &filter_block) - @matcher.matches?(actual, &filter_block) + def does_not_match?(actual, &) + @matcher.matches?(actual, &) end def description diff --git a/lib/capybara/rspec/matchers/have_selector.rb b/lib/capybara/rspec/matchers/have_selector.rb index 36cca464e..714ff7c8a 100644 --- a/lib/capybara/rspec/matchers/have_selector.rb +++ b/lib/capybara/rspec/matchers/have_selector.rb @@ -6,7 +6,7 @@ module Capybara module RSpecMatchers module Matchers class HaveSelector < CountableWrappedElementMatcher - def initialize(*args, **kw_args, &filter_block) + def initialize(*args, **kw_args, &) super return unless (@args.size < 2) && @kw_args.keys.any?(String) diff --git a/lib/capybara/rspec/matchers/match_style.rb b/lib/capybara/rspec/matchers/match_style.rb index 4b60cf9d4..601d6b05f 100644 --- a/lib/capybara/rspec/matchers/match_style.rb +++ b/lib/capybara/rspec/matchers/match_style.rb @@ -6,9 +6,9 @@ module Capybara module RSpecMatchers module Matchers class MatchStyle < WrappedElementMatcher - def initialize(styles = nil, **kw_args, &filter_block) + def initialize(styles = nil, **kw_args, &) styles, kw_args = kw_args, {} if styles.nil? - super(styles, **kw_args, &filter_block) + super(styles, **kw_args, &) end def element_matches?(el) @@ -33,7 +33,7 @@ module Matchers ## # @deprecated class HaveStyle < MatchStyle - def initialize(*args, **kw_args, &filter_block) + def initialize(*args, **kw_args, &) warn 'HaveStyle matcher is deprecated, please use the MatchStyle matcher instead' super end