show_me_the_cookies 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -1
- data/lib/show_me_the_cookies.rb +3 -1
- data/lib/show_me_the_cookies/adapters/poltergeist.rb +39 -37
- data/lib/show_me_the_cookies/adapters/rack_test.rb +48 -41
- data/lib/show_me_the_cookies/adapters/selenium.rb +36 -32
- data/lib/show_me_the_cookies/adapters/selenium_chrome.rb +11 -0
- data/lib/show_me_the_cookies/adapters/webkit.rb +47 -45
- data/lib/show_me_the_cookies/version.rb +3 -1
- data/show_me_the_cookies.gemspec +2 -1
- data/spec/app/set_cookie.rb +5 -0
- data/spec/drivers/poltergeist_spec.rb +14 -5
- data/spec/drivers/rack-test_spec.rb +15 -6
- data/spec/drivers/selenium_chrome_spec.rb +28 -0
- data/spec/drivers/selenium_spec.rb +9 -7
- data/spec/drivers/unknown_driver_spec.rb +5 -4
- data/spec/drivers/webkit_spec.rb +6 -5
- data/spec/shared_examples_for_api.rb +11 -12
- data/spec/spec_helper.rb +7 -7
- metadata +49 -8
- checksums.yaml +0 -15
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Show me the cookies
|
2
2
|
|
3
|
-
[![Build Status](https://semaphoreapp.com/api/v1/projects/9a0dc444-fd04-4187-95a7-7a07abecbad7/201807/shields_badge.png)](https://semaphoreapp.com/nruth/show_me_the_cookies) [![Gem Version](https://badge.fury.io/rb/show_me_the_cookies.svg)](http://badge.fury.io/rb/show_me_the_cookies)
|
3
|
+
[![Build Status](https://semaphoreapp.com/api/v1/projects/9a0dc444-fd04-4187-95a7-7a07abecbad7/201807/shields_badge.png)](https://semaphoreapp.com/nruth/show_me_the_cookies) [![Gem Version](https://badge.fury.io/rb/show_me_the_cookies.svg)](http://badge.fury.io/rb/show_me_the_cookies) [![Inline docs](http://inch-ci.org/github/nruth/show_me_the_cookies.svg?branch=master)](http://inch-ci.org/github/nruth/show_me_the_cookies) [![endorse](https://api.coderwall.com/nruth/endorsecount.png)](https://coderwall.com/nruth)
|
4
4
|
|
5
5
|
Some helpers for poking around at your Capybara driven browser's cookies in integration tests.
|
6
6
|
|
@@ -28,6 +28,12 @@ You may add new drivers for your application by implementing an adapter class an
|
|
28
28
|
|
29
29
|
# removes session cookies and expired persistent cookies
|
30
30
|
expire_cookies
|
31
|
+
|
32
|
+
# creates a cookie
|
33
|
+
create_cookie(cookie_name, cookie_value)
|
34
|
+
|
35
|
+
# creates a cookie for the path or domain
|
36
|
+
create_cookie(cookie_name, cookie_value, :path => "...", :domain => "...")
|
31
37
|
|
32
38
|
|
33
39
|
## Installation
|
data/lib/show_me_the_cookies.rb
CHANGED
@@ -2,13 +2,14 @@ module ShowMeTheCookies
|
|
2
2
|
require 'show_me_the_cookies/adapters/rack_test'
|
3
3
|
require 'show_me_the_cookies/adapters/poltergeist'
|
4
4
|
require 'show_me_the_cookies/adapters/selenium'
|
5
|
+
require 'show_me_the_cookies/adapters/selenium_chrome'
|
5
6
|
require 'show_me_the_cookies/adapters/webkit'
|
6
7
|
|
7
8
|
@adapters = {}
|
8
9
|
class << self
|
9
10
|
attr_reader :adapters
|
10
11
|
|
11
|
-
# Register your own capybara-driver cookie adapter.
|
12
|
+
# Register your own capybara-driver cookie adapter.
|
12
13
|
# Use the same name as the one Capybara does to identify that driver.
|
13
14
|
# Implement the interface of spec/shared_examples_for_api, as seen in lib/show_me_the_cookies/drivers
|
14
15
|
def register_adapter(driver, adapter)
|
@@ -18,6 +19,7 @@ module ShowMeTheCookies
|
|
18
19
|
|
19
20
|
# to register your own adapter/driver do this in your test setup code somewhere e.g. spec/support
|
20
21
|
register_adapter(:selenium, ShowMeTheCookies::Selenium)
|
22
|
+
register_adapter(:selenium_chrome, ShowMeTheCookies::SeleniumChrome)
|
21
23
|
register_adapter(:rack_test, ShowMeTheCookies::RackTest)
|
22
24
|
register_adapter(:poltergeist, ShowMeTheCookies::Poltergeist)
|
23
25
|
register_adapter(:webkit, ShowMeTheCookies::Webkit)
|
@@ -1,48 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module ShowMeTheCookies
|
2
|
+
class Poltergeist
|
3
|
+
def initialize(driver)
|
4
|
+
@browser = driver.browser
|
5
|
+
@driver = driver
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def get_me_the_cookie(name)
|
9
|
+
cookie = cookies_hash[name.to_s]
|
10
|
+
translate(cookie) unless cookie.nil?
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def get_me_the_cookies
|
14
|
+
cookies_hash.values.map(&method(:translate))
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def expire_cookies
|
18
|
+
cookies_hash.each do |name, cookie|
|
19
|
+
delete_cookie(name) if (cookie.expires rescue nil).nil?
|
20
|
+
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def delete_cookie(name)
|
24
|
+
@browser.remove_cookie(name.to_s)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def create_cookie(name, value, options)
|
28
|
+
# see: https://github.com/jonleighton/poltergeist#manipulating-cookies
|
29
|
+
@driver.set_cookie(name, value, options)
|
30
|
+
end
|
30
31
|
|
31
|
-
private
|
32
|
+
private
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def cookies_hash
|
35
|
+
@browser.cookies
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
def translate(cookie)
|
39
|
+
{
|
40
|
+
:name => cookie.name,
|
41
|
+
:domain => cookie.domain,
|
42
|
+
:value => cookie.value,
|
43
|
+
:expires => (cookie.expires rescue nil),
|
44
|
+
:path => cookie.path,
|
45
|
+
:secure => cookie.secure?,
|
46
|
+
:httponly => cookie.httponly?
|
47
|
+
}
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
@@ -1,53 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module ShowMeTheCookies
|
2
|
+
class RackTest
|
3
|
+
def initialize(rack_test_driver)
|
4
|
+
@rack_test_driver = rack_test_driver
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def get_me_the_cookie(cookie_name)
|
8
|
+
found = cookies.select {|c| c.name == cookie_name}
|
9
|
+
found.empty? ? nil : _translate_cookie(found.first)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def get_me_the_cookies
|
13
|
+
cookies.map {|c| _translate_cookie(c) }
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def expire_cookies
|
17
|
+
cookies.reject! do |existing_cookie|
|
18
|
+
# See http://j-ferguson.com/testing/bdd/hacking-capybara-cookies/
|
19
|
+
# catch session cookies/no expiry (nil) and past expiry (true)
|
20
|
+
existing_cookie.expired? != false
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def delete_cookie(cookie_name)
|
25
|
+
cookies.reject! do |existing_cookie|
|
26
|
+
existing_cookie.name.downcase == cookie_name.to_s
|
27
|
+
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
def create_cookie(name, value, options)
|
31
|
+
cookie_raw = "#{name}=#{Rack::Utils.escape(value)}"
|
32
|
+
(cookie_raw = "#{cookie_raw}; domain=#{options[:domain]}") if options.has_key?(:domain)
|
33
|
+
(cookie_raw = "#{cookie_raw}; path=#{options[:path]}") if options.has_key?(:path)
|
34
|
+
cookie_jar.merge(cookie_raw)
|
35
|
+
end
|
35
36
|
|
36
|
-
private
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
private
|
38
|
+
def cookie_jar
|
39
|
+
@rack_test_driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def cookies
|
43
|
+
cookie_jar.instance_variable_get(:@cookies)
|
44
|
+
end
|
45
|
+
|
46
|
+
def httponly?(cookie)
|
47
|
+
(cookie.instance_variable_get(:@options) || {}).has_key?("HttpOnly")
|
48
|
+
end
|
44
49
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def _translate_cookie(cookie)
|
51
|
+
{:name => cookie.name,
|
52
|
+
:domain => cookie.domain,
|
53
|
+
:value => cookie.value,
|
54
|
+
:expires => cookie.expires,
|
55
|
+
:path => cookie.path,
|
56
|
+
:secure => cookie.secure?,
|
57
|
+
:httponly => httponly?(cookie)}
|
58
|
+
end
|
52
59
|
end
|
53
60
|
end
|
@@ -1,45 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module ShowMeTheCookies
|
2
|
+
class Selenium
|
3
|
+
def initialize(driver)
|
4
|
+
@browser = driver.browser
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def get_me_the_cookie(cookie_name)
|
8
|
+
@browser.manage.cookie_named(cookie_name)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def get_me_the_cookies
|
12
|
+
@browser.manage.all_cookies
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def expire_cookies
|
16
|
+
@browser.manage.all_cookies.each do |c|
|
17
|
+
# we don't need to catch the expired cookies here
|
18
|
+
# the browser will do it for us (duh!)
|
19
|
+
@browser.manage.delete_cookie(c[:name]) if c[:expires].nil?
|
20
|
+
end
|
18
21
|
end
|
19
|
-
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
def delete_cookie(cookie_name)
|
24
|
+
@browser.manage.delete_cookie(cookie_name)
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def create_cookie(cookie_name, cookie_value, options)
|
28
|
+
unless on_the_page?
|
29
|
+
fail(
|
30
|
+
SeleniumSiteNotVisitedError,
|
31
|
+
"Can't set a cookie on about:blank. Visit a url in your app first."
|
32
|
+
)
|
33
|
+
end
|
34
|
+
@browser.manage.add_cookie(
|
35
|
+
{ name: cookie_name, value: cookie_value }.merge(options)
|
29
36
|
)
|
30
37
|
end
|
31
|
-
@browser.manage.add_cookie({name: cookie_name, value: cookie_value}.merge(options))
|
32
|
-
end
|
33
38
|
|
34
|
-
|
39
|
+
protected
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
def on_the_page?
|
42
|
+
current_url = @browser.current_url
|
43
|
+
current_url && current_url != '' && current_url != 'about:blank'
|
44
|
+
end
|
39
45
|
end
|
40
46
|
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
class ShowMeTheCookies::Selenium::SiteNotVisitedError < StandardError
|
47
|
+
class SeleniumSiteNotVisitedError < StandardError
|
48
|
+
end
|
45
49
|
end
|
@@ -1,58 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module ShowMeTheCookies
|
2
|
+
class Webkit
|
3
|
+
def initialize(driver)
|
4
|
+
@browser = driver.browser
|
5
|
+
@driver = driver
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def get_me_the_cookie(name)
|
9
|
+
cookie = cookie_jar.find(name)
|
10
|
+
translate(cookie) unless cookie.nil?
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def get_me_the_cookies
|
14
|
+
cookies.each.map(&method(:translate))
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def expire_cookies
|
18
|
+
cookies.each do |cookie|
|
19
|
+
delete_cookie(cookie.name) if cookie.expires.nil?
|
20
|
+
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# Since QTWebkit doesn't seem to offer deletion, clearing all and re-setting the rest seems to be it
|
24
|
+
def delete_cookie(name)
|
25
|
+
old_cookies = cookies
|
26
|
+
@browser.clear_cookies
|
27
|
+
old_cookies.each do |cookie|
|
28
|
+
@browser.set_cookie(cookie) unless cookie.name == name.to_s
|
29
|
+
end
|
28
30
|
end
|
29
|
-
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def create_cookie(name, value, options)
|
33
|
+
host = options.delete(:domain) || (Capybara.app_host ? URI(Capybara.app_host).host : '127.0.0.1')
|
34
|
+
puts "Webkit create_cookie options not supported: #{options.inspect}" if options && (options != {})
|
35
|
+
@browser.set_cookie("#{name}=#{value}; domain=#{host}")
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
+
private
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
# see https://github.com/thoughtbot/capybara-webkit/blob/master/lib/capybara/webkit/cookie_jar.rb
|
41
|
+
def cookie_jar
|
42
|
+
@driver.cookies
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def cookies
|
46
|
+
@browser.get_cookies.map { |c| WEBrick::Cookie.parse_set_cookie(c) }
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
def translate(cookie)
|
50
|
+
{
|
51
|
+
:name => cookie.name,
|
52
|
+
:domain => cookie.domain,
|
53
|
+
:value => cookie.value,
|
54
|
+
:expires => (cookie.expires rescue nil),
|
55
|
+
:path => cookie.path,
|
56
|
+
:secure => cookie.secure.nil? ? false : true
|
57
|
+
}
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
data/show_me_the_cookies.gemspec
CHANGED
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.add_dependency('capybara', '~> 2.0')
|
21
21
|
s.add_development_dependency 'rake' # for releases
|
22
|
-
s.add_development_dependency 'rspec' # for testing
|
22
|
+
s.add_development_dependency 'rspec', '~> 3.0' # for testing
|
23
23
|
s.add_development_dependency 'sinatra' # for testing
|
24
24
|
s.add_development_dependency 'poltergeist' # for testing
|
25
25
|
s.add_development_dependency 'selenium-webdriver' # removed from capy2 deps
|
26
|
+
s.add_development_dependency 'chromedriver-helper' # chromedriver installer
|
26
27
|
s.add_development_dependency 'capybara-webkit' # for testing
|
27
28
|
end
|
data/spec/app/set_cookie.rb
CHANGED
@@ -32,3 +32,8 @@ get '/set_with_domain/:key/:value' do
|
|
32
32
|
response.set_cookie params[:key], {:value => params[:value], :path => '/', :domain => '.lvh.me'}
|
33
33
|
"Setting #{params[:key]}=#{params[:value]}"
|
34
34
|
end
|
35
|
+
|
36
|
+
get '/set_httponly/:key/:value' do
|
37
|
+
response.set_cookie params[:key], {:value => params[:value], :path => '/', :httponly => true}
|
38
|
+
"Setting httponly #{params[:key]}=#{params[:value]}"
|
39
|
+
end
|
@@ -2,17 +2,26 @@ require 'spec_helper'
|
|
2
2
|
require 'shared_examples_for_api'
|
3
3
|
require 'capybara/poltergeist'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe 'Poltergeist', type: :feature do
|
6
6
|
before(:each) do
|
7
7
|
Capybara.current_driver = :poltergeist
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
10
|
+
describe 'the testing rig' do
|
11
|
+
it 'should load the sinatra app' do
|
12
12
|
visit '/'
|
13
|
-
page.
|
13
|
+
expect(page).to have_content('Cookie setter ready')
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
describe 'get_me_the_cookie' do
|
18
|
+
it 'reads httponly option' do
|
19
|
+
visit '/set_httponly/foo/bar'
|
20
|
+
expect(get_me_the_cookie('foo')).to include(
|
21
|
+
name: 'foo', value: 'bar', httponly: true
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it_behaves_like 'the API'
|
18
27
|
end
|
@@ -1,17 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'shared_examples_for_api'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'RackTest', type: :feature do
|
5
5
|
before(:each) do
|
6
6
|
Capybara.current_driver = :rack_test
|
7
7
|
end
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
9
|
+
describe 'the testing rig' do
|
10
|
+
it 'should load the sinatra app' do
|
11
11
|
visit '/'
|
12
|
-
page.
|
12
|
+
expect(page).to have_content('Cookie setter ready')
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
describe 'get_me_the_cookie' do
|
17
|
+
it 'reads httponly option' do
|
18
|
+
visit '/set_httponly/foo/bar'
|
19
|
+
expect(get_me_the_cookie('foo')).to include(
|
20
|
+
name: 'foo', value: 'bar', httponly: true
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it_behaves_like 'the API'
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared_examples_for_api'
|
3
|
+
|
4
|
+
Capybara.register_driver :selenium_chrome do |app|
|
5
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
describe 'Selenium Webdriver Chrome', type: :feature do
|
10
|
+
before(:each) do
|
11
|
+
Capybara.current_driver = :selenium_chrome
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'the testing rig' do
|
15
|
+
it 'should load the sinatra app' do
|
16
|
+
visit '/'
|
17
|
+
expect(page).to have_content('Cookie setter ready')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_behaves_like 'the API'
|
22
|
+
|
23
|
+
it 'raises an exception when writing a cookie before visiting the app' do
|
24
|
+
expect { create_cookie('choc', 'milk') }.to(
|
25
|
+
raise_error(ShowMeTheCookies::SeleniumSiteNotVisitedError)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
@@ -1,21 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'shared_examples_for_api'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'Selenium Webdriver Firefox', type: :feature do
|
5
5
|
before(:each) do
|
6
6
|
Capybara.current_driver = :selenium
|
7
7
|
end
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
9
|
+
describe 'the testing rig' do
|
10
|
+
it 'should load the sinatra app' do
|
11
11
|
visit '/'
|
12
|
-
page.
|
12
|
+
expect(page).to have_content('Cookie setter ready')
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
it_behaves_like
|
16
|
+
it_behaves_like 'the API'
|
17
17
|
|
18
|
-
it
|
19
|
-
expect {create_cookie('choc', 'milk')}.to
|
18
|
+
it 'raises an exception when writing a cookie before visiting the app' do
|
19
|
+
expect { create_cookie('choc', 'milk') }.to(
|
20
|
+
raise_error(ShowMeTheCookies::SeleniumSiteNotVisitedError)
|
21
|
+
)
|
20
22
|
end
|
21
23
|
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'shared_examples_for_api'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'RackTest when rack-test adapter uninstalled', type: :feature do
|
5
5
|
before(:each) do
|
6
6
|
Capybara.current_driver = :rack_test
|
7
7
|
ShowMeTheCookies.register_adapter(:rack_test, nil)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
describe "error messages" do
|
10
|
+
describe 'error messages' do
|
12
11
|
it "should tell me I'm unsupported" do
|
13
|
-
expect{get_me_the_cookies}.to raise_error(
|
12
|
+
expect { get_me_the_cookies }.to raise_error(
|
13
|
+
ShowMeTheCookies::UnknownDriverError
|
14
|
+
)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/spec/drivers/webkit_spec.rb
CHANGED
@@ -2,17 +2,18 @@ require 'spec_helper'
|
|
2
2
|
require 'shared_examples_for_api'
|
3
3
|
require 'capybara-webkit'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe 'Webkit', type: :feature do
|
6
6
|
before(:each) do
|
7
7
|
Capybara.current_driver = :webkit
|
8
|
+
page.driver.allow_url('subdomain.lvh.me')
|
8
9
|
end
|
9
10
|
|
10
|
-
describe
|
11
|
-
it
|
11
|
+
describe 'the testing rig' do
|
12
|
+
it 'should load the sinatra app' do
|
12
13
|
visit '/'
|
13
|
-
page.
|
14
|
+
expect(page).to have_content('Cookie setter ready')
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
it_behaves_like
|
18
|
+
it_behaves_like 'the API'
|
18
19
|
end
|
@@ -4,21 +4,21 @@ shared_examples "the API" do
|
|
4
4
|
describe "get_me_the_cookie" do
|
5
5
|
it "returns the cookie hash" do
|
6
6
|
visit '/set/foo/bar'
|
7
|
-
get_me_the_cookie('foo').
|
7
|
+
expect(get_me_the_cookie('foo')).to include(:name => "foo", :value => "bar", :expires => nil, :secure => false)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns nil for cookies that do not exist" do
|
12
|
-
get_me_the_cookie('some_unset_cookie').
|
12
|
+
expect(get_me_the_cookie('some_unset_cookie')).to be_nil
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "get_me_the_cookies" do
|
16
16
|
it "returns an array of standardised cookie hashes" do
|
17
17
|
visit '/set/foo/bar'
|
18
|
-
page.
|
19
|
-
get_me_the_cookies.first.
|
18
|
+
expect(page).to have_content("Setting foo=bar")
|
19
|
+
expect(get_me_the_cookies.first).to include(:name => "foo", :value => "bar", :expires => nil, :secure => false)
|
20
20
|
visit '/set/myopic/mice'
|
21
|
-
get_me_the_cookies.length.
|
21
|
+
expect(get_me_the_cookies.length).to be(2)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -27,7 +27,7 @@ shared_examples "the API" do
|
|
27
27
|
describe "show_me_the_cookie" do
|
28
28
|
it "inspects the cookie hash" do
|
29
29
|
visit '/set/foo/bar'
|
30
|
-
|
30
|
+
expect($stdout).to receive(:puts).with("foo: "+get_me_the_cookie('foo').inspect)
|
31
31
|
show_me_the_cookie('foo')
|
32
32
|
end
|
33
33
|
end
|
@@ -36,13 +36,12 @@ shared_examples "the API" do
|
|
36
36
|
it "returns a string representation of the get_me_the_cookies hash" do
|
37
37
|
visit '/set/foo/bar'
|
38
38
|
visit '/set/myopic/mice'
|
39
|
-
|
39
|
+
expect($stdout).to receive(:puts).with("Cookies: "+get_me_the_cookies.inspect)
|
40
40
|
show_me_the_cookies
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
45
|
describe "for manipulating cookies" do
|
47
46
|
describe "delete_cookie(cookie_name)" do
|
48
47
|
it "deletes a k/v pair from the session cookie" do
|
@@ -71,7 +70,7 @@ shared_examples "the API" do
|
|
71
70
|
create_cookie("choc", "milk")
|
72
71
|
visit "/get/choc"
|
73
72
|
cookies_should_contain("choc", "milk")
|
74
|
-
page.
|
73
|
+
expect(page).to have_content("Got cookie choc=milk")
|
75
74
|
end
|
76
75
|
|
77
76
|
it "accepts symbols" do
|
@@ -80,7 +79,7 @@ shared_examples "the API" do
|
|
80
79
|
create_cookie(:choc, :milk)
|
81
80
|
visit "/get/choc"
|
82
81
|
cookies_should_contain("choc", "milk")
|
83
|
-
page.
|
82
|
+
expect(page).to have_content("Got cookie choc=milk")
|
84
83
|
end
|
85
84
|
|
86
85
|
it "creates a cookie with path and domain" do
|
@@ -90,14 +89,14 @@ shared_examples "the API" do
|
|
90
89
|
cookies_should_contain("choc", "milk")
|
91
90
|
|
92
91
|
visit("/get/choc")
|
93
|
-
page.
|
92
|
+
expect(page).to have_content("Got cookie choc=milk")
|
94
93
|
|
95
94
|
visit '/set_with_domain/choc/doublemilk'
|
96
95
|
cookies_should_contain("choc", "doublemilk")
|
97
96
|
cookies_should_not_contain('choc', 'milk')
|
98
97
|
|
99
98
|
visit("/get/choc")
|
100
|
-
page.
|
99
|
+
expect(page).to have_content("Got cookie choc=doublemilk")
|
101
100
|
end
|
102
101
|
end
|
103
102
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'capybara/rspec'
|
2
2
|
|
3
|
-
require File.join(File.dirname(__FILE__), *%w
|
3
|
+
require File.join(File.dirname(__FILE__), *%w(app set_cookie))
|
4
4
|
Capybara.app = Sinatra::Application
|
5
5
|
|
6
6
|
require 'show_me_the_cookies'
|
7
7
|
RSpec.configure do |config|
|
8
|
-
config.include
|
8
|
+
config.include(ShowMeTheCookies, type: :feature)
|
9
9
|
end
|
10
10
|
|
11
11
|
Capybara.server_port = 36363
|
@@ -15,12 +15,12 @@ def cookies_should_contain(key, value)
|
|
15
15
|
key_present = get_me_the_cookies.any? {|c| c[:name] == key}
|
16
16
|
value_present = get_me_the_cookies.any? {|c| c[:value] == value}
|
17
17
|
msg = "Cookie not found: #{key}=#{value} in #{get_me_the_cookies.inspect}"
|
18
|
-
(key_present
|
18
|
+
expect(key_present && value_present).to be_truthy, msg
|
19
19
|
end
|
20
20
|
|
21
21
|
def cookies_should_not_contain(key, value)
|
22
|
-
key_present = get_me_the_cookies.any? {|c| c[:name] == key}
|
23
|
-
value_present = get_me_the_cookies.any? {|c| c[:value] == value}
|
22
|
+
key_present = get_me_the_cookies.any? { |c| c[:name] == key }
|
23
|
+
value_present = get_me_the_cookies.any? { |c| c[:value] == value }
|
24
24
|
msg = "Unwanted cookie found: #{key}=#{value} in #{get_me_the_cookies.inspect}"
|
25
|
-
(key_present
|
26
|
-
end
|
25
|
+
expect(key_present && value_present).to be_falsey, msg
|
26
|
+
end
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: show_me_the_cookies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Nicholas Rutherford
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: capybara
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,6 +30,7 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,23 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sinatra
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
44
66
|
requirements:
|
45
67
|
- - ! '>='
|
46
68
|
- !ruby/object:Gem::Version
|
@@ -48,13 +70,15 @@ dependencies:
|
|
48
70
|
type: :development
|
49
71
|
prerelease: false
|
50
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
51
74
|
requirements:
|
52
75
|
- - ! '>='
|
53
76
|
- !ruby/object:Gem::Version
|
54
77
|
version: '0'
|
55
78
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
79
|
+
name: poltergeist
|
57
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
58
82
|
requirements:
|
59
83
|
- - ! '>='
|
60
84
|
- !ruby/object:Gem::Version
|
@@ -62,13 +86,15 @@ dependencies:
|
|
62
86
|
type: :development
|
63
87
|
prerelease: false
|
64
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
65
90
|
requirements:
|
66
91
|
- - ! '>='
|
67
92
|
- !ruby/object:Gem::Version
|
68
93
|
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
95
|
+
name: selenium-webdriver
|
71
96
|
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
72
98
|
requirements:
|
73
99
|
- - ! '>='
|
74
100
|
- !ruby/object:Gem::Version
|
@@ -76,13 +102,15 @@ dependencies:
|
|
76
102
|
type: :development
|
77
103
|
prerelease: false
|
78
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
79
106
|
requirements:
|
80
107
|
- - ! '>='
|
81
108
|
- !ruby/object:Gem::Version
|
82
109
|
version: '0'
|
83
110
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
111
|
+
name: chromedriver-helper
|
85
112
|
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
86
114
|
requirements:
|
87
115
|
- - ! '>='
|
88
116
|
- !ruby/object:Gem::Version
|
@@ -90,6 +118,7 @@ dependencies:
|
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
93
122
|
requirements:
|
94
123
|
- - ! '>='
|
95
124
|
- !ruby/object:Gem::Version
|
@@ -97,6 +126,7 @@ dependencies:
|
|
97
126
|
- !ruby/object:Gem::Dependency
|
98
127
|
name: capybara-webkit
|
99
128
|
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
100
130
|
requirements:
|
101
131
|
- - ! '>='
|
102
132
|
- !ruby/object:Gem::Version
|
@@ -104,6 +134,7 @@ dependencies:
|
|
104
134
|
type: :development
|
105
135
|
prerelease: false
|
106
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
107
138
|
requirements:
|
108
139
|
- - ! '>='
|
109
140
|
- !ruby/object:Gem::Version
|
@@ -123,12 +154,14 @@ files:
|
|
123
154
|
- lib/show_me_the_cookies/adapters/poltergeist.rb
|
124
155
|
- lib/show_me_the_cookies/adapters/rack_test.rb
|
125
156
|
- lib/show_me_the_cookies/adapters/selenium.rb
|
157
|
+
- lib/show_me_the_cookies/adapters/selenium_chrome.rb
|
126
158
|
- lib/show_me_the_cookies/adapters/webkit.rb
|
127
159
|
- lib/show_me_the_cookies/version.rb
|
128
160
|
- show_me_the_cookies.gemspec
|
129
161
|
- spec/app/set_cookie.rb
|
130
162
|
- spec/drivers/poltergeist_spec.rb
|
131
163
|
- spec/drivers/rack-test_spec.rb
|
164
|
+
- spec/drivers/selenium_chrome_spec.rb
|
132
165
|
- spec/drivers/selenium_spec.rb
|
133
166
|
- spec/drivers/unknown_driver_spec.rb
|
134
167
|
- spec/drivers/webkit_spec.rb
|
@@ -137,31 +170,39 @@ files:
|
|
137
170
|
homepage: https://github.com/nruth/show_me_the_cookies
|
138
171
|
licenses:
|
139
172
|
- MIT
|
140
|
-
metadata: {}
|
141
173
|
post_install_message:
|
142
174
|
rdoc_options: []
|
143
175
|
require_paths:
|
144
176
|
- lib
|
145
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
146
179
|
requirements:
|
147
180
|
- - ! '>='
|
148
181
|
- !ruby/object:Gem::Version
|
149
182
|
version: '0'
|
183
|
+
segments:
|
184
|
+
- 0
|
185
|
+
hash: -3361807691243350282
|
150
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
none: false
|
151
188
|
requirements:
|
152
189
|
- - ! '>='
|
153
190
|
- !ruby/object:Gem::Version
|
154
191
|
version: '0'
|
192
|
+
segments:
|
193
|
+
- 0
|
194
|
+
hash: -3361807691243350282
|
155
195
|
requirements: []
|
156
196
|
rubyforge_project:
|
157
|
-
rubygems_version:
|
197
|
+
rubygems_version: 1.8.23.2
|
158
198
|
signing_key:
|
159
|
-
specification_version:
|
199
|
+
specification_version: 3
|
160
200
|
summary: Cookie manipulation for Capybara drivers
|
161
201
|
test_files:
|
162
202
|
- spec/app/set_cookie.rb
|
163
203
|
- spec/drivers/poltergeist_spec.rb
|
164
204
|
- spec/drivers/rack-test_spec.rb
|
205
|
+
- spec/drivers/selenium_chrome_spec.rb
|
165
206
|
- spec/drivers/selenium_spec.rb
|
166
207
|
- spec/drivers/unknown_driver_spec.rb
|
167
208
|
- spec/drivers/webkit_spec.rb
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
ZjRjNmQ2OGNiNGIzMzMzYjI4Y2FkNzM5Yzk0MjkyYWE5YTRhMTIxMg==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MjliMmU5ZDJhOGJhMmJjY2YxNDc3OTljNWQyYWZlZTg1MGNmOTk1Mg==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YWEzNmJhMjA3YzE1ZmM5YWVkYzM2NDU2ZGVhMGI4M2IyZDBmYTdlOWUwMjc2
|
10
|
-
ZTEwMWZhZTQ1ZjE2MGU4ZWJjMzZkZDJjZDE4ZGUxZDhkNGRmZjYwOTIyMGU1
|
11
|
-
NTMyNWM3MWJmOTE3MGNkZGVmMGM3NzdhNzQ5ZmU5YWZiNWIwNjk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
M2ZhOTAyNGRkN2EyYmI3MjQ5N2EwNzlmOTYwNzRlZjQ4NmE4ZThiYWE3MWMz
|
14
|
-
YjgwMzRmZTQwOGFlYTYzNTdiNDUzZWI2NWNjY2JmYzdmMjBhMzRlOGQ4NjZj
|
15
|
-
OTNiYmM4NGRkMjdmODY0MjM2ZmEzNjAwNDVmM2NlOGIzMzBlYWU=
|