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
|
||||
end
|
||||
|
||||
def cleanup!
|
||||
browser.clear_cookies
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def url(path)
|
||||
|
|
|
@ -228,6 +228,10 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
|||
end
|
||||
alias_method :source, :body
|
||||
|
||||
def cleanup!
|
||||
clear_cookies
|
||||
end
|
||||
|
||||
def get(*args, &block); reset_cache; super; end
|
||||
def post(*args, &block); reset_cache; super; end
|
||||
def put(*args, &block); reset_cache; super; end
|
||||
|
@ -268,9 +272,4 @@ private
|
|||
env
|
||||
end
|
||||
|
||||
def reset_cache
|
||||
@body = nil
|
||||
@html = nil
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -95,7 +95,6 @@ shared_examples_for 'driver' do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
shared_examples_for "driver with javascript support" do
|
||||
|
@ -176,3 +175,22 @@ shared_examples_for "driver with frame support" do
|
|||
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
|
||||
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|
|
||||
erb view.to_sym
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ if RUBY_PLATFORM =~ /java/
|
|||
it_should_behave_like "driver with javascript support"
|
||||
it_should_behave_like "driver with header support"
|
||||
it_should_behave_like "driver with status code support"
|
||||
|
||||
it_should_behave_like "driver with cookies support"
|
||||
end
|
||||
else
|
||||
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 header support"
|
||||
it_should_behave_like "driver with status code support"
|
||||
|
||||
it_should_behave_like "driver with cookies support"
|
||||
end
|
||||
|
|
|
@ -14,5 +14,5 @@ describe Capybara::Driver::RackTest do
|
|||
it_should_behave_like "driver"
|
||||
it_should_behave_like "driver with header support"
|
||||
it_should_behave_like "driver with status code support"
|
||||
|
||||
it_should_behave_like "driver with cookies support"
|
||||
end
|
||||
|
|
|
@ -9,4 +9,5 @@ describe Capybara::Driver::Selenium do
|
|||
it_should_behave_like "driver with javascript support"
|
||||
it_should_behave_like "driver with frame support"
|
||||
it_should_behave_like "driver without status code support"
|
||||
it_should_behave_like "driver with cookies support"
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ if RUBY_PLATFORM =~ /java/
|
|||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ describe Capybara::Session do
|
|||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue