show_me_the_cookies 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -1
- data/README.md +65 -50
- data/lib/show_me_the_cookies.rb +36 -19
- data/lib/show_me_the_cookies/akephalos.rb +61 -0
- data/lib/show_me_the_cookies/rack_test.rb +27 -3
- data/lib/show_me_the_cookies/selenium.rb +13 -2
- data/lib/show_me_the_cookies/version.rb +1 -1
- data/show_me_the_cookies.gemspec +4 -1
- data/spec/app/set_cookie.rb +25 -0
- data/spec/request/akephalos_spec.rb +18 -0
- data/spec/request/rack-test_spec.rb +17 -0
- data/spec/request/selenium_spec.rb +17 -0
- data/spec/shared_examples_for_api.rb +94 -0
- data/spec/spec_helper.rb +9 -0
- metadata +64 -17
- data/.document +0 -5
- data/.rspec +0 -1
- data/LICENSE.txt +0 -20
- data/lib/show_me_the_cookies/culerity.rb +0 -13
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,28 +1,54 @@
|
|
1
|
-
Show me the cookies
|
2
|
-
===================
|
1
|
+
# Show me the cookies
|
3
2
|
|
4
|
-
Some helpers for
|
3
|
+
Some helpers for poking around at your browser's cookies in integration tests.
|
5
4
|
|
6
|
-
|
5
|
+
## API
|
7
6
|
|
8
|
-
|
7
|
+
# puts a string summary of the cookie
|
8
|
+
show_me_the_cookie(cookie_name)
|
9
|
+
|
10
|
+
# returns a hash of the cookie
|
11
|
+
# form: {:name, :domain, :value, :expires, :path}
|
12
|
+
get_me_the_cookie(cookie_name)
|
13
|
+
|
14
|
+
# puts a string summary of all cookies
|
15
|
+
show_me_the_cookies
|
16
|
+
|
17
|
+
# returns an array of cookie hashes
|
18
|
+
# form: [{:name, :domain, :value, :expires, :path}]
|
19
|
+
get_me_the_cookies
|
20
|
+
|
21
|
+
# deletes the named cookie
|
22
|
+
delete_cookie(cookie_name)
|
23
|
+
|
24
|
+
# removes session cookies and expired persistent cookies
|
25
|
+
expire_cookies
|
9
26
|
|
10
|
-
|
11
|
-
==================================
|
27
|
+
## Contributing
|
12
28
|
|
13
|
-
|
29
|
+
If you find this useful, the best way to say thanks is to take a poke around the code and send feedback upstream.
|
14
30
|
|
15
|
-
|
31
|
+
Bugs / requests should go in [Github issues](https://github.com/nruth/show_me_the_cookies/issues).
|
16
32
|
|
17
|
-
|
18
|
-
|
33
|
+
Code contributions should be sent by github pull request, or contact [me](https://github.com/nruth) with a link
|
34
|
+
to your repository branch.
|
35
|
+
|
36
|
+
Patches should be small isolated changes, and testable, or preferably tested.
|
37
|
+
|
38
|
+
More tests are welcome.
|
39
|
+
|
40
|
+
New drivers should be accompanied by a passing API spec.
|
41
|
+
Driver-specific edge cases should not be added to the shared spec unless thought to be of general interest.
|
42
|
+
API spec should not be changed because something doesn't work, fix the driver or make a plugin gem.
|
19
43
|
|
20
|
-
|
21
|
-
-----------
|
22
|
-
gem install show\_me\_the\_cookies, or whatever fits your situation.
|
44
|
+
## Installation
|
23
45
|
|
24
|
-
|
25
|
-
|
46
|
+
Add to your gemfile's test group:
|
47
|
+
|
48
|
+
gem "show\_me\_the\_cookies"
|
49
|
+
|
50
|
+
|
51
|
+
## RSpec
|
26
52
|
|
27
53
|
in step_helper or your support directory:
|
28
54
|
|
@@ -30,9 +56,9 @@ in step_helper or your support directory:
|
|
30
56
|
config.include ShowMeTheCookies, :type => :request
|
31
57
|
end
|
32
58
|
|
33
|
-
Example usage
|
34
|
-
--------------
|
59
|
+
### Example usage
|
35
60
|
|
61
|
+
In a request spec, using [Capybara](https://github.com/jnicklas/capybara)
|
36
62
|
|
37
63
|
it "remember-me is on by default" do
|
38
64
|
member = Member.make
|
@@ -47,7 +73,7 @@ Example usage
|
|
47
73
|
page.should have_content("Dashboard")
|
48
74
|
page.should have_no_content("Login")
|
49
75
|
# Given I close my browser (clearing the session)
|
50
|
-
|
76
|
+
expire_cookies
|
51
77
|
|
52
78
|
# When I come back next time
|
53
79
|
visit dashboard_path
|
@@ -56,20 +82,16 @@ Example usage
|
|
56
82
|
end
|
57
83
|
|
58
84
|
|
59
|
-
Cucumber
|
60
|
-
|
85
|
+
## Cucumber
|
86
|
+
|
61
87
|
|
62
88
|
Install by loading the gem and adding the following to your stepdefs or support files
|
63
89
|
|
64
90
|
World(ShowMeTheCookies)
|
65
|
-
Before('@announce') do
|
66
|
-
@announce = true
|
67
|
-
end
|
68
91
|
|
69
|
-
|
70
|
-
-------------
|
92
|
+
### Features
|
71
93
|
|
72
|
-
@javascript
|
94
|
+
@javascript
|
73
95
|
Scenario: remembering users so they don't have to log in again for a while
|
74
96
|
Given I am a site member
|
75
97
|
When I go to the dashboard
|
@@ -80,7 +102,7 @@ Example Usage
|
|
80
102
|
And I return to the dashboard url
|
81
103
|
Then I should see "Welcome back"
|
82
104
|
|
83
|
-
@rack_test
|
105
|
+
@rack_test
|
84
106
|
Scenario: don't remember users across browser restarts if they don't want it
|
85
107
|
Given I am a site member
|
86
108
|
When I go to the dashboard
|
@@ -92,36 +114,29 @@ Example Usage
|
|
92
114
|
Then I should see the log-in screen
|
93
115
|
|
94
116
|
|
95
|
-
|
96
|
-
------------
|
97
|
-
|
98
|
-
for example cookie_steps.rb
|
117
|
+
### Stepdefs
|
99
118
|
|
100
119
|
Then /^show me the cookies!$/ do
|
101
|
-
|
120
|
+
puts inspect_cookies
|
102
121
|
end
|
103
122
|
|
104
|
-
Given /^I close my browser \(clearing the
|
105
|
-
|
123
|
+
Given /^I close my browser \(clearing the session\)$/ do
|
124
|
+
expire_cookies
|
106
125
|
end
|
107
126
|
|
108
|
-
|
109
|
-
|
127
|
+
## Addendum
|
128
|
+
|
129
|
+
At time of writing, Rails session cookies looked something like '\_appname\_session',
|
130
|
+
and can be found with browser resource tracker (e.g. firebug) or using Rails 3's
|
131
|
+
Rails.application.config.session_options[:key]
|
110
132
|
|
111
|
-
|
133
|
+
## History, Credits, and Acknowledgements
|
112
134
|
|
113
|
-
|
135
|
+
Original development took place when testing Devise 0.1's "Remember me" functionality under rails 2.3.x with capybara rack-test and/or selenium.
|
114
136
|
|
115
|
-
|
116
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
117
|
-
* Fork the project
|
118
|
-
* Start a feature/bugfix branch
|
119
|
-
* Commit and push until you are happy with your contribution
|
120
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
121
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
137
|
+
Initial release as a gist [here](https://gist.github.com/484787), early development sponsored by [Medify](http://www.medify.co.uk).
|
122
138
|
|
123
|
-
|
124
|
-
============
|
125
|
-
Copyright (c) 2011 Nicholas Rutherford. See LICENSE.txt for
|
126
|
-
further details.
|
139
|
+
Contributions outside of github have been made by:
|
127
140
|
|
141
|
+
* [Leandro Pedroni](https://github.com/ilpoldo) -- Rails 3 session cookie detection (no longer in the code but present in readme)
|
142
|
+
* [Matthew Nielsen](https://github.com/xunker) -- added culerity support & encouraged gem release
|
data/lib/show_me_the_cookies.rb
CHANGED
@@ -1,34 +1,51 @@
|
|
1
1
|
module ShowMeTheCookies
|
2
|
-
|
3
|
-
require 'show_me_the_cookies/culerity'
|
4
2
|
require 'show_me_the_cookies/rack_test'
|
5
3
|
require 'show_me_the_cookies/selenium'
|
4
|
+
require 'show_me_the_cookies/akephalos'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
raise "unsupported driver, use rack::test, selenium/webdriver or culerity"
|
18
|
-
end
|
6
|
+
# puts a string summary of the cookie
|
7
|
+
def show_me_the_cookie(cookie_name)
|
8
|
+
puts "#{cookie_name}: #{get_me_the_cookie(cookie_name).inspect}"
|
9
|
+
end
|
10
|
+
|
11
|
+
# returns a hash of the cookie
|
12
|
+
# form: {:name, :domain, :value, :expires, :path}
|
13
|
+
def get_me_the_cookie(cookie_name)
|
14
|
+
current_driver_adapter.get_me_the_cookie(cookie_name)
|
19
15
|
end
|
20
16
|
|
17
|
+
# puts a string summary of all cookies
|
21
18
|
def show_me_the_cookies
|
22
|
-
|
19
|
+
puts "Cookies: #{get_me_the_cookies.inspect}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# returns an array of cookie hashes
|
23
|
+
# form: [{:name, :domain, :value, :expires, :path}]
|
24
|
+
def get_me_the_cookies
|
25
|
+
current_driver_adapter.get_me_the_cookies
|
23
26
|
end
|
24
27
|
|
28
|
+
# deletes the named cookie
|
25
29
|
def delete_cookie(cookie_name)
|
26
|
-
announce current_driver_adapter.show_me_the_cookies if @announce
|
27
30
|
current_driver_adapter.delete_cookie(cookie_name)
|
28
|
-
|
29
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
# removes session cookies and expired persistent cookies
|
34
|
+
def expire_cookies
|
35
|
+
current_driver_adapter.expire_cookies
|
30
36
|
end
|
31
37
|
|
32
38
|
private
|
33
|
-
|
39
|
+
def adapters
|
40
|
+
@@drivers ||= {
|
41
|
+
:selenium => ShowMeTheCookies::Selenium,
|
42
|
+
:rack_test => ShowMeTheCookies::RackTest,
|
43
|
+
:akephalos => ShowMeTheCookies::Akephalos
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def current_driver_adapter
|
48
|
+
adapter = adapters[Capybara.current_driver] || raise("Unsupported driver #{driver}, use one of #{drivers.keys}")
|
49
|
+
adapter.new(Capybara.current_session.driver)
|
50
|
+
end
|
34
51
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class ShowMeTheCookies::Akephalos
|
2
|
+
def initialize(driver)
|
3
|
+
@driver = driver
|
4
|
+
@browser = driver.browser
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_me_the_cookie(cookie_name)
|
8
|
+
cookie = get_me_the_raw_cookie(cookie_name)
|
9
|
+
cookie && _translate_cookie(cookie)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_me_the_cookies
|
13
|
+
cookies.map {|c| _translate_cookie(c) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete_cookie(cookie_name)
|
17
|
+
cookie = get_me_the_raw_cookie(cookie_name)
|
18
|
+
@browser.cookies.delete(cookie) if cookie
|
19
|
+
end
|
20
|
+
|
21
|
+
def expire_cookies
|
22
|
+
cookies.each do |c|
|
23
|
+
# it drops expired cookies for us, so just remove session cookies
|
24
|
+
# we don't care that it's a badly decoded java date object, just that it's present
|
25
|
+
delete_cookie(c.name) if c.expires == nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def get_me_the_raw_cookie(cookie_name)
|
31
|
+
@browser.cookies[cookie_name.to_s]
|
32
|
+
end
|
33
|
+
|
34
|
+
def cookies
|
35
|
+
@browser.cookies.to_a
|
36
|
+
end
|
37
|
+
|
38
|
+
def _translate_cookie(cookie)
|
39
|
+
c = {:name => cookie.name.to_s,
|
40
|
+
:domain => cookie.domain,
|
41
|
+
:value => cookie.value,
|
42
|
+
:expires => cookie.expires,
|
43
|
+
:path => cookie.path
|
44
|
+
}
|
45
|
+
# Akephalos2 returns a java.util.Date or somesuch that looks like this, so we
|
46
|
+
# remove it if necessary
|
47
|
+
#
|
48
|
+
# {:value=>"249920784.1048820629.1318215489.1318215489.1318215489.1",
|
49
|
+
# :path=>"/",
|
50
|
+
# :domain=>"gw.lvh.me",
|
51
|
+
# :name=>"__utma",
|
52
|
+
# :expires=>
|
53
|
+
# #<DRb::DRbUnknown:0x11d7825d0
|
54
|
+
# @buf=
|
55
|
+
# "\004\bU:\031Java::JavaUtil::Date\"3\254?sr\000\016java.util.Datehj\201\001KYt\031\003\000\000xpw\b\000\000\001A\233&\250\200x",
|
56
|
+
# @name="Java::">},
|
57
|
+
#
|
58
|
+
c[:expires] = nil if c[:expires].class.name == "DRb::DRbUnknown"
|
59
|
+
c
|
60
|
+
end
|
61
|
+
end
|
@@ -3,12 +3,24 @@ class ShowMeTheCookies::RackTest
|
|
3
3
|
@rack_test_driver = rack_test_driver
|
4
4
|
end
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def get_me_the_cookie(cookie_name)
|
7
|
+
_translate_cookie cookies.select {|c| c.name == cookie_name}.first
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_me_the_cookies
|
11
|
+
cookies.map {|c| _translate_cookie(c) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def expire_cookies
|
15
|
+
cookies.reject! do |existing_cookie|
|
16
|
+
# See http://j-ferguson.com/testing/bdd/hacking-capybara-cookies/
|
17
|
+
# catch session cookies/no expiry (nil) and past expiry (true)
|
18
|
+
existing_cookie.expired? != false
|
19
|
+
end
|
8
20
|
end
|
9
21
|
|
10
22
|
def delete_cookie(cookie_name)
|
11
|
-
|
23
|
+
cookies.reject! do |existing_cookie|
|
12
24
|
existing_cookie.name.downcase == cookie_name
|
13
25
|
end
|
14
26
|
end
|
@@ -17,4 +29,16 @@ private
|
|
17
29
|
def cookie_jar
|
18
30
|
@rack_test_driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
|
19
31
|
end
|
32
|
+
|
33
|
+
def cookies
|
34
|
+
cookie_jar.instance_variable_get(:@cookies)
|
35
|
+
end
|
36
|
+
|
37
|
+
def _translate_cookie(cookie)
|
38
|
+
{:name => cookie.name,
|
39
|
+
:domain => cookie.domain,
|
40
|
+
:value => cookie.value,
|
41
|
+
:expires => cookie.expires,
|
42
|
+
:path => cookie.path}
|
43
|
+
end
|
20
44
|
end
|
@@ -4,8 +4,19 @@ class ShowMeTheCookies::Selenium
|
|
4
4
|
self
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
@browser.manage.
|
7
|
+
def get_me_the_cookie(cookie_name)
|
8
|
+
@browser.manage.cookie_named(cookie_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_me_the_cookies
|
12
|
+
@browser.manage.all_cookies
|
13
|
+
end
|
14
|
+
|
15
|
+
def expire_cookies
|
16
|
+
cookies_to_delete = @browser.manage.all_cookies.each do |c|
|
17
|
+
# we don't need to catch the expired cookies here, the browser will do it for us (duh!)
|
18
|
+
@browser.manage.delete_cookie(c[:name]) if c[:expires] == nil
|
19
|
+
end
|
9
20
|
end
|
10
21
|
|
11
22
|
def delete_cookie(cookie_name)
|
data/show_me_the_cookies.gemspec
CHANGED
@@ -17,5 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
|
-
s.add_dependency('capybara', '~> 1.0
|
20
|
+
s.add_dependency('capybara', '~> 1.0')
|
21
|
+
s.add_development_dependency 'rspec'
|
22
|
+
s.add_development_dependency 'sinatra'
|
23
|
+
s.add_development_dependency 'akephalos2'
|
21
24
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
|
3
|
+
get '/' do
|
4
|
+
"Cookie setter ready"
|
5
|
+
end
|
6
|
+
|
7
|
+
get '/set/:key/:value' do
|
8
|
+
response.set_cookie params[:key], {:value => params[:value], :path => '/'}
|
9
|
+
"Setting #{params[:key]}=#{params[:value]}"
|
10
|
+
end
|
11
|
+
|
12
|
+
get '/delete/:key' do
|
13
|
+
response.delete_cookie params[:key], :path => '/'
|
14
|
+
"Deleting #{params[:key]}"
|
15
|
+
end
|
16
|
+
|
17
|
+
get '/set_persistent/:key/:value' do
|
18
|
+
response.set_cookie params[:key], {:value => params[:value], :path => '/', :expires => Time.now + 60*60*24*365}
|
19
|
+
"Setting #{params[:key]}=#{params[:value]}"
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/set_stale/:key/:value' do
|
23
|
+
response.set_cookie params[:key], {:value => params[:value], :path => '/', :expires => Time.now}
|
24
|
+
"Setting #{params[:key]}=#{params[:value]}"
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared_examples_for_api'
|
3
|
+
require 'akephalos'
|
4
|
+
|
5
|
+
describe "Akephalos (HTMLUnit)", :type => :request do
|
6
|
+
before(:each) do
|
7
|
+
Capybara.current_driver = :akephalos
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "the testing rig" do
|
11
|
+
it "should load the sinatra app" do
|
12
|
+
visit '/'
|
13
|
+
page.should have_content("Cookie setter ready")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_behaves_like "the API"
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared_examples_for_api'
|
3
|
+
|
4
|
+
describe "RackTest", :type => :request do
|
5
|
+
before(:each) do
|
6
|
+
Capybara.current_driver = :rack_test
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "the testing rig" do
|
10
|
+
it "should load the sinatra app" do
|
11
|
+
visit '/'
|
12
|
+
page.should have_content("Cookie setter ready")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it_behaves_like "the API"
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared_examples_for_api'
|
3
|
+
|
4
|
+
describe "Selenium Webdriver", :type => :request do
|
5
|
+
before(:each) do
|
6
|
+
Capybara.current_driver = :selenium
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "the testing rig" do
|
10
|
+
it "should load the sinatra app" do
|
11
|
+
visit '/'
|
12
|
+
page.should have_content("Cookie setter ready")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it_behaves_like "the API"
|
17
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
shared_examples "the API" do
|
2
|
+
def cookies_should_contain(key, value)
|
3
|
+
key_present = get_me_the_cookies.any? {|c| c[:name] == key}
|
4
|
+
value_present = get_me_the_cookies.any? {|c| c[:value] == value}
|
5
|
+
msg = "Cookie not found: #{key}=#{value} in #{get_me_the_cookies.inspect}"
|
6
|
+
(key_present and value_present).should be_true, msg
|
7
|
+
end
|
8
|
+
|
9
|
+
def cookies_should_not_contain(key, value)
|
10
|
+
key_present = get_me_the_cookies.any? {|c| c[:name] == key}
|
11
|
+
value_present = get_me_the_cookies.any? {|c| c[:value] == value}
|
12
|
+
msg = "Unwanted cookie found: #{key}=#{value} in #{get_me_the_cookies.inspect}"
|
13
|
+
(key_present and value_present).should be_false, msg
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "for getting cookie hashes" do
|
17
|
+
describe "get_me_the_cookie" do
|
18
|
+
it "returns the cookie hash" do
|
19
|
+
visit '/set/foo/bar'
|
20
|
+
get_me_the_cookie('foo').should include(:name => "foo", :value => "bar", :expires => nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "get_me_the_cookies" do
|
25
|
+
it "returns an array of standardised cookie hashes" do
|
26
|
+
visit '/set/foo/bar'
|
27
|
+
page.should have_content("Setting foo=bar")
|
28
|
+
get_me_the_cookies.first.should include(:name => "foo", :value => "bar", :expires => nil)
|
29
|
+
visit '/set/myopic/mice'
|
30
|
+
get_me_the_cookies.length.should be(2)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "for viewing cookies" do
|
36
|
+
describe "show_me_the_cookie" do
|
37
|
+
it "inspects the cookie hash" do
|
38
|
+
visit '/set/foo/bar'
|
39
|
+
should_receive(:puts).with("foo: "+get_me_the_cookie('foo').inspect)
|
40
|
+
show_me_the_cookie('foo')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "show_me_the_cookies" do
|
45
|
+
it "returns a string representation of the get_me_the_cookies hash" do
|
46
|
+
visit '/set/foo/bar'
|
47
|
+
visit '/set/myopic/mice'
|
48
|
+
should_receive(:puts).with("Cookies: "+get_me_the_cookies.inspect)
|
49
|
+
show_me_the_cookies
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "for manipulating cookies" do
|
55
|
+
describe "delete_cookie(cookie_name)" do
|
56
|
+
it "deletes a k/v pair from the session cookie" do
|
57
|
+
visit '/set/choc/milk'
|
58
|
+
visit '/set/extras/hazlenut'
|
59
|
+
cookies_should_contain('extras', 'hazlenut')
|
60
|
+
cookies_should_contain('choc', 'milk')
|
61
|
+
|
62
|
+
visit '/delete/choc'
|
63
|
+
page.should have_content("Deleting choc")
|
64
|
+
cookies_should_contain('extras', 'hazlenut')
|
65
|
+
cookies_should_not_contain('choc', 'milk')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "expire_cookies" do
|
70
|
+
it "removes cookies without expiry times set" do
|
71
|
+
visit '/set/choc/milk'
|
72
|
+
visit '/set/extras/hazlenut'
|
73
|
+
visit '/set/myopic/mice'
|
74
|
+
cookies_should_contain('choc', 'milk')
|
75
|
+
cookies_should_contain('extras', 'hazlenut')
|
76
|
+
cookies_should_contain('myopic','mice')
|
77
|
+
|
78
|
+
expire_cookies
|
79
|
+
cookies_should_not_contain('choc', 'milk')
|
80
|
+
cookies_should_not_contain('extras', 'hazlenut')
|
81
|
+
cookies_should_not_contain('myopic','mice')
|
82
|
+
end
|
83
|
+
|
84
|
+
it "removes cookies which are past their expiry time, or the browser does" do
|
85
|
+
visit '/set_stale/rotting/fruit'
|
86
|
+
visit '/set_persistent/fresh/vegetables'
|
87
|
+
|
88
|
+
expire_cookies
|
89
|
+
cookies_should_not_contain('rotting','fruit')
|
90
|
+
cookies_should_contain('fresh','vegetables')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: show_me_the_cookies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.2.2
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nicholas Rutherford
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-10-16 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: capybara
|
@@ -26,14 +25,55 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
28
|
+
hash: 15
|
30
29
|
segments:
|
31
30
|
- 1
|
32
31
|
- 0
|
33
|
-
|
34
|
-
version: 1.0.0
|
32
|
+
version: "1.0"
|
35
33
|
type: :runtime
|
36
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: sinatra
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: akephalos2
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
37
77
|
description: Cookie manipulation for Capybara drivers -- viewing, deleting, ...
|
38
78
|
email:
|
39
79
|
- nick.rutherford@gmail.com
|
@@ -44,20 +84,22 @@ extensions: []
|
|
44
84
|
extra_rdoc_files: []
|
45
85
|
|
46
86
|
files:
|
47
|
-
- .document
|
48
87
|
- .gitignore
|
49
|
-
- .rspec
|
50
88
|
- Gemfile
|
51
|
-
- LICENSE.txt
|
52
89
|
- README.md
|
53
90
|
- Rakefile
|
54
91
|
- lib/show_me_the_cookies.rb
|
55
|
-
- lib/show_me_the_cookies/
|
92
|
+
- lib/show_me_the_cookies/akephalos.rb
|
56
93
|
- lib/show_me_the_cookies/rack_test.rb
|
57
94
|
- lib/show_me_the_cookies/selenium.rb
|
58
95
|
- lib/show_me_the_cookies/version.rb
|
59
96
|
- show_me_the_cookies.gemspec
|
60
|
-
|
97
|
+
- spec/app/set_cookie.rb
|
98
|
+
- spec/request/akephalos_spec.rb
|
99
|
+
- spec/request/rack-test_spec.rb
|
100
|
+
- spec/request/selenium_spec.rb
|
101
|
+
- spec/shared_examples_for_api.rb
|
102
|
+
- spec/spec_helper.rb
|
61
103
|
homepage: https://github.com/nruth/show_me_the_cookies
|
62
104
|
licenses:
|
63
105
|
- MIT
|
@@ -87,9 +129,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
129
|
requirements: []
|
88
130
|
|
89
131
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
132
|
+
rubygems_version: 1.8.10
|
91
133
|
signing_key:
|
92
134
|
specification_version: 3
|
93
135
|
summary: Cookie manipulation for Capybara drivers
|
94
|
-
test_files:
|
95
|
-
|
136
|
+
test_files:
|
137
|
+
- spec/app/set_cookie.rb
|
138
|
+
- spec/request/akephalos_spec.rb
|
139
|
+
- spec/request/rack-test_spec.rb
|
140
|
+
- spec/request/selenium_spec.rb
|
141
|
+
- spec/shared_examples_for_api.rb
|
142
|
+
- spec/spec_helper.rb
|
data/.document
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/LICENSE.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2011 Nicholas Rutherford
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class ShowMeTheCookies::Culerity
|
2
|
-
def initialize(driver)
|
3
|
-
@browser = driver.browser
|
4
|
-
end
|
5
|
-
|
6
|
-
def show_me_the_cookies
|
7
|
-
@browser.cookies.send_remote(:inspect)
|
8
|
-
end
|
9
|
-
|
10
|
-
def delete_cookie(cookie_name)
|
11
|
-
@browser.remove_cookie('localhost', cookie_name)
|
12
|
-
end
|
13
|
-
end
|