File tree Expand file tree Collapse file tree 2 files changed +19
-11
lines changed
lib/selenium/webdriver/common/interactions
spec/unit/selenium/webdriver/common/interactions Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -80,18 +80,22 @@ def type
80
80
end
81
81
82
82
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
85
86
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?
89
90
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
91
95
end
92
96
93
97
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
95
99
96
100
DIRECTIONS [ direction ]
97
101
end
Original file line number Diff line number Diff line change @@ -119,8 +119,12 @@ module Interactions
119
119
let ( :press ) { PointerPress . new ( source , direction , button ) }
120
120
121
121
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 )
124
128
end
125
129
126
130
it 'raises an ArgumentError if button is negative' do
@@ -131,8 +135,8 @@ module Interactions
131
135
expect { PointerPress . new ( source , direction , 1141 ) } . not_to raise_error
132
136
end
133
137
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 )
136
140
end
137
141
end
138
142
You can’t perform that action at this time.
0 commit comments