show_me_the_cookies 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjEyNjJhYzcwMDI4MTc5MTQ0OWJmODEwNWMwYmQxMzI0YzY0NjhhMA==
4
+ ZjRjNmQ2OGNiNGIzMzMzYjI4Y2FkNzM5Yzk0MjkyYWE5YTRhMTIxMg==
5
5
  data.tar.gz: !binary |-
6
- MzlmMDQyOTkzNzViYmQxYWEyNTQyMzVkNDE0Mzc0OTg2YjBlMmYzYw==
6
+ MjliMmU5ZDJhOGJhMmJjY2YxNDc3OTljNWQyYWZlZTg1MGNmOTk1Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDU4NDM0MTIzYjE3MzE5MzFjYzMyNDNiNGYxNTU0NzBkOWNmNjIyNmUxYzVk
10
- ZjBlMTEwZTcyMzgxMjhiOGEyOWE1MjM1MTNjNmQ2ZmM4YWQwNzk1NDI5MjUw
11
- M2Q0ODk2OTM4YmM4YzJmNWEzMmJlNWRiMWQ4YzcwZGFjZjI3ODQ=
9
+ YWEzNmJhMjA3YzE1ZmM5YWVkYzM2NDU2ZGVhMGI4M2IyZDBmYTdlOWUwMjc2
10
+ ZTEwMWZhZTQ1ZjE2MGU4ZWJjMzZkZDJjZDE4ZGUxZDhkNGRmZjYwOTIyMGU1
11
+ NTMyNWM3MWJmOTE3MGNkZGVmMGM3NzdhNzQ5ZmU5YWZiNWIwNjk=
12
12
  data.tar.gz: !binary |-
13
- ZjRlZmNlYjNhZDFmZGRlMGZjN2MzNDQwYTJkYjcwMmRkNDk3OWZmZTgyYTZl
14
- NGVlZWY0OWZjNjU0Nzc2ZmMwMGRjYWNiY2ViYTc2YTdlOTkxNGNlNTM5N2Qy
15
- NmZkYzBhYWE2NGUyM2NlMDAyM2NlNWVhMTRmYmVhODhiMjExNjY=
13
+ M2ZhOTAyNGRkN2EyYmI3MjQ5N2EwNzlmOTYwNzRlZjQ4NmE4ZThiYWE3MWMz
14
+ YjgwMzRmZTQwOGFlYTYzNTdiNDUzZWI2NWNjY2JmYzdmMjBhMzRlOGQ4NjZj
15
+ OTNiYmM4NGRkMjdmODY0MjM2ZmEzNjAwNDVmM2NlOGIzMzBlYWU=
data/Gemfile CHANGED
@@ -2,7 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in show_me_the_cookies.gemspec
4
4
  gemspec
5
-
6
- group :development do
7
- gem "bundler", ">=1.0.15"
8
- end
data/README.md CHANGED
@@ -1,10 +1,10 @@
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)
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)
4
4
 
5
5
  Some helpers for poking around at your Capybara driven browser's cookies in integration tests.
6
6
 
7
- Supports Capybara's bundled drivers (rack-test, Selenium Webdriver) and Poltergeist (PhantomJS).
7
+ Provides drivers for rack-test, [selenium-webdriver](https://rubygems.org/gems/selenium-webdriver)), [Poltergeist](https://github.com/teampoltergeist/poltergeist) (PhantomJS) and [capybara-webkit](https://github.com/thoughtbot/capybara-webkit).
8
8
  You may add new drivers for your application by implementing an adapter class and calling ShowMeTheCookies.register_adapter in your test code (e.g. a spec/support file).
9
9
 
10
10
  ## API
@@ -117,6 +117,10 @@ for example
117
117
 
118
118
  which indicates how to use the selenium adapter with a custom selenium testing profile.
119
119
 
120
+ ## Usage / License / Support
121
+
122
+ This software is provided free of charge for use at your own risk, see [MIT License](http://opensource.org/licenses/MIT). If you have trouble making the software work try posting on stackoverflow. If you find a bug or don't understand the documentation open a [github issue](https://github.com/nruth/show_me_the_cookies/issues).
123
+
120
124
  ## Contributing
121
125
 
122
126
  Bugs should be raised in the [issue tracker](https://github.com/nruth/show_me_the_cookies/issues).
@@ -126,6 +130,23 @@ to your repository branch. Please run the tests, and add new ones.
126
130
 
127
131
  New drivers will be selectively accepted. Be sure that the api spec passes. If you prefer to keep the driver in your own repository send me the address and I'll add a link in the docs.
128
132
 
133
+ ### Development and running the tests
134
+
135
+ bundle install
136
+ bundle exec rspec
137
+
138
+ If you get DNS lookup failures try this in the terminal
139
+
140
+ host lvh.me
141
+
142
+ You should get a quick response of
143
+
144
+ lvh.me has address 127.0.0.1
145
+
146
+ If you don't see this your router or similar is interfering with the DNS for security reasons, blocking a loopback lookup result.
147
+ You can get around this by changing your DNS server to [Google's public DNS service](https://developers.google.com/speed/public-dns/) 8.8.8.8 to run the tests. You can turn this off again afterwards.
148
+ Alternatively you can add an /etc/hosts entry looping back lvh.me to 127.0.0.1.
149
+
129
150
  ## History, Credits, and Acknowledgements
130
151
 
131
152
  [Contributors](https://github.com/nruth/show_me_the_cookies/contributors)
@@ -54,8 +54,11 @@ module ShowMeTheCookies
54
54
  current_driver_adapter.expire_cookies
55
55
  end
56
56
 
57
- def create_cookie(name, value)
58
- current_driver_adapter.create_cookie(name, value)
57
+ # can take the following options:
58
+ # :path
59
+ # :domain
60
+ def create_cookie(name, value, options = {})
61
+ current_driver_adapter.create_cookie(name, value, options)
59
62
  end
60
63
 
61
64
  private
@@ -23,8 +23,9 @@ class ShowMeTheCookies::Poltergeist
23
23
  @browser.remove_cookie(name.to_s)
24
24
  end
25
25
 
26
- def create_cookie(name, value)
27
- @driver.set_cookie(name, value)
26
+ def create_cookie(name, value, options)
27
+ # see: https://github.com/jonleighton/poltergeist#manipulating-cookies
28
+ @driver.set_cookie(name, value, options)
28
29
  end
29
30
 
30
31
  private
@@ -26,8 +26,11 @@ class ShowMeTheCookies::RackTest
26
26
  end
27
27
  end
28
28
 
29
- def create_cookie(name, value)
30
- cookie_jar[name] = value
29
+ def create_cookie(name, value, options)
30
+ cookie_raw = "#{name}=#{Rack::Utils.escape(value)}"
31
+ (cookie_raw = "#{cookie_raw}; domain=#{options[:domain]}") if options.has_key?(:domain)
32
+ (cookie_raw = "#{cookie_raw}; path=#{options[:path]}") if options.has_key?(:path)
33
+ cookie_jar.merge(cookie_raw)
31
34
  end
32
35
 
33
36
  private
@@ -22,13 +22,13 @@ class ShowMeTheCookies::Selenium
22
22
  @browser.manage.delete_cookie(cookie_name)
23
23
  end
24
24
 
25
- def create_cookie(cookie_name, cookie_value)
25
+ def create_cookie(cookie_name, cookie_value, options)
26
26
  unless is_on_the_page?
27
27
  raise ShowMeTheCookies::Selenium::SiteNotVisitedError.new(
28
28
  "Can't set a cookie on about:blank. Visit a url in your app first."
29
29
  )
30
30
  end
31
- @browser.manage.add_cookie(name: cookie_name, value: cookie_value)
31
+ @browser.manage.add_cookie({name: cookie_name, value: cookie_value}.merge(options))
32
32
  end
33
33
 
34
34
  private
@@ -28,8 +28,10 @@ class ShowMeTheCookies::Webkit
28
28
  end
29
29
  end
30
30
 
31
- def create_cookie(name, value)
32
- @browser.set_cookie("#{name}=#{value}; domain=127.0.0.1")
31
+ def create_cookie(name, value, options)
32
+ host = options.delete(:domain) || (Capybara.app_host ? URI(Capybara.app_host).host : '127.0.0.1')
33
+ puts "Webkit create_cookie options not supported: #{options.inspect}" if options && (options != {})
34
+ @browser.set_cookie("#{name}=#{value}; domain=#{host}")
33
35
  end
34
36
 
35
37
  private
@@ -1,3 +1,3 @@
1
1
  module ShowMeTheCookies
2
- VERSION = "2.4.0"
2
+ VERSION = "2.5.0"
3
3
  end
@@ -27,3 +27,8 @@ get '/set_stale/:key/:value' do
27
27
  response.set_cookie params[:key], {:value => params[:value], :path => '/', :expires => Time.now}
28
28
  "Setting #{params[:key]}=#{params[:value]}"
29
29
  end
30
+
31
+ get '/set_with_domain/:key/:value' do
32
+ response.set_cookie params[:key], {:value => params[:value], :path => '/', :domain => '.lvh.me'}
33
+ "Setting #{params[:key]}=#{params[:value]}"
34
+ end
@@ -1,19 +1,5 @@
1
1
  shared_examples "the API" do
2
2
 
3
- def cookies_should_contain(key, value)
4
- key_present = get_me_the_cookies.any? {|c| c[:name] == key}
5
- value_present = get_me_the_cookies.any? {|c| c[:value] == value}
6
- msg = "Cookie not found: #{key}=#{value} in #{get_me_the_cookies.inspect}"
7
- (key_present and value_present).should be_true, msg
8
- end
9
-
10
- def cookies_should_not_contain(key, value)
11
- key_present = get_me_the_cookies.any? {|c| c[:name] == key}
12
- value_present = get_me_the_cookies.any? {|c| c[:value] == value}
13
- msg = "Unwanted cookie found: #{key}=#{value} in #{get_me_the_cookies.inspect}"
14
- (key_present and value_present).should be_false, msg
15
- end
16
-
17
3
  describe "for getting cookie hashes" do
18
4
  describe "get_me_the_cookie" do
19
5
  it "returns the cookie hash" do
@@ -56,6 +42,7 @@ shared_examples "the API" do
56
42
  end
57
43
  end
58
44
 
45
+
59
46
  describe "for manipulating cookies" do
60
47
  describe "delete_cookie(cookie_name)" do
61
48
  it "deletes a k/v pair from the session cookie" do
@@ -80,20 +67,38 @@ shared_examples "the API" do
80
67
  describe "create_cookie(cookie_name, cookie_value)" do
81
68
  it "creates a cookie" do
82
69
  # need to first hit a page to set a cookie (selenium)
83
- visit('/')
84
- create_cookie('choc', 'milk')
85
- visit '/get/choc'
86
- cookies_should_contain('choc', 'milk')
70
+ visit("/")
71
+ create_cookie("choc", "milk")
72
+ visit "/get/choc"
73
+ cookies_should_contain("choc", "milk")
87
74
  page.should have_content("Got cookie choc=milk")
88
75
  end
89
76
 
90
77
  it "accepts symbols" do
91
- visit('/')
78
+ # need to first hit a page to set a cookie (selenium)
79
+ visit("/")
92
80
  create_cookie(:choc, :milk)
93
- visit '/get/choc'
94
- cookies_should_contain('choc', 'milk')
81
+ visit "/get/choc"
82
+ cookies_should_contain("choc", "milk")
95
83
  page.should have_content("Got cookie choc=milk")
96
84
  end
85
+
86
+ it "creates a cookie with path and domain" do
87
+ # need to first hit a page to set a cookie (selenium)
88
+ visit("/")
89
+ create_cookie("choc", "milk", path: "/", domain: ".lvh.me")
90
+ cookies_should_contain("choc", "milk")
91
+
92
+ visit("/get/choc")
93
+ page.should have_content("Got cookie choc=milk")
94
+
95
+ visit '/set_with_domain/choc/doublemilk'
96
+ cookies_should_contain("choc", "doublemilk")
97
+ cookies_should_not_contain('choc', 'milk')
98
+
99
+ visit("/get/choc")
100
+ page.should have_content("Got cookie choc=doublemilk")
101
+ end
97
102
  end
98
103
 
99
104
  describe "expire_cookies" do
data/spec/spec_helper.rb CHANGED
@@ -6,4 +6,21 @@ Capybara.app = Sinatra::Application
6
6
  require 'show_me_the_cookies'
7
7
  RSpec.configure do |config|
8
8
  config.include ShowMeTheCookies, :type => :feature
9
+ end
10
+
11
+ Capybara.server_port = 36363
12
+ Capybara.app_host = "http://subdomain.lvh.me:#{Capybara.server_port}"
13
+
14
+ def cookies_should_contain(key, value)
15
+ key_present = get_me_the_cookies.any? {|c| c[:name] == key}
16
+ value_present = get_me_the_cookies.any? {|c| c[:value] == value}
17
+ msg = "Cookie not found: #{key}=#{value} in #{get_me_the_cookies.inspect}"
18
+ (key_present and value_present).should be_true, msg
19
+ end
20
+
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}
24
+ msg = "Unwanted cookie found: #{key}=#{value} in #{get_me_the_cookies.inspect}"
25
+ (key_present and value_present).should be_false, msg
9
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: show_me_the_cookies
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Rutherford