2016-12-15 12:04:01 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2016-12-15 12:04:01 -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
|
2016-12-15 12:04:01 -05:00
|
|
|
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
|
|
|
|
asset_host].each do |m|
|
|
|
|
expect(session.config.public_send(m)).to eq Capybara.public_send(m)
|
|
|
|
end
|
2016-12-15 12:04:01 -05:00
|
|
|
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'
|
2016-12-15 12:04:01 -05:00
|
|
|
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'
|
2016-12-15 12:04:01 -05:00
|
|
|
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/)
|
2016-12-15 12:04:01 -05:00
|
|
|
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/)
|
2016-12-15 12:04:01 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'uses the config from the session' do
|
2016-12-15 12:04:01 -05:00
|
|
|
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/)
|
2016-12-15 12:04:01 -05:00
|
|
|
end
|
|
|
|
end
|
2018-02-28 19:11:41 -05:00
|
|
|
end
|