Skip to content

Commit

Permalink
style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jul 16, 2018
1 parent eed0af6 commit e320f5d
Show file tree
Hide file tree
Showing 149 changed files with 2,988 additions and 3,008 deletions.
22 changes: 1 addition & 21 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require:

AllCops:
DisabledByDefault: false
TargetRubyVersion: 2.3.0
TargetRubyVersion: 2.3
Exclude:
- 'capybara.gemspec'

Expand Down Expand Up @@ -48,10 +48,6 @@ Lint/UnusedMethodArgument:
- 'lib/capybara/driver/base.rb'
- 'lib/capybara/driver/node.rb'

Lint/HandleExceptions:
Exclude:
- 'spec/**/*'

Layout/EndAlignment:
EnforcedStyleAlignWith: variable

Expand All @@ -68,20 +64,12 @@ Naming/UncommunicativeMethodParamName:
- 'y'
- 'on'

Style/RescueStandardError:
Exclude:
- 'spec/**/*'
- 'lib/capybara/spec/**/*'

Style/ParallelAssignment:
Enabled: false

Style/SingleLineMethods:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/Alias:
Enabled: false

Expand All @@ -97,9 +85,6 @@ Style/DoubleNegation:
Style/ClassVars:
Enabled: false

Style/GuardClause:
Enabled: false

Style/EmptyElse:
EnforcedStyle: empty

Expand All @@ -111,11 +96,6 @@ Style/NumericLiterals:
- 'lib/capybara/spec/**/*'
- 'spec/**/*'

Style/MultilineIfModifier:
Exclude:
- 'lib/capybara/spec/**/*'
- 'spec/**/*'

Layout/EmptyLineBetweenDefs:
AllowAdjacentOneLineDefs: true

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'rspec/core/rake_task'
require 'cucumber/rake/task'
require 'yard'

desc "Run all examples with Firefox non-marionette"
desc 'Run all examples with Firefox non-marionette'

rspec_opts = %w[--color]

Expand Down
76 changes: 39 additions & 37 deletions capybara.gemspec
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
lib = File.expand_path('../lib/', __FILE__)
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$:.unshift lib unless $:.include?(lib)

require 'capybara/version'

Gem::Specification.new do |s|
s.name = "capybara"
s.name = 'capybara'
s.version = Capybara::VERSION
s.required_ruby_version = ">= 2.3.0"
s.license = "MIT"
s.required_ruby_version = '>= 2.3.0'
s.license = 'MIT'

s.authors = ["Thomas Walpole", "Jonas Nicklas"]
s.email = ["twalpole@gmail.com", "jonas.nicklas@gmail.com"]
s.description = "Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website"
s.authors = ['Thomas Walpole', 'Jonas Nicklas']
s.email = ['twalpole@gmail.com', 'jonas.nicklas@gmail.com']
s.description = 'Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website'

s.files = Dir.glob("{lib,spec}/**/*") + %w[README.md History.md License.txt]
s.files = Dir.glob('{lib,spec}/**/*') + %w[README.md History.md License.txt]

s.homepage = "https://github.com/teamcapybara/capybara"
s.homepage = 'https://github.com/teamcapybara/capybara'
s.metadata = {
"changelog_uri" => "https://github.com/teamcapybara/capybara/blob/master/History.md",
"source_code_uri" => "https://github.com/teamcapybara/capybara"
'changelog_uri' => 'https://github.com/teamcapybara/capybara/blob/master/History.md',
'source_code_uri' => 'https://github.com/teamcapybara/capybara'
}
s.require_paths = ["lib"]
s.summary = "Capybara aims to simplify the process of integration testing Rack applications, such as Rails, Sinatra or Merb"

s.add_runtime_dependency("addressable")
s.add_runtime_dependency("mini_mime", [">= 0.1.3"])
s.add_runtime_dependency("nokogiri", ["~> 1.8"])
s.add_runtime_dependency("rack", [">= 1.6.0"])
s.add_runtime_dependency("rack-test", [">= 0.6.3"])
s.add_runtime_dependency("xpath", ["~>3.1"])

s.add_development_dependency("cucumber", [">= 2.3.0"])
s.add_development_dependency("erubi") # dependency specification needed by rbx
s.add_development_dependency("fuubar", [">= 1.0.0"])
s.add_development_dependency("launchy", [">= 2.0.4"])
s.add_development_dependency("minitest")
s.add_development_dependency("puma")
s.add_development_dependency("rake")
s.add_development_dependency("rspec", [">= 3.4.0"])
s.add_development_dependency("selenium-webdriver", ["~>3.5"])
s.add_development_dependency("sinatra", [">= 1.4.0"])
s.add_development_dependency("webdrivers") if ENV['CI']
s.add_development_dependency("yard", [">= 0.9.0"])
s.require_paths = ['lib']
s.summary = 'Capybara aims to simplify the process of integration testing Rack applications, such as Rails, Sinatra or Merb'

s.add_runtime_dependency('addressable')
s.add_runtime_dependency('mini_mime', ['>= 0.1.3'])
s.add_runtime_dependency('nokogiri', ['~> 1.8'])
s.add_runtime_dependency('rack', ['>= 1.6.0'])
s.add_runtime_dependency('rack-test', ['>= 0.6.3'])
s.add_runtime_dependency('xpath', ['~>3.1'])

s.add_development_dependency('cucumber', ['>= 2.3.0'])
s.add_development_dependency('erubi') # dependency specification needed by rbx
s.add_development_dependency('fuubar', ['>= 1.0.0'])
s.add_development_dependency('launchy', ['>= 2.0.4'])
s.add_development_dependency('minitest')
s.add_development_dependency('puma')
s.add_development_dependency('rake')
s.add_development_dependency('rspec', ['>= 3.4.0'])
s.add_development_dependency('selenium-webdriver', ['~>3.5'])
s.add_development_dependency('sinatra', ['>= 1.4.0'])
s.add_development_dependency('webdrivers') if ENV['CI']
s.add_development_dependency('yard', ['>= 0.9.0'])

if RUBY_ENGINE == 'rbx'
s.add_development_dependency("json")
s.add_development_dependency("racc")
s.add_development_dependency("rubysl")
s.add_development_dependency('json')
s.add_development_dependency('racc')
s.add_development_dependency('rubysl')
end

s.signing_key = 'gem-private_key.pem' if File.exist?("gem-private_key.pem")
s.signing_key = 'gem-private_key.pem' if File.exist?('gem-private_key.pem')
s.cert_chain = ['gem-public_cert.pem']
end
11 changes: 5 additions & 6 deletions lib/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,23 +445,22 @@ module Selenium; end
begin
require 'rack/handler/puma'
rescue LoadError
raise LoadError, "Capybara is unable to load `puma` for its server, please add `puma` to your project or specify a different server via something like `Capybara.server = :webrick`."
raise LoadError, 'Capybara is unable to load `puma` for its server, please add `puma` to your project or specify a different server via something like `Capybara.server = :webrick`.'
end
# If we just run the Puma Rack handler it installs signal handlers which prevent us from being able to interrupt tests.
# Therefore construct and run the Server instance ourselves.
# Rack::Handler::Puma.run(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))

conf = Rack::Handler::Puma.config(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))
conf = Rack::Handler::Puma.config(app, { Host: host, Port: port, Threads: '0:4', workers: 0, daemon: false }.merge(options))
events = conf.options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio

events.log "Capybara starting Puma..."
events.log 'Capybara starting Puma...'
events.log "* Version #{Puma::Const::PUMA_VERSION} , codename: #{Puma::Const::CODE_NAME}"
events.log "* Min threads: #{conf.options[:min_threads]}, max threads: #{conf.options[:max_threads]}"

Puma::Server.new(conf.app, events, conf.options).tap do |s|
s.binder.parse conf.options[:binds], s.events
s.min_threads = conf.options[:min_threads]
s.max_threads = conf.options[:max_threads]
s.min_threads, s.max_threads = conf.options[:min_threads], conf.options[:max_threads]
end.run.join
end

Expand All @@ -472,7 +471,7 @@ module Selenium; end
config.default_selector = :css
config.default_max_wait_time = 2
config.ignore_hidden_elements = true
config.default_host = "http://www.example.com"
config.default_host = 'http://www.example.com'
config.automatic_reload = true
config.match = :smart
config.exact = false
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize
attr_writer :reuse_server

def threadsafe=(bool)
raise "Threadsafe setting cannot be changed once a session is created" if (bool != threadsafe) && Session.instance_created?
raise 'Threadsafe setting cannot be changed once a session is created' if (bool != threadsafe) && Session.instance_created?
@threadsafe = bool
end

Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
module Capybara
module DSL
def self.included(base)
warn "including Capybara::DSL in the global scope is not recommended!" if base == Object
warn 'including Capybara::DSL in the global scope is not recommended!' if base == Object
super
end

def self.extended(base)
warn "extending the main object with Capybara::DSL is not recommended!" if base == TOPLEVEL_BINDING.eval("self")
warn 'extending the main object with Capybara::DSL is not recommended!' if base == TOPLEVEL_BINDING.eval('self')
super
end

Expand Down
6 changes: 3 additions & 3 deletions lib/capybara/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Helpers
# @return [String] Normalized text
#
def normalize_whitespace(text)
warn "DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver"
warn 'DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver'
text.to_s.gsub(/[[:space:]]+/, ' ').strip
end

Expand All @@ -33,7 +33,7 @@ def to_regexp(text, exact: false, all_whitespace: false, options: nil)
return text if text.is_a?(Regexp)

escaped = Regexp.escape(text)
escaped = escaped.gsub("\\ ", "[[:blank:]]") if all_whitespace
escaped = escaped.gsub('\\ ', '[[:blank:]]') if all_whitespace
escaped = "\\A#{escaped}\\z" if exact
Regexp.new(escaped, options)
end
Expand All @@ -48,7 +48,7 @@ def to_regexp(text, exact: false, all_whitespace: false, options: nil)
# @return [String] The modified HTML code
#
def inject_asset_host(html, host: Capybara.asset_host)
if host && Nokogiri::HTML(html).css("base").empty?
if host && Nokogiri::HTML(html).css('base').empty?
match = html.match(/<head[^<]*?>/)
return html.clone.insert match.end(0), "<base href='#{host}' />" if match
end
Expand Down
6 changes: 3 additions & 3 deletions lib/capybara/minitest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ def #{new_name} *args, &block
end

class Capybara::Session
include Capybara::Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
end

class Capybara::Node::Base
include Capybara::Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
end

class Capybara::Node::Simple
include Capybara::Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
end
14 changes: 6 additions & 8 deletions lib/capybara/node/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def uncheck(locator = nil, **options)
def select(value = nil, from: nil, **options)
el = from ? find_select_or_datalist_input(from, options) : self

if el.respond_to?(:tag_name) && (el.tag_name == "input")
if el.respond_to?(:tag_name) && (el.tag_name == 'input')
select_datalist_option(el, value)
else
el.find(:option, value, options).select_option
Expand Down Expand Up @@ -258,11 +258,9 @@ def find_select_or_datalist_input(from, options)

def select_datalist_option(input, value)
datalist_options = input.evaluate_script(DATALIST_OPTIONS_SCRIPT)
if (option = datalist_options.find { |o| o['value'] == value || o['label'] == value })
input.set(option['value'])
else
raise ::Capybara::ElementNotFound, %(Unable to find datalist option "#{value}")
end
option = datalist_options.find { |o| o.values_at('value', 'label').include?(value) }
raise ::Capybara::ElementNotFound, %(Unable to find datalist option "#{value}") unless option
input.set(option['value'])
rescue ::Capybara::NotSupportedByDriverError
# Implement for drivers that don't support JS
datalist = find(:xpath, XPath.descendant(:datalist)[XPath.attr(:id) == input[:list]], visible: false)
Expand All @@ -273,7 +271,7 @@ def select_datalist_option(input, value)
def while_visible(element, visible_css)
visible_css = { opacity: 1, display: 'block', visibility: 'visible' } if visible_css == true
_update_style(element, visible_css)
raise ExpectationNotMet, "The style changes in :make_visible did not make the file input visible" unless element.visible?
raise ExpectationNotMet, 'The style changes in :make_visible did not make the file input visible' unless element.visible?
begin
yield element
ensure
Expand All @@ -284,7 +282,7 @@ def while_visible(element, visible_css)
def _update_style(element, style)
element.execute_script(UPDATE_STYLE_SCRIPT, style)
rescue Capybara::NotSupportedByDriverError
warn "The :make_visible option is not supported by the current driver - ignoring"
warn 'The :make_visible option is not supported by the current driver - ignoring'
end

def _reset_style(element)
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/node/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def synchronize(seconds = session_options.default_max_wait_time, errors: nil)
raise e unless driver.wait? && catch_error?(e, errors)
raise e if timer.expired?
sleep(0.05)
raise Capybara::FrozenInTime, "Time appears to be frozen. Capybara does not work with libraries which freeze time, consider using time travelling instead" if timer.stalled?
raise Capybara::FrozenInTime, 'Time appears to be frozen. Capybara does not work with libraries which freeze time, consider using time travelling instead' if timer.stalled?
reload if session_options.automatic_reload
retry
ensure
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/node/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def [](attribute)
#
def style(*styles)
styles = styles.flatten.map(&:to_s)
raise ArgumentError, "You must specify at least one CSS style" if styles.empty?
raise ArgumentError, 'You must specify at least one CSS style' if styles.empty?
begin
synchronize { base.style(styles) }
rescue NotImplementedError => e
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/node/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def has_no_table?(locator = nil, **options, &optional_filter_block)
#
def assert_matches_selector(*args, &optional_filter_block)
_verify_match_result(args, optional_filter_block) do |result|
raise Capybara::ExpectationNotMet, "Item does not match the provided selector" unless result.include? self
raise Capybara::ExpectationNotMet, 'Item does not match the provided selector' unless result.include? self
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/node/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def value
if multiple?
native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content }
else
option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first
option = native.xpath(".//option[@selected='selected']").first || native.xpath('.//option').first
option[:value] || option.content if option
end
elsif tag_name == 'input' && %w[radio checkbox].include?(native[:type])
Expand All @@ -100,7 +100,7 @@ def value
# @return [Boolean] Whether the element is visible
#
def visible?(check_ancestors = true)
return false if (tag_name == 'input') && (native[:type] == "hidden")
return false if (tag_name == 'input') && (native[:type] == 'hidden')

if check_ancestors
!native.xpath("boolean(./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none') or @hidden or name()='script' or name()='head'])")
Expand Down
23 changes: 12 additions & 11 deletions lib/capybara/queries/base_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ def count_specified?
end

def count_message
message = +""
if options[:count]
message << " #{options[:count]} #{Capybara::Helpers.declension('time', 'times', options[:count])}"
elsif options[:between]
message << " between #{options[:between].first} and #{options[:between].last} times"
elsif options[:maximum]
message << " at most #{options[:maximum]} #{Capybara::Helpers.declension('time', 'times', options[:maximum])}"
elsif options[:minimum]
message << " at least #{options[:minimum]} #{Capybara::Helpers.declension('time', 'times', options[:minimum])}"
message = +''
count, between, maximum, minimum = options.values_at(:count, :between, :maximum, :minimum)
if count
message << " #{count} #{Capybara::Helpers.declension('time', 'times', count)}"
elsif between
message << " between #{between.first} and #{between.last} times"
elsif maximum
message << " at most #{maximum} #{Capybara::Helpers.declension('time', 'times', maximum)}"
elsif minimum
message << " at least #{minimum} #{Capybara::Helpers.declension('time', 'times', minimum)}"
end
message
end
Expand All @@ -90,8 +91,8 @@ def assert_valid_keys
invalid_keys = @options.keys - valid_keys
return if invalid_keys.empty?

invalid_names = invalid_keys.map(&:inspect).join(", ")
valid_names = valid_keys.map(&:inspect).join(", ")
invalid_names = invalid_keys.map(&:inspect).join(', ')
valid_names = valid_keys.map(&:inspect).join(', ')
raise ArgumentError, "invalid keys #{invalid_names}, should be one of #{valid_names}"
end
end
Expand Down
Loading

0 comments on commit e320f5d

Please sign in to comment.