Skip to content

Commit

Permalink
fix all lint cop violations
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 5, 2018
1 parent e249e38 commit 0049659
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 122 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ Layout/EmptyLinesAroundModuleBody:
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

# Offense count: 1
Lint/HandleExceptions:
Exclude:
- 'lib/watirspec.rb'
72 changes: 1 addition & 71 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Lint/AmbiguousBlockAssociation:
Exclude:
- 'support/version_differ.rb'

# Offense count: 2
Lint/AmbiguousOperator:
Exclude:
- 'lib/watir/browser.rb'
- 'spec/watirspec/support/rspec_matchers.rb'

# Offense count: 2
Lint/AmbiguousRegexpLiteral:
Exclude:
- 'lib/watir/generator/html.rb'
- 'spec/watirspec/elements/filefield_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Lint/DeprecatedClassMethods:
Exclude:
- 'lib/watirspec/remote_server.rb'

# Offense count: 2
Lint/DuplicateMethods:
Exclude:
- 'lib/watirspec.rb'

# Offense count: 5
Lint/HandleExceptions:
Exclude:
- 'lib/watirspec.rb'
- 'spec/unit/wait_spec.rb'
- 'spec/watirspec/wait_spec.rb'

# Offense count: 1
Lint/IneffectiveAccessModifier:
Exclude:
- 'lib/watir/attribute_helper.rb'

# Offense count: 1
Lint/ShadowedException:
Exclude:
- 'lib/watir/alert.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/watir/locators/text_field/validator.rb'

# Offense count: 1
# Cop supports --auto-correct.
Lint/UriRegexp:
Exclude:
- 'lib/watir/browser.rb'

# Offense count: 2
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
Lint/UselessAccessModifier:
Exclude:
- 'lib/watir/elements/date_field.rb'
- 'lib/watir/elements/date_time_field.rb'

# Offense count: 3
Lint/UselessAssignment:
Exclude:
- 'lib/watir/attribute_helper.rb'
- 'spec/watirspec/elements/element_spec.rb'

# Offense count: 31
Metrics/AbcSize:
Max: 50
Expand Down Expand Up @@ -245,6 +174,7 @@ Style/BarePercentLiterals:
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'lib/watir/attribute_helper.rb'
- 'lib/watir/generator/base/spec_extractor.rb'
- 'lib/watir/window.rb'
- 'spec/unit/container_spec.rb'
Expand Down
2 changes: 1 addition & 1 deletion lib/watir/alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def selector_string

def assert_exists
@alert = @browser.driver.switch_to.alert
rescue Selenium::WebDriver::Error::NoAlertPresentError, Selenium::WebDriver::Error::NoSuchAlertError
rescue Selenium::WebDriver::Error::NoSuchAlertError
raise Exception::UnknownObjectException, 'unable to locate alert'
end

Expand Down
31 changes: 16 additions & 15 deletions lib/watir/attribute_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ module Watir
#

module AttributeHelper
class << self
private

def extended(klass)
klass.class_eval do
# undefine deprecated methods to use them for Element attributes
%i[id type].each { |m| undef_method m if method_defined? m }
end
end
end

def inherit_attributes_from(kls)
kls.typed_attributes.each do |type, attrs|
attrs.each { |method, attr| attribute type, method, attr }
Expand All @@ -17,12 +28,11 @@ def typed_attributes
end

def attribute_list
@attribute_list ||= (
list = typed_attributes.values.flatten
list += ancestors[1..-1].map do |e|
e.attribute_list if e.respond_to?(:attribute_list)
end.compact.flatten
).uniq
@attribute_list ||= (typed_attributes.values.flatten +
ancestors[1..-1].map { |e|
e.attribute_list if e.respond_to?(:attribute_list)
}.compact.flatten
).uniq
end

alias_method :attributes, :attribute_list
Expand All @@ -40,15 +50,6 @@ def attribute(type, method, attr)
define_attribute(type, method, attr)
end

private

def self.extended(klass)
klass.class_eval do
# undefine deprecated methods to use them for Element attributes
[:id, :type].each { |m| undef_method m if method_defined? m }
end
end

def define_attribute(type, name, attr)
case type.to_s
when 'String'
Expand Down
4 changes: 2 additions & 2 deletions lib/watir/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def initialize(browser = :chrome, *args)
case browser
when ::Symbol, String
selenium_args = Watir::Capabilities.new(browser, *args).to_args
@driver = Selenium::WebDriver.for *selenium_args
@driver = Selenium::WebDriver.for(*selenium_args)
when Selenium::WebDriver::Driver
@driver = browser
else
Expand Down Expand Up @@ -78,7 +78,7 @@ def inspect
#

def goto(uri)
uri = "http://#{uri}" unless uri =~ URI.regexp
uri = "http://#{uri}" unless uri =~ URI::DEFAULT_PARSER.make_regexp

@driver.navigate.to uri
@after_hooks.run
Expand Down
2 changes: 0 additions & 2 deletions lib/watir/elements/date_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def set!(date)
end
alias_method :set, :set!
alias_method :value=, :set

protected
end # DateField

module Container
Expand Down
2 changes: 0 additions & 2 deletions lib/watir/elements/date_time_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def set!(date)
end
alias_method :set, :set!
alias_method :value=, :set

protected
end # DateTimeField

module Container
Expand Down
2 changes: 1 addition & 1 deletion lib/watir/generator/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
inflect.plural 'tbody', 'tbodys'
inflect.plural 'canvas', 'canvases'
inflect.plural 'ins', 'inses'
inflect.plural /^s$/, 'ss'
inflect.plural(/^s$/, 'ss')
inflect.plural 'meta', 'metas'
inflect.plural 'details', 'detailses'
inflect.plural 'data', 'datas'
Expand Down
2 changes: 1 addition & 1 deletion lib/watir/locators/text_field/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Watir
module Locators
class TextField
class Validator < Element::Validator
def validate(element, selector)
def validate(element, _selector)
return unless element.tag_name.downcase == 'input'
element
end
Expand Down
2 changes: 1 addition & 1 deletion lib/watirspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module WatirSpec
class << self
attr_accessor :browser_args, :unguarded, :implementation
attr_accessor :browser_args, :unguarded

def htmls
@htmls ||= [File.expand_path("../../spec/watirspec/html", __FILE__)]
Expand Down
2 changes: 1 addition & 1 deletion lib/watirspec/remote_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def jar

if File.exist?(ENV['REMOTE_SERVER_BINARY'] || '')
ENV['REMOTE_SERVER_BINARY']
elsif ENV['LOCAL_SELENIUM'] && File.exists?(local)
elsif ENV['LOCAL_SELENIUM'] && File.exist?(local)
local
elsif !Dir.glob('*selenium*.jar').empty?
Dir.glob('*selenium*.jar').first
Expand Down
10 changes: 4 additions & 6 deletions spec/unit/wait_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
end

it "uses provided interval" do
begin
expect {
Watir::Wait.until(timeout: 0.4, interval: 0.2) do
@result = @result.nil? ? 1 : @result + 1
false
end
rescue Watir::Wait::TimeoutError
end
}.to raise_timeout_exception
expect(@result).to eq 2
end

Expand Down Expand Up @@ -60,13 +59,12 @@
end

it "uses provided interval" do
begin
expect {
Watir::Wait.while(timeout: 0.4, interval: 0.2) do
@result = @result.nil? ? 1 : @result + 1
true
end
rescue Watir::Wait::TimeoutError
end
}.to raise_timeout_exception
expect(@result).to eq 2
end

Expand Down
10 changes: 2 additions & 8 deletions spec/watirspec/elements/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,11 @@
end

it "returns false if the element has style='visibility: hidden;" do
msg = /WARN Watir \[\"visible_element\"\]/
expect {
expect(browser.div(id: 'wants_newsletter')).to_not be_visible
}
expect { expect(browser.div(id: 'wants_newsletter')).to_not be_visible }
end

it "returns false if one of the parent elements is hidden" do
msg = /WARN Watir \[\"visible_element\"\]/
expect {
expect(browser.div(id: 'hidden_parent')).to_not be_visible
}
expect { expect(browser.div(id: 'hidden_parent')).to_not be_visible }
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/watirspec/elements/filefield_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
it "does not alter its argument" do
value = File.expand_path '.travis.yml'
browser.file_field.value = value
expect(value).to match /\.travis\.yml$/
expect(value).to match(/\.travis\.yml$/)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/watirspec/support/rspec_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def supports_block_expectations?

RSpec::Matchers.define :exist do |*args|
match do |actual|
actual.exists? *args
actual.exists?(*args)
end

failure_message do |obj|
Expand Down
10 changes: 2 additions & 8 deletions spec/watirspec/wait_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ def present?
element = browser.div(id: 'bar')
expect(element).to receive(:present?).twice

begin
element.wait_until_present(timeout: 0.4, interval: 0.2)
rescue Watir::Wait::TimeoutError
end
expect { element.wait_until_present(timeout: 0.4, interval: 0.2) }.to raise_timeout_exception
end
end

Expand All @@ -150,10 +147,7 @@ def present?
element = browser.div(id: 'foo')
expect(element).to receive(:present?).twice

begin
element.wait_until_present(timeout: 0.4, interval: 0.2)
rescue Watir::Wait::TimeoutError
end
expect { element.wait_until_present(timeout: 0.4, interval: 0.2) }.to raise_timeout_exception
end

it "does not error when element goes stale" do
Expand Down
2 changes: 1 addition & 1 deletion support/version_differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def diff(old_version, new_version)

# requires YARD > 0.8.2.1 (i.e. next release at the time of writing)
content = `yard diff --all --query '!@private && @api.text != "private" && object.visibility == :public' #{left} #{right} 2>&1`
str.puts content.split("\n").map { |line| line.empty? ? line : " #{line}" }
str.puts(content.split("\n").map { |line| line.empty? ? line : " #{line}" })
str.puts "\n\n"

str.string
Expand Down

0 comments on commit 0049659

Please sign in to comment.