mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Pass new and previous session to using_session
block if it accepts
This commit is contained in:
parent
0eb272e5a6
commit
e60f1194eb
4 changed files with 24 additions and 4 deletions
|
@ -11,6 +11,11 @@ AllCops:
|
||||||
|
|
||||||
#################### Lint ################################
|
#################### Lint ################################
|
||||||
|
|
||||||
|
Layout/SpaceAroundMethodCallOperator:
|
||||||
|
Enabled: true
|
||||||
|
Style/ExponentialNotation:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Layout/LineLength:
|
Layout/LineLength:
|
||||||
Description: 'Limit lines to 80 characters.'
|
Description: 'Limit lines to 80 characters.'
|
||||||
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
|
||||||
|
|
|
@ -350,7 +350,8 @@ module Capybara
|
||||||
#
|
#
|
||||||
# Yield a block using a specific session name or {Capybara::Session} instance.
|
# Yield a block using a specific session name or {Capybara::Session} instance.
|
||||||
#
|
#
|
||||||
def using_session(name_or_session)
|
def using_session(name_or_session, &block)
|
||||||
|
previous_session = current_session
|
||||||
previous_session_info = {
|
previous_session_info = {
|
||||||
specified_session: specified_session,
|
specified_session: specified_session,
|
||||||
session_name: session_name,
|
session_name: session_name,
|
||||||
|
@ -363,7 +364,12 @@ module Capybara
|
||||||
else
|
else
|
||||||
self.session_name = name_or_session
|
self.session_name = name_or_session
|
||||||
end
|
end
|
||||||
yield
|
|
||||||
|
if block.arity.zero?
|
||||||
|
yield
|
||||||
|
else
|
||||||
|
yield current_session, previous_session
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
self.session_name, self.specified_session = previous_session_info.values_at(:session_name, :specified_session)
|
self.session_name, self.specified_session = previous_session_info.values_at(:session_name, :specified_session)
|
||||||
self.current_driver, self.app = previous_session_info.values_at(:current_driver, :app) if threadsafe
|
self.current_driver, self.app = previous_session_info.values_at(:current_driver, :app) if threadsafe
|
||||||
|
|
|
@ -128,11 +128,11 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do
|
||||||
# Without ignore_query option
|
# Without ignore_query option
|
||||||
expect do
|
expect do
|
||||||
expect(@session).not_to have_current_path('/with_js')
|
expect(@session).not_to have_current_path('/with_js')
|
||||||
end. not_to raise_exception
|
end.not_to raise_exception
|
||||||
|
|
||||||
# With ignore_query option
|
# With ignore_query option
|
||||||
expect do
|
expect do
|
||||||
expect(@session).not_to have_current_path('/with_js', ignore_query: true)
|
expect(@session).not_to have_current_path('/with_js', ignore_query: true)
|
||||||
end. not_to raise_exception
|
end.not_to raise_exception
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -238,6 +238,15 @@ RSpec.describe Capybara::DSL do
|
||||||
end
|
end
|
||||||
expect(Capybara.current_session).to eq(original_session)
|
expect(Capybara.current_session).to eq(original_session)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should pass the new session if block accepts' do
|
||||||
|
original_session = Capybara.current_session
|
||||||
|
Capybara.using_session(:administrator) do |admin_session, prev_session|
|
||||||
|
expect(admin_session).to be(Capybara.current_session)
|
||||||
|
expect(prev_session).to be(original_session)
|
||||||
|
expect(prev_session).not_to be(admin_session)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#session_name' do
|
describe '#session_name' do
|
||||||
|
|
Loading…
Reference in a new issue