Cleanup some rubocop style warnings
This commit is contained in:
parent
fb5c64e4de
commit
952d373026
25
.rubocop.yml
25
.rubocop.yml
|
@ -46,10 +46,8 @@ Lint/UnusedMethodArgument:
|
||||||
- 'lib/capybara/driver/node.rb'
|
- 'lib/capybara/driver/node.rb'
|
||||||
|
|
||||||
Lint/HandleExceptions:
|
Lint/HandleExceptions:
|
||||||
Enabled: false
|
Exclude:
|
||||||
|
- 'spec/**/*'
|
||||||
Lint/Loop:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Layout/EndAlignment:
|
Layout/EndAlignment:
|
||||||
EnforcedStyleAlignWith: variable
|
EnforcedStyleAlignWith: variable
|
||||||
|
@ -68,7 +66,9 @@ Naming/UncommunicativeMethodParamName:
|
||||||
- 'on'
|
- 'on'
|
||||||
|
|
||||||
Style/RescueStandardError:
|
Style/RescueStandardError:
|
||||||
Enabled: false
|
Exclude:
|
||||||
|
- 'spec/**/*'
|
||||||
|
- 'lib/capybara/spec/**/*'
|
||||||
|
|
||||||
Style/ParallelAssignment:
|
Style/ParallelAssignment:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
@ -79,19 +79,13 @@ Style/SingleLineMethods:
|
||||||
Style/StringLiterals:
|
Style/StringLiterals:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Style/RegexpLiteral:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Style/RescueModifier:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Style/Alias:
|
Style/Alias:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Style/AndOr:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Style/Documentation:
|
Style/Documentation:
|
||||||
|
Exclude:
|
||||||
|
- 'lib/capybara/spec/**/*'
|
||||||
|
- 'spec/**/*'
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
Style/DoubleNegation:
|
Style/DoubleNegation:
|
||||||
|
@ -106,9 +100,6 @@ Style/GuardClause:
|
||||||
Style/EmptyElse:
|
Style/EmptyElse:
|
||||||
EnforcedStyle: empty
|
EnforcedStyle: empty
|
||||||
|
|
||||||
Style/RedundantReturn:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Style/ClassAndModuleChildren:
|
Style/ClassAndModuleChildren:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
||||||
s.email = ["twalpole@gmail.com", "jonas.nicklas@gmail.com"]
|
s.email = ["twalpole@gmail.com", "jonas.nicklas@gmail.com"]
|
||||||
s.description = "Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website"
|
s.description = "Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website"
|
||||||
|
|
||||||
s.files = Dir.glob("{lib,spec,.yard}/**/*") + %w(README.md History.md License.txt .yardopts)
|
s.files = Dir.glob("{lib,spec,.yard}/**/*") + %w[README.md History.md License.txt .yardopts]
|
||||||
|
|
||||||
s.homepage = "https://github.com/teamcapybara/capybara"
|
s.homepage = "https://github.com/teamcapybara/capybara"
|
||||||
s.require_paths = ["lib"]
|
s.require_paths = ["lib"]
|
||||||
|
@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_runtime_dependency("xpath", ["~>3.0"])
|
s.add_runtime_dependency("xpath", ["~>3.0"])
|
||||||
|
|
||||||
s.add_development_dependency("cucumber", [">= 2.3.0"])
|
s.add_development_dependency("cucumber", [">= 2.3.0"])
|
||||||
s.add_development_dependency("erubi") # dependency specification needed by rbx
|
s.add_development_dependency("erubi") # dependency specification needed by rbx
|
||||||
s.add_development_dependency("fuubar", [">= 1.0.0"])
|
s.add_development_dependency("fuubar", [">= 1.0.0"])
|
||||||
s.add_development_dependency("launchy", [">= 2.0.4"])
|
s.add_development_dependency("launchy", [">= 2.0.4"])
|
||||||
s.add_development_dependency("minitest")
|
s.add_development_dependency("minitest")
|
||||||
|
@ -39,14 +39,12 @@ Gem::Specification.new do |s|
|
||||||
s.add_development_dependency("webdrivers") if ENV['CI']
|
s.add_development_dependency("webdrivers") if ENV['CI']
|
||||||
s.add_development_dependency("yard", [">= 0.9.0"])
|
s.add_development_dependency("yard", [">= 0.9.0"])
|
||||||
|
|
||||||
if RUBY_ENGINE == 'rbx' then
|
if RUBY_ENGINE == 'rbx'
|
||||||
s.add_development_dependency("json")
|
s.add_development_dependency("json")
|
||||||
s.add_development_dependency("racc")
|
s.add_development_dependency("racc")
|
||||||
s.add_development_dependency("rubysl")
|
s.add_development_dependency("rubysl")
|
||||||
end
|
end
|
||||||
|
|
||||||
if File.exist?("gem-private_key.pem")
|
s.signing_key = 'gem-private_key.pem' if File.exist?("gem-private_key.pem")
|
||||||
s.signing_key = 'gem-private_key.pem'
|
|
||||||
end
|
|
||||||
s.cert_chain = ['gem-public_cert.pem']
|
s.cert_chain = ['gem-public_cert.pem']
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,5 +21,5 @@ When(/^I use a matcher that fails$/) do
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^the failing exception should be nice$/) do
|
Then(/^the failing exception should be nice$/) do
|
||||||
expect(@error_message).to match %r{expected to find visible css \"h1#doesnotexist\"}
|
expect(@error_message).to match(/expected to find visible css \"h1#doesnotexist\"/)
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,7 +81,7 @@ module Capybara
|
||||||
|
|
||||||
def deprecate(method, alternate_method, once = false)
|
def deprecate(method, alternate_method, once = false)
|
||||||
@deprecation_notified ||= {}
|
@deprecation_notified ||= {}
|
||||||
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead" unless once and @deprecation_notified[method]
|
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead" unless once && @deprecation_notified[method]
|
||||||
@deprecation_notified[method] = true
|
@deprecation_notified[method] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -286,7 +286,7 @@ module Capybara
|
||||||
|
|
||||||
def _reset_style(element)
|
def _reset_style(element)
|
||||||
session.execute_script(RESET_STYLE_SCRIPT, element)
|
session.execute_script(RESET_STYLE_SCRIPT, element)
|
||||||
rescue # swallow extra errors
|
rescue StandardError # rubocop:disable Lint/HandleExceptions swallow extra errors
|
||||||
end
|
end
|
||||||
|
|
||||||
def _check_with_label(selector, checked, locator, allow_label_click: session_options.automatic_label_click, **options)
|
def _check_with_label(selector, checked, locator, allow_label_click: session_options.automatic_label_click, **options)
|
||||||
|
@ -294,13 +294,13 @@ module Capybara
|
||||||
begin
|
begin
|
||||||
el = find(selector, locator, options)
|
el = find(selector, locator, options)
|
||||||
el.set(checked)
|
el.set(checked)
|
||||||
rescue => e
|
rescue StandardError => e
|
||||||
raise unless allow_label_click && catch_error?(e)
|
raise unless allow_label_click && catch_error?(e)
|
||||||
begin
|
begin
|
||||||
el ||= find(selector, locator, options.merge(visible: :all))
|
el ||= find(selector, locator, options.merge(visible: :all))
|
||||||
res = find(:label, for: el, visible: true).click unless el.checked? == checked
|
res = find(:label, for: el, visible: true).click unless el.checked? == checked
|
||||||
res
|
res
|
||||||
rescue # swallow extra errors - raise original
|
rescue StandardError # swallow extra errors - raise original
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,7 +81,7 @@ module Capybara
|
||||||
start_time = Capybara::Helpers.monotonic_time
|
start_time = Capybara::Helpers.monotonic_time
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
rescue => e
|
rescue StandardError => e
|
||||||
session.raise_server_error!
|
session.raise_server_error!
|
||||||
raise e unless driver.wait? && catch_error?(e, errors)
|
raise e unless driver.wait? && catch_error?(e, errors)
|
||||||
raise e if (Capybara::Helpers.monotonic_time - start_time) >= seconds
|
raise e if (Capybara::Helpers.monotonic_time - start_time) >= seconds
|
||||||
|
|
|
@ -40,7 +40,7 @@ module Capybara
|
||||||
def has_title?(title, **options)
|
def has_title?(title, **options)
|
||||||
assert_title(title, options)
|
assert_title(title, options)
|
||||||
rescue Capybara::ExpectationNotMet
|
rescue Capybara::ExpectationNotMet
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -52,7 +52,7 @@ module Capybara
|
||||||
def has_no_title?(title, **options)
|
def has_no_title?(title, **options)
|
||||||
assert_no_title(title, options)
|
assert_no_title(title, options)
|
||||||
rescue Capybara::ExpectationNotMet
|
rescue Capybara::ExpectationNotMet
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -62,7 +62,7 @@ module Capybara
|
||||||
synchronize(query.wait) do
|
synchronize(query.wait) do
|
||||||
yield(query)
|
yield(query)
|
||||||
end
|
end
|
||||||
return true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,7 +54,7 @@ module Capybara
|
||||||
# @return [String] The text of the element
|
# @return [String] The text of the element
|
||||||
#
|
#
|
||||||
def text(type = nil)
|
def text(type = nil)
|
||||||
type ||= :all unless session_options.ignore_hidden_elements or session_options.visible_text_only
|
type ||= :all unless session_options.ignore_hidden_elements || session_options.visible_text_only
|
||||||
synchronize do
|
synchronize do
|
||||||
if type == :all
|
if type == :all
|
||||||
base.all_text
|
base.all_text
|
||||||
|
@ -355,7 +355,7 @@ module Capybara
|
||||||
begin
|
begin
|
||||||
reloaded = query_scope.reload.first(@query.name, @query.locator, @query.options)
|
reloaded = query_scope.reload.first(@query.name, @query.locator, @query.options)
|
||||||
@base = reloaded.base if reloaded
|
@base = reloaded.base if reloaded
|
||||||
rescue => e
|
rescue StandardError => e
|
||||||
raise e unless catch_error?(e)
|
raise e unless catch_error?(e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -366,7 +366,7 @@ module Capybara
|
||||||
%(#<Capybara::Node::Element tag="#{base.tag_name}" path="#{base.path}">)
|
%(#<Capybara::Node::Element tag="#{base.tag_name}" path="#{base.path}">)
|
||||||
rescue NotSupportedByDriverError
|
rescue NotSupportedByDriverError
|
||||||
%(#<Capybara::Node::Element tag="#{base.tag_name}">)
|
%(#<Capybara::Node::Element tag="#{base.tag_name}">)
|
||||||
rescue => e
|
rescue StandardError => e
|
||||||
raise unless session.driver.invalid_element_errors.any? { |et| e.is_a?(et) }
|
raise unless session.driver.invalid_element_errors.any? { |et| e.is_a?(et) }
|
||||||
|
|
||||||
%(Obsolete #<Capybara::Node::Element>)
|
%(Obsolete #<Capybara::Node::Element>)
|
||||||
|
|
|
@ -298,11 +298,11 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def ambiguous?(query, result)
|
def ambiguous?(query, result)
|
||||||
query.match == :one or query.match == :smart and result.size > 1
|
((query.match == :one) || (query.match == :smart)) && (result.size > 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prefer_exact?(query)
|
def prefer_exact?(query)
|
||||||
query.match == :smart or query.match == :prefer_exact
|
(query.match == :smart) || (query.match == :prefer_exact)
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_include_minimum?(opts)
|
def options_include_minimum?(opts)
|
||||||
|
|
|
@ -508,7 +508,7 @@ module Capybara
|
||||||
def matches_selector?(*args, &optional_filter_block)
|
def matches_selector?(*args, &optional_filter_block)
|
||||||
assert_matches_selector(*args, &optional_filter_block)
|
assert_matches_selector(*args, &optional_filter_block)
|
||||||
rescue Capybara::ExpectationNotMet
|
rescue Capybara::ExpectationNotMet
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -544,7 +544,7 @@ module Capybara
|
||||||
def not_matches_selector?(*args, &optional_filter_block)
|
def not_matches_selector?(*args, &optional_filter_block)
|
||||||
assert_not_matches_selector(*args, &optional_filter_block)
|
assert_not_matches_selector(*args, &optional_filter_block)
|
||||||
rescue Capybara::ExpectationNotMet
|
rescue Capybara::ExpectationNotMet
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -45,7 +45,7 @@ module Capybara
|
||||||
attr_name = name.to_s
|
attr_name = name.to_s
|
||||||
if attr_name == 'value'
|
if attr_name == 'value'
|
||||||
value
|
value
|
||||||
elsif tag_name == 'input' and native[:type] == 'checkbox' and attr_name == 'checked'
|
elsif (tag_name == 'input') && (native[:type] == 'checkbox') && (attr_name == 'checked')
|
||||||
native['checked'] == 'checked'
|
native['checked'] == 'checked'
|
||||||
else
|
else
|
||||||
native[attr_name]
|
native[attr_name]
|
||||||
|
|
|
@ -56,7 +56,7 @@ module Capybara
|
||||||
|
|
||||||
matches_node_filters?(node) && matches_filter_block?(node)
|
matches_node_filters?(node) && matches_filter_block?(node)
|
||||||
rescue *(node.respond_to?(:session) ? node.session.driver.invalid_element_errors : [])
|
rescue *(node.respond_to?(:session) ? node.session.driver.invalid_element_errors : [])
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible
|
def visible
|
||||||
|
|
|
@ -57,8 +57,8 @@ module Capybara
|
||||||
message << " in #{@actual_text.inspect}"
|
message << " in #{@actual_text.inspect}"
|
||||||
|
|
||||||
details_message = []
|
details_message = []
|
||||||
details_message << case_insensitive_message if @node and !@expected_text.is_a? Regexp
|
details_message << case_insensitive_message if @node && !@expected_text.is_a?(Regexp)
|
||||||
details_message << invisible_message if @node and check_visible_text? and report_on_invisible
|
details_message << invisible_message if @node && check_visible_text? && report_on_invisible
|
||||||
details_message.compact!
|
details_message.compact!
|
||||||
|
|
||||||
message << ". (However, #{details_message.join(' and ')}.)" unless details_message.empty?
|
message << ". (However, #{details_message.join(' and ')}.)" unless details_message.empty?
|
||||||
|
@ -78,7 +78,9 @@ module Capybara
|
||||||
if invisible_count != @count
|
if invisible_count != @count
|
||||||
"it was found #{invisible_count} #{Capybara::Helpers.declension('time', 'times', invisible_count)} including non-visible text"
|
"it was found #{invisible_count} #{Capybara::Helpers.declension('time', 'times', invisible_count)} including non-visible text"
|
||||||
end
|
end
|
||||||
rescue # An error getting the non-visible text (if element goes out of scope) should not affect the response
|
rescue StandardError
|
||||||
|
# An error getting the non-visible text (if element goes out of scope) should not affect the response
|
||||||
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_keys
|
def valid_keys
|
||||||
|
|
|
@ -218,11 +218,11 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def submits?
|
def submits?
|
||||||
(tag_name == 'input' and %w[submit image].include?(type)) || (tag_name == 'button' and [nil, "submit"].include?(type))
|
(tag_name == 'input' && %w[submit image].include?(type)) || (tag_name == 'button' && [nil, "submit"].include?(type))
|
||||||
end
|
end
|
||||||
|
|
||||||
def checkable?
|
def checkable?
|
||||||
tag_name == 'input' and %w[checkbox radio].include?(type)
|
tag_name == 'input' && %w[checkbox radio].include?(type)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -97,10 +97,9 @@ module Capybara
|
||||||
|
|
||||||
if @query.options[:maximum]
|
if @query.options[:maximum]
|
||||||
max_opt = Integer(@query.options[:maximum])
|
max_opt = Integer(@query.options[:maximum])
|
||||||
begin
|
loop do
|
||||||
@result_cache << @results_enum.next while @result_cache.size <= max_opt
|
return 1 if @result_cache.size > max_opt
|
||||||
return 1
|
@result_cache << @results_enum.next
|
||||||
rescue StopIteration
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ module Capybara
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
return 0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_count?
|
def matches_count?
|
||||||
|
@ -130,7 +129,7 @@ module Capybara
|
||||||
message << ", found #{count} #{Capybara::Helpers.declension('match', 'matches', count)}: " << full_results.map(&:text).map(&:inspect).join(", ")
|
message << ", found #{count} #{Capybara::Helpers.declension('match', 'matches', count)}: " << full_results.map(&:text).map(&:inspect).join(", ")
|
||||||
end
|
end
|
||||||
unless rest.empty?
|
unless rest.empty?
|
||||||
elements = rest.map { |el| el.text rescue "<<ERROR>>" }.map(&:inspect).join(", ")
|
elements = rest.map { |el| el.text rescue "<<ERROR>>" }.map(&:inspect).join(", ") # rubocop:disable Style/RescueModifier
|
||||||
message << ". Also found " << elements << ", which matched the selector but not all filters."
|
message << ". Also found " << elements << ", which matched the selector but not all filters."
|
||||||
end
|
end
|
||||||
message
|
message
|
||||||
|
|
|
@ -44,7 +44,7 @@ module Capybara
|
||||||
raise ::Capybara::ElementNotFound unless [matcher_1_matches?, matcher_2_matches?].all?
|
raise ::Capybara::ElementNotFound unless [matcher_1_matches?, matcher_2_matches?].all?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
rescue
|
rescue StandardError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -72,7 +72,7 @@ module Capybara
|
||||||
raise ::Capybara::ElementNotFound unless [matcher_1_matches?, matcher_2_matches?].any?
|
raise ::Capybara::ElementNotFound unless [matcher_1_matches?, matcher_2_matches?].any?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
rescue
|
rescue StandardError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,14 +25,14 @@ module Capybara
|
||||||
yield(wrap(actual))
|
yield(wrap(actual))
|
||||||
rescue Capybara::ExpectationNotMet => e
|
rescue Capybara::ExpectationNotMet => e
|
||||||
@failure_message = e.message
|
@failure_message = e.message
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_does_not_match?(actual)
|
def wrap_does_not_match?(actual)
|
||||||
yield(wrap(actual))
|
yield(wrap(actual))
|
||||||
rescue Capybara::ExpectationNotMet => e
|
rescue Capybara::ExpectationNotMet => e
|
||||||
@failure_message_when_negated = e.message
|
@failure_message_when_negated = e.message
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def session_query_args
|
def session_query_args
|
||||||
|
|
|
@ -234,7 +234,7 @@ Capybara.add_selector(:link_or_button) do
|
||||||
self.class.all.values_at(:link, :button).map { |selector| selector.xpath.call(locator, options) }.reduce(:union)
|
self.class.all.values_at(:link, :button).map { |selector| selector.xpath.call(locator, options) }.reduce(:union)
|
||||||
end
|
end
|
||||||
|
|
||||||
filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| node.tag_name == "a" or !(value ^ node.disabled?) }
|
filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| node.tag_name == "a" || !(value ^ node.disabled?) }
|
||||||
|
|
||||||
describe { |disabled: nil, **_options| " that is disabled" if disabled == true }
|
describe { |disabled: nil, **_options| " that is disabled" if disabled == true }
|
||||||
end
|
end
|
||||||
|
|
|
@ -137,7 +137,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
||||||
begin
|
begin
|
||||||
@browser.manage.delete_all_cookies
|
@browser.manage.delete_all_cookies
|
||||||
clear_storage
|
clear_storage
|
||||||
rescue Selenium::WebDriver::Error::UnhandledError
|
rescue Selenium::WebDriver::Error::UnhandledError # rubocop:disable Lint/HandleExceptions
|
||||||
# delete_all_cookies fails when we've previously gone
|
# delete_all_cookies fails when we've previously gone
|
||||||
# to about:blank, so we rescue this error and do nothing
|
# to about:blank, so we rescue this error and do nothing
|
||||||
# instead.
|
# instead.
|
||||||
|
@ -167,7 +167,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
||||||
@browser.navigate.to("about:blank")
|
@browser.navigate.to("about:blank")
|
||||||
sleep 0.1 # slight wait for alert
|
sleep 0.1 # slight wait for alert
|
||||||
@browser.switch_to.alert.accept
|
@browser.switch_to.alert.accept
|
||||||
rescue modal_error # rubocop:disable Metrics/BlockNesting
|
rescue modal_error # rubocop:disable Metrics/BlockNesting, Lint/HandleExceptions
|
||||||
# alert now gone, should mean navigation happened
|
# alert now gone, should mean navigation happened
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -264,7 +264,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
||||||
|
|
||||||
def quit
|
def quit
|
||||||
@browser&.quit
|
@browser&.quit
|
||||||
rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED
|
rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED # rubocop:disable Lint/HandleExceptions
|
||||||
# Browser must have already gone
|
# Browser must have already gone
|
||||||
rescue Selenium::WebDriver::Error::UnknownError => e
|
rescue Selenium::WebDriver::Error::UnknownError => e
|
||||||
unless silenced_unknown_error_message?(e.message) # Most likely already gone
|
unless silenced_unknown_error_message?(e.message) # Most likely already gone
|
||||||
|
@ -339,6 +339,7 @@ private
|
||||||
warn "sessionStorage clear requested but is not available for this driver"
|
warn "sessionStorage clear requested but is not available for this driver"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:clear_local_storage]
|
if options[:clear_local_storage]
|
||||||
if @browser.respond_to? :local_storage
|
if @browser.respond_to? :local_storage
|
||||||
@browser.local_storage.clear
|
@browser.local_storage.clear
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
if tag_name == "select" and multiple?
|
if tag_name == "select" && multiple?
|
||||||
native.find_elements(:css, "option:checked").map { |n| n[:value] || n.text }
|
native.find_elements(:css, "option:checked").map { |n| n[:value] || n.text }
|
||||||
else
|
else
|
||||||
native[:value]
|
native[:value]
|
||||||
|
@ -90,12 +90,13 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue StandardError => e
|
||||||
if e.is_a?(::Selenium::WebDriver::Error::ElementClickInterceptedError) ||
|
if e.is_a?(::Selenium::WebDriver::Error::ElementClickInterceptedError) ||
|
||||||
e.message =~ /Other element would receive the click/
|
e.message =~ /Other element would receive the click/
|
||||||
begin
|
begin
|
||||||
driver.execute_script("arguments[0].scrollIntoView({behavior: 'instant', block: 'center', inline: 'center'})", self)
|
driver.execute_script("arguments[0].scrollIntoView({behavior: 'instant', block: 'center', inline: 'center'})", self)
|
||||||
rescue # Swallow error if scrollIntoView with options isn't supported
|
rescue StandardError # rubocop:disable Lint/HandleExceptions
|
||||||
|
# Swallow error if scrollIntoView with options isn't supported
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
raise e
|
raise e
|
||||||
|
@ -198,7 +199,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
private
|
private
|
||||||
|
|
||||||
def boolean_attr(val)
|
def boolean_attr(val)
|
||||||
val and val != "false"
|
val && (val != "false")
|
||||||
end
|
end
|
||||||
|
|
||||||
# a reference to the select node if this is an option node
|
# a reference to the select node if this is an option node
|
||||||
|
|
|
@ -99,11 +99,11 @@ module Capybara
|
||||||
@using_ssl = true
|
@using_ssl = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
if res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPRedirection)
|
||||||
return res.body == app.object_id.to_s
|
return res.body == app.object_id.to_s
|
||||||
end
|
end
|
||||||
rescue SystemCallError
|
rescue SystemCallError
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait_for_pending_requests
|
def wait_for_pending_requests
|
||||||
|
|
|
@ -83,7 +83,7 @@ module Capybara
|
||||||
raise "A configuration block is only accepted when Capybara.threadsafe == true" unless Capybara.threadsafe
|
raise "A configuration block is only accepted when Capybara.threadsafe == true" unless Capybara.threadsafe
|
||||||
yield config
|
yield config
|
||||||
end
|
end
|
||||||
@server = if config.run_server and @app and driver.needs_server?
|
@server = if config.run_server && @app && driver.needs_server?
|
||||||
Capybara::Server.new(@app, port: config.server_port, host: config.server_host, reportable_errors: config.server_errors).boot
|
Capybara::Server.new(@app, port: config.server_port, host: config.server_host, reportable_errors: config.server_errors).boot
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
|
@ -878,7 +878,7 @@ module Capybara
|
||||||
driver.switch_to_window handle
|
driver.switch_to_window handle
|
||||||
return Window.new(self, handle) if yield
|
return Window.new(self, handle) if yield
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue StandardError => e
|
||||||
driver.switch_to_window(original_window_handle)
|
driver.switch_to_window(original_window_handle)
|
||||||
raise e
|
raise e
|
||||||
else
|
else
|
||||||
|
|
|
@ -49,7 +49,7 @@ module Capybara
|
||||||
def has_current_path?(path, **options)
|
def has_current_path?(path, **options)
|
||||||
assert_current_path(path, options)
|
assert_current_path(path, options)
|
||||||
rescue Capybara::ExpectationNotMet
|
rescue Capybara::ExpectationNotMet
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -64,7 +64,7 @@ module Capybara
|
||||||
def has_no_current_path?(path, **options)
|
def has_no_current_path?(path, **options)
|
||||||
assert_no_current_path(path, options)
|
assert_no_current_path(path, options)
|
||||||
rescue Capybara::ExpectationNotMet
|
rescue Capybara::ExpectationNotMet
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -74,7 +74,7 @@ module Capybara
|
||||||
document.synchronize(query.wait) do
|
document.synchronize(query.wait) do
|
||||||
yield(query)
|
yield(query)
|
||||||
end
|
end
|
||||||
return true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,7 +76,7 @@ Capybara::SpecHelper.spec '#assert_text' do
|
||||||
@session.visit('/with_html')
|
@session.visit('/with_html')
|
||||||
expect do
|
expect do
|
||||||
@session.assert_text(/xxxxyzzz/)
|
@session.assert_text(/xxxxyzzz/)
|
||||||
end.to raise_error(Capybara::ExpectationNotMet, /\Aexpected to find text matching \/xxxxyzzz\/ in "This is a test\\nHeader Class(.+)"\Z/)
|
end.to raise_error(Capybara::ExpectationNotMet, %r{\Aexpected to find text matching /xxxxyzzz/ in "This is a test\\nHeader Class(.+)"\Z})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should escape any characters that would have special meaning in a regexp" do
|
it "should escape any characters that would have special meaning in a regexp" do
|
||||||
|
|
|
@ -93,12 +93,12 @@ Capybara::SpecHelper.spec '#click_link' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should find a link matching an exact regex pattern" do
|
it "should find a link matching an exact regex pattern" do
|
||||||
@session.click_link('labore', href: /\/with_simple_html/)
|
@session.click_link('labore', href: %r{/with_simple_html})
|
||||||
expect(@session).to have_content('Bar')
|
expect(@session).to have_content('Bar')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should find a link matching a partial regex pattern" do
|
it "should find a link matching a partial regex pattern" do
|
||||||
@session.click_link('labore', href: /\/with_simple/)
|
@session.click_link('labore', href: %r{/with_simple})
|
||||||
expect(@session).to have_content('Bar')
|
expect(@session).to have_content('Bar')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ Capybara::SpecHelper.spec '#click_link' do
|
||||||
|
|
||||||
it "should follow redirects back to itself" do
|
it "should follow redirects back to itself" do
|
||||||
@session.click_link('BackToMyself')
|
@session.click_link('BackToMyself')
|
||||||
expect(@session).to have_css('#referrer', text: /\/with_html$/)
|
expect(@session).to have_css('#referrer', text: %r{/with_html$})
|
||||||
expect(@session).to have_content('This is a test')
|
expect(@session).to have_content('This is a test')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ Capybara::SpecHelper.spec '#has_link?' do
|
||||||
expect(@session).to have_link('awesome title')
|
expect(@session).to have_link('awesome title')
|
||||||
expect(@session).to have_link('A link', href: '/with_simple_html')
|
expect(@session).to have_link('A link', href: '/with_simple_html')
|
||||||
expect(@session).to have_link(:'A link', href: :'/with_simple_html')
|
expect(@session).to have_link(:'A link', href: :'/with_simple_html')
|
||||||
expect(@session).to have_link('A link', href: /\/with_simple_html/)
|
expect(@session).to have_link('A link', href: %r{/with_simple_html})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be false if the given link is not on the page" do
|
it "should be false if the given link is not on the page" do
|
||||||
|
@ -34,6 +34,6 @@ Capybara::SpecHelper.spec '#has_no_link?' do
|
||||||
it "should be true if the given link is not on the page" do
|
it "should be true if the given link is not on the page" do
|
||||||
expect(@session).to have_no_link('monkey')
|
expect(@session).to have_no_link('monkey')
|
||||||
expect(@session).to have_no_link('A link', href: '/nonexistent-href')
|
expect(@session).to have_no_link('A link', href: '/nonexistent-href')
|
||||||
expect(@session).to have_no_link('A link', href: /\/nonexistent-href/)
|
expect(@session).to have_no_link('A link', href: %r{/nonexistent-href})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'opens file from the default directory', requires: [:screenshot] do
|
it 'opens file from the default directory', requires: [:screenshot] do
|
||||||
expected_file_regex = %r{capybara-\d+\.png}
|
expected_file_regex = /capybara-\d+\.png/
|
||||||
allow(@session.driver).to receive(:save_screenshot)
|
allow(@session.driver).to receive(:save_screenshot)
|
||||||
allow(Launchy).to receive(:open)
|
allow(Launchy).to receive(:open)
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter(requires, metadata)
|
def filter(requires, metadata)
|
||||||
if requires and metadata[:capybara_skip]
|
if requires && metadata[:capybara_skip]
|
||||||
requires.any? do |require|
|
requires.any? do |require|
|
||||||
metadata[:capybara_skip].include?(require)
|
metadata[:capybara_skip].include?(require)
|
||||||
end
|
end
|
||||||
|
|
|
@ -120,12 +120,13 @@ module Capybara
|
||||||
res = yield if block_given?
|
res = yield if block_given?
|
||||||
prev_size = size
|
prev_size = size
|
||||||
start_time = Capybara::Helpers.monotonic_time
|
start_time = Capybara::Helpers.monotonic_time
|
||||||
begin
|
loop do
|
||||||
sleep 0.05
|
sleep 0.05
|
||||||
cur_size = size
|
cur_size = size
|
||||||
return res if cur_size == prev_size
|
return res if cur_size == prev_size
|
||||||
prev_size = cur_size
|
prev_size = cur_size
|
||||||
end while (Capybara::Helpers.monotonic_time - start_time) < seconds
|
break if (Capybara::Helpers.monotonic_time - start_time) >= seconds
|
||||||
|
end
|
||||||
raise Capybara::WindowError, "Window size not stable within #{seconds} seconds."
|
raise Capybara::WindowError, "Window size not stable within #{seconds} seconds."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
||||||
it "fails if has_no_selector? returns false" do
|
it "fails if has_no_selector? returns false" do
|
||||||
expect do
|
expect do
|
||||||
expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
|
expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
|
||||||
end.to raise_error(%r{expected not to find visible css "h1"})
|
end.to raise_error(/expected not to find visible css "h1"/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -251,7 +251,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
||||||
it "fails if has_no_selector? returns false" do
|
it "fails if has_no_selector? returns false" do
|
||||||
expect do
|
expect do
|
||||||
expect(page).not_to have_selector(:css, 'h1', text: 'test')
|
expect(page).not_to have_selector(:css, 'h1', text: 'test')
|
||||||
end.to raise_error(%r{expected not to find visible css "h1" with text "test"})
|
end.to raise_error(/expected not to find visible css "h1" with text "test"/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,7 +35,7 @@ RSpec.describe Capybara::Server do
|
||||||
ensure
|
ensure
|
||||||
Capybara.server_host = nil
|
Capybara.server_host = nil
|
||||||
end
|
end
|
||||||
end unless ENV['TRAVIS'] && (RUBY_ENGINE == 'jruby') or Gem.win_platform?
|
end unless (ENV['TRAVIS'] && (RUBY_ENGINE == 'jruby')) || Gem.win_platform?
|
||||||
|
|
||||||
it "should use specified port" do
|
it "should use specified port" do
|
||||||
Capybara.server_port = 22789
|
Capybara.server_port = 22789
|
||||||
|
|
Loading…
Reference in New Issue