Make Capybara::Driver::RackTest#reset! more comprehensive

So that it resets request, responses and headers as well as cookies
This commit is contained in:
Jonas Nicklas 2011-01-19 11:29:20 +00:00 committed by Joel Chippindale
parent a04e0b4d1d
commit 3cd365819b
3 changed files with 40 additions and 1 deletions

View File

@ -249,7 +249,7 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
alias_method :source, :body
def reset!
clear_cookies
clear_rack_mock_session
end
def get(*args, &block); reset_cache; super; end
@ -275,6 +275,13 @@ private
Rack::MockSession.new(app, Capybara.default_host || "www.example.com")
end
# Rack::Test::Methods does not provide methods for manipulating the session
# list so these must be manipulated directly.
def clear_rack_mock_session
@_rack_test_sessions = nil
@_rack_mock_sessions = nil
end
def request_path
request.path rescue ""
end

View File

@ -69,6 +69,10 @@ class TestApp < Sinatra::Base
request.cookies['capybara']
end
get '/get_header' do
env['HTTP_FOO']
end
get '/:view' do |view|
erb view.to_sym
end

View File

@ -53,4 +53,32 @@ describe Capybara::Driver::RackTest do
it_should_behave_like "driver with status code support"
it_should_behave_like "driver with cookies support"
it_should_behave_like "driver with infinite redirect detection"
describe '#reset!' do
it { @driver.visit('/foo'); lambda { @driver.reset! }.should change(@driver, :current_url).to('') }
it 'should reset headers' do
@driver.header('FOO', 'BAR')
@driver.visit('/get_header')
@driver.body.should include('BAR')
@driver.reset!
@driver.visit('/get_header')
@driver.body.should_not include('BAR')
end
it 'should reset response' do
@driver.visit('/foo')
lambda { @driver.response }.should_not raise_error
@driver.reset!
lambda { @driver.response }.should raise_error
end
it 'should request response' do
@driver.visit('/foo')
lambda { @driver.request }.should_not raise_error
@driver.reset!
lambda { @driver.request }.should raise_error
end
end
end