2016-12-10 13:33:25 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2016-12-10 13:33:25 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Capybara::Session do
|
2018-07-10 17:18:39 -04:00
|
|
|
context '#new' do
|
|
|
|
it 'should raise an error if passed non-existent driver' do
|
2018-04-27 14:01:47 -04:00
|
|
|
expect do
|
|
|
|
Capybara::Session.new(:quox, TestApp).driver
|
|
|
|
end.to raise_error(Capybara::DriverNotFoundError)
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'verifies a passed app is a rack app' do
|
2018-04-27 14:01:47 -04:00
|
|
|
expect do
|
2018-07-10 17:18:39 -04:00
|
|
|
Capybara::Session.new(:unknown, random: 'hash')
|
|
|
|
end.to raise_error TypeError, 'The second parameter to Session::new should be a rack app if passed.'
|
2018-04-27 14:01:47 -04:00
|
|
|
end
|
2016-12-10 13:33:25 -05:00
|
|
|
end
|
2016-12-15 12:04:01 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'current_driver' do
|
2018-05-11 15:37:45 -04:00
|
|
|
around do |example|
|
|
|
|
orig_driver = Capybara.current_driver
|
|
|
|
example.run
|
|
|
|
Capybara.current_driver = orig_driver
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'is global when threadsafe false' do
|
2016-12-15 12:04:01 -05:00
|
|
|
Capybara.threadsafe = false
|
|
|
|
Capybara.current_driver = :selenium
|
|
|
|
thread = Thread.new do
|
|
|
|
Capybara.current_driver = :random
|
|
|
|
end
|
|
|
|
thread.join
|
|
|
|
expect(Capybara.current_driver).to eq :random
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'is thread specific threadsafe true' do
|
2016-12-15 12:04:01 -05:00
|
|
|
Capybara.threadsafe = true
|
|
|
|
Capybara.current_driver = :selenium
|
|
|
|
thread = Thread.new do
|
|
|
|
Capybara.current_driver = :random
|
|
|
|
end
|
|
|
|
thread.join
|
|
|
|
expect(Capybara.current_driver).to eq :selenium
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'session_name' do
|
2018-05-11 15:37:45 -04:00
|
|
|
around do |example|
|
|
|
|
orig_name = Capybara.session_name
|
|
|
|
example.run
|
|
|
|
Capybara.session_name = orig_name
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'is global when threadsafe false' do
|
2016-12-15 12:04:01 -05:00
|
|
|
Capybara.threadsafe = false
|
2018-07-10 17:18:39 -04:00
|
|
|
Capybara.session_name = 'sess1'
|
2016-12-15 12:04:01 -05:00
|
|
|
thread = Thread.new do
|
2018-07-10 17:18:39 -04:00
|
|
|
Capybara.session_name = 'sess2'
|
2016-12-15 12:04:01 -05:00
|
|
|
end
|
|
|
|
thread.join
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(Capybara.session_name).to eq 'sess2'
|
2016-12-15 12:04:01 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'is thread specific when threadsafe true' do
|
2016-12-15 12:04:01 -05:00
|
|
|
Capybara.threadsafe = true
|
2018-07-10 17:18:39 -04:00
|
|
|
Capybara.session_name = 'sess1'
|
2016-12-15 12:04:01 -05:00
|
|
|
thread = Thread.new do
|
2018-07-10 17:18:39 -04:00
|
|
|
Capybara.session_name = 'sess2'
|
2016-12-15 12:04:01 -05:00
|
|
|
end
|
|
|
|
thread.join
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(Capybara.session_name).to eq 'sess1'
|
2016-12-15 12:04:01 -05:00
|
|
|
end
|
|
|
|
end
|
2018-11-28 19:21:29 -05:00
|
|
|
|
|
|
|
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
|
2019-04-10 18:02:02 -04:00
|
|
|
|
|
|
|
it 'resets the document' do
|
|
|
|
session = Capybara::Session.new(:rack_test, TestApp)
|
|
|
|
document = session.document
|
|
|
|
session.quit
|
|
|
|
expect(session.document.base).not_to eql document.base
|
|
|
|
end
|
2018-11-28 19:21:29 -05:00
|
|
|
end
|
2016-12-10 13:33:25 -05:00
|
|
|
end
|