Skip to content

Commit 3dc3d0c

Browse files
Merge pull request #320 from JaniJegoroff/rubocop-warning-fixes
Rubocop warning fixes
2 parents 4ba5ed9 + e539d7c commit 3dc3d0c

35 files changed

+418
-402
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
*.gem
2-
.*
32
*.lock

.rubocop.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Custom config for RuboCop static code analysis
2+
3+
Metrics/LineLength:
4+
Max: 125
5+
6+
Style/ConstantName:
7+
Enabled: false
8+
9+
Metrics/MethodLength:
10+
Max: 30

Rakefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ require 'rubygems'
33
require 'rake'
44
require 'date'
55
require 'posix/spawn'
6+
require 'rubocop/rake_task'
67

78
# Defines gem name.
89
def repo_name
@@ -226,4 +227,11 @@ end
226227
desc 'Remove non-ascii bytes'
227228
task :byte do
228229
remove_non_ascii
229-
end
230+
end
231+
232+
desc 'Execute RuboCop static code analysis'
233+
RuboCop::RakeTask.new(:rubocop) do |t|
234+
t.patterns = %w(lib)
235+
t.options = %w(-D)
236+
t.fail_on_error = false
237+
end

android_tests/lib/android/specs/common/device.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
wait { current_activity.include?('Settings').must_equal true }
2525
end
2626

27-
t 'is_installed' do
28-
wait { is_installed?('fake_app').must_equal false }
27+
t 'installed' do
28+
wait { app_installed?('fake_app').must_equal false }
2929
end
3030

3131
t 'reset' do

android_tests/lib/android/specs/install.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ def pkg
55
end
66

77
def installed
8-
is_installed?(pkg).must_equal true
8+
app_installed?(pkg).must_equal true
99
end
1010

1111
def not_installed
12-
is_installed?(pkg).must_equal false
12+
app_installed?(pkg).must_equal false
1313
end
1414

1515
t 'install/uninstall' do

appium_lib.gemspec

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ Gem::Specification.new do |s|
2828
s.add_development_dependency 'rake', '~> 10.2', '>= 10.2.2'
2929
s.add_development_dependency 'yard', '~> 0.8', '>= 0.8.7.3'
3030

31+
s.add_development_dependency 'rubocop', '~> 0.30'
32+
3133
s.files = `git ls-files`.split "\n"
32-
end
34+
end

ios_tests/lib/ios/specs/device/device.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def go_back
2727
screen.must_equal catalog
2828
end
2929

30-
t 'is_installed' do
31-
installed = is_installed? "Derrp"
30+
t 'app_installed' do
31+
installed = app_installed? "Derrp"
3232
installed.must_equal false
3333
end
3434

lib/appium_lib/android/client_xpath.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Appium
44
module Android
5-
def _nodeset_to_uiselector opts={}
5+
def _nodeset_to_uiselector(opts = {})
66
results = ''
77

88
nodes = opts[:nodes]
@@ -11,16 +11,16 @@ def _nodeset_to_uiselector opts={}
1111
nodes = [nodes[0]] if first
1212

1313
nodes.each do |node|
14-
results += %Q(new UiSelector().className("#{node.name}").instance(#{node.attr('instance')});)
14+
results += %(new UiSelector().className("#{node.name}").instance(#{node.attr('instance')});)
1515
end
1616

1717
results.strip
1818
end
1919

20-
def _client_xpath opts={}
20+
def _client_xpath(opts = {})
2121
root_node = Nokogiri::XML(get_source).children.first
2222

23-
instance = Hash.new -1
23+
instance = Hash.new(-1)
2424

2525
root_node.traverse do |node|
2626
number = instance[node.name] += 1
@@ -33,15 +33,15 @@ def _client_xpath opts={}
3333
_nodeset_to_uiselector nodes: nodes, first: first
3434
end
3535

36-
def client_xpath xpath
36+
def client_xpath(xpath)
3737
find_element :uiautomator, _client_xpath(xpath: xpath, first: true)
3838
end
3939

40-
def client_xpaths xpath
40+
def client_xpaths(xpath)
4141
find_elements :uiautomator, _client_xpath(xpath: xpath, first: false)
4242
end
4343
end
4444
end
4545

4646
# http://stackoverflow.com/questions/9199415/getting-first-node-in-xpath-result-set
47-
# '(//android.widget.TextView)[1]' not '//android.widget.TextView[1]'
47+
# '(//android.widget.TextView)[1]' not '//android.widget.TextView[1]'

lib/appium_lib/android/element/alert.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Android
33
# Click the first alert button that contains value or by index.
44
# @param value [Integer, String] either an integer index of the button or the button's name
55
# @return [void]
6-
def alert_click value
6+
def alert_click(value)
77
button(value).click
88
end
99

@@ -35,4 +35,4 @@ def alert_dismiss_text
3535
first_button.text
3636
end
3737
end # module Android
38-
end # module Appium
38+
end # module Appium

lib/appium_lib/android/element/button.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ module Android
77
private
88

99
# @private
10-
def _button_visible_selectors opts={}
10+
def _button_visible_selectors(opts = {})
1111
button_index = opts.fetch :button_index, false
1212
image_button_index = opts.fetch :image_button_index, false
1313

1414
if button_index && image_button_index
15-
"new UiSelector().className(#{Button}).instance(#{button_index});" +
16-
"new UiSelector().className(#{ImageButton}).instance(#{image_button_index});"
15+
"new UiSelector().className(#{Button}).instance(#{button_index});" \
16+
"new UiSelector().className(#{ImageButton}).instance(#{image_button_index});"
1717
else
18-
"new UiSelector().className(#{Button});" +
19-
"new UiSelector().className(#{ImageButton});"
18+
"new UiSelector().className(#{Button});" \
19+
"new UiSelector().className(#{ImageButton});"
2020
end
2121
end
2222

2323
# @private
24-
def _button_exact_string value
24+
def _button_exact_string(value)
2525
button = string_visible_exact Button, value
2626
image_button = string_visible_exact ImageButton, value
2727
button + image_button
2828
end
2929

3030
# @private
31-
def _button_contains_string value
31+
def _button_contains_string(value)
3232
button = string_visible_contains Button, value
3333
image_button = string_visible_contains ImageButton, value
3434
button + image_button
@@ -40,12 +40,12 @@ def _button_contains_string value
4040
# @param value [String, Integer] the value to exactly match.
4141
# If int then the button at that index is returned.
4242
# @return [Button]
43-
def button value
43+
def button(value)
4444
# Don't use ele_index because that only works on one element type.
4545
# Android needs to combine button and image button to match iOS.
4646
if value.is_a? Numeric
4747
index = value
48-
raise "#{index} is not a valid index. Must be >= 1" if index <= 0
48+
fail "#{index} is not a valid index. Must be >= 1" if index <= 0
4949

5050
return find_element :uiautomator, _button_visible_selectors(index: index)
5151
end
@@ -57,7 +57,7 @@ def button value
5757
# If value is omitted, all buttons are returned.
5858
# @param value [String] the value to search for
5959
# @return [Array<Button>]
60-
def buttons value=false
60+
def buttons(value = false)
6161
return find_elements :uiautomator, _button_visible_selectors unless value
6262
find_elements :uiautomator, _button_contains_string(value)
6363
end
@@ -73,28 +73,28 @@ def first_button
7373
def last_button
7474
# uiautomator index doesn't support last
7575
# and it's 0 indexed
76-
button_index = tags(Button).length
77-
button_index -= 1 if button_index > 0
76+
button_index = tags(Button).length
77+
button_index -= 1 if button_index > 0
7878
image_button_index = tags(ImageButton).length
7979
image_button_index -= 1 if image_button_index > 0
8080

8181
find_element :uiautomator,
8282
_button_visible_selectors(button_index: button_index,
83-
image_button_index: image_button_index)
83+
image_button_index: image_button_index)
8484
end
8585

8686
# Find the first button that exactly matches value.
8787
# @param value [String] the value to match exactly
8888
# @return [Button]
89-
def button_exact value
89+
def button_exact(value)
9090
find_element :uiautomator, _button_exact_string(value)
9191
end
9292

9393
# Find all buttons that exactly match value.
9494
# @param value [String] the value to match exactly
9595
# @return [Array<Button>]
96-
def buttons_exact value
96+
def buttons_exact(value)
9797
find_elements :uiautomator, _button_exact_string(value)
9898
end
9999
end # module Android
100-
end # module Appium
100+
end # module Appium
+12-13
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
module Appium
22
module Android
3-
43
# Find the first element containing value
54
# @param value [String] the value to search for
65
# @return [Element]
7-
def find value
6+
def find(value)
87
complex_find_contains '*', value
98
end
109

1110
# Find all elements containing value
1211
# @param value [String] the value to search for
1312
# @return [Array<Element>]
14-
def finds value
13+
def finds(value)
1514
complex_finds_contains '*', value
1615
end
1716

1817
# Find the first element exactly matching value
1918
# @param value [String] the value to search for
2019
# @return [Element]
21-
def find_exact value
20+
def find_exact(value)
2221
complex_find_exact '*', value
2322
end
2423

2524
# Find all elements exactly matching value
2625
# @param value [String] the value to search for
2726
# @return [Array<Element>]
28-
def finds_exact value
27+
def finds_exact(value)
2928
complex_finds_exact '*', value
3029
end
3130

3231
# @private
33-
def scroll_uiselector content
34-
"new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(#{content}.instance(0));"
35-
end
32+
def scroll_uiselector(content)
33+
"new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(#{content}.instance(0));"
34+
end
3635

3736
# Scroll to the first element containing target text or description.
3837
# @param text [String] the text to search for in the text value and content description
3938
# @return [Element] the element scrolled to
40-
def scroll_to text
41-
text = %Q("#{text}")
39+
def scroll_to(text)
40+
text = %("#{text}")
4241

4342
args = scroll_uiselector("new UiSelector().textContains(#{text})") +
4443
scroll_uiselector("new UiSelector().descriptionContains(#{text})")
@@ -49,13 +48,13 @@ def scroll_to text
4948
# Scroll to the first element with the exact target text or description.
5049
# @param text [String] the text to search for in the text value and content description
5150
# @return [Element] the element scrolled to
52-
def scroll_to_exact text
53-
text = %Q("#{text}")
51+
def scroll_to_exact(text)
52+
text = %("#{text}")
5453

5554
args = scroll_uiselector("new UiSelector().text(#{text})") +
5655
scroll_uiselector("new UiSelector().description(#{text})")
5756

5857
find_element :uiautomator, args
5958
end
6059
end # module Android
61-
end # module Appium
60+
end # module Appium

lib/appium_lib/android/element/text.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Android
77
# @param value [String, Integer] the value to find.
88
# If int then the TextView at that index is returned.
99
# @return [TextView]
10-
def text value
10+
def text(value)
1111
return ele_index TextView, value if value.is_a? Numeric
1212
complex_find_contains TextView, value
1313
end
@@ -16,7 +16,7 @@ def text value
1616
# If value is omitted, all texts are returned.
1717
# @param value [String] the value to search for
1818
# @return [Array<TextView>]
19-
def texts value=false
19+
def texts(value = false)
2020
return tags TextView unless value
2121
complex_finds_contains TextView, value
2222
end
@@ -36,15 +36,15 @@ def last_text
3636
# Find the first TextView that exactly matches value.
3737
# @param value [String] the value to match exactly
3838
# @return [TextView]
39-
def text_exact value
39+
def text_exact(value)
4040
complex_find_exact TextView, value
4141
end
4242

4343
# Find all TextViews that exactly match value.
4444
# @param value [String] the value to match exactly
4545
# @return [Array<TextView>]
46-
def texts_exact value
46+
def texts_exact(value)
4747
complex_finds_exact TextView, value
4848
end
4949
end # module Android
50-
end # module Appium
50+
end # module Appium

lib/appium_lib/android/element/textfield.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Android
66
# @param value [String, Integer] the text to match exactly.
77
# If int then the EditText at that index is returned.
88
# @return [EditText]
9-
def textfield value
9+
def textfield(value)
1010
return ele_index EditText, value if value.is_a? Numeric
1111
complex_find_contains EditText, value
1212
end
@@ -15,7 +15,7 @@ def textfield value
1515
# If value is omitted, all EditTexts are returned.
1616
# @param value [String] the value to search for
1717
# @return [Array<EditText>]
18-
def textfields value=false
18+
def textfields(value = false)
1919
return tags EditText unless value
2020
complex_finds_contains EditText, value
2121
end
@@ -35,15 +35,15 @@ def last_textfield
3535
# Find the first EditText that exactly matches value.
3636
# @param value [String] the value to match exactly
3737
# @return [EditText]
38-
def textfield_exact value
38+
def textfield_exact(value)
3939
complex_find_exact EditText, value
4040
end
4141

4242
# Find all EditTexts that exactly match value.
4343
# @param value [String] the value to match exactly
4444
# @return [Array<EditText>]
45-
def textfields_exact value
45+
def textfields_exact(value)
4646
complex_finds_exact EditText, value
4747
end
4848
end # module Android
49-
end # module Appium
49+
end # module Appium

0 commit comments

Comments
 (0)