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

69 lines
2.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-02-28 19:11:41 -05:00
require 'spec_helper'
require 'capybara/dsl'
RSpec.describe Capybara::SessionConfig do
2018-07-10 17:18:39 -04:00
describe 'threadsafe' do
it 'defaults to global session options' do
Capybara.threadsafe = true
session = Capybara::Session.new(:rack_test, TestApp)
2018-02-28 19:11:41 -05:00
%i[default_host app_host always_include_port run_server
default_selector default_max_wait_time ignore_hidden_elements
automatic_reload match exact raise_server_errors visible_text_only
automatic_label_click enable_aria_label save_path
2022-08-29 05:08:45 -04:00
asset_host default_retry_interval].each do |m|
2018-02-28 19:11:41 -05:00
expect(session.config.public_send(m)).to eq Capybara.public_send(m)
end
end
it "doesn't change global session when changed" do
Capybara.threadsafe = true
2018-07-10 17:18:39 -04:00
host = 'http://my.example.com'
session = Capybara::Session.new(:rack_test, TestApp) do |config|
config.default_host = host
config.automatic_label_click = !config.automatic_label_click
config.server_errors << ArgumentError
end
expect(Capybara.default_host).not_to eq host
expect(session.config.default_host).to eq host
expect(Capybara.automatic_label_click).not_to eq session.config.automatic_label_click
expect(Capybara.server_errors).not_to eq session.config.server_errors
end
it "doesn't allow session configuration block when false" do
Capybara.threadsafe = false
expect do
Capybara::Session.new(:rack_test, TestApp) { |config| }
2018-07-10 17:18:39 -04:00
end.to raise_error 'A configuration block is only accepted when Capybara.threadsafe == true'
end
it "doesn't allow session config when false" do
Capybara.threadsafe = false
session = Capybara::Session.new(:rack_test, TestApp)
2017-05-28 11:54:55 -04:00
expect { session.config.default_selector = :title }.to raise_error(/Per session settings are only supported when Capybara.threadsafe == true/)
expect do
session.configure do |config|
config.exact = true
end
2017-05-28 11:54:55 -04:00
end.to raise_error(/Session configuration is only supported when Capybara.threadsafe == true/)
end
2018-07-10 17:18:39 -04:00
it 'uses the config from the session' do
Capybara.threadsafe = true
session = Capybara::Session.new(:rack_test, TestApp) do |config|
config.default_selector = :link
end
session.visit('/with_html')
expect(session.find('foo').tag_name).to eq 'a'
end
it "won't change threadsafe once a session is created" do
Capybara.threadsafe = true
Capybara.threadsafe = false
2017-05-28 11:54:55 -04:00
Capybara::Session.new(:rack_test, TestApp)
expect { Capybara.threadsafe = true }.to raise_error(/Threadsafe setting cannot be changed once a session is created/)
end
end
2018-02-28 19:11:41 -05:00
end