show_me_the_cookies 1.1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Some helpers for poking around at your Capybara driven browser's cookies in integration tests.
4
4
 
5
- Supports Capybara's bundled drivers (rack-test, Selenium Webdriver), and adapters for other
6
- drivers may be added (at time of writing Akephalos is also available).
5
+ Supports Capybara's bundled drivers (rack-test, Selenium Webdriver) and Poltergeist (PhantomJS).
6
+ 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).
7
7
 
8
8
  ## API
9
9
 
@@ -27,20 +27,6 @@ drivers may be added (at time of writing Akephalos is also available).
27
27
  # removes session cookies and expired persistent cookies
28
28
  expire_cookies
29
29
 
30
- ## Contributing
31
-
32
- If you find this useful, the best way to say thanks is to take a poke around the code and send feedback upstream.
33
- Bugs / requests / suggestions should be raised in the [Github issues](https://github.com/nruth/show_me_the_cookies/issues) tracker.
34
-
35
- Code contributions should be sent by github pull request, or contact [me](https://github.com/nruth) with a link
36
- to your repository branch.
37
- Patches should be small, isolated, testable, and preferably tested.
38
-
39
- New drivers should be accompanied by a passing API spec.
40
- Driver-specific edge cases should not be added to the shared spec unless thought to be of general interest.
41
- API spec should not be changed because something doesn't work – try to fix the driver, or make an addon gem.
42
-
43
- More tests are welcome.
44
30
 
45
31
  ## Installation
46
32
 
@@ -54,7 +40,7 @@ Add to your gemfile's test group:
54
40
  in step_helper or your support directory:
55
41
 
56
42
  RSpec.configure do |config|
57
- config.include ShowMeTheCookies, :type => :request
43
+ config.include ShowMeTheCookies, :type => :feature
58
44
  end
59
45
 
60
46
  ### Example usage
@@ -116,6 +102,20 @@ Install by loading the gem and adding the following to your stepdefs or support
116
102
  expire_cookies
117
103
  end
118
104
 
105
+
106
+ ## Contributing
107
+
108
+ If you find this useful some ways to say thanks are reviewing the code and/or kind words or other feedback by Github message.
109
+ Bugs should be raised in the [issue tracker](https://github.com/nruth/show_me_the_cookies/issues).
110
+
111
+ Code contributions should be sent as Github pull requests, or by messaging [me](https://github.com/nruth) with a link
112
+ to your repository branch. Please run the tests, and add new ones.
113
+
114
+ New drivers are unlikely to be accepted at this stage. You can instead add them to your application's test setup.
115
+ If you come up with an interesting new driver/adapter mail me with a link to a repository or gist and I'll link to it here.
116
+ Hopefully the API shared-spec will come in useful when working on your own driver.
117
+
118
+
119
119
  ## History, Credits, and Acknowledgements
120
120
 
121
121
  [Contributors](https://github.com/nruth/show_me_the_cookies/contributors)
@@ -1,8 +1,22 @@
1
1
  module ShowMeTheCookies
2
- require 'show_me_the_cookies/rack_test'
3
- require 'show_me_the_cookies/selenium'
4
- require 'show_me_the_cookies/akephalos'
5
- require 'show_me_the_cookies/poltergeist'
2
+ require 'show_me_the_cookies/adapters/rack_test'
3
+ require 'show_me_the_cookies/adapters/selenium'
4
+
5
+ @adapters = {}
6
+ class << self
7
+ attr_reader :adapters
8
+
9
+ # Register your own capybara-driver cookie adapter.
10
+ # Use the same name as the one Capybara does to identify that driver.
11
+ # Implement the interface of spec/shared_examples_for_api, as seen in lib/show_me_the_cookies/drivers
12
+ def register_adapter(driver, adapter)
13
+ adapters[driver] = adapter
14
+ end
15
+ end
16
+
17
+ # to register your own adapter/driver do this in your test setup code somewhere e.g. spec/support
18
+ register_adapter(:selenium, ShowMeTheCookies::Selenium)
19
+ register_adapter(:rack_test, ShowMeTheCookies::RackTest)
6
20
 
7
21
  # puts a string summary of the cookie
8
22
  def show_me_the_cookie(cookie_name)
@@ -37,19 +51,10 @@ module ShowMeTheCookies
37
51
  end
38
52
 
39
53
  private
40
- def adapters
41
- @@drivers ||= {
42
- :selenium => ShowMeTheCookies::Selenium,
43
- :rack_test => ShowMeTheCookies::RackTest,
44
- :akephalos => ShowMeTheCookies::Akephalos,
45
- :poltergeist => ShowMeTheCookies::Poltergeist
46
- }
47
- end
48
-
49
54
  def current_driver_adapter
50
- adapter = adapters[Capybara.current_driver]
55
+ adapter = ShowMeTheCookies.adapters[Capybara.current_driver]
51
56
  if adapter.nil?
52
- if driver_uses_selenium?
57
+ if driver_uses_selenium? # to support custom selenium drivers / configs (whatever they are?)
53
58
  adapter = adapters[:selenium]
54
59
  else
55
60
  raise("Unsupported driver #{Capybara.current_driver}, use one of #{adapters.keys}")
@@ -1,7 +1,6 @@
1
1
  class ShowMeTheCookies::Selenium
2
2
  def initialize(driver)
3
3
  @browser = driver.browser
4
- self
5
4
  end
6
5
 
7
6
  def get_me_the_cookie(cookie_name)
@@ -1,3 +1,3 @@
1
1
  module ShowMeTheCookies
2
- VERSION = "1.1.4"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -17,9 +17,7 @@ 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', '~> 2.0')
21
21
  s.add_development_dependency 'rspec'
22
22
  s.add_development_dependency 'sinatra'
23
- s.add_development_dependency 'akephalos2'
24
- s.add_development_dependency 'poltergeist'
25
23
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'shared_examples_for_api'
3
3
 
4
- describe "RackTest", :type => :request do
4
+ describe "RackTest", :type => :feature do
5
5
  before(:each) do
6
6
  Capybara.current_driver = :rack_test
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'shared_examples_for_api'
3
3
 
4
- describe "Selenium Webdriver", :type => :request do
4
+ describe "Selenium Webdriver", :type => :feature do
5
5
  before(:each) do
6
6
  Capybara.current_driver = :selenium
7
7
  end
data/spec/spec_helper.rb CHANGED
@@ -5,5 +5,5 @@ Capybara.app = Sinatra::Application
5
5
 
6
6
  require 'show_me_the_cookies'
7
7
  RSpec.configure do |config|
8
- config.include ShowMeTheCookies, :type => :request
8
+ config.include ShowMeTheCookies, :type => :feature
9
9
  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: 1.1.4
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-05 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '1.0'
21
+ version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: '2.0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -59,38 +59,6 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: akephalos2
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: poltergeist
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
62
  description: Cookie manipulation for Capybara drivers -- viewing, deleting, ...
95
63
  email:
96
64
  - nick.rutherford@gmail.com
@@ -103,18 +71,13 @@ files:
103
71
  - README.md
104
72
  - Rakefile
105
73
  - lib/show_me_the_cookies.rb
106
- - lib/show_me_the_cookies/akephalos.rb
107
- - lib/show_me_the_cookies/poltergeist.rb
108
- - lib/show_me_the_cookies/rack_test.rb
109
- - lib/show_me_the_cookies/selenium.rb
74
+ - lib/show_me_the_cookies/adapters/rack_test.rb
75
+ - lib/show_me_the_cookies/adapters/selenium.rb
110
76
  - lib/show_me_the_cookies/version.rb
111
77
  - show_me_the_cookies.gemspec
112
78
  - spec/app/set_cookie.rb
113
- - spec/request/akephalos_spec.rb
114
- - spec/request/custom_spec.rb
115
- - spec/request/poltergeist_spec.rb
116
- - spec/request/rack-test_spec.rb
117
- - spec/request/selenium_spec.rb
79
+ - spec/drivers/rack-test_spec.rb
80
+ - spec/drivers/selenium_spec.rb
118
81
  - spec/shared_examples_for_api.rb
119
82
  - spec/spec_helper.rb
120
83
  homepage: https://github.com/nruth/show_me_the_cookies
@@ -130,18 +93,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
93
  - - ! '>='
131
94
  - !ruby/object:Gem::Version
132
95
  version: '0'
133
- segments:
134
- - 0
135
- hash: 2634854024742574363
136
96
  required_rubygems_version: !ruby/object:Gem::Requirement
137
97
  none: false
138
98
  requirements:
139
99
  - - ! '>='
140
100
  - !ruby/object:Gem::Version
141
101
  version: '0'
142
- segments:
143
- - 0
144
- hash: 2634854024742574363
145
102
  requirements: []
146
103
  rubyforge_project:
147
104
  rubygems_version: 1.8.23
@@ -150,10 +107,7 @@ specification_version: 3
150
107
  summary: Cookie manipulation for Capybara drivers
151
108
  test_files:
152
109
  - spec/app/set_cookie.rb
153
- - spec/request/akephalos_spec.rb
154
- - spec/request/custom_spec.rb
155
- - spec/request/poltergeist_spec.rb
156
- - spec/request/rack-test_spec.rb
157
- - spec/request/selenium_spec.rb
110
+ - spec/drivers/rack-test_spec.rb
111
+ - spec/drivers/selenium_spec.rb
158
112
  - spec/shared_examples_for_api.rb
159
113
  - spec/spec_helper.rb
@@ -1,61 +0,0 @@
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
@@ -1,42 +0,0 @@
1
- class ShowMeTheCookies::Poltergeist
2
- def initialize(driver)
3
- @browser = driver.browser
4
- end
5
-
6
- def get_me_the_cookie(name)
7
- cookie = cookies_hash[name.to_s]
8
- translate(cookie) unless cookie.nil?
9
- end
10
-
11
- def get_me_the_cookies
12
- cookies_hash.values.map(&method(:translate))
13
- end
14
-
15
- def expire_cookies
16
- cookies_hash.each do |name, cookie|
17
- delete_cookie(name) if (cookie.expires rescue nil).nil?
18
- end
19
- end
20
-
21
- def delete_cookie(name)
22
- @browser.remove_cookie(name.to_s)
23
- end
24
-
25
- private
26
-
27
- def cookies_hash
28
- @browser.cookies
29
- end
30
-
31
- def translate(cookie)
32
- {
33
- :name => cookie.name,
34
- :domain => cookie.domain,
35
- :value => cookie.value,
36
- :expires => (cookie.expires rescue nil),
37
- :path => cookie.path,
38
- :secure => cookie.secure?,
39
- :httponly => cookie.httponly?
40
- }
41
- end
42
- end
@@ -1,18 +0,0 @@
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
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'shared_examples_for_api'
3
-
4
- describe "Custom Webdriver", :type => :request do
5
- before(:all) do
6
- Capybara.register_driver :custom do |app|
7
- Capybara::Selenium::Driver.new(app, :resynchronize => true)
8
- end
9
- end
10
- before(:each) do
11
- Capybara.current_driver = :custom
12
- end
13
-
14
- describe "the testing rig" do
15
- it "should load the sinatra app" do
16
- visit '/'
17
- page.should have_content("Cookie setter ready")
18
- end
19
- end
20
-
21
- it_behaves_like "the API"
22
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- require 'shared_examples_for_api'
3
- require 'capybara/poltergeist'
4
-
5
- describe "Poltergeist", :type => :request do
6
- before(:each) do
7
- Capybara.current_driver = :poltergeist
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