Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: lib/show_me_the_cookies.rb show_me_the_cookies.gemspec
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class ShowMeTheCookies::Poltergeist | ||
def initialize(driver) | ||
@browser = driver.browser | ||
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.values.map(&method(:translate)) | ||
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) | ||
@browser.remove_cookie(name.to_s) | ||
end | ||
|
||
private | ||
|
||
def cookies_hash | ||
@browser.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 |
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,18 @@ | ||
require 'spec_helper' | ||
require 'shared_examples_for_api' | ||
require 'capybara/poltergeist' | ||
|
||
describe "Poltergeist", :type => :request do | ||
before(:each) do | ||
Capybara.current_driver = :poltergeist | ||
end | ||
|
||
describe "the testing rig" do | ||
it "should load the sinatra app" do | ||
visit '/' | ||
page.should have_content("Cookie setter ready") | ||
end | ||
end | ||
|
||
it_behaves_like "the API" | ||
end |