show_me_the_cookies 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -34
- data/lib/show_me_the_cookies.rb +14 -2
- data/lib/show_me_the_cookies/version.rb +1 -1
- data/spec/request/custom_spec.rb +22 -0
- metadata +6 -4
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Show me the cookies
|
2
2
|
|
3
|
-
Some helpers for poking around at your browser's cookies in integration tests.
|
3
|
+
Some helpers for poking around at your Capybara driven browser's cookies in integration tests.
|
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).
|
4
7
|
|
5
8
|
## API
|
6
9
|
|
@@ -27,20 +30,18 @@ Some helpers for poking around at your browser's cookies in integration tests.
|
|
27
30
|
## Contributing
|
28
31
|
|
29
32
|
If you find this useful, the best way to say thanks is to take a poke around the code and send feedback upstream.
|
30
|
-
|
31
|
-
Bugs / requests should go in [Github issues](https://github.com/nruth/show_me_the_cookies/issues).
|
33
|
+
Bugs / requests / suggestions should be raised in the [Github issues](https://github.com/nruth/show_me_the_cookies/issues) tracker.
|
32
34
|
|
33
35
|
Code contributions should be sent by github pull request, or contact [me](https://github.com/nruth) with a link
|
34
36
|
to your repository branch.
|
35
|
-
|
36
|
-
Patches should be small isolated changes, and testable, or preferably tested.
|
37
|
-
|
38
|
-
More tests are welcome.
|
37
|
+
Patches should be small, isolated, testable, and preferably tested.
|
39
38
|
|
40
39
|
New drivers should be accompanied by a passing API spec.
|
41
40
|
Driver-specific edge cases should not be added to the shared spec unless thought to be of general interest.
|
42
41
|
API spec should not be changed because something doesn't work, fix the driver or make a plugin gem.
|
43
42
|
|
43
|
+
More tests are welcome.
|
44
|
+
|
44
45
|
## Installation
|
45
46
|
|
46
47
|
Add to your gemfile's test group:
|
@@ -60,25 +61,12 @@ in step_helper or your support directory:
|
|
60
61
|
|
61
62
|
In a request spec, using [Capybara](https://github.com/jnicklas/capybara)
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
within '#member_login' do
|
68
|
-
fill_in "Email", :with => member.email
|
69
|
-
fill_in "Password", :with => member.password
|
70
|
-
click_on "Sign in"
|
71
|
-
end
|
72
|
-
|
73
|
-
page.should have_content("Dashboard")
|
74
|
-
page.should have_no_content("Login")
|
75
|
-
# Given I close my browser (clearing the session)
|
64
|
+
specify "user login is remembered across browser restarts" do
|
65
|
+
log_in_as_user
|
66
|
+
should_be_logged_in
|
67
|
+
#browser restart = session cookie is lost
|
76
68
|
expire_cookies
|
77
|
-
|
78
|
-
# When I come back next time
|
79
|
-
visit dashboard_path
|
80
|
-
page.should have_content("Dashboard")
|
81
|
-
page.should have_no_content("Login")
|
69
|
+
should_be_logged_in
|
82
70
|
end
|
83
71
|
|
84
72
|
|
@@ -124,19 +112,14 @@ Install by loading the gem and adding the following to your stepdefs or support
|
|
124
112
|
expire_cookies
|
125
113
|
end
|
126
114
|
|
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]
|
132
|
-
|
133
115
|
## History, Credits, and Acknowledgements
|
134
116
|
|
135
|
-
|
117
|
+
[Contributors](https://github.com/nruth/show_me_the_cookies/contributors)
|
136
118
|
|
119
|
+
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.
|
137
120
|
Initial release as a gist [here](https://gist.github.com/484787), early development sponsored by [Medify](http://www.medify.co.uk).
|
138
121
|
|
139
122
|
Contributions outside of github have been made by:
|
140
123
|
|
141
|
-
* [Leandro Pedroni](https://github.com/ilpoldo)
|
142
|
-
* [Matthew Nielsen](https://github.com/xunker)
|
124
|
+
* [Leandro Pedroni](https://github.com/ilpoldo)
|
125
|
+
* [Matthew Nielsen](https://github.com/xunker)
|
data/lib/show_me_the_cookies.rb
CHANGED
@@ -45,7 +45,19 @@ private
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def current_driver_adapter
|
48
|
-
adapter = adapters[Capybara.current_driver]
|
48
|
+
adapter = adapters[Capybara.current_driver]
|
49
|
+
if adapter.nil?
|
50
|
+
if driver_uses_selenium?
|
51
|
+
adapter = adapters[:selenium]
|
52
|
+
else
|
53
|
+
raise("Unsupported driver #{Capybara.current_driver}, use one of #{Capybara.drivers.keys}")
|
54
|
+
end
|
55
|
+
end
|
49
56
|
adapter.new(Capybara.current_session.driver)
|
50
57
|
end
|
51
|
-
|
58
|
+
|
59
|
+
def driver_uses_selenium?
|
60
|
+
driver = Capybara.drivers[Capybara.current_driver].call(nil)
|
61
|
+
driver.is_a?(Capybara::Selenium::Driver)
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nicholas Rutherford
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-12-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: capybara
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- show_me_the_cookies.gemspec
|
97
97
|
- spec/app/set_cookie.rb
|
98
98
|
- spec/request/akephalos_spec.rb
|
99
|
+
- spec/request/custom_spec.rb
|
99
100
|
- spec/request/rack-test_spec.rb
|
100
101
|
- spec/request/selenium_spec.rb
|
101
102
|
- spec/shared_examples_for_api.rb
|
@@ -136,6 +137,7 @@ summary: Cookie manipulation for Capybara drivers
|
|
136
137
|
test_files:
|
137
138
|
- spec/app/set_cookie.rb
|
138
139
|
- spec/request/akephalos_spec.rb
|
140
|
+
- spec/request/custom_spec.rb
|
139
141
|
- spec/request/rack-test_spec.rb
|
140
142
|
- spec/request/selenium_spec.rb
|
141
143
|
- spec/shared_examples_for_api.rb
|