-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module ShowMeTheCookies | ||
class Cuprite | ||
def initialize(driver) | ||
@browser = driver.browser | ||
@driver = driver | ||
end | ||
|
||
def get_me_the_cookie(name) | ||
cookie = cookies_hash[name.to_s] | ||
translate(cookie) unless cookie.nil? | ||
end | ||
|
||
def get_me_the_cookies | ||
cookies_hash.map {|name, cookie| translate(cookie) } | ||
end | ||
|
||
def expire_cookies | ||
cookies_hash.each do |name, cookie| | ||
delete_cookie(name) if (cookie.expires rescue nil).nil? | ||
end | ||
end | ||
|
||
def delete_cookie(name) | ||
@driver.remove_cookie(name.to_s) | ||
end | ||
|
||
def create_cookie(name, value, options) | ||
# see: https://github.com/rubycdp/cuprite#manipulating-cookies | ||
@driver.set_cookie(name, value, options) | ||
end | ||
|
||
private | ||
|
||
def cookies_hash | ||
@driver.cookies | ||
end | ||
|
||
def translate(cookie) | ||
{ | ||
:name => cookie.name, | ||
:domain => cookie.domain, | ||
:value => cookie.value, | ||
:expires => (cookie.expires rescue nil), | ||
:path => cookie.path, | ||
:secure => cookie.secure?, | ||
:httponly => cookie.httponly? | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
require 'shared_examples_for_api' | ||
require 'capybara/cuprite' | ||
|
||
RSpec.describe 'Cuprite', type: :feature do | ||
before(:each) do | ||
Capybara.current_driver = :cuprite | ||
end | ||
|
||
describe 'the testing rig' do | ||
it 'should load the sinatra app' do | ||
visit '/' | ||
expect(page).to have_content('Cookie setter ready') | ||
end | ||
end | ||
|
||
describe 'get_me_the_cookie' do | ||
it 'reads httponly option' do | ||
visit '/set_httponly/foo/bar' | ||
expect(get_me_the_cookie('foo')).to include( | ||
name: 'foo', value: 'bar', httponly: true | ||
) | ||
end | ||
end | ||
|
||
it_behaves_like 'the API' | ||
end |