Skip to content

Commit 29ea618

Browse files
jimvmandreastt
authored andcommitted
rb: deal with invalid type argument
When an invalid type argument is given, an ArgumentError should be raised. Signed-off-by: Andreas Tolfsen <[email protected]>
1 parent 147d4df commit 29ea618

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

rb/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def network_connection_type
1313
end
1414

1515
def network_connection_type=(connection_type)
16+
raise ArgumentError, "Invalid connection type" unless valid_type? connection_type
17+
1618
connection_value = type_to_values[connection_type]
1719

1820
@bridge.setNetworkConnection connection_value
@@ -27,6 +29,10 @@ def type_to_values
2729
def values_to_type
2830
type_to_values.invert
2931
end
32+
33+
def valid_type?(type)
34+
type_to_values.keys.include? type
35+
end
3036
end
3137
end
3238
end

rb/spec/unit/selenium/webdriver/common/driver_extensions/has_network_connection_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class FakeDriver
3030

3131
driver.network_connection_type = :airplane_mode
3232
end
33+
34+
it "returns an error when an invalid argument is given" do
35+
expect { driver.network_connection_type = :something }.
36+
to raise_error(ArgumentError, "Invalid connection type")
37+
end
3338
end
3439
end
3540
end

0 commit comments

Comments
 (0)