Skip to content

Commit

Permalink
define_method doesn't support anonymous blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Apr 14, 2024
1 parent 812e06e commit 4fd2c2f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 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, &|
Matchers::HaveSelector.new(selector, expr, **options, &)
define_method "have_#{selector}" do |expr, **options, &filter_block|
Matchers::HaveSelector.new(selector, expr, **options, &filter_block)
end

define_method "match_#{selector}" do |expr, **options, &|
Matchers::MatchSelector.new(selector, expr, **options, &)
define_method "match_#{selector}" do |expr, **options, &filter_block|
Matchers::MatchSelector.new(selector, expr, **options, &filter_block)
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, &|
Matchers::HaveSelector.new(selector, locator, **options, &)
define_method "have_#{selector}" do |locator = nil, **options, &filter_block|
Matchers::HaveSelector.new(selector, locator, **options, &filter_block)
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, &|
Matchers::HaveSelector.new(:field, locator, **options.merge(state => true), &)
define_method "have_#{state}_field" do |locator = nil, **options, &filter_block|
Matchers::HaveSelector.new(:field, locator, **options.merge(state => true), &filter_block)
end
end

Expand Down Expand Up @@ -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, &|
Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, **kw_args, &))
define_method "have_no_#{matcher_type}" do |*args, **kw_args, &filter_block|
Matchers::NegatedMatcher.new(send("have_#{matcher_type}", *args, **kw_args, &filter_block))
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, &|
Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, **kw_args, &))
define_method "not_match_#{matcher_type}" do |*args, **kw_args, &filter_block|
Matchers::NegatedMatcher.new(send("match_#{matcher_type}", *args, **kw_args, &filter_block))
end
end

Expand Down

0 comments on commit 4fd2c2f

Please sign in to comment.