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

85 lines
2.2 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
2018-07-10 17:18:39 -04:00
context '#new' do
it 'should raise an error if passed non-existent driver' do
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
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.'
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
session = Capybara::Session.new(:rack_test, TestApp)
driver = session.driver
session.quit
expect(session.driver).not_to eql driver
end
end
end