2011-10-06 10:13:06 +00:00
|
|
|
require 'spec_helper'
|
2012-07-08 19:17:08 +00:00
|
|
|
require 'capybara/webkit/cookie_jar'
|
2011-10-06 10:13:06 +00:00
|
|
|
|
2012-07-08 19:17:08 +00:00
|
|
|
describe Capybara::Webkit::CookieJar do
|
2011-10-06 10:13:06 +00:00
|
|
|
let(:browser) {
|
|
|
|
browser = double("Browser")
|
|
|
|
browser.stub(:get_cookies) { [
|
|
|
|
"cookie1=1; domain=.example.org; path=/",
|
|
|
|
"cookie1=2; domain=.example.org; path=/dir1/",
|
|
|
|
"cookie1=3; domain=.facebook.com; path=/",
|
|
|
|
"cookie2=4; domain=.sub1.example.org; path=/",
|
|
|
|
] }
|
|
|
|
browser
|
|
|
|
}
|
|
|
|
|
2012-07-08 19:17:08 +00:00
|
|
|
subject { Capybara::Webkit::CookieJar.new(browser) }
|
2011-10-06 10:13:06 +00:00
|
|
|
|
2011-10-14 19:23:00 +00:00
|
|
|
describe "#find" do
|
|
|
|
it "returns a cookie object" do
|
2013-08-11 14:36:53 +00:00
|
|
|
subject.find("cookie1", "www.facebook.com").domain.should eq ".facebook.com"
|
2011-10-14 19:23:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the right cookie for every given domain/path" do
|
2013-08-11 14:36:53 +00:00
|
|
|
subject.find("cookie1", "example.org").value.should eq "1"
|
|
|
|
subject.find("cookie1", "www.facebook.com").value.should eq "3"
|
|
|
|
subject.find("cookie2", "sub1.example.org").value.should eq "4"
|
2011-10-06 10:13:06 +00:00
|
|
|
end
|
|
|
|
|
2011-10-06 13:07:45 +00:00
|
|
|
it "does not return a cookie from other domain" do
|
2013-08-11 14:36:53 +00:00
|
|
|
subject.find("cookie2", "www.example.org").should eq nil
|
2011-10-06 10:13:06 +00:00
|
|
|
end
|
|
|
|
|
2011-10-06 13:07:45 +00:00
|
|
|
it "respects path precedence rules" do
|
2013-08-11 14:36:53 +00:00
|
|
|
subject.find("cookie1", "www.example.org").value.should eq "1"
|
|
|
|
subject.find("cookie1", "www.example.org", "/dir1/123").value.should eq "2"
|
2011-10-14 19:23:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#[]" do
|
|
|
|
it "returns the first matching cookie's value" do
|
2013-08-11 14:36:53 +00:00
|
|
|
subject["cookie1", "example.org"].should eq "1"
|
2011-10-14 19:23:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil if no cookie is found" do
|
2013-08-11 14:36:53 +00:00
|
|
|
subject["notexisting"].should eq nil
|
2011-10-06 10:13:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|