From 8fe051d29d7c36a9b0ed0caeff0dedcdce30f948 Mon Sep 17 00:00:00 2001 From: Augustin Gottlieb <33221555+aguspe@users.noreply.github.com> Date: Tue, 3 Dec 2024 07:41:16 +0100 Subject: [PATCH] [rb] Add tests for the cookie named, and updates type (#14843) * add tests for the cookie named, and updates type * update gemfile lock --- rb/Gemfile.lock | 4 +--- rb/lib/selenium/webdriver/common/manager.rb | 2 +- rb/sig/lib/selenium/webdriver/common/manager.rbs | 4 ++-- rb/spec/integration/selenium/webdriver/manager_spec.rb | 5 +++++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rb/Gemfile.lock b/rb/Gemfile.lock index 3c9f67c9bf9f8..b09123411d0c7 100644 --- a/rb/Gemfile.lock +++ b/rb/Gemfile.lock @@ -13,7 +13,7 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (8.0.0) + activesupport (7.2.2) base64 benchmark (>= 0.3) bigdecimal @@ -25,7 +25,6 @@ GEM minitest (>= 5.1) securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) - uri (>= 0.13.1) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) @@ -162,7 +161,6 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.6.0) - uri (1.0.2) webmock (3.24.0) addressable (>= 2.8.0) crack (>= 0.3.2) diff --git a/rb/lib/selenium/webdriver/common/manager.rb b/rb/lib/selenium/webdriver/common/manager.rb index 6ba94fca8d829..d080e0ead6ef7 100644 --- a/rb/lib/selenium/webdriver/common/manager.rb +++ b/rb/lib/selenium/webdriver/common/manager.rb @@ -65,7 +65,7 @@ def add_cookie(opts = {}) # Get the cookie with the given name # # @param [String] name the name of the cookie - # @return [Hash, nil] the cookie, or nil if it wasn't found. + # @return [Hash, nil] the cookie, or throws a NoSuchCookieError if it wasn't found. # def cookie_named(name) diff --git a/rb/sig/lib/selenium/webdriver/common/manager.rbs b/rb/sig/lib/selenium/webdriver/common/manager.rbs index bf61f3e18c4b4..bb214a709a84b 100644 --- a/rb/sig/lib/selenium/webdriver/common/manager.rbs +++ b/rb/sig/lib/selenium/webdriver/common/manager.rbs @@ -11,7 +11,7 @@ module Selenium def add_cookie: (?Hash[Symbol, untyped] opts) -> void - def cookie_named: (String name) -> Hash[Symbol, untyped] + def cookie_named: (String name) -> (Hash[Symbol, untyped] | Error::NoSuchCookieError) def delete_cookie: (String name) -> String @@ -33,7 +33,7 @@ module Selenium def strip_port: (String str) -> String? - def convert_cookie: (Hash[String, untyped] cookie) -> Hash[Symbol, untyped] + def convert_cookie: (String) -> (Hash[Symbol, untyped] | Error::NoSuchCookieError) end end end diff --git a/rb/spec/integration/selenium/webdriver/manager_spec.rb b/rb/spec/integration/selenium/webdriver/manager_spec.rb index f06afd7302cc9..d8d9d791ddc74 100644 --- a/rb/spec/integration/selenium/webdriver/manager_spec.rb +++ b/rb/spec/integration/selenium/webdriver/manager_spec.rb @@ -248,6 +248,11 @@ module WebDriver driver.manage.delete_all_cookies expect(driver.manage.all_cookies).to be_empty end + + it 'throws error when fetching non-existent cookie' do + expect { driver.manage.cookie_named('non-existent') } + .to raise_exception(Error::NoSuchCookieError) + end end end # Options end # WebDriver