Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Poltergeist support.

Conflicts:
	lib/show_me_the_cookies.rb
	show_me_the_cookies.gemspec
  • Loading branch information...
commit 29bebe397e1857768b46ea9c1a14c9ef03b3e043 1 parent 8910644
@mjtko mjtko authored committed
View
42 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
View
1  show_me_the_cookies.gemspec
@@ -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
View
18 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
Please sign in to comment.
Something went wrong with that request. Please try again.