mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Add cleanup method to clear cookies for Celerity/Culerity and RackTest, with tests for Selenium included
This commit is contained in:
parent
a94f9949d5
commit
5ad348d776
10 changed files with 59 additions and 27 deletions
|
@ -138,6 +138,10 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
|
||||||
@_browser
|
@_browser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cleanup!
|
||||||
|
browser.clear_cookies
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def url(path)
|
def url(path)
|
||||||
|
|
|
@ -228,6 +228,10 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
||||||
end
|
end
|
||||||
alias_method :source, :body
|
alias_method :source, :body
|
||||||
|
|
||||||
|
def cleanup!
|
||||||
|
clear_cookies
|
||||||
|
end
|
||||||
|
|
||||||
def get(*args, &block); reset_cache; super; end
|
def get(*args, &block); reset_cache; super; end
|
||||||
def post(*args, &block); reset_cache; super; end
|
def post(*args, &block); reset_cache; super; end
|
||||||
def put(*args, &block); reset_cache; super; end
|
def put(*args, &block); reset_cache; super; end
|
||||||
|
@ -268,9 +272,4 @@ private
|
||||||
env
|
env
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_cache
|
|
||||||
@body = nil
|
|
||||||
@html = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -95,7 +95,6 @@ shared_examples_for 'driver' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for "driver with javascript support" do
|
shared_examples_for "driver with javascript support" do
|
||||||
|
@ -176,3 +175,22 @@ shared_examples_for "driver with frame support" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_examples_for "driver with cookies support" do
|
||||||
|
describe "#cleanup" do
|
||||||
|
it "should set and clean cookies" do
|
||||||
|
@driver.visit('/get_cookie')
|
||||||
|
@driver.body.should_not include('test_cookie')
|
||||||
|
|
||||||
|
@driver.visit('/set_cookie')
|
||||||
|
@driver.body.should include('Cookie set to test_cookie')
|
||||||
|
|
||||||
|
@driver.visit('/get_cookie')
|
||||||
|
@driver.body.should include('test_cookie')
|
||||||
|
|
||||||
|
@driver.cleanup!
|
||||||
|
@driver.visit('/get_cookie')
|
||||||
|
@driver.body.should_not include('test_cookie')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -50,6 +50,16 @@ class TestApp < Sinatra::Base
|
||||||
redirect back
|
redirect back
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/set_cookie' do
|
||||||
|
cookie_value = 'test_cookie'
|
||||||
|
response.set_cookie('capybara', cookie_value)
|
||||||
|
"Cookie set to #{cookie_value}"
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/get_cookie' do
|
||||||
|
request.cookies['capybara']
|
||||||
|
end
|
||||||
|
|
||||||
get '/:view' do |view|
|
get '/:view' do |view|
|
||||||
erb view.to_sym
|
erb view.to_sym
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ if RUBY_PLATFORM =~ /java/
|
||||||
it_should_behave_like "driver with javascript support"
|
it_should_behave_like "driver with javascript support"
|
||||||
it_should_behave_like "driver with header support"
|
it_should_behave_like "driver with header support"
|
||||||
it_should_behave_like "driver with status code support"
|
it_should_behave_like "driver with status code support"
|
||||||
|
it_should_behave_like "driver with cookies support"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
|
puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
|
||||||
|
|
|
@ -9,5 +9,5 @@ describe Capybara::Driver::Culerity do
|
||||||
it_should_behave_like "driver with javascript support"
|
it_should_behave_like "driver with javascript support"
|
||||||
it_should_behave_like "driver with header support"
|
it_should_behave_like "driver with header support"
|
||||||
it_should_behave_like "driver with status code support"
|
it_should_behave_like "driver with status code support"
|
||||||
|
it_should_behave_like "driver with cookies support"
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,5 +14,5 @@ describe Capybara::Driver::RackTest do
|
||||||
it_should_behave_like "driver"
|
it_should_behave_like "driver"
|
||||||
it_should_behave_like "driver with header support"
|
it_should_behave_like "driver with header support"
|
||||||
it_should_behave_like "driver with status code support"
|
it_should_behave_like "driver with status code support"
|
||||||
|
it_should_behave_like "driver with cookies support"
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,4 +9,5 @@ describe Capybara::Driver::Selenium do
|
||||||
it_should_behave_like "driver with javascript support"
|
it_should_behave_like "driver with javascript support"
|
||||||
it_should_behave_like "driver with frame support"
|
it_should_behave_like "driver with frame support"
|
||||||
it_should_behave_like "driver without status code support"
|
it_should_behave_like "driver without status code support"
|
||||||
|
it_should_behave_like "driver with cookies support"
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ if RUBY_PLATFORM =~ /java/
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#driver' do
|
describe '#driver' do
|
||||||
it "should be a rack test driver" do
|
it "should be a celerity driver" do
|
||||||
@session.driver.should be_an_instance_of(Capybara::Driver::Celerity)
|
@session.driver.should be_an_instance_of(Capybara::Driver::Celerity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe Capybara::Session do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#driver' do
|
describe '#driver' do
|
||||||
it "should be a rack test driver" do
|
it "should be a culerity driver" do
|
||||||
@session.driver.should be_an_instance_of(Capybara::Driver::Culerity)
|
@session.driver.should be_an_instance_of(Capybara::Driver::Culerity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue