File tree Expand file tree Collapse file tree
lib/selenium/webdriver/common/interactions
spec/unit/selenium/webdriver/common/interactions Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments