From 0fe411a6dadf5028c12560ce77b43358ad1a019f Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Wed, 28 Nov 2018 16:21:29 -0800 Subject: [PATCH] Add Session#quit --- lib/capybara/session.rb | 12 ++++++++++++ spec/session_spec.rb | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index 77b48fea..63436530 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -134,6 +134,18 @@ module Capybara alias_method :cleanup!, :reset! alias_method :reset_session!, :reset! + ## + # + # Disconnect from the current driver. A new driver will be instantiated on the next interaction + # + # + def quit + @driver.quit if @driver.respond_to? :quit + @driver = nil + @touched = false + @server&.reset_error! + end + ## # # Raise errors encountered in the server diff --git a/spec/session_spec.rb b/spec/session_spec.rb index 093a4121..d169bb37 100644 --- a/spec/session_spec.rb +++ b/spec/session_spec.rb @@ -72,4 +72,13 @@ RSpec.describe Capybara::Session do expect(Capybara.session_name).to eq 'sess1' end end + + context 'quit' do + it 'will reset the driver' do + session = Capybara::Session.new(:rack_test, TestApp) + driver = session.driver + session.quit + expect(session.driver).not_to eql driver + end + end end