diff --git a/.rubocop.yml b/.rubocop.yml index c89cb3b5..d394832d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,7 @@ require: AllCops: DisabledByDefault: false - TargetRubyVersion: 2.2.2 + TargetRubyVersion: 2.3.0 Exclude: - 'capybara.gemspec' diff --git a/.travis.yml b/.travis.yml index 4b86878b..9daaa76a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ dist: trusty services: - docker rvm: - - 2.5.0 + - 2.5.1 - 2.3.6 - jruby-9.1.16.0 gemfile: @@ -33,7 +33,7 @@ cache: matrix: include: - gemfile: Gemfile - rvm: 2.5.0 + rvm: 2.5.1 env: CAPYBARA_CHROME_REMOTE=true - gemfile: gemfiles/Gemfile.rspec-34 rvm: 2.3.6 @@ -44,10 +44,10 @@ matrix: packages: - awesome - gemfile: Gemfile - rvm: 2.2.2 + rvm: 2.5.1 env: HEADLESS=true - gemfile: gemfiles/Gemfile.beta-versions - rvm: 2.5.0 + rvm: 2.5.1 env: CAPYBARA_FF=true addons: firefox: latest-beta @@ -70,11 +70,10 @@ matrix: allow_failures: - gemfile: gemfiles/Gemfile.beta-versions - gemfile: gemfiles/Gemfile.edge-marionette - - rvm: rbx-3 - env: CAPYBARA_CHROME_REMOTE=true before_install: - gem update --system - # - gem update bundler + - gem install bundler - if [[ $BUNDLE_GEMFILE =~ Gemfile.edge-marionette$ ]]; then pushd ..; git clone --depth 1 https://github.com/SeleniumHQ/selenium.git; diff --git a/appveyor.yml b/appveyor.yml index b9c2a4cf..d683ec0a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,7 @@ environment: - RUBY_VERSION: 25 CAPYBARA_IE: true BUNDLE_GEMFILE: gemfiles/Gemfile.ie - - RUBY_VERSION: 22 + - RUBY_VERSION: 23 matrix: allow_failures: diff --git a/capybara.gemspec b/capybara.gemspec index 70008701..8164af30 100644 --- a/capybara.gemspec +++ b/capybara.gemspec @@ -6,7 +6,7 @@ require 'capybara/version' Gem::Specification.new do |s| s.name = "capybara" s.version = Capybara::VERSION - s.required_ruby_version = ">= 2.2.2" + s.required_ruby_version = ">= 2.3.0" s.license = "MIT" s.authors = ["Thomas Walpole", "Jonas Nicklas"] diff --git a/lib/capybara/driver/base.rb b/lib/capybara/driver/base.rb index 6f104014..b89ba425 100644 --- a/lib/capybara/driver/base.rb +++ b/lib/capybara/driver/base.rb @@ -155,6 +155,6 @@ class Capybara::Driver::Base end def session_options - (@session && @session.config) || Capybara.session_options + @session&.config || Capybara.session_options end end diff --git a/lib/capybara/node/actions.rb b/lib/capybara/node/actions.rb index 8fe3647d..e108327e 100644 --- a/lib/capybara/node/actions.rb +++ b/lib/capybara/node/actions.rb @@ -307,7 +307,7 @@ module Capybara end end - UPDATE_STYLE_SCRIPT = <<-'JS'.freeze + UPDATE_STYLE_SCRIPT = <<-'JS' var el = arguments[0]; el.capybara_style_cache = el.style.cssText; var css = arguments[1]; @@ -318,7 +318,7 @@ module Capybara } JS - RESET_STYLE_SCRIPT = <<-'JS'.freeze + RESET_STYLE_SCRIPT = <<-'JS' var el = arguments[0]; if (el.hasOwnProperty('capybara_style_cache')) { el.style.cssText = el.capybara_style_cache; @@ -326,7 +326,7 @@ module Capybara } JS - DATALIST_OPTIONS_SCRIPT = <<-'JS'.freeze + DATALIST_OPTIONS_SCRIPT = <<-'JS' Array.prototype.slice.call((arguments[0].list||{}).options || []). filter(function(el){ return !el.disabled }). map(function(el){ return { "value": el.value, "label": el.label} }) diff --git a/lib/capybara/node/matchers.rb b/lib/capybara/node/matchers.rb index 3a819342..4316eb8a 100644 --- a/lib/capybara/node/matchers.rb +++ b/lib/capybara/node/matchers.rb @@ -596,7 +596,7 @@ module Capybara # def assert_text(*args) _verify_text(args) do |count, query| - unless query.matches_count?(count) && ((count > 0) || query.expects_none?) + unless query.matches_count?(count) && (count.positive? || query.expects_none?) raise Capybara::ExpectationNotMet, query.failure_message end end @@ -612,7 +612,7 @@ module Capybara # def assert_no_text(*args) _verify_text(args) do |count, query| - if query.matches_count?(count) && ((count > 0) || query.expects_none?) + if query.matches_count?(count) && (count.positive? || query.expects_none?) raise Capybara::ExpectationNotMet, query.negative_failure_message end end diff --git a/lib/capybara/queries/ancestor_query.rb b/lib/capybara/queries/ancestor_query.rb index 94f92cd2..824b9aaa 100644 --- a/lib/capybara/queries/ancestor_query.rb +++ b/lib/capybara/queries/ancestor_query.rb @@ -13,7 +13,7 @@ module Capybara end def description - child_query = @child_node && @child_node.instance_variable_get(:@query) + child_query = @child_node&.instance_variable_get(:@query) desc = super desc += " that is an ancestor of #{child_query.description}" if child_query desc diff --git a/lib/capybara/queries/base_query.rb b/lib/capybara/queries/base_query.rb index 3757c32f..b9ab4dec 100644 --- a/lib/capybara/queries/base_query.rb +++ b/lib/capybara/queries/base_query.rb @@ -59,11 +59,11 @@ module Capybara # Generates a failure message from the query description and count options. # def failure_message - String.new("expected to find #{description}") << count_message + +"expected to find #{description}" << count_message end def negative_failure_message - String.new("expected not to find #{description}") << count_message + +"expected not to find #{description}" << count_message end private @@ -73,7 +73,7 @@ module Capybara end def count_message - message = "".dup + message = +"" if options[:count] message << " #{options[:count]} #{Capybara::Helpers.declension('time', 'times', options[:count])}" elsif options[:between] diff --git a/lib/capybara/queries/current_path_query.rb b/lib/capybara/queries/current_path_query.rb index 8d2cf3a2..255237c3 100644 --- a/lib/capybara/queries/current_path_query.rb +++ b/lib/capybara/queries/current_path_query.rb @@ -19,7 +19,7 @@ module Capybara def resolves_for?(session) uri = ::Addressable::URI.parse(session.current_url) uri.query = nil if uri && options[:ignore_query] - @actual_path = options[:url] ? uri.to_s : uri && uri.request_uri + @actual_path = options[:url] ? uri.to_s : uri&.request_uri if @expected_path.is_a? Regexp @actual_path.to_s.match(@expected_path) diff --git a/lib/capybara/queries/selector_query.rb b/lib/capybara/queries/selector_query.rb index ce9b4aae..057205bd 100644 --- a/lib/capybara/queries/selector_query.rb +++ b/lib/capybara/queries/selector_query.rb @@ -31,7 +31,7 @@ module Capybara def label; selector.label || selector.name; end def description - @description = "".dup + @description = +"" @description << "visible " if visible == :visible @description << "non-visible " if visible == :hidden @description << "#{label} #{locator.inspect}" diff --git a/lib/capybara/queries/sibling_query.rb b/lib/capybara/queries/sibling_query.rb index e2066131..2eb45c90 100644 --- a/lib/capybara/queries/sibling_query.rb +++ b/lib/capybara/queries/sibling_query.rb @@ -16,7 +16,7 @@ module Capybara def description desc = super - sibling_query = @sibling_node && @sibling_node.instance_variable_get(:@query) + sibling_query = @sibling_node&.instance_variable_get(:@query) desc += " that is a sibling of #{sibling_query.description}" if sibling_query desc end diff --git a/lib/capybara/queries/text_query.rb b/lib/capybara/queries/text_query.rb index 32c62859..aec03b59 100644 --- a/lib/capybara/queries/text_query.rb +++ b/lib/capybara/queries/text_query.rb @@ -50,7 +50,7 @@ module Capybara end def build_message(report_on_invisible) - message = "".dup + message = +"" unless (COUNT_KEYS & @options.keys).empty? message << " but found #{@count} #{Capybara::Helpers.declension('time', 'times', @count)}" end diff --git a/lib/capybara/result.rb b/lib/capybara/result.rb index 93b20b56..acae5ea1 100644 --- a/lib/capybara/result.rb +++ b/lib/capybara/result.rb @@ -50,7 +50,7 @@ module Capybara idx, length = args max_idx = case idx when Integer - if idx >= 0 + if !idx.negative? length.nil? ? idx : idx + length - 1 else nil diff --git a/lib/capybara/selector.rb b/lib/capybara/selector.rb index 1bbd9ad3..6f9b97df 100644 --- a/lib/capybara/selector.rb +++ b/lib/capybara/selector.rb @@ -11,7 +11,7 @@ Capybara::Selector::FilterSet.add(:_field) do expression_filter(:placeholder) { |xpath, val| xpath[XPath.attr(:placeholder) == val] } describe do |checked: nil, unchecked: nil, disabled: nil, multiple: nil, **_options| - desc, states = "".dup, [] + desc, states = +"", [] states << 'checked' if checked || (unchecked == false) states << 'not checked' if unchecked || (checked == false) states << 'disabled' if disabled == true @@ -94,7 +94,7 @@ Capybara.add_selector(:field) do with.is_a?(Regexp) ? node.value =~ with : node.value == with.to_s end describe do |type: nil, **options| - desc = "".dup + desc = +"" (expression_filters.keys - [:type]).each { |ef| desc << " with #{ef} #{options[ef]}" if options.key?(ef) } desc << " of type #{type.inspect}" if type desc << " with value #{options[:with].to_s.inspect}" if options.key?(:with) @@ -170,7 +170,7 @@ Capybara.add_selector(:link) do end describe do |**options| - desc = "".dup + desc = +"" desc << " with href #{options[:href].inspect}" if options[:href] desc << " with no href attribute" if options.fetch(:href, true).nil? end @@ -217,7 +217,7 @@ Capybara.add_selector(:button) do filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| !(value ^ node.disabled?) } describe do |disabled: nil, **options| - desc = "".dup + desc = +"" desc << " that is disabled" if disabled == true desc << describe_all_expression_filters(options) desc @@ -277,7 +277,7 @@ Capybara.add_selector(:fillable_field) do end describe do |options| - desc = "".dup + desc = +"" desc << describe_all_expression_filters(options) desc << " with value #{options[:with].to_s.inspect}" if options.key?(:with) desc @@ -310,7 +310,7 @@ Capybara.add_selector(:radio_button) do filter(:option) { |node, value| node.value == value.to_s } describe do |option: nil, **options| - desc = "".dup + desc = +"" desc << " with value #{option.inspect}" if option desc << describe_all_expression_filters(options) desc @@ -341,7 +341,7 @@ Capybara.add_selector(:checkbox) do filter(:option) { |node, value| node.value == value.to_s } describe do |option: nil, **options| - desc = "".dup + desc = +"" desc << " with value #{option.inspect}" if option desc << describe_all_expression_filters(options) desc @@ -401,7 +401,7 @@ Capybara.add_selector(:select) do end describe do |options: nil, with_options: nil, selected: nil, with_selected: nil, **opts| - desc = "".dup + desc = +"" desc << " with options #{options.inspect}" if options desc << " with at least options #{with_options.inspect}" if with_options desc << " with #{selected.inspect} selected" if selected @@ -434,7 +434,7 @@ Capybara.add_selector(:datalist_input) do end describe do |options: nil, with_options: nil, **opts| - desc = "".dup + desc = +"" desc << " with options #{options.inspect}" if options desc << " with at least options #{with_options.inspect}" if with_options desc << describe_all_expression_filters(opts) @@ -461,7 +461,7 @@ Capybara.add_selector(:option) do filter(:selected, :boolean) { |node, value| !(value ^ node.selected?) } describe do |**options| - desc = "".dup + desc = +"" desc << " that is#{' not' unless options[:disabled]} disabled" if options.key?(:disabled) desc << " that is#{' not' unless options[:selected]} selected" if options.key?(:selected) desc @@ -481,7 +481,7 @@ Capybara.add_selector(:datalist_option) do filter(:disabled, :boolean) { |node, value| !(value ^ node.disabled?) } describe do |**options| - desc = "".dup + desc = +"" desc << " that is#{' not' unless options[:disabled]} disabled" if options.key?(:disabled) desc end @@ -508,7 +508,7 @@ Capybara.add_selector(:file_field) do filter_set(:_field, %i[disabled multiple name]) describe do |**options| - desc = "".dup + desc = +"" desc << describe_all_expression_filters(options) desc end @@ -550,7 +550,7 @@ Capybara.add_selector(:label) do end describe do |**options| - desc = "".dup + desc = +"" desc << " for #{options[:for]}" if options[:for] desc end @@ -574,7 +574,7 @@ Capybara.add_selector(:table) do end describe do |caption: nil, **_options| - desc = "".dup + desc = +"" desc << " with caption #{caption}" if caption desc end @@ -598,7 +598,7 @@ Capybara.add_selector(:frame) do end describe do |name: nil, **_options| - desc = "".dup + desc = +"" desc << " with name #{name}" if name desc end diff --git a/lib/capybara/selector/css.rb b/lib/capybara/selector/css.rb index 22437c6c..11a75a66 100644 --- a/lib/capybara/selector/css.rb +++ b/lib/capybara/selector/css.rb @@ -5,7 +5,7 @@ module Capybara class CSS def self.escape(str) value = str.dup - out = "".dup + out = +"" out << value.slice!(0...1) if value =~ /^[-_]/ out << (value[0] =~ NMSTART ? value.slice!(0...1) : escape_char(value.slice!(0...1))) out << value.gsub(/[^a-zA-Z0-9_-]/) { |c| escape_char c } @@ -16,7 +16,7 @@ module Capybara c =~ %r{[ -/:-~]} ? "\\#{c}" : format("\\%06x", c.ord) end - S = '\u{80}-\u{D7FF}\u{E000}-\u{FFFD}\u{10000}-\u{10FFFF}'.freeze + S = '\u{80}-\u{D7FF}\u{E000}-\u{FFFD}\u{10000}-\u{10FFFF}' H = /[0-9a-fA-F]/ UNICODE = /\\#{H}{1,6}[ \t\r\n\f]?/ NONASCII = /[#{S}]/ diff --git a/lib/capybara/selector/selector.rb b/lib/capybara/selector/selector.rb index 48453c90..cd7239ed 100644 --- a/lib/capybara/selector/selector.rb +++ b/lib/capybara/selector/selector.rb @@ -168,7 +168,7 @@ module Capybara # @return [Boolean] Whether or not to use this selector # def match?(locator) - @match and @match.call(locator) + @match&.call(locator) end ## diff --git a/lib/capybara/selenium/driver.rb b/lib/capybara/selenium/driver.rb index d7836434..1e05021b 100644 --- a/lib/capybara/selenium/driver.rb +++ b/lib/capybara/selenium/driver.rb @@ -263,7 +263,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base end def quit - @browser.quit if @browser + @browser&.quit rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED # Browser must have already gone rescue Selenium::WebDriver::Error::UnknownError => e diff --git a/lib/capybara/server.rb b/lib/capybara/server.rb index 9e3c2452..77a12742 100644 --- a/lib/capybara/server.rb +++ b/lib/capybara/server.rb @@ -33,7 +33,7 @@ module Capybara end def pending_requests? - @counter.value > 0 + @counter.value.positive? end def call(env) @@ -86,7 +86,7 @@ module Capybara end def responsive? - return false if @server_thread && @server_thread.join(0) + return false if @server_thread&.join(0) begin res = if !@using_ssl @@ -162,7 +162,7 @@ module Capybara server = TCPServer.new(host, 0) server.addr[1] ensure - server.close if server + server&.close end end end diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index 8e228353..cd86adf3 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -126,7 +126,7 @@ module Capybara driver.reset! @touched = false end - @server.wait_for_pending_requests if @server + @server&.wait_for_pending_requests raise_server_error! end alias_method :cleanup!, :reset! diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 76be66ae..80c6fd2c 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -86,7 +86,7 @@ module Capybara Capybara::Session.class_variable_set(:@@instance_created, false) # Work around limit on when threadsafe can be changed Capybara.threadsafe = bool session = session.current_session if session.respond_to?(:current_session) - session.instance_variable_set(:@config, nil) if session + session&.instance_variable_set(:@config, nil) end end diff --git a/lib/capybara/version.rb b/lib/capybara/version.rb index 1af19ccb..a06289fc 100644 --- a/lib/capybara/version.rb +++ b/lib/capybara/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Capybara - VERSION = '3.1.0'.freeze + VERSION = '3.1.0' end