Parameter cleanup

This commit is contained in:
Thomas Walpole 2016-08-17 16:14:39 -07:00
parent 71f0c8578f
commit aa73e3a94d
24 changed files with 113 additions and 183 deletions

View File

@ -117,7 +117,7 @@ class Capybara::Driver::Base
# @return [String] the message shown in the modal
# @raise [Capybara::ModalNotFound] if modal dialog hasn't been found
#
def accept_modal(type, options={}, &blk)
def accept_modal(type, **options, &blk)
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#accept_modal'
end
@ -130,7 +130,7 @@ class Capybara::Driver::Base
# @return [String] the message shown in the modal
# @raise [Capybara::ModalNotFound] if modal dialog hasn't been found
#
def dismiss_modal(type, options={}, &blk)
def dismiss_modal(type, **options, &blk)
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#dismiss_modal'
end

View File

@ -27,7 +27,7 @@ module Capybara
# @param value String or Array. Array is only allowed if node has 'multiple' attribute
# @param options [Hash{}] Driver specific options for how to set a value on a node
def set(value, options={})
def set(value, **options)
raise NotImplementedError
end

View File

@ -20,8 +20,7 @@ module Capybara
#
# @return [Capybara::Node::Element] The element clicked
#
def click_link_or_button(locator=nil, options={})
locator, options = nil, locator if locator.is_a? Hash
def click_link_or_button(locator=nil, **options)
find(:link_or_button, locator, options).click
end
alias_method :click_on, :click_link_or_button
@ -38,8 +37,7 @@ module Capybara
# @param options See {Capybara::Node::Finders#find_link}
#
# @return [Capybara::Node::Element] The element clicked
def click_link(locator=nil, options={})
locator, options = nil, locator if locator.is_a? Hash
def click_link(locator=nil, **options)
find(:link, locator, options).click
end
@ -56,8 +54,7 @@ module Capybara
# @param [String] locator Which button to find
# @param options See {Capybara::Node::Finders#find_button}
# @return [Capybara::Node::Element] The element clicked
def click_button(locator=nil, options={})
locator, options = nil, locator if locator.is_a? Hash
def click_button(locator=nil, **options)
find(:button, locator, options).click
end
@ -83,11 +80,7 @@ module Capybara
# @option options [String, Array<String>] :class Match fields that match the class(es) provided
#
# @return [Capybara::Node::Element] The element filled_in
def fill_in(locator, options={})
locator, options = nil, locator if locator.is_a? Hash
raise "Must pass a hash containing 'with'" if not options.is_a?(Hash) or not options.has_key?(:with)
with = options.delete(:with)
fill_options = options.delete(:fill_options)
def fill_in(locator=nil, with:, fill_options: {}, **options)
options[:with] = options.delete(:currently_with) if options.has_key?(:currently_with)
find(:fillable_field, locator, options).set(with, fill_options)
end
@ -113,8 +106,8 @@ module Capybara
# @macro label_click
#
# @return [Capybara::Node::Element] The element chosen or the label clicked
def choose(locator, options={})
_check_with_label(:radio_button, true, locator, options)
def choose(locator=nil, **options)
_check_with_label(:radio_button, true, locator, **options)
end
##
@ -136,8 +129,8 @@ module Capybara
# @macro waiting_behavior
#
# @return [Capybara::Node::Element] The element checked or the label clicked
def check(locator, options={})
_check_with_label(:checkbox, true, locator, options)
def check(locator, **options)
_check_with_label(:checkbox, true, locator, **options)
end
##
@ -159,8 +152,8 @@ module Capybara
# @macro waiting_behavior
#
# @return [Capybara::Node::Element] The element unchecked or the label clicked
def uncheck(locator, options={})
_check_with_label(:checkbox, false, locator, options)
def uncheck(locator=nil, **options)
_check_with_label(:checkbox, false, locator, **options)
end
##
@ -180,9 +173,8 @@ module Capybara
# @option options [String] :from The id, name or label of the select box
#
# @return [Capybara::Node::Element] The option element selected
def select(value, options={})
if options.has_key?(:from)
from = options.delete(:from)
def select(value=nil, from: nil, **options)
if from
find(:select, from, options).find(:option, value, options).select_option
else
find(:option, value, options).select_option
@ -203,9 +195,8 @@ module Capybara
# @param [Hash{:from => String}] options The id, name or label of the select box
#
# @return [Capybara::Node::Element] The option element unselected
def unselect(value, options={})
if options.has_key?(:from)
from = options.delete(:from)
def unselect(value=nil, from: nil, **options)
if from
find(:select, from, options).find(:option, value, options).unselect_option
else
find(:option, value, options).unselect_option
@ -233,8 +224,7 @@ module Capybara
# @option options [true, Hash] make_visible A Hash of CSS styles to change before attempting to attach the file, if `true` { opacity: 1, display: 'block', visibility: 'visible' } is used (may not be supported by all drivers)
#
# @return [Capybara::Node::Element] The file field element
def attach_file(locator, path, options={})
locator, path, options = nil, locator, path if path.is_a? Hash
def attach_file(locator=nil, path, **options)
Array(path).each do |p|
raise Capybara::FileNotFound, "cannot attach file, #{p} does not exist" unless File.exist?(p.to_s)
end
@ -290,12 +280,8 @@ module Capybara
end
end
def _check_with_label(selector, checked, locator, options)
locator, options = nil, locator if locator.is_a? Hash
allow_label_click = options.delete(:allow_label_click) { session_options.automatic_label_click }
synchronize(Capybara::Queries::BaseQuery.wait(options, session_options.default_max_wait_time)) do
def _check_with_label(selector, checked, locator, allow_label_click: session_options.automatic_label_click, **options)
synchronize(Capybara::Queries::BaseQuery::wait(options, session_options.default_max_wait_time)) do
begin
el = find(selector, locator, options)
el.set(checked)

View File

@ -74,7 +74,7 @@ module Capybara
# @return [Object] The result of the given block
# @raise [Capybara::FrozenInTime] If the return value of `Time.now` appears stuck
#
def synchronize(seconds=session_options.default_max_wait_time, options = {})
def synchronize(seconds=session_options.default_max_wait_time, errors: nil)
start_time = Capybara::Helpers.monotonic_time
if session.synchronized
@ -86,7 +86,7 @@ module Capybara
rescue => e
session.raise_server_error!
raise e unless driver.wait?
raise e unless catch_error?(e, options[:errors])
raise e unless catch_error?(e, errors)
raise e if (Capybara::Helpers.monotonic_time - start_time) >= seconds
sleep(0.05)
raise Capybara::FrozenInTime, "time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead" if Capybara::Helpers.monotonic_time == start_time

View File

@ -15,7 +15,7 @@ module Capybara
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
# @return [true]
#
def assert_title(title, options = {})
def assert_title(title, **options)
_verify_title(title,options) { |query| raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self) }
end
@ -26,7 +26,7 @@ module Capybara
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
# @return [true]
#
def assert_no_title(title, options = {})
def assert_no_title(title, **options)
_verify_title(title,options) { |query| raise Capybara::ExpectationNotMet, query.negative_failure_message if query.resolves_for?(self) }
end
@ -36,7 +36,7 @@ module Capybara
# @macro title_query_params
# @return [Boolean]
#
def has_title?(title, options = {})
def has_title?(title, **options)
assert_title(title, options)
rescue Capybara::ExpectationNotMet
return false
@ -48,7 +48,7 @@ module Capybara
# @macro title_query_params
# @return [Boolean]
#
def has_no_title?(title, options = {})
def has_no_title?(title, **options)
assert_no_title(title, options)
rescue Capybara::ExpectationNotMet
return false

View File

@ -94,9 +94,7 @@ module Capybara
# @param [Hash{}] options Driver specific options for how to set the value
#
# @return [Capybara::Node::Element] The element
def set(value, options={})
options ||= {}
def set(value, **options)
raise Capybara::ReadOnlyElementError, "Attempt to set readonly element with value: #{value}" if readonly?
driver_supports_options = (base.method(:set).arity != 1)

View File

@ -123,8 +123,7 @@ module Capybara
# @return [Capybara::Node::Element] The found element
#
def find_field(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def find_field(locator=nil, **options, &optional_filter_block)
find(:field, locator, options, &optional_filter_block)
end
alias_method :field_labeled, :find_field
@ -145,8 +144,7 @@ module Capybara
# @option options [String, Array<String>] class Match links that match the class(es) provided
# @return [Capybara::Node::Element] The found element
#
def find_link(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def find_link(locator=nil, **options, &optional_filter_block)
find(:link, locator, options, &optional_filter_block)
end
@ -174,8 +172,7 @@ module Capybara
# @option options [String, Array<String>] class Match buttons that match the class(es) provided
# @return [Capybara::Node::Element] The found element
#
def find_button(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def find_button(locator=nil, **options, &optional_filter_block)
find(:button, locator, options, &optional_filter_block)
end
@ -189,7 +186,7 @@ module Capybara
#
# @return [Capybara::Node::Element] The found element
#
def find_by_id(id, options={}, &optional_filter_block)
def find_by_id(id, **options, &optional_filter_block)
find(:id, id, options, &optional_filter_block)
end
@ -286,12 +283,11 @@ module Capybara
# @param [Hash] options Additional options; see {#all}
# @return [Capybara::Node::Element] The found element or nil
#
def first(*args, &optional_filter_block)
def first(*args, **options, &optional_filter_block)
if session_options.wait_on_first_by_default
options = if args.last.is_a?(Hash) then args.pop.dup else {} end
args.push({minimum: 1}.merge(options))
options = {minimum: 1}.merge(options)
end
all(*args, &optional_filter_block).first
all(*args, **options, &optional_filter_block).first
rescue Capybara::ExpectationNotMet
nil
end

View File

@ -203,7 +203,7 @@ module Capybara
# @option options [Integer] :count (nil) Number of times the expression should occur
# @return [Boolean] If the expression exists
#
def has_xpath?(path, options={}, &optional_filter_block)
def has_xpath?(path, **options, &optional_filter_block)
has_selector?(:xpath, path, options, &optional_filter_block)
end
@ -215,7 +215,7 @@ module Capybara
# @param (see Capybara::Node::Finders#has_xpath?)
# @return [Boolean]
#
def has_no_xpath?(path, options={}, &optional_filter_block)
def has_no_xpath?(path, **options, &optional_filter_block)
has_no_selector?(:xpath, path, options, &optional_filter_block)
end
@ -242,7 +242,7 @@ module Capybara
# @option options [Integer] :count (nil) Number of times the selector should occur
# @return [Boolean] If the selector exists
#
def has_css?(path, options={}, &optional_filter_block)
def has_css?(path, **options, &optional_filter_block)
has_selector?(:css, path, options, &optional_filter_block)
end
@ -254,7 +254,7 @@ module Capybara
# @param (see Capybara::Node::Finders#has_css?)
# @return [Boolean]
#
def has_no_css?(path, options={}, &optional_filter_block)
def has_no_css?(path, **options, &optional_filter_block)
has_no_selector?(:css, path, options, &optional_filter_block)
end
@ -268,8 +268,7 @@ module Capybara
# @option options [String, Regexp] :href The value the href attribute must be
# @return [Boolean] Whether it exists
#
def has_link?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_link?(locator, **options, &optional_filter_block)
has_selector?(:link, locator, options, &optional_filter_block)
end
@ -281,8 +280,7 @@ module Capybara
# @param (see Capybara::Node::Finders#has_link?)
# @return [Boolean] Whether it doesn't exist
#
def has_no_link?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_no_link?(locator, **options, &optional_filter_block)
has_no_selector?(:link, locator, options, &optional_filter_block)
end
@ -294,8 +292,7 @@ module Capybara
# @param [String] locator The text, value or id of a button to check for
# @return [Boolean] Whether it exists
#
def has_button?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_button?(locator, **options, &optional_filter_block)
has_selector?(:button, locator, options, &optional_filter_block)
end
@ -307,8 +304,7 @@ module Capybara
# @param [String] locator The text, value or id of a button to check for
# @return [Boolean] Whether it doesn't exist
#
def has_no_button?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_no_button?(locator, **options, &optional_filter_block)
has_no_selector?(:button, locator, options, &optional_filter_block)
end
@ -334,8 +330,7 @@ module Capybara
# @option options [String] :type The type attribute of the field
# @return [Boolean] Whether it exists
#
def has_field?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_field?(locator, **options, &optional_filter_block)
has_selector?(:field, locator, options, &optional_filter_block)
end
@ -349,8 +344,7 @@ module Capybara
# @option options [String] :type The type attribute of the field
# @return [Boolean] Whether it doesn't exist
#
def has_no_field?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_no_field?(locator, **options, &optional_filter_block)
has_no_selector?(:field, locator, options, &optional_filter_block)
end
@ -363,8 +357,7 @@ module Capybara
# @param [String] locator The label, name or id of a checked field
# @return [Boolean] Whether it exists
#
def has_checked_field?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_checked_field?(locator=nil, **options, &optional_filter_block)
has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
end
@ -377,8 +370,7 @@ module Capybara
# @param [String] locator The label, name or id of a checked field
# @return [Boolean] Whether it doesn't exist
#
def has_no_checked_field?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_no_checked_field?(locator=nil, **options, &optional_filter_block)
has_no_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
end
@ -391,8 +383,7 @@ module Capybara
# @param [String] locator The label, name or id of an unchecked field
# @return [Boolean] Whether it exists
#
def has_unchecked_field?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_unchecked_field?(locator=nil, **options, &optional_filter_block)
has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
end
@ -405,8 +396,7 @@ module Capybara
# @param [String] locator The label, name or id of an unchecked field
# @return [Boolean] Whether it doesn't exist
#
def has_no_unchecked_field?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_no_unchecked_field?(locator=nil, **options, &optional_filter_block)
has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
end
@ -439,8 +429,7 @@ module Capybara
# @option options [String, Array] :with_selected Partial set of options which should minimally be selected
# @return [Boolean] Whether it exists
#
def has_select?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_select?(locator, **options, &optional_filter_block)
has_selector?(:select, locator, options, &optional_filter_block)
end
@ -452,8 +441,7 @@ module Capybara
# @param (see Capybara::Node::Matchers#has_select?)
# @return [Boolean] Whether it doesn't exist
#
def has_no_select?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_no_select?(locator, **options, &optional_filter_block)
has_no_selector?(:select, locator, options, &optional_filter_block)
end
@ -467,8 +455,7 @@ module Capybara
# @param [String] locator The id or caption of a table
# @return [Boolean] Whether it exist
#
def has_table?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_table?(locator, **options, &optional_filter_block)
has_selector?(:table, locator, options, &optional_filter_block)
end
@ -480,8 +467,7 @@ module Capybara
# @param (see Capybara::Node::Matchers#has_table?)
# @return [Boolean] Whether it doesn't exist
#
def has_no_table?(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def has_no_table?(locator, **options, &optional_filter_block)
has_no_selector?(:table, locator, options, &optional_filter_block)
end

View File

@ -5,7 +5,7 @@ module Capybara
# @api private
module Queries
class CurrentPathQuery < BaseQuery
def initialize(expected_path, options = {})
def initialize(expected_path, **options)
super(options)
@expected_path = expected_path
warn "DEPRECATED: The :only_path option is deprecated in favor of the :ignore_query option" if options.has_key?(:only_path)

View File

@ -7,11 +7,11 @@ module Capybara
VALID_KEYS = COUNT_KEYS + [:text, :id, :class, :visible, :exact, :exact_text, :match, :wait, :filter_set]
VALID_MATCH = [:first, :smart, :prefer_exact, :one]
def initialize(*args, &filter_block)
def initialize(*args, session_options:, **options, &filter_block)
@resolved_node = nil
@options = if args.last.is_a?(Hash) then args.pop.dup else {} end
@options = options.dup
super(@options)
self.session_options = session_options
@filter_block = filter_block
if args[0].is_a?(Symbol)
@ -27,6 +27,7 @@ module Capybara
warn "Unused parameters passed to #{self.class.name} : #{args}" unless args.empty?
# TODO: make this better somehow
# for compatibility with Capybara 2.0
if session_options.exact_options and @selector == Selector.all[:option]
@options[:exact] = true

View File

@ -3,15 +3,13 @@ module Capybara
# @api private
module Queries
class TextQuery < BaseQuery
def initialize(*args)
@type = (args.first.is_a?(Symbol) || args.first.nil?) ? args.shift : nil
# @type = (Capybara.ignore_hidden_elements or Capybara.visible_text_only) ? :visible : :all if @type.nil?
@options = if args.last.is_a?(Hash) then args.pop.dup else {} end
def initialize(type=nil, expected_text, session_options:, **options)
@type = type
@type = (Capybara.ignore_hidden_elements or Capybara.visible_text_only) ? :visible : :all if @type.nil?
@expected_text = expected_text
@options = options
super(@options)
@type = (session_options.ignore_hidden_elements or session_options.visible_text_only) ? :visible : :all if @type.nil?
@expected_text = args.shift
self.session_options = session_options
unless @expected_text.is_a?(Regexp)
@expected_text = Capybara::Helpers.normalize_whitespace(@expected_text)
end

View File

@ -3,7 +3,7 @@ module Capybara
# @api private
module Queries
class TitleQuery < BaseQuery
def initialize(expected_title, options = {})
def initialize(expected_title, **options)
@expected_title = expected_title
@options = options
super(@options)

View File

@ -13,7 +13,7 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
}
attr_reader :app, :options
def initialize(app, options={})
def initialize(app, **options)
raise ArgumentError, "rack-test requires a rack application, but none was given" unless app
@session = nil
@app = app

View File

@ -10,11 +10,6 @@ RSpec.configure do |config|
config.include Capybara::RSpecMatchers, :type => :feature
config.include Capybara::RSpecMatchers, :type => :view
# A work-around to support accessing the current example that works in both
# RSpec 2 and RSpec 3.
fetch_current_example = RSpec.respond_to?(:current_example) ?
proc { RSpec.current_example } : proc { |context| context.example }
# The before and after blocks must run instantaneously, because Capybara
# might not actually be used in all examples where it's included.
config.after do
@ -26,7 +21,7 @@ RSpec.configure do |config|
config.before do
if self.class.include?(Capybara::DSL)
example = fetch_current_example.call(self)
example = RSpec.current_example
Capybara.current_driver = Capybara.javascript_driver if example.metadata[:js]
Capybara.current_driver = example.metadata[:driver] if example.metadata[:driver]
end

View File

@ -268,26 +268,25 @@ module Capybara
::RSpec::Matchers.define_negated_matcher :not_match_selector, :match_selector if defined?(::RSpec::Matchers)
# RSpec matcher for whether elements(s) matching a given xpath selector exist
# See {Capybara::Node::Matchers#has_xpath?}
def have_xpath(xpath, options={}, &optional_filter_block)
def have_xpath(xpath, **options, &optional_filter_block)
HaveSelector.new(:xpath, xpath, options, &optional_filter_block)
end
# RSpec matcher for whether the current element matches a given xpath selector
def match_xpath(xpath, options={}, &optional_filter_block)
def match_xpath(xpath, **options, &optional_filter_block)
MatchSelector.new(:xpath, xpath, options, &optional_filter_block)
end
# RSpec matcher for whether elements(s) matching a given css selector exist
# See {Capybara::Node::Matchers#has_css?}
def have_css(css, options={}, &optional_filter_block)
def have_css(css, **options, &optional_filter_block)
HaveSelector.new(:css, css, options, &optional_filter_block)
end
# RSpec matcher for whether the current element matches a given css selector
def match_css(css, options={}, &optional_filter_block)
def match_css(css, **options, &optional_filter_block)
MatchSelector.new(:css, css, options, &optional_filter_block)
end
@ -298,62 +297,55 @@ module Capybara
end
alias_method :have_content, :have_text
def have_title(title, options = {})
def have_title(title, **options)
HaveTitle.new(title, options)
end
# RSpec matcher for the current path
# See {Capybara::SessionMatchers#assert_current_path}
def have_current_path(path, options = {})
def have_current_path(path, **options)
HaveCurrentPath.new(path, options)
end
# RSpec matcher for links
# See {Capybara::Node::Matchers#has_link?}
def have_link(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def have_link(locator, **options, &optional_filter_block)
HaveSelector.new(:link, locator, options, &optional_filter_block)
end
# RSpec matcher for buttons
# See {Capybara::Node::Matchers#has_button?}
def have_button(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def have_button(locator, **options, &optional_filter_block)
HaveSelector.new(:button, locator, options, &optional_filter_block)
end
# RSpec matcher for links
# See {Capybara::Node::Matchers#has_field?}
def have_field(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def have_field(locator, **options, &optional_filter_block)
HaveSelector.new(:field, locator, options, &optional_filter_block)
end
# RSpec matcher for checked fields
# See {Capybara::Node::Matchers#has_checked_field?}
def have_checked_field(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def have_checked_field(locator=nil, **options, &optional_filter_block)
HaveSelector.new(:field, locator, options.merge(checked: true), &optional_filter_block)
end
# RSpec matcher for unchecked fields
# See {Capybara::Node::Matchers#has_unchecked_field?}
def have_unchecked_field(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def have_unchecked_field(locator=nil, **options, &optional_filter_block)
HaveSelector.new(:field, locator, options.merge(unchecked: true), &optional_filter_block)
end
# RSpec matcher for select elements
# See {Capybara::Node::Matchers#has_select?}
def have_select(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def have_select(locator, **options, &optional_filter_block)
HaveSelector.new(:select, locator, options, &optional_filter_block)
end
# RSpec matcher for table elements
# See {Capybara::Node::Matchers#has_table?}
def have_table(locator=nil, options={}, &optional_filter_block)
locator, options = nil, locator if locator.is_a? Hash
def have_table(locator, **options, &optional_filter_block)
HaveSelector.new(:table, locator, options, &optional_filter_block)
end
@ -363,7 +355,7 @@ module Capybara
# expect(window).to become_closed(wait: 0.8)
# @param options [Hash] optional param
# @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum wait time
def become_closed(options = {})
def become_closed(**options)
BecomeClosed.new(options)
end
end

View File

@ -1,20 +1,3 @@
# frozen_string_literal: true
require 'capybara/selector/filters/node_filter'
require 'capybara/selector/filters/expression_filter'
module Capybara
class Selector
def self.const_missing(const_name)
case const_name
when :Filter
warn "DEPRECATED: Capybara::Selector::Filter is deprecated, please use Capybara::Selector::Filters::NodeFilter instead"
Filters::NodeFilter
when :ExpressionFilter
warn "DEPRECATED: Capybara::Selector::ExpressionFilter is deprecated, please use Capybara::Selector::Filters::ExpressionFilter instead"
Filters::ExpressionFilter
else
super
end
end
end
end

View File

@ -64,9 +64,8 @@ module Capybara
private
def add_filter(name, filter_class, *types_and_options, &block)
options = types_and_options.last.is_a?(Hash) ? types_and_options.pop.dup : {}
types_and_options.each { |k| options[k] = true}
def add_filter(name, filter_class, *types, **options, &block)
types.each { |k| options[k] = true}
filters[name] = filter_class.new(name, block, options)
end
end

View File

@ -3,7 +3,7 @@ module Capybara
class Selector
module Filters
class Base
def initialize(name, block, options={})
def initialize(name, block, **options)
@name = name
@block = block
@options = options

View File

@ -35,7 +35,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
@browser
end
def initialize(app, options={})
def initialize(app, **options)
load_selenium
@session = nil
@app = app
@ -102,7 +102,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
unwrap_script_result(result)
end
def save_screenshot(path, _options={})
def save_screenshot(path, **_options)
browser.save_screenshot(path)
end
@ -231,7 +231,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
browser.switch_to.window(handle) { yield }
end
def accept_modal(_type, options={})
def accept_modal(_type, **options)
if headless_chrome?
raise ArgumentError, "Block that triggers the system modal is missing" unless block_given?
insert_modal_handlers(true, options[:with])
@ -249,7 +249,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
end
end
def dismiss_modal(_type, options={})
def dismiss_modal(_type, **options)
if headless_chrome?
raise ArgumentError, "Block that triggers the system modal is missing" unless block_given?
insert_modal_handlers(false, options[:with])
@ -423,7 +423,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
end
end
def find_modal(options={})
def find_modal(text: nil, **options)
# Selenium has its own built in wait (2 seconds)for a modal to show up, so this wait is really the minimum time
# Actual wait time may be longer than specified
wait = Selenium::WebDriver::Wait.new(
@ -432,15 +432,15 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
begin
wait.until do
alert = @browser.switch_to.alert
regexp = options[:text].is_a?(Regexp) ? options[:text] : Regexp.escape(options[:text].to_s)
regexp = text.is_a?(Regexp) ? text : Regexp.escape(text.to_s)
alert.text.match(regexp) ? alert : nil
end
rescue Selenium::WebDriver::Error::TimeOutError
raise Capybara::ModalNotFound.new("Unable to find modal dialog#{" with #{options[:text]}" if options[:text]}")
raise Capybara::ModalNotFound.new("Unable to find modal dialog#{" with #{text}" if text}")
end
end
def find_headless_modal(options={})
def find_headless_modal(text: nil, **options)
# Selenium has its own built in wait (2 seconds)for a modal to show up, so this wait is really the minimum time
# Actual wait time may be longer than specified
wait = Selenium::WebDriver::Wait.new(
@ -451,11 +451,11 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
called, alert_text = evaluate_script('window.capybara && window.capybara.current_modal_status()')
if called
execute_script('window.capybara && window.capybara.modal_handlers.shift()')
regexp = options[:text].is_a?(Regexp) ? options[:text] : Regexp.escape(options[:text].to_s)
regexp = text.is_a?(Regexp) ? text : Regexp.escape(text.to_s)
if alert_text.match(regexp)
alert_text
else
raise Capybara::ModalNotFound.new("Unable to find modal dialog#{" with #{options[:text]}" if options[:text]}")
raise Capybara::ModalNotFound.new("Unable to find modal dialog#{" with #{text}" if text}")
end
elsif called.nil?
# page changed so modal_handler data has gone away

View File

@ -36,7 +36,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
# :none => append the new value to the existing value <br/>
# :backspace => send backspace keystrokes to clear the field <br/>
# Array => an array of keys to send before the value being set, e.g. [[:command, 'a'], :backspace]
def set(value, options={})
def set(value, **options)
tag_name = self.tag_name
type = self[:type]

View File

@ -475,9 +475,7 @@ module Capybara
# `within_frame` methods
# @raise [ArgumentError] if both or neither arguments were provided
#
def switch_to_window(window = nil, options= {}, &window_locator)
options, window = window, nil if window.is_a? Hash
def switch_to_window(window = nil, **options, &window_locator)
block_given = block_given?
if window && block_given
raise ArgumentError, "`switch_to_window` can take either a block or a window, not both"
@ -660,9 +658,8 @@ module Capybara
# @return [String] the message shown in the modal
# @raise [Capybara::ModalNotFound] if modal dialog hasn't been found
#
#
def accept_alert(text_or_options=nil, options={}, &blk)
accept_modal(:alert, text_or_options, options, &blk)
def accept_alert(text=nil, **options, &blk)
accept_modal(:alert, text, options, &blk)
end
##
@ -671,8 +668,8 @@ module Capybara
#
# @macro modal_params
#
def accept_confirm(text_or_options=nil, options={}, &blk)
accept_modal(:confirm, text_or_options, options, &blk)
def accept_confirm(text=nil, **options, &blk)
accept_modal(:confirm, text, options, &blk)
end
##
@ -681,8 +678,8 @@ module Capybara
#
# @macro modal_params
#
def dismiss_confirm(text_or_options=nil, options={}, &blk)
dismiss_modal(:confirm, text_or_options, options, &blk)
def dismiss_confirm(text=nil, **options, &blk)
dismiss_modal(:confirm, text, options, &blk)
end
##
@ -692,8 +689,8 @@ module Capybara
# @macro modal_params
# @option options [String] :with Response to provide to the prompt
#
def accept_prompt(text_or_options=nil, options={}, &blk)
accept_modal(:prompt, text_or_options, options, &blk)
def accept_prompt(text=nil, **options, &blk)
accept_modal(:prompt, text, options, &blk)
end
##
@ -702,8 +699,8 @@ module Capybara
#
# @macro modal_params
#
def dismiss_prompt(text_or_options=nil, options={}, &blk)
dismiss_modal(:prompt, text_or_options, options, &blk)
def dismiss_prompt(text=nil, **options, &blk)
dismiss_modal(:prompt, text, options, &blk)
end
##
@ -750,7 +747,7 @@ module Capybara
# @param [String] path the path to where it should be saved
# @param [Hash] options a customizable set of options
# @return [String] the path to which the file was saved
def save_screenshot(path = nil, options = {})
def save_screenshot(path = nil, **options)
path = prepare_path(path, 'png')
driver.save_screenshot(path, options)
path
@ -767,7 +764,7 @@ module Capybara
# @param [String] path the path to where it should be saved
# @param [Hash] options a customizable set of options
#
def save_and_open_screenshot(path = nil, options = {})
def save_and_open_screenshot(path = nil, **options)
path = save_screenshot(path, options)
open_file(path)
end
@ -857,7 +854,6 @@ module Capybara
options
end
def open_file(path)
begin
require "launchy"

View File

@ -18,7 +18,7 @@ module Capybara
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
# @return [true]
#
def assert_current_path(path, options={})
def assert_current_path(path, **options)
_verify_current_path(path,options) { |query| raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self) }
end
@ -32,7 +32,7 @@ module Capybara
# @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
# @return [true]
#
def assert_no_current_path(path, options={})
def assert_no_current_path(path, **options)
_verify_current_path(path,options) { |query| raise Capybara::ExpectationNotMet, query.negative_failure_message if query.resolves_for?(self) }
end
@ -45,7 +45,7 @@ module Capybara
# @macro current_path_query_params
# @return [Boolean]
#
def has_current_path?(path, options={})
def has_current_path?(path, **options)
assert_current_path(path, options)
rescue Capybara::ExpectationNotMet
return false
@ -60,7 +60,7 @@ module Capybara
# @macro current_path_query_params
# @return [Boolean]
#
def has_no_current_path?(path, options={})
def has_no_current_path?(path, **options)
assert_no_current_path(path, options)
rescue Capybara::ExpectationNotMet
return false

View File

@ -113,7 +113,7 @@ Capybara::SpecHelper.spec "#fill_in" do
end
it "should throw an exception if a hash containing 'with' is not provided" do
expect {@session.fill_in 'Name', 'ignu'}.to raise_error(RuntimeError, /with/)
expect {@session.fill_in 'Name'}.to raise_error(ArgumentError, /with/)
end
it "should wait for asynchronous load", requires: [:js] do

View File

@ -1,4 +1,4 @@
# frozen_string_literal: true
module Capybara
VERSION = '2.17.0'
VERSION = '3.0.0.dev'
end