spec/watirspec/cookies_spec.rb in watir-7.2.2 vs spec/watirspec/cookies_spec.rb in watir-7.3.0
- old
+ new
@@ -78,10 +78,37 @@
expect(cookie[:name]).to eq 'path'
expect(cookie[:value]).to eq 'b'
expect(cookie[:path]).to eq '/set_cookie'
end
+ it 'adds a cookie with samesite value' do
+ browser.goto WatirSpec.url_for 'index.html'
+
+ options = {same_site: 'Strict'}
+ browser.cookies.add 'samesite', 'strict', options
+
+ cookie = browser.cookies.to_a.find { |e| e[:name] == 'samesite' }
+
+ expect(cookie[:name]).to eq 'samesite'
+ expect(cookie[:value]).to eq 'strict'
+ expect(cookie[:same_site]).to eq 'Strict'
+ end
+
+ it 'adds a cookie with httponly value' do
+ browser.goto WatirSpec.url_for 'index.html'
+
+ options = {http_only: true}
+ browser.cookies.add 'httponly', 'true', options
+
+ cookie = browser.cookies.to_a.find { |e| e[:name] == 'httponly' }
+
+ expect(cookie[:name]).to eq 'httponly'
+ expect(cookie[:value]).to eq 'true'
+ expect(cookie[:http_only]).to be true
+ expect(browser.execute_script('return document.cookie')).to be_empty
+ end
+
it 'adds a cookie with expiration' do
browser.goto WatirSpec.url_for 'index.html'
expires = ::Time.now + 10_000
options = {expires: expires}
@@ -143,10 +170,10 @@
describe '#load', except: {browser: :ie} do
it 'loads cookies from file' do
browser.cookies.clear
browser.cookies.load file
expected = browser.cookies.to_a
- actual = YAML.safe_load(File.read(file), permitted_classes: [::Symbol])
+ actual = YAML.safe_load_file(file, permitted_classes: [::Symbol])
expected.each { |cookie| cookie.delete(:expires) }
actual.each { |cookie| cookie.delete(:expires) }
expect(actual).to eq(expected)