From 9856938e59be876c96634bf6be4b2873b75b200f Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sat, 23 Oct 2021 22:17:35 -0700 Subject: [PATCH] Minor code cleanup --- lib/capybara/helpers.rb | 2 +- lib/capybara/rack_test/node.rb | 2 +- lib/capybara/selector/css.rb | 2 +- lib/capybara/selenium/nodes/chrome_node.rb | 1 + lib/capybara/spec/session/has_text_spec.rb | 2 +- lib/capybara/spec/session/node_spec.rb | 2 +- spec/rspec/features_spec.rb | 2 +- spec/selenium_spec_firefox.rb | 4 ++-- spec/selenium_spec_ie.rb | 2 +- 9 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/capybara/helpers.rb b/lib/capybara/helpers.rb index 56ac7e7c..9adb3a9c 100644 --- a/lib/capybara/helpers.rb +++ b/lib/capybara/helpers.rb @@ -75,7 +75,7 @@ module Capybara filter = %r{lib/capybara/|lib/rspec/|lib/minitest/} new_trace = trace.take_while { |line| line !~ filter } - new_trace = trace.reject { |line| line =~ filter } if new_trace.empty? + new_trace = trace.grep_v(filter) if new_trace.empty? new_trace = trace.dup if new_trace.empty? new_trace.first.split(/:in /, 2).first diff --git a/lib/capybara/rack_test/node.rb b/lib/capybara/rack_test/node.rb index 9c338ce4..b2d09347 100644 --- a/lib/capybara/rack_test/node.rb +++ b/lib/capybara/rack_test/node.rb @@ -216,7 +216,7 @@ private min, max, step = (native['min'] || 0).to_f, (native['max'] || 100).to_f, (native['step'] || 1).to_f value = value.to_f value = value.clamp(min, max) - value = ((value - min) / step).round * step + min + value = (((value - min) / step).round * step) + min native['value'] = value.clamp(min, max) end diff --git a/lib/capybara/selector/css.rb b/lib/capybara/selector/css.rb index d4f39632..95ad762f 100644 --- a/lib/capybara/selector/css.rb +++ b/lib/capybara/selector/css.rb @@ -43,7 +43,7 @@ module Capybara when '"', "'" selector << parse_string(char, str) when '\\' - selector << char + str.getc + selector << (char + str.getc) when ',' selectors << selector.strip selector.clear diff --git a/lib/capybara/selenium/nodes/chrome_node.rb b/lib/capybara/selenium/nodes/chrome_node.rb index 103affd2..8d2b83f5 100644 --- a/lib/capybara/selenium/nodes/chrome_node.rb +++ b/lib/capybara/selenium/nodes/chrome_node.rb @@ -63,6 +63,7 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node def visible? return super unless native_displayed? + begin bridge.send(:execute, :is_element_displayed, id: native_id) rescue Selenium::WebDriver::Error::UnknownCommandError diff --git a/lib/capybara/spec/session/has_text_spec.rb b/lib/capybara/spec/session/has_text_spec.rb index 2e16f0ca..90fc6b3e 100644 --- a/lib/capybara/spec/session/has_text_spec.rb +++ b/lib/capybara/spec/session/has_text_spec.rb @@ -356,7 +356,7 @@ Capybara::SpecHelper.spec '#has_no_text?' do expect(@session).to have_no_text(/xxxxyzzz/) end - it 'should be false if the text in the page matches given regexp' do + it 'should be false if the text in the page matches given regexp' do @session.visit('/with_html') expect(@session).not_to have_no_text(/Lorem/) end diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index fa43cda9..13d6f020 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -1115,7 +1115,7 @@ Capybara::SpecHelper.spec 'node' do end describe '#evaluate_script', requires: %i[js es_args] do - it 'should evaluate the given script in the context of the element and return whatever it produces' do + it 'should evaluate the given script in the context of the element and return whatever it produces' do @session.visit('/with_js') el = @session.find(:css, '#with_change_event') expect(el.evaluate_script('this.value')).to eq('default value') diff --git a/spec/rspec/features_spec.rb b/spec/rspec/features_spec.rb index 3a46d6eb..edaf6111 100644 --- a/spec/rspec/features_spec.rb +++ b/spec/rspec/features_spec.rb @@ -94,7 +94,7 @@ ffeature 'if ffeature aliases focused tag then' do # rubocop:disable RSpec/Focus expect(example.metadata[:focus]).to eq true end - scenario 'other scenarios also has metatag focus tag ' do |example| + scenario 'other scenarios also has metatag focus tag' do |example| expect(example.metadata[:focus]).to eq true end end diff --git a/spec/selenium_spec_firefox.rb b/spec/selenium_spec_firefox.rb index 62fe45ef..1f78968b 100644 --- a/spec/selenium_spec_firefox.rb +++ b/spec/selenium_spec_firefox.rb @@ -59,8 +59,8 @@ Capybara::SpecHelper.run_specs TestSessions::SeleniumFirefox, 'selenium', capyba when 'Capybara::Session selenium #attach_file with multipart form should fire change once when uploading multiple files from empty' pending "FF < 62 doesn't support setting all files at once" if firefox_lt?(62, @session) when 'Capybara::Session selenium #accept_confirm should work with nested modals' - skip 'Broken in 63 <= FF < 69 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358' if firefox_gte?(63, @session) && firefox_lt?(69, @session) - skip 'Hangs in 69 <= FF < 71 - Dont know what issue for this - previous issue was closed as fixed but it is not' if firefox_gte?(69, @session) && firefox_lt?(71, @session) + skip 'Broken in 63 <= FF < 69 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358' if firefox_gte?(63, @session) && firefox_lt?(69, @session) + skip 'Hangs in 69 <= FF < 71 - Dont know what issue for this - previous issue was closed as fixed but it is not' if firefox_gte?(69, @session) && firefox_lt?(71, @session) skip 'Broken again intermittently in FF 71 - jus skip it' when 'Capybara::Session selenium #click_link can download a file' skip 'Need to figure out testing of file downloading on windows platform' if Gem.win_platform? diff --git a/spec/selenium_spec_ie.rb b/spec/selenium_spec_ie.rb index 56737b4c..6aece41b 100644 --- a/spec/selenium_spec_ie.rb +++ b/spec/selenium_spec_ie.rb @@ -88,7 +88,7 @@ Capybara::SpecHelper.run_specs TestSessions::SeleniumIE, 'selenium', capybara_sk pending "Window 7 and 8.1 don't support 308 http status code" when /#scroll_to can scroll an element to the center of the viewport$/, /#scroll_to can scroll an element to the center of the scrolling element$/ - pending " IE doesn't support ScrollToOptions" + pending "IE doesn't support ScrollToOptions" when /#attach_file with multipart form should fire change once for each set of files uploaded$/, /#attach_file with multipart form should fire change once when uploading multiple files from empty$/, /#attach_file with multipart form should not break when using HTML5 multiple file input uploading multiple files$/