1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

minor cleanup

This commit is contained in:
Thomas Walpole 2018-10-12 16:21:53 -07:00
parent 8d95ab33fe
commit 288f95c299
6 changed files with 18 additions and 14 deletions

View file

@ -12,6 +12,13 @@ AllCops:
Metrics/LineLength:
Description: 'Limit lines to 80 characters.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
Exclude:
- 'spec/**/*'
- 'lib/capybara/spec/**/*'
IgnoredPatterns:
- '\s*# '
- '\s*(raise|warn) '
Max: 120
Enabled: false
Metrics/BlockLength:

View file

@ -32,7 +32,7 @@ module Capybara
def_delegators :full_results, :size, :length, :last, :values_at, :inspect, :sample
alias :index :find_index
alias index find_index
def each(&block)
return enum_for(:each) unless block_given?

View file

@ -64,7 +64,7 @@ Capybara.add_selector(:field) do
describe_expression_filters do |type: nil, **options|
desc = +''
(expression_filters.keys - [:type]).each { |ef| desc << " with #{ef} #{options[ef]}" if options.key?(ef) }
(expression_filters.keys & options.keys).each { |ef| desc << " with #{ef} #{options[ef]}" }
desc << " of type #{type.inspect}" if type
desc
end
@ -77,9 +77,8 @@ end
Capybara.add_selector(:fieldset) do
xpath do |locator, legend: nil, **|
locator_matchers = (XPath.attr(:id) == locator.to_s) | XPath.child(:legend)[XPath.string.n.is(locator.to_s)]
locator_matchers |= XPath.attr(test_id) == locator if test_id
xpath = XPath.descendant(:fieldset)
xpath = xpath[locator_matchers] unless locator.nil?
locator_matchers |= XPath.attr(test_id) == locator.to_s if test_id
xpath = XPath.descendant(:fieldset)[locator && locator_matchers]
xpath = xpath[XPath.child(:legend)[XPath.string.n.is(legend)]] if legend
xpath
end

View file

@ -97,10 +97,7 @@ private
def upload(local_file)
return nil unless local_file
unless File.file?(local_file)
raise ArgumentError, "You may only upload files: #{local_file.inspect}"
end
raise ArgumentError, "You may only upload files: #{local_file.inspect}" unless File.file?(local_file)
result = bridge.http.call(:post, "session/#{bridge.session_id}/file", file: Selenium::WebDriver::Zipper.zip_file(local_file))
result['value']

View file

@ -48,9 +48,7 @@ module Capybara
res = @checker.request { |http| http.get('/__identify__') }
if res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPRedirection)
return res.body == app.object_id.to_s
end
return res.body == app.object_id.to_s if res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPRedirection)
rescue SystemCallError, Net::ReadTimeout, OpenSSL::SSL::SSLError
false
end

View file

@ -2,12 +2,15 @@
module XPath
module DSL
UPPERCASE_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'
LOWERCASE_LETTERS = 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ'
def lowercase
method(:translate, 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ', 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ')
method(:translate, UPPERCASE_LETTERS, LOWERCASE_LETTERS)
end
def uppercase
method(:translate, 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ')
method(:translate, LOWERCASE_LETTERS, UPPERCASE_LETTERS)
end
end
end