Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Apr 14, 2024
1 parent 8426427 commit 36d4be2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 14 additions & 14 deletions lib/capybara/rspec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions lib/capybara/rspec/matchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/rspec/matchers/have_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions lib/capybara/rspec/matchers/match_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 36d4be2

Please sign in to comment.