Skip to content

Commit

Permalink
minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed May 9, 2022
1 parent 82138ab commit 3f7c358
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/capybara/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def filter_backtrace(trace)
def warn(message, uplevel: 1)
Kernel.warn(message, uplevel: uplevel)
end

if defined?(Process::CLOCK_MONOTONIC_RAW)
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC_RAW; end
elsif defined?(Process::CLOCK_MONOTONIC_PRECISE)
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 @@ -17,7 +17,7 @@ def path; @empty_file.path; end
def size; 0; end
def read; ''; end
def append_to(_); end
def set_encoding(_); end
def set_encoding(_); end # rubocop:disable Naming/AccessorMethodName
end

def params(button)
Expand Down
9 changes: 4 additions & 5 deletions lib/capybara/selector/filter_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ def expression_filter_descriptions
private

def options_with_defaults(options)
expression_filters.chain(node_filters)
.select { |_n, filter| filter.default? }
.each_with_object(options.dup) do |(name, filter), opts|
opts[name] = filter.default unless opts.key?(name)
end
expression_filters
.chain(node_filters)
.filter_map { |name, filter| [name, filter.default] if filter.default? }
.to_h.merge!(options)
end

def add_filter(name, filter_class, *types, matcher: nil, **options, &block)
Expand Down
7 changes: 2 additions & 5 deletions lib/capybara/selector/regexp_disassembler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ def combine(strs)
suffixes = [[]]
strs.reverse_each do |str|
if str.is_a? Set
prefixes = str.each_with_object([]) { |s, memo| memo.concat combine(s) }

result = []
prefixes.product(suffixes) { |pair| result << pair.flatten(1) }
suffixes = result
prefixes = str.flat_map { |s| combine(s) }
suffixes = prefixes.product(suffixes).map { |pair| pair.flatten(1) }
else
suffixes.each { |arr| arr.unshift str }
end
Expand Down
6 changes: 2 additions & 4 deletions lib/capybara/selenium/extensions/html5_drag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ def html5_drop(*args)
input.set_file(args)
driver.execute_script DROP_FILE, self, input
else
items = args.each_with_object([]) do |arg, arr|
arg.each_with_object(arr) do |(type, data), arr_|
arr_ << { type: type, data: data }
end
items = args.flat_map do |arg|
arg.map { |(type, data)| { type: type, data: data } }
end
driver.execute_script DROP_STRING, items, self
end
Expand Down
4 changes: 1 addition & 3 deletions lib/capybara/selenium/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def value
end

def style(styles)
styles.each_with_object({}) do |style, result|
result[style] = native.css_value(style)
end
styles.to_h { |style| [style, native.css_value(style)] }
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 @@ -528,7 +528,7 @@
expect(@session.find(:link, 'test-foo')[:id]).to eq 'foo'
end
end

it 'should warn if passed count options' do
allow(Capybara::Helpers).to receive(:warn)
@session.find('//h1', count: 44)
Expand Down

0 comments on commit 3f7c358

Please sign in to comment.