Skip to content

Commit d5a708a

Browse files
committed
[rb] fix PointerPress error handling
1 parent a528503 commit d5a708a

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

‎rb/lib/selenium/webdriver/common/interactions/pointer_input.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,22 @@ def type
8080
end
8181

8282
def assert_button(button)
83-
if button.is_a? Symbol
84-
raise TypeError, "#{button.inspect} is not a valid button!" unless BUTTONS.key? button
83+
case button
84+
when Symbol
85+
raise ArgumentError, "#{button} is not a valid button!" unless BUTTONS.key? button
8586

86-
button = BUTTONS[button]
87-
end
88-
raise ArgumentError, 'Button number cannot be negative!' unless button >= 0
87+
BUTTONS[button]
88+
when Integer
89+
raise ArgumentError, 'Button number cannot be negative!' if button.negative?
8990

90-
button
91+
button
92+
else
93+
raise TypeError, "button must be a positive integer or one of #{BUTTONS.keys}, not #{button.class}"
94+
end
9195
end
9296

9397
def assert_direction(direction)
94-
raise TypeError, "#{direction.inspect} is not a valid button direction" unless DIRECTIONS.key? direction
98+
raise ArgumentError, "#{direction.inspect} is not a valid button direction" unless DIRECTIONS.key? direction
9599

96100
DIRECTIONS[direction]
97101
end

‎rb/spec/unit/selenium/webdriver/common/interactions/pointer_input_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ module Interactions
119119
let(:press) { PointerPress.new(source, direction, button) }
120120

121121
describe '#initialize' do
122-
it 'raises a TypeError if invalid button symbol' do
123-
expect { PointerPress.new(source, direction, :none) }.to raise_error(TypeError)
122+
it 'raises a ArgumentError if invalid button symbol' do
123+
expect { PointerPress.new(source, direction, :none) }.to raise_error(ArgumentError)
124+
end
125+
126+
it 'raises an TypeError if button is not a symbol or integer' do
127+
expect { PointerPress.new(source, direction, 'wrong') }.to raise_error(TypeError)
124128
end
125129

126130
it 'raises an ArgumentError if button is negative' do
@@ -131,8 +135,8 @@ module Interactions
131135
expect { PointerPress.new(source, direction, 1141) }.not_to raise_error
132136
end
133137

134-
it 'raises a TypeError if invalid direction' do
135-
expect { PointerPress.new(source, :none, button) }.to raise_error(TypeError)
138+
it 'raises a ArgumentError if invalid direction' do
139+
expect { PointerPress.new(source, :none, button) }.to raise_error(ArgumentError)
136140
end
137141
end
138142

0 commit comments

Comments
 (0)