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

minor code cleanup

This commit is contained in:
Thomas Walpole 2022-05-09 14:37:08 -07:00
parent 82138ab117
commit 3f7c358564
7 changed files with 12 additions and 20 deletions

View file

@ -84,7 +84,7 @@ module Capybara
def warn(message, uplevel: 1) def warn(message, uplevel: 1)
Kernel.warn(message, uplevel: uplevel) Kernel.warn(message, uplevel: uplevel)
end end
if defined?(Process::CLOCK_MONOTONIC_RAW) if defined?(Process::CLOCK_MONOTONIC_RAW)
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC_RAW; end def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC_RAW; end
elsif defined?(Process::CLOCK_MONOTONIC_PRECISE) elsif defined?(Process::CLOCK_MONOTONIC_PRECISE)

View file

@ -17,7 +17,7 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
def size; 0; end def size; 0; end
def read; ''; end def read; ''; end
def append_to(_); end def append_to(_); end
def set_encoding(_); end def set_encoding(_); end # rubocop:disable Naming/AccessorMethodName
end end
def params(button) def params(button)

View file

@ -101,11 +101,10 @@ module Capybara
private private
def options_with_defaults(options) def options_with_defaults(options)
expression_filters.chain(node_filters) expression_filters
.select { |_n, filter| filter.default? } .chain(node_filters)
.each_with_object(options.dup) do |(name, filter), opts| .filter_map { |name, filter| [name, filter.default] if filter.default? }
opts[name] = filter.default unless opts.key?(name) .to_h.merge!(options)
end
end end
def add_filter(name, filter_class, *types, matcher: nil, **options, &block) def add_filter(name, filter_class, *types, matcher: nil, **options, &block)

View file

@ -69,11 +69,8 @@ module Capybara
suffixes = [[]] suffixes = [[]]
strs.reverse_each do |str| strs.reverse_each do |str|
if str.is_a? Set if str.is_a? Set
prefixes = str.each_with_object([]) { |s, memo| memo.concat combine(s) } prefixes = str.flat_map { |s| combine(s) }
suffixes = prefixes.product(suffixes).map { |pair| pair.flatten(1) }
result = []
prefixes.product(suffixes) { |pair| result << pair.flatten(1) }
suffixes = result
else else
suffixes.each { |arr| arr.unshift str } suffixes.each { |arr| arr.unshift str }
end end

View file

@ -39,10 +39,8 @@ class Capybara::Selenium::Node
input.set_file(args) input.set_file(args)
driver.execute_script DROP_FILE, self, input driver.execute_script DROP_FILE, self, input
else else
items = args.each_with_object([]) do |arg, arr| items = args.flat_map do |arg|
arg.each_with_object(arr) do |(type, data), arr_| arg.map { |(type, data)| { type: type, data: data } }
arr_ << { type: type, data: data }
end
end end
driver.execute_script DROP_STRING, items, self driver.execute_script DROP_STRING, items, self
end end

View file

@ -37,9 +37,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
end end
def style(styles) def style(styles)
styles.each_with_object({}) do |style, result| styles.to_h { |style| [style, native.css_value(style)] }
result[style] = native.css_value(style)
end
end end
## ##

View file

@ -528,7 +528,7 @@ Capybara::SpecHelper.spec '#find' do
expect(@session.find(:link, 'test-foo')[:id]).to eq 'foo' expect(@session.find(:link, 'test-foo')[:id]).to eq 'foo'
end end
end end
it 'should warn if passed count options' do it 'should warn if passed count options' do
allow(Capybara::Helpers).to receive(:warn) allow(Capybara::Helpers).to receive(:warn)
@session.find('//h1', count: 44) @session.find('//h1', count: 44)