1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/spec/session_spec.rb

92 lines
2.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-02-28 19:11:41 -05:00
require 'spec_helper'
RSpec.describe Capybara::Session do
2019-10-15 20:40:27 -04:00
describe '#new' do
2018-07-10 17:18:39 -04:00
it 'should raise an error if passed non-existent driver' do
expect do
2019-07-15 17:49:21 -04:00
described_class.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
expect do
2019-07-15 17:49:21 -04:00
described_class.new(:unknown, random: 'hash')
2018-07-10 17:18:39 -04:00
end.to raise_error TypeError, 'The second parameter to Session::new should be a rack app if passed.'
end
end
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
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
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
Capybara.threadsafe = false
2018-07-10 17:18:39 -04:00
Capybara.session_name = 'sess1'
thread = Thread.new do
2018-07-10 17:18:39 -04:00
Capybara.session_name = 'sess2'
end
thread.join
2018-07-10 17:18:39 -04:00
expect(Capybara.session_name).to eq 'sess2'
end
2018-07-10 17:18:39 -04:00
it 'is thread specific when threadsafe true' do
Capybara.threadsafe = true
2018-07-10 17:18:39 -04:00
Capybara.session_name = 'sess1'
thread = Thread.new do
2018-07-10 17:18:39 -04:00
Capybara.session_name = 'sess2'
end
thread.join
2018-07-10 17:18:39 -04:00
expect(Capybara.session_name).to eq 'sess1'
end
end
2018-11-28 19:21:29 -05:00
context 'quit' do
it 'will reset the driver' do
2019-07-15 17:49:21 -04:00
session = described_class.new(:rack_test, TestApp)
2018-11-28 19:21:29 -05:00
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
2019-07-15 17:49:21 -04:00
session = described_class.new(:rack_test, TestApp)
2019-04-10 18:02:02 -04:00
document = session.document
session.quit
expect(session.document.base).not_to eql document.base
end
2018-11-28 19:21:29 -05:00
end
end