spec/watirspec/cookies_spec.rb in watir-6.16.5 vs spec/watirspec/cookies_spec.rb in watir-6.17.0

- old
+ new

@@ -40,11 +40,11 @@ expect(browser.cookies[:non_monster]).to eq(nil) end end not_compliant_on :internet_explorer do - it 'adds a cookie' do + it 'adds a cookie without options' do browser.goto set_cookie_url verify_cookies_count 1 browser.cookies.add 'foo', 'bar' verify_cookies_count 2 @@ -61,33 +61,53 @@ cookie = browser.cookies[:foo] expect(cookie[:expires]).to be_kind_of(Time) end end - # TODO: - Split this up into multiple tests or figure out which parts are not compliant - not_compliant_on :chrome, :internet_explorer, :safari, :firefox do - it 'adds a cookie with options' do + it 'adds a cookie with path' do + browser.goto set_cookie_url + + options = {path: '/set_cookie'} + + browser.cookies.add 'path', 'b', options + cookie = browser.cookies.to_a.find { |e| e[:name] == 'path' } + + expect(cookie).to_not be_nil + 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 expiration' do + browser.goto set_cookie_url + + expires = Time.now + 10_000 + options = {expires: expires} + + browser.cookies.add 'expiration', 'b', options + cookie = browser.cookies.to_a.find { |e| e[:name] == 'expiration' } + + expect(cookie).to_not be_nil + expect(cookie[:name]).to eq 'expiration' + expect(cookie[:value]).to eq 'b' + # a few ms slack + expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i) + end + + bug 'https://bugs.chromium.org/p/chromedriver/issues/detail?id=2727', :chrome, :safari do + it 'adds a cookie with security' do browser.goto set_cookie_url - expires = Time.now + 10_000 - options = {path: '/set_cookie', - secure: true, - expires: expires} + options = {secure: true} - browser.cookies.add 'a', 'b', options - cookie = browser.cookies.to_a.find { |e| e[:name] == 'a' } + browser.cookies.add 'secure', 'b', options + cookie = browser.cookies.to_a.find { |e| e[:name] == 'secure' } expect(cookie).to_not be_nil - expect(cookie[:name]).to eq 'a' + expect(cookie[:name]).to eq 'secure' expect(cookie[:value]).to eq 'b' - - expect(cookie[:path]).to eq '/set_cookie' expect(cookie[:secure]).to be true - - expect(cookie[:expires]).to be_kind_of(Time) - # a few ms slack - expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i) end end not_compliant_on :internet_explorer do it 'removes a cookie' do @@ -96,19 +116,17 @@ browser.cookies.delete 'monster' verify_cookies_count 0 end - bug 'https://code.google.com/p/selenium/issues/detail?id=5487', :safari do - it 'clears all cookies' do - browser.goto set_cookie_url - browser.cookies.add 'foo', 'bar' - verify_cookies_count 2 + it 'clears all cookies' do + browser.goto set_cookie_url + browser.cookies.add 'foo', 'bar' + verify_cookies_count 2 - browser.cookies.clear - verify_cookies_count 0 - end + browser.cookies.clear + verify_cookies_count 0 end end not_compliant_on :internet_explorer do let(:file) { "#{Dir.tmpdir}/cookies" } @@ -122,23 +140,20 @@ it 'saves cookies to file' do expect(IO.read(file)).to eq(browser.cookies.to_a.to_yaml) end end - bug 'https://github.com/mozilla/geckodriver/issues/1000', :firefox do - describe '#load' do - it 'loads cookies from file' do - browser.cookies.clear - browser.cookies.load file - expected = browser.cookies.to_a - actual = YAML.safe_load(IO.read(file), [::Symbol]) + describe '#load' do + it 'loads cookies from file' do + browser.cookies.clear + browser.cookies.load file + expected = browser.cookies.to_a + actual = YAML.safe_load(IO.read(file), [::Symbol]) - # https://code.google.com/p/selenium/issues/detail?id=6834 - expected.each { |cookie| cookie.delete(:expires) } - actual.each { |cookie| cookie.delete(:expires) } + expected.each { |cookie| cookie.delete(:expires) } + actual.each { |cookie| cookie.delete(:expires) } - expect(actual).to eq(expected) - end + expect(actual).to eq(expected) end end end def set_cookie_url