Skip to content

Commit

Permalink
Add Poltergeist support.
Browse files Browse the repository at this point in the history
Conflicts:
	lib/show_me_the_cookies.rb
	show_me_the_cookies.gemspec
  • Loading branch information
mjtko authored and nruth committed Feb 6, 2013
1 parent 8910644 commit 29bebe3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/show_me_the_cookies/poltergeist.rb
@@ -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
1 change: 1 addition & 0 deletions show_me_the_cookies.gemspec
Expand Up @@ -20,4 +20,5 @@ Gem::Specification.new do |s|
s.add_dependency('capybara', '~> 2.0')
s.add_development_dependency 'rspec'
s.add_development_dependency 'sinatra'
s.add_development_dependency 'poltergeist'
end
18 changes: 18 additions & 0 deletions spec/request/poltergeist_spec.rb
@@ -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

0 comments on commit 29bebe3

Please sign in to comment.