Prefer match? when match data not needed
This commit is contained in:
parent
0873c9052d
commit
08e0f610ec
|
@ -107,7 +107,7 @@ module Capybara
|
|||
!find_xpath(VISIBILITY_XPATH)
|
||||
else
|
||||
# No need for an xpath if only checking the current element
|
||||
!(native.key?('hidden') || (native[:style] =~ /display:\s?none/) || %w[script head].include?(tag_name))
|
||||
!(native.key?('hidden') || (/display:\s?none/.match? native[:style]) || %w[script head].include?(tag_name))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -368,13 +368,13 @@ module Capybara
|
|||
def matches_id_filter?(node)
|
||||
return true unless use_default_id_filter? && options[:id].is_a?(Regexp)
|
||||
|
||||
node[:id] =~ options[:id]
|
||||
options[:id].match? node[:id]
|
||||
end
|
||||
|
||||
def matches_class_filter?(node)
|
||||
return true unless use_default_class_filter? && options[:class].is_a?(Regexp)
|
||||
|
||||
node[:class] =~ options[:class]
|
||||
options[:class].match? node[:class]
|
||||
end
|
||||
|
||||
def matches_style_filter?(node)
|
||||
|
@ -382,7 +382,7 @@ module Capybara
|
|||
when String, nil
|
||||
true
|
||||
when Regexp
|
||||
node[:style] =~ options[:style]
|
||||
options[:style].match? node[:style]
|
||||
when Hash
|
||||
matches_style?(node, options[:style])
|
||||
end
|
||||
|
@ -392,7 +392,7 @@ module Capybara
|
|||
@actual_styles = node.initial_cache[:style] || node.style(*styles.keys)
|
||||
styles.all? do |style, value|
|
||||
if value.is_a? Regexp
|
||||
@actual_styles[style.to_s] =~ value
|
||||
value.match? @actual_styles[style.to_s]
|
||||
else
|
||||
@actual_styles[style.to_s] == value
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ module Capybara
|
|||
@actual_styles = node.style(*@expected_styles.keys)
|
||||
@expected_styles.all? do |style, value|
|
||||
if value.is_a? Regexp
|
||||
@actual_styles[style] =~ value
|
||||
value.match? @actual_styles[style]
|
||||
else
|
||||
@actual_styles[style] == value
|
||||
end
|
||||
|
|
|
@ -56,7 +56,7 @@ private
|
|||
end
|
||||
|
||||
def request_method
|
||||
self[:method].to_s.match?(/post/i) ? :post : :get
|
||||
/post/i.match?(self[:method]) ? :post : :get
|
||||
end
|
||||
|
||||
def merge_param!(params, key, value)
|
||||
|
|
|
@ -45,7 +45,7 @@ end
|
|||
|
||||
Capybara.add_selector(:id, locator_type: [String, Symbol, Regexp]) do
|
||||
xpath { |id| builder(XPath.descendant).add_attribute_conditions(id: id) }
|
||||
locator_filter { |node, id| id.is_a?(Regexp) ? node[:id] =~ id : true }
|
||||
locator_filter { |node, id| id.is_a?(Regexp) ? id.match?(node[:id]) : true }
|
||||
end
|
||||
|
||||
Capybara.add_selector(:field, locator_type: [String, Symbol]) do
|
||||
|
@ -71,7 +71,7 @@ Capybara.add_selector(:field, locator_type: [String, Symbol]) do
|
|||
node_filter(:readonly, :boolean) { |node, value| !(value ^ node.readonly?) }
|
||||
node_filter(:with) do |node, with|
|
||||
val = node.value
|
||||
(with.is_a?(Regexp) ? val =~ with : val == with.to_s).tap do |res|
|
||||
(with.is_a?(Regexp) ? with.match?(val) : val == with.to_s).tap do |res|
|
||||
add_error("Expected value to be #{with.inspect} but was #{val.inspect}") unless res
|
||||
end
|
||||
end
|
||||
|
@ -219,7 +219,7 @@ Capybara.add_selector(:fillable_field, locator_type: [String, Symbol]) do
|
|||
|
||||
node_filter(:with) do |node, with|
|
||||
val = node.value
|
||||
(with.is_a?(Regexp) ? val =~ with : val == with.to_s).tap do |res|
|
||||
(with.is_a?(Regexp) ? with.match?(val) : val == with.to_s).tap do |res|
|
||||
add_error("Expected value to be #{with.inspect} but was #{val.inspect}") unless res
|
||||
end
|
||||
end
|
||||
|
@ -618,7 +618,7 @@ Capybara.add_selector(:element, locator_type: [String, Symbol]) do
|
|||
node_filter(:attributes, matcher: /.+/) do |node, name, val|
|
||||
next true unless val.is_a?(Regexp)
|
||||
|
||||
(node[name] =~ val).tap do |res|
|
||||
(val.match? node[name]).tap do |res|
|
||||
add_error("Expected #{name} to match #{val.inspect} but it was #{node[name]}") unless res
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Capybara
|
|||
def self.escape(str)
|
||||
value = str.dup
|
||||
out = +''
|
||||
out << value.slice!(0...1) if value =~ /^[-_]/
|
||||
out << value.slice!(0...1) if value.match?(/^[-_]/)
|
||||
out << (value[0].match?(NMSTART) ? value.slice!(0...1) : escape_char(value.slice!(0...1)))
|
||||
out << value.gsub(/[^a-zA-Z0-9_-]/) { |char| escape_char char }
|
||||
out
|
||||
|
|
|
@ -34,7 +34,7 @@ module Capybara
|
|||
|
||||
def handles_option?(option_name)
|
||||
if matcher?
|
||||
option_name =~ @matcher
|
||||
@matcher.match? option_name
|
||||
else
|
||||
@name == option_name
|
||||
end
|
||||
|
|
|
@ -338,7 +338,7 @@ private
|
|||
end
|
||||
|
||||
def silenced_unknown_error_message?(msg)
|
||||
silenced_unknown_error_messages.any? { |regex| msg =~ regex }
|
||||
silenced_unknown_error_messages.any? { |regex| msg.match? regex }
|
||||
end
|
||||
|
||||
def silenced_unknown_error_messages
|
||||
|
|
|
@ -8,7 +8,7 @@ module Capybara::Selenium::Driver::ChromeDriver
|
|||
begin
|
||||
super
|
||||
rescue NoMethodError => e
|
||||
raise unless e.message =~ /full_screen_window/
|
||||
raise unless e.message.match?(/full_screen_window/)
|
||||
|
||||
result = bridge.http.call(:post, "session/#{bridge.session_id}/window/fullscreen", {})
|
||||
result['value']
|
||||
|
@ -19,7 +19,7 @@ module Capybara::Selenium::Driver::ChromeDriver
|
|||
def resize_window_to(handle, width, height)
|
||||
super
|
||||
rescue Selenium::WebDriver::Error::UnknownError => err
|
||||
raise unless err.message =~ /failed to change window state/
|
||||
raise unless err.message.match?(/failed to change window state/)
|
||||
|
||||
# Chromedriver doesn't wait long enough for state to change when coming out of fullscreen
|
||||
# and raises unnecessary error. Wait a bit and try again.
|
||||
|
|
|
@ -36,7 +36,7 @@ module Capybara
|
|||
attr_reader :disable_markup
|
||||
|
||||
def html_content?
|
||||
!!(@headers['Content-Type'] =~ /html/)
|
||||
/html/.match?(@headers['Content-Type'])
|
||||
end
|
||||
|
||||
def insert_disable(html)
|
||||
|
|
|
@ -77,14 +77,14 @@ module Capybara
|
|||
|
||||
remove_method :app_host=
|
||||
def app_host=(url)
|
||||
raise ArgumentError, "Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}." if url && url !~ URI::DEFAULT_PARSER.make_regexp
|
||||
raise ArgumentError, "Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}." unless url.nil? || url.match?(URI::DEFAULT_PARSER.make_regexp)
|
||||
|
||||
@app_host = url
|
||||
end
|
||||
|
||||
remove_method :default_host=
|
||||
def default_host=(url)
|
||||
raise ArgumentError, "Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}." if url && url !~ URI::DEFAULT_PARSER.make_regexp
|
||||
raise ArgumentError, "Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}." unless url.nil? || url.match?(URI::DEFAULT_PARSER.make_regexp)
|
||||
|
||||
@default_host = url
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue