mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
More Ruby keyword arguments changes support
This commit is contained in:
parent
6d18eea5ab
commit
de542cc2d5
4 changed files with 28 additions and 17 deletions
|
@ -209,13 +209,15 @@ module Capybara
|
|||
# @!method wont_have_xpath
|
||||
# See {Capybara::Node::Matchers#has_no_xpath?}
|
||||
|
||||
%w[text content title current_path].each do |assertion|
|
||||
infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
|
||||
infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
|
||||
end
|
||||
# This currently doesn't work for Ruby 2.8 due to Minitest not forwarding keyword args separately
|
||||
# %w[text content title current_path].each do |assertion|
|
||||
# infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
|
||||
# infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
|
||||
# end
|
||||
|
||||
# rubocop:disable Style/MultilineBlockChain
|
||||
(%w[selector xpath css link button field select table checked_field unchecked_field
|
||||
(%w[text content title current_path
|
||||
selector xpath css link button field select table checked_field unchecked_field
|
||||
ancestor sibling].flat_map do |assertion|
|
||||
[%W[assert_#{assertion} must_have_#{assertion}],
|
||||
%W[refute_#{assertion} wont_have_#{assertion}]]
|
||||
|
@ -228,14 +230,15 @@ module Capybara
|
|||
%W[refute_matches_#{assertion} wont_match_#{assertion}]]
|
||||
end).each do |(meth, new_name)|
|
||||
class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
|
||||
def #{new_name} *args, &block
|
||||
::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, &block)
|
||||
def #{new_name} *args, **kw_args, &block
|
||||
::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, **kw_args, &block)
|
||||
end
|
||||
ASSERTION
|
||||
|
||||
::Minitest::Expectation.class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
|
||||
def #{new_name} *args, &block
|
||||
ctx.#{meth}(target, *args, &block)
|
||||
def #{new_name} *args, **kw_args, &block
|
||||
raise "Calling ##{new_name} outside of test." unless ctx
|
||||
ctx.#{meth}(target, *args, **kw_args, &block)
|
||||
end
|
||||
ASSERTION
|
||||
end
|
||||
|
@ -243,9 +246,9 @@ module Capybara
|
|||
|
||||
##
|
||||
# @deprecated
|
||||
def must_have_style(*args, &block)
|
||||
def must_have_style(*args, **kw_args, &block)
|
||||
warn 'must_have_style is deprecated, please use must_match_style'
|
||||
must_match_style(*args, &block)
|
||||
must_match_style(*args, **kw_args, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -60,14 +60,15 @@ module Capybara
|
|||
# @param styles [Hash]
|
||||
# @return [Boolean] If the styles match
|
||||
#
|
||||
def matches_style?(styles, **options)
|
||||
def matches_style?(styles = nil, **options)
|
||||
styles, options = options, {} if styles.nil?
|
||||
make_predicate(options) { assert_matches_style(styles, **options) }
|
||||
end
|
||||
|
||||
##
|
||||
# @deprecated Use {#matches_style?} instead.
|
||||
#
|
||||
def has_style?(styles, **options)
|
||||
def has_style?(styles = nil, **options)
|
||||
warn "DEPRECATED: has_style? is deprecated, please use matches_style? : #{Capybara::Helpers.filter_backtrace(caller)}"
|
||||
matches_style?(styles, **options)
|
||||
end
|
||||
|
@ -122,7 +123,8 @@ module Capybara
|
|||
# @param styles [Hash]
|
||||
# @raise [Capybara::ExpectationNotMet] If the element doesn't have the specified styles
|
||||
#
|
||||
def assert_matches_style(styles, **options)
|
||||
def assert_matches_style(styles = nil, **options)
|
||||
styles, options = options, {} if styles.nil?
|
||||
query_args, query_opts = _set_query_session_options(styles, options)
|
||||
query = Capybara::Queries::StyleQuery.new(*query_args, **query_opts)
|
||||
synchronize(query.wait) do
|
||||
|
@ -134,7 +136,7 @@ module Capybara
|
|||
##
|
||||
# @deprecated Use {#assert_matches_style} instead.
|
||||
#
|
||||
def assert_style(styles, **options)
|
||||
def assert_style(styles = nil, **options)
|
||||
warn 'assert_style is deprecated, please use assert_matches_style instead'
|
||||
assert_matches_style(styles, **options)
|
||||
end
|
||||
|
|
|
@ -146,14 +146,15 @@ module Capybara
|
|||
# RSpec matcher for element style.
|
||||
#
|
||||
# @see Capybara::Node::Matchers#matches_style?
|
||||
def match_style(styles, **options)
|
||||
def match_style(styles = nil, **options)
|
||||
styles, options = options, {} if styles.nil?
|
||||
Matchers::MatchStyle.new(styles, **options)
|
||||
end
|
||||
|
||||
##
|
||||
# @deprecated
|
||||
#
|
||||
def have_style(styles, **options)
|
||||
def have_style(styles = nil, **options)
|
||||
warn "DEPRECATED: have_style is deprecated, please use match_style : #{Capybara::Helpers.filter_backtrace(caller)}"
|
||||
match_style(styles, **options)
|
||||
end
|
||||
|
|
|
@ -6,6 +6,11 @@ module Capybara
|
|||
module RSpecMatchers
|
||||
module Matchers
|
||||
class MatchStyle < WrappedElementMatcher
|
||||
def initialize(styles = nil, **kw_args, &filter_block)
|
||||
styles, kw_args = kw_args, {} if styles.nil?
|
||||
super(styles, **kw_args, &filter_block)
|
||||
end
|
||||
|
||||
def element_matches?(el)
|
||||
el.assert_matches_style(*@args, **@kw_args)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue