File tree Expand file tree Collapse file tree 7 files changed +48
-15
lines changed
spec/unit/selenium/webdriver Expand file tree Collapse file tree 7 files changed +48
-15
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,8 @@ def initialize(options: nil, **opts)
90
90
# @param [Boolean, String, Integer] value Value of the option
91
91
#
92
92
93
- def add_option ( name , value )
93
+ def add_option ( name , value = nil )
94
+ @options [ name . keys . first ] = name . values . first if value . nil? && name . is_a? ( Hash )
94
95
@options [ name ] = value
95
96
end
96
97
Original file line number Diff line number Diff line change @@ -28,8 +28,9 @@ class Options < WebDriver::Options
28
28
automatic_profiling : 'safari:automaticProfiling' } . freeze
29
29
BROWSER = 'safari'
30
30
31
- def add_option ( name , value )
32
- raise ArgumentError , 'Safari does not support options that are not namespaced' unless name . to_s . include? ( ':' )
31
+ def add_option ( name , value = nil )
32
+ key = name . is_a? ( Hash ) ? name . keys . first : name
33
+ raise ArgumentError , 'Safari does not support options that are not namespaced' unless key . to_s . include? ( ':' )
33
34
34
35
super
35
36
end
Original file line number Diff line number Diff line change @@ -177,10 +177,15 @@ module Chrome
177
177
end
178
178
179
179
describe '#add_option' do
180
- it 'adds an option' do
180
+ it 'adds an option with ordered pairs ' do
181
181
options . add_option ( :foo , 'bar' )
182
182
expect ( options . instance_variable_get ( '@options' ) [ :foo ] ) . to eq ( 'bar' )
183
183
end
184
+
185
+ it 'adds an option with Hash' do
186
+ options . add_option ( foo : 'bar' )
187
+ expect ( options . instance_variable_get ( '@options' ) [ :foo ] ) . to eq ( 'bar' )
188
+ end
184
189
end
185
190
186
191
describe '#add_preference' do
Original file line number Diff line number Diff line change @@ -133,10 +133,15 @@ module Edge
133
133
end
134
134
135
135
describe '#add_option' do
136
- it 'adds an option' do
136
+ it 'adds an option with ordered pairs ' do
137
137
options . add_option ( :foo , 'bar' )
138
138
expect ( options . instance_variable_get ( '@options' ) [ :foo ] ) . to eq ( 'bar' )
139
139
end
140
+
141
+ it 'adds an option with Hash' do
142
+ options . add_option ( foo : 'bar' )
143
+ expect ( options . instance_variable_get ( '@options' ) [ :foo ] ) . to eq ( 'bar' )
144
+ end
140
145
end
141
146
142
147
describe '#add_preference' do
Original file line number Diff line number Diff line change @@ -125,10 +125,15 @@ module Firefox
125
125
end
126
126
127
127
describe '#add_option' do
128
- it 'adds an option' do
128
+ it 'adds an option with ordered pairs ' do
129
129
options . add_option ( :foo , 'bar' )
130
130
expect ( options . instance_variable_get ( '@options' ) [ :foo ] ) . to eq ( 'bar' )
131
131
end
132
+
133
+ it 'adds an option with Hash' do
134
+ options . add_option ( foo : 'bar' )
135
+ expect ( options . instance_variable_get ( '@options' ) [ :foo ] ) . to eq ( 'bar' )
136
+ end
132
137
end
133
138
134
139
describe '#add_preference' do
Original file line number Diff line number Diff line change @@ -102,9 +102,14 @@ module IE
102
102
end
103
103
104
104
describe '#add_option' do
105
- it 'adds an option' do
105
+ it 'adds an option with ordered pairs ' do
106
106
options . add_option ( :foo , 'bar' )
107
- expect ( options . options [ :foo ] ) . to eq ( 'bar' )
107
+ expect ( options . instance_variable_get ( '@options' ) [ :foo ] ) . to eq ( 'bar' )
108
+ end
109
+
110
+ it 'adds an option with Hash' do
111
+ options . add_option ( foo : 'bar' )
112
+ expect ( options . instance_variable_get ( '@options' ) [ :foo ] ) . to eq ( 'bar' )
108
113
end
109
114
end
110
115
Original file line number Diff line number Diff line change @@ -59,15 +59,26 @@ module Safari
59
59
end
60
60
61
61
describe '#add_option' do
62
- it 'adds an option if name spaced' do
63
- options . add_option ( 'safari:foo' , 'bar' )
64
- expect ( options . instance_variable_get ( '@options' ) [ 'safari:foo' ] ) . to eq ( 'bar' )
62
+ context 'when namespaced' do
63
+ it 'adds an option with ordered pairs' do
64
+ options . add_option ( 'safari:foo' , 'bar' )
65
+ expect ( options . instance_variable_get ( '@options' ) [ 'safari:foo' ] ) . to eq ( 'bar' )
66
+ end
67
+
68
+ it 'adds an option with Hash' do
69
+ options . add_option ( 'safari:foo' : 'bar' )
70
+ expect ( options . instance_variable_get ( '@options' ) [ :'safari:foo' ] ) . to eq ( 'bar' )
71
+ end
65
72
end
66
73
67
- # Note that this only applies to the method, weird things can still happen
68
- # if stuff is passed into the constructor
69
- it 'raises exception if not name spaced' do
70
- expect { options . add_option ( 'foo' , 'bar' ) } . to raise_exception ( ArgumentError )
74
+ context 'when not namespaced' do
75
+ it 'raises exception with ordered pairs' do
76
+ expect { options . add_option ( 'foo' , 'bar' ) } . to raise_exception ( ArgumentError )
77
+ end
78
+
79
+ it 'raises exception with Hash' do
80
+ expect { options . add_option ( foo : 'bar' ) } . to raise_exception ( ArgumentError )
81
+ end
71
82
end
72
83
end
73
84
You can’t perform that action at this time.
0 commit comments