Skip to content

Commit

Permalink
Style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Sep 5, 2020
1 parent 239802d commit f59df7e
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ bin
gem-private_key.pem
save_path_tmp
vendor/bundle
.byebug_history
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require:
- rubocop-performance

AllCops:
NewCops: enable
DisabledByDefault: false
TargetRubyVersion: 2.5
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end
task :release do
version = Capybara::VERSION
puts "Releasing #{version}, y/n?"
exit(1) unless STDIN.gets.chomp == 'y'
exit(1) unless $stdin.gets.chomp == 'y'
sh "git commit -am 'tagged #{version}' && " \
"git tag #{version} && " \
'gem build capybara.gemspec && ' \
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def javascript_driver
@javascript_driver || :selenium
end

def deprecate(method, alternate_method, once = false)
def deprecate(method, alternate_method, once: false)
@deprecation_notified ||= {}
unless once && @deprecation_notified[method]
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead: #{Capybara::Helpers.filter_backtrace(caller)}"
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/node/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def value
# @param [Boolean] check_ancestors Whether to inherit visibility from ancestors
# @return [Boolean] Whether the element is visible
#
def visible?(check_ancestors = true)
def visible?(check_ancestors = true) # rubocop:disable Style/OptionalBooleanParameter
return false if (tag_name == 'input') && (native[:type] == 'hidden')
return false if tag_name == 'template'

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/queries/ancestor_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def resolve_for(node, exact = nil)
end
end

def description(applied = false)
def description(applied = false) # rubocop:disable Style/OptionalBooleanParameter
child_query = @child_node&.instance_variable_get(:@query)
desc = super
desc += " that is an ancestor of #{child_query.description}" if child_query
Expand Down
12 changes: 5 additions & 7 deletions lib/capybara/queries/selector_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def initialize(*args,
def name; selector.name; end
def label; selector.label || selector.name; end

def description(only_applied = false)
def description(only_applied = false) # rubocop:disable Style/OptionalBooleanParameter
desc = +''
show_for = show_for_stage(only_applied)

Expand Down Expand Up @@ -95,11 +95,9 @@ def description(only_applied = false)
desc << ' that also matches the custom filter block' if @filter_block && show_for[:node]

desc << " within #{@resolved_node.inspect}" if describe_within?
if locator.is_a?(String) && locator.start_with?('#', './/', '//')
unless selector.raw_locator?
desc << "\nNote: It appears you may be passing a CSS selector or XPath expression rather than a locator. " \
"Please see the documentation for acceptable locator values.\n\n"
end
if locator.is_a?(String) && locator.start_with?('#', './/', '//') && !selector.raw_locator?
desc << "\nNote: It appears you may be passing a CSS selector or XPath expression rather than a locator. " \
"Please see the documentation for acceptable locator values.\n\n"
end
desc
end
Expand Down Expand Up @@ -653,7 +651,7 @@ def distance_segment_segment(l1p1, l1p2, l2p1, l2p2)

d = u.dot w
e = v.dot w
cap_d = (a * c) - (b * b)
cap_d = (a * c) - (b**2)
sD = tD = cap_d

# compute the line parameters of the two closest points
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/queries/sibling_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def resolve_for(node, exact = nil)
end
end

def description(applied = false)
def description(applied = false) # rubocop:disable Style/OptionalBooleanParameter
desc = super
sibling_query = @sibling_node&.instance_variable_get(:@query)
desc += " that is a sibling of #{sibling_query.description}" if sibling_query
Expand Down
1 change: 1 addition & 0 deletions lib/capybara/rack_test/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
def initialize(app, **options)
raise ArgumentError, 'rack-test requires a rack application, but none was given' unless app

super()
@app = app
@options = DEFAULT_OPTIONS.merge(options)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/rack_test/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
# That check should be based solely on the form element's 'enctype' attribute value,
# which should probably be provided to Rack::Test in its non-GET request methods.
class NilUploadedFile < Rack::Test::UploadedFile
def initialize
def initialize # rubocop:disable Lint/MissingSuper
@empty_file = Tempfile.new('nil_uploaded_file')
@empty_file.close
end
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/registration_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def method_missing(method_name, *args, **options, &block)
super
end

def respond_to_missing?(method_name, include_private = false)
def respond_to_missing?(method_name, include_all)
@registered.respond_to?(method_name) || super
end

Expand Down
4 changes: 3 additions & 1 deletion lib/capybara/registrations/patches/puma_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ module Puma
module MiniSSL
class Socket
def read_nonblock(size, *_)
wait_states = %i[wait_readable wait_writable]

loop do
output = engine_read_all
return output if output

data = @socket.read_nonblock(size, exception: false)
raise IO::EAGAINWaitReadable if %i[wait_readable wait_writable].include? data
raise IO::EAGAINWaitReadable if wait_states.include? data
return nil if data.nil?

@engine.inject(data)
Expand Down
8 changes: 2 additions & 6 deletions lib/capybara/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,9 @@ def compare_count
return load_up_to(count + 1) <=> count
end

if min && (min = Integer(min))
return -1 if load_up_to(min) < min
end
return -1 if min && (min = Integer(min)) && (load_up_to(min) < min)

if max && (max = Integer(max))
return 1 if load_up_to(max + 1) > max
end
return 1 if max && (max = Integer(max)) && (load_up_to(max + 1) > max)

if between
min, max = (between.begin && between.min) || 1, between.end
Expand Down
3 changes: 2 additions & 1 deletion lib/capybara/selector/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def handled_custom_options(filter, options)
end

def parameter_names(block)
block.parameters.select { |(type, _name)| %i[key keyreq].include? type }.map { |(_type, name)| name }
key_types = %i[key keyreq]
block.parameters.select { |(type, _name)| key_types.include? type }.map { |(_type, name)| name }
end

def expression(type, allowed_filters, &block)
Expand Down
3 changes: 2 additions & 1 deletion lib/capybara/selector/definition/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
end

describe_expression_filters do |**options|
booleans, values = options.partition { |_k, v| [true, false].include? v }.map(&:to_h)
boolean_values = [true, false]
booleans, values = options.partition { |_k, v| boolean_values.include? v }.map(&:to_h)
desc = describe_all_expression_filters(**values)
desc + booleans.map do |k, v|
v ? " with #{k} attribute" : "without #{k} attribute"
Expand Down
1 change: 1 addition & 0 deletions lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def browser
end

def initialize(app, **options)
super()
self.class.load_selenium
@app = app
@browser = nil
Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/selenium/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ def normalize_keys(keys)
end
end

def each_key(keys)
normalize_keys(keys).each { |key| yield(key) }
def each_key(keys, &block)
normalize_keys(keys).each(&block)
end

def find_context
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/selenium/nodes/chrome_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def file_errors
end
end

def browser_version(to_float = true)
def browser_version(to_float: true)
caps = capabilities
ver = (caps[:browser_version] || caps[:version])
ver = ver.to_f if to_float
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/server/animation_disabler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def html_content?
end

def insert_disable(html)
html.sub(%r{(</head>)}, disable_markup + '\\1')
html.sub(%r{(</head>)}, "#{disable_markup}\\1")
end

DISABLE_MARKUP_TEMPLATE = <<~HTML
Expand Down
15 changes: 8 additions & 7 deletions lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ def within(*args, **kw_args)
#
# @param [String] locator Id or legend of the fieldset
#
def within_fieldset(locator)
within(:fieldset, locator) { yield }
def within_fieldset(locator, &block)
within(:fieldset, locator, &block)
end

##
Expand All @@ -365,8 +365,8 @@ def within_fieldset(locator)
#
# @param [String] locator Id or caption of the table
#
def within_table(locator)
within(:table, locator) { yield }
def within_table(locator, &block)
within(:table, locator, &block)
end

##
Expand Down Expand Up @@ -398,8 +398,9 @@ def switch_to_frame(frame)
driver.switch_to_frame(:parent)
when :top
idx = scopes.index(:frame)
top_level_scopes = [:frame, nil]
if idx
if scopes.slice(idx..-1).any? { |scope| ![:frame, nil].include?(scope) }
if scopes.slice(idx..-1).any? { |scope| !top_level_scopes.include?(scope) }
raise Capybara::ScopeError, "`switch_to_frame(:top)` cannot be called from inside a descendant frame's "\
'`within` block.'
end
Expand Down Expand Up @@ -788,7 +789,7 @@ def current_scope
#
# Yield a block using a specific maximum wait time.
#
def using_wait_time(seconds)
def using_wait_time(seconds, &block)
if Capybara.threadsafe
begin
previous_wait_time = config.default_max_wait_time
Expand All @@ -798,7 +799,7 @@ def using_wait_time(seconds)
config.default_max_wait_time = previous_wait_time
end
else
Capybara.using_wait_time(seconds) { yield }
Capybara.using_wait_time(seconds, &block)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/spec/session/find_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
end
end

context 'with frozen time', requires: [:js] do
context 'with frozen time', requires: [:js] do # rubocop:disable RSpec/EmptyExampleGroup
if defined?(Process::CLOCK_MONOTONIC)
it 'will time out even if time is frozen' do
@session.visit('/with_js')
Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/spec/session/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@

describe '#==' do
it 'preserve object identity' do
expect(@session.find('//h1') == @session.find('//h1')).to be true # rubocop:disable Lint/UselessComparison
expect(@session.find('//h1') === @session.find('//h1')).to be true # rubocop:disable Style/CaseEquality, Lint/UselessComparison
expect(@session.find('//h1') == @session.find('//h1')).to be true # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
expect(@session.find('//h1') === @session.find('//h1')).to be true # rubocop:disable Style/CaseEquality, Lint/BinaryOperatorWithIdenticalOperands
expect(@session.find('//h1').eql?(@session.find('//h1'))).to be false
end

Expand Down
8 changes: 4 additions & 4 deletions lib/capybara/spec/session/save_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
it 'can store files in a specified directory' do
Capybara.save_path = alternative_path
@session.save_page
path = Dir.glob(alternative_path + '/capybara-*.html').first
path = Dir.glob("#{alternative_path}/capybara-*.html").first
expect(File.read(path)).to include('Another World')
end

Expand All @@ -43,14 +43,14 @@
it 'can store files in a specified directory with a given filename' do
Capybara.save_path = alternative_path
@session.save_page('capybara-001133.html')
path = alternative_path + '/capybara-001133.html'
path = "#{alternative_path}/capybara-001133.html"
expect(File.read(path)).to include('Another World')
end

it 'can store files in a specified directory with a given relative filename' do
Capybara.save_path = alternative_path
@session.save_page('tmp/capybara-001144.html')
path = alternative_path + '/tmp/capybara-001144.html'
path = "#{alternative_path}/tmp/capybara-001144.html"
expect(File.read(path)).to include('Another World')
end

Expand All @@ -63,7 +63,7 @@
it 'returns an absolute path in given directory' do
Capybara.save_path = alternative_path
result = @session.save_page
path = File.expand_path(Dir.glob(alternative_path + '/capybara-*.html').first, alternative_path)
path = File.expand_path(Dir.glob("#{alternative_path}/capybara-*.html").first, alternative_path)
expect(result).to eq(path)
end

Expand Down
18 changes: 8 additions & 10 deletions lib/capybara/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def spec(name, *options, &block)

def run_specs(session, name, **options, &filter_block)
specs = @specs
RSpec.describe Capybara::Session, name, options do # rubocop:disable RSpec/EmptyExampleGroup
RSpec.describe Capybara::Session, name, options do
include Capybara::SpecHelper
include Capybara::RSpecMatchers

Expand All @@ -72,11 +72,11 @@ def run_specs(session, name, **options, &filter_block)
end

before :each, psc: true do
SpecHelper.reset_threadsafe(true, session)
SpecHelper.reset_threadsafe(bool: true, session: session)
end

after psc: true do
SpecHelper.reset_threadsafe(false, session)
SpecHelper.reset_threadsafe(session: session)
end

before :each, :exact_false do
Expand All @@ -91,7 +91,7 @@ def run_specs(session, name, **options, &filter_block)
end
end

def reset_threadsafe(bool = false, session = nil)
def reset_threadsafe(bool: false, session: nil)
# Work around limit on when threadsafe can be changed
Capybara::Session.class_variable_set(:@@instance_created, false) # rubocop:disable Style/ClassVars
Capybara.threadsafe = bool
Expand All @@ -109,11 +109,9 @@ def silence_stream(stream)
stream.reopen(old_stream)
end

def quietly
silence_stream(STDOUT) do
silence_stream(STDERR) do
yield
end
def quietly(&block)
silence_stream($stdout) do
silence_stream($stderr, &block)
end
end

Expand All @@ -133,4 +131,4 @@ def with_os_path_separators(path)
end
end

Dir[File.dirname(__FILE__) + '/session/**/*.rb'].each { |file| require_relative file }
Dir["#{File.dirname(__FILE__)}/session/**/*.rb"].each { |file| require_relative file }
7 changes: 4 additions & 3 deletions lib/capybara/spec/test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TestApp < Sinatra::Base
class TestAppError < Exception; end # rubocop:disable Lint/InheritException
class TestAppOtherError < Exception # rubocop:disable Lint/InheritException
def initialize(string1, msg)
super()
@something = string1
@message = msg
end
Expand Down Expand Up @@ -89,11 +90,11 @@ def initialize(string1, msg)
end

get '/form/get' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
%(<pre id="results">#{params[:form].to_yaml}</pre>)
end

post '/relative' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
%(<pre id="results">#{params[:form].to_yaml}</pre>)
end

get '/favicon.ico' do
Expand Down Expand Up @@ -180,7 +181,7 @@ def initialize(string1, msg)

post '/form' do
self.class.form_post_count += 1
'<pre id="results">' + params[:form].merge('post_count' => self.class.form_post_count).to_yaml + '</pre>'
%(<pre id="results">#{params[:form].merge('post_count' => self.class.form_post_count).to_yaml}</pre>)
end

post '/upload_empty' do
Expand Down
Loading

0 comments on commit f59df7e

Please sign in to comment.