Skip to content

Commit

Permalink
Remove support for Ruby 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Mar 29, 2020
1 parent 8691568 commit 5a01431
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -4,7 +4,7 @@ require:

AllCops:
DisabledByDefault: false
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
Exclude:
- 'vendor/**/*'
- 'gemfiles/vendor/**/*'
Expand Down
12 changes: 6 additions & 6 deletions .travis.yml
Expand Up @@ -34,26 +34,26 @@ cache:
matrix:
include:
- gemfile: gemfiles/Gemfile.gumbo
rvm: 2.5
rvm: 2.6
script: bundle exec rake rack_smoke
- gemfile: Gemfile
rvm: 2.5
rvm: 2.6
env: CAPYBARA_REMOTE=true
- gemfile: Gemfile
rvm: 2.5
rvm: 2.6
env:
- CAPYBARA_REMOTE=true
- CAPYBARA_FF=true
- gemfile: gemfiles/Gemfile.base-versions
rvm: 2.4
rvm: 2.5
env: CAPYBARA_FF=true
addons:
firefox: latest
apt:
packages:
- awesome
- gemfile: gemfiles/Gemfile.base-versions
rvm: 2.4
rvm: 2.5
- gemfile: Gemfile
rvm: 2.6
env: HEADLESS=true
Expand Down Expand Up @@ -102,7 +102,7 @@ matrix:
addons:
firefox: latest
- gemfile: Gemfile
rvm: 2.5
rvm: 2.6
env: CHROME_BETA=true HEADLESS=true
addons:
chrome: beta
Expand Down
7 changes: 7 additions & 0 deletions History.md
@@ -1,3 +1,10 @@
# Version 3.33.0
Release date: unreleased

### Changed

* Ruby 2.5.0+ is now required

# Version 3.32.0
Relesae date: unreleased

Expand Down
2 changes: 1 addition & 1 deletion capybara.gemspec
Expand Up @@ -8,7 +8,7 @@ require 'capybara/version'
Gem::Specification.new do |s|
s.name = 'capybara'
s.version = Capybara::VERSION
s.required_ruby_version = '>= 2.4.0'
s.required_ruby_version = '>= 2.5.0'
s.license = 'MIT'

s.authors = ['Thomas Walpole', 'Jonas Nicklas']
Expand Down
8 changes: 3 additions & 5 deletions features/step_definitions/capybara_steps.rb
Expand Up @@ -13,11 +13,9 @@
end

When(/^I use a matcher that fails$/) do
begin
expect(page).to have_css('h1#doesnotexist')
rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
@error_message = e.message
end
expect(page).to have_css('h1#doesnotexist')
rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
@error_message = e.message
end

Then(/^the failing exception should be nice$/) do
Expand Down
36 changes: 16 additions & 20 deletions lib/capybara/node/actions.rb
Expand Up @@ -308,16 +308,14 @@ def attach_file(locator = nil, paths, make_visible: nil, **options) # rubocop:di

def find_select_or_datalist_input(from, options)
synchronize(Capybara::Queries::BaseQuery.wait(options, session_options.default_max_wait_time)) do
find(:select, from, **options)
rescue Capybara::ElementNotFound => select_error # rubocop:disable Naming/RescuedExceptionsVariableName
raise if %i[selected with_selected multiple].any? { |option| options.key?(option) }

begin
find(:select, from, **options)
rescue Capybara::ElementNotFound => select_error # rubocop:disable Naming/RescuedExceptionsVariableName
raise if %i[selected with_selected multiple].any? { |option| options.key?(option) }

begin
find(:datalist_input, from, **options)
rescue Capybara::ElementNotFound => dlinput_error # rubocop:disable Naming/RescuedExceptionsVariableName
raise Capybara::ElementNotFound, "#{select_error.message} and #{dlinput_error.message}"
end
find(:datalist_input, from, **options)
rescue Capybara::ElementNotFound => dlinput_error # rubocop:disable Naming/RescuedExceptionsVariableName
raise Capybara::ElementNotFound, "#{select_error.message} and #{dlinput_error.message}"
end
end
end
Expand Down Expand Up @@ -367,18 +365,16 @@ def _check_with_label(selector, checked, locator,
options[:allow_self] = true if locator.nil?

synchronize(Capybara::Queries::BaseQuery.wait(options, session_options.default_max_wait_time)) do
el = find(selector, locator, **options)
el.set(checked)
rescue StandardError => e
raise unless allow_label_click && catch_error?(e)

begin
el = find(selector, locator, **options)
el.set(checked)
rescue StandardError => e
raise unless allow_label_click && catch_error?(e)

begin
el ||= find(selector, locator, **options.merge(visible: :all))
el.session.find(:label, for: el, visible: true).click unless el.checked? == checked
rescue StandardError # swallow extra errors - raise original
raise e
end
el ||= find(selector, locator, **options.merge(visible: :all))
el.session.find(:label, for: el, visible: true).click unless el.checked? == checked
rescue StandardError # swallow extra errors - raise original
raise e
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions lib/capybara/node/matchers.rb
Expand Up @@ -201,12 +201,10 @@ def assert_any_of_selectors(*args, wait: nil, **options, &optional_filter_block)
selector = extract_selector(args)
synchronize(wait) do
res = args.map do |locator|
begin
assert_selector(selector, locator, options, &optional_filter_block)
break nil
rescue Capybara::ExpectationNotMet => e
e.message
end
assert_selector(selector, locator, options, &optional_filter_block)
break nil
rescue Capybara::ExpectationNotMet => e
e.message
end
raise Capybara::ExpectationNotMet, res.join(' or ') if res

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/queries/style_query.rb
Expand Up @@ -34,7 +34,7 @@ def failure_message
private

def stringify_keys(hsh)
hsh.each_with_object({}) { |(k, v), str_keys| str_keys[k.to_s] = v }
hsh.transform_keys(&:to_s)
end

def valid_keys
Expand Down
8 changes: 4 additions & 4 deletions lib/capybara/selector/definition.rb
Expand Up @@ -189,7 +189,7 @@ def describe_expression_filters(&block)
def describe_all_expression_filters(**opts)
expression_filters.map do |ef_name, ef|
if ef.matcher?
handled_custom_keys(ef, opts.keys).map { |key| " with #{ef_name}[#{key} => #{opts[key]}]" }.join
handled_custom_options(ef, opts).map { |option, value| " with #{ef_name}[#{option} => #{value}]" }.join
elsif opts.key?(ef_name)
" with #{ef_name} #{opts[ef_name]}"
end
Expand Down Expand Up @@ -251,9 +251,9 @@ def locator_types

private

def handled_custom_keys(filter, keys)
keys.select do |key|
filter.handles_option?(key) && !::Capybara::Queries::SelectorQuery::VALID_KEYS.include?(key)
def handled_custom_options(filter, options)
options.select do |option, _|
filter.handles_option?(option) && !::Capybara::Queries::SelectorQuery::VALID_KEYS.include?(option)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/selector/definition/table.rb
Expand Up @@ -43,7 +43,7 @@
end

expression_filter(:cols, valid_values: [Array]) do |xpath, cols|
raise ArgumentError, ':cols must be an Array of Arrays' unless cols.all? { |col| col.is_a? Array }
raise ArgumentError, ':cols must be an Array of Arrays' unless cols.all?(Array)

rows = cols.transpose
col_conditions = rows.map { |row| match_row(row, match_size: true) }.reduce(:&)
Expand Down
16 changes: 7 additions & 9 deletions lib/capybara/selenium/driver_specializations/chrome_driver.rb
Expand Up @@ -13,14 +13,12 @@ def self.extended(base)

def fullscreen_window(handle)
within_given_window(handle) do
begin
super
rescue NoMethodError => e
raise unless e.message.match?(/full_screen_window/)

result = bridge.http.call(:post, "session/#{bridge.session_id}/window/fullscreen", {})
result['value']
end
super
rescue NoMethodError => e
raise unless e.message.match?(/full_screen_window/)

result = bridge.http.call(:post, "session/#{bridge.session_id}/window/fullscreen", {})
result['value']
end
end

Expand Down Expand Up @@ -65,7 +63,7 @@ def storage_types_to_clear
end

def clear_all_storage?
storage_clears.none? { |s| s == false }
storage_clears.none? false
end

def uniform_storage_clear?
Expand Down
16 changes: 7 additions & 9 deletions lib/capybara/selenium/driver_specializations/edge_driver.rb
Expand Up @@ -13,14 +13,12 @@ def fullscreen_window(handle)
return super if edgedriver_version < 75

within_given_window(handle) do
begin
super
rescue NoMethodError => e
raise unless e.message.match?(/full_screen_window/)

result = bridge.http.call(:post, "session/#{bridge.session_id}/window/fullscreen", {})
result['value']
end
super
rescue NoMethodError => e
raise unless e.message.match?(/full_screen_window/)

result = bridge.http.call(:post, "session/#{bridge.session_id}/window/fullscreen", {})
result['value']
end
end

Expand Down Expand Up @@ -74,7 +72,7 @@ def storage_types_to_clear
end

def clear_all_storage?
storage_clears.none? { |s| s == false }
storage_clears.none? false
end

def uniform_storage_clear?
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/selenium/nodes/firefox_node.rb
Expand Up @@ -42,7 +42,7 @@ def set_file(value) # rubocop:disable Naming/AccessorMethodName

def send_keys(*args)
# https://github.com/mozilla/geckodriver/issues/846
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none? { |arg| arg.is_a? Array }
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none?(Array)

native.click
_send_keys(args).perform
Expand Down
8 changes: 3 additions & 5 deletions lib/capybara/selenium/patches/logs.rb
Expand Up @@ -33,11 +33,9 @@ def log(type)
end

Array(data).map do |l|
begin
::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
rescue KeyError
next
end
::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
rescue KeyError
next
end
rescue ::Selenium::WebDriver::Error::UnknownCommandError
raise NotImplementedError, LOG_MSG
Expand Down
32 changes: 14 additions & 18 deletions lib/capybara/spec/test_app.rb
Expand Up @@ -188,28 +188,24 @@ def initialize(string1, msg)
end

post '/upload' do
begin
buffer = []
buffer << "Content-type: #{params.dig(:form, :document, :type)}"
buffer << "File content: #{params.dig(:form, :document, :tempfile).read}"
buffer.join(' | ')
rescue StandardError
'No file uploaded'
end
buffer = []
buffer << "Content-type: #{params.dig(:form, :document, :type)}"
buffer << "File content: #{params.dig(:form, :document, :tempfile).read}"
buffer.join(' | ')
rescue StandardError
'No file uploaded'
end

post '/upload_multiple' do
begin
docs = params.dig(:form, :multiple_documents)
buffer = [docs.size.to_s]
docs.each do |doc|
buffer << "Content-type: #{doc[:type]}"
buffer << "File content: #{doc[:tempfile].read}"
end
buffer.join(' | ')
rescue StandardError
'No files uploaded'
docs = params.dig(:form, :multiple_documents)
buffer = [docs.size.to_s]
docs.each do |doc|
buffer << "Content-type: #{doc[:type]}"
buffer << "File content: #{doc[:tempfile].read}"
end
buffer.join(' | ')
rescue StandardError
'No files uploaded'
end

get '/apple-touch-icon-precomposed.png' do
Expand Down

0 comments on commit 5a01431

Please sign in to comment.