2016-03-07 16:52:19 -08:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 16:11:41 -08:00
|
|
|
|
2010-09-17 18:56:32 -05:00
|
|
|
require 'spec_helper'
|
2009-12-31 13:51:22 -05:00
|
|
|
|
2014-04-03 10:25:03 -07:00
|
|
|
RSpec.describe Capybara do
|
2015-04-14 13:56:30 -07:00
|
|
|
describe 'default_max_wait_time' do
|
2019-07-15 14:49:21 -07:00
|
|
|
before { @previous_default_time = described_class.default_max_wait_time }
|
2019-02-25 15:50:24 -08:00
|
|
|
|
2019-07-15 14:49:21 -07:00
|
|
|
after { described_class.default_max_wait_time = @previous_default_time } # rubocop:disable RSpec/InstanceVariable
|
2010-09-15 18:19:25 +02:00
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should be changeable' do
|
2019-07-15 14:49:21 -07:00
|
|
|
expect(described_class.default_max_wait_time).not_to eq(5)
|
|
|
|
described_class.default_max_wait_time = 5
|
|
|
|
expect(described_class.default_max_wait_time).to eq(5)
|
2015-04-14 13:56:30 -07:00
|
|
|
end
|
2009-12-31 13:51:22 -05:00
|
|
|
end
|
2010-07-29 15:20:11 +02:00
|
|
|
|
|
|
|
describe '.register_driver' do
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should add a new driver' do
|
2019-07-15 14:49:21 -07:00
|
|
|
described_class.register_driver :schmoo do |app|
|
2011-04-08 16:14:05 +01:00
|
|
|
Capybara::RackTest::Driver.new(app)
|
2010-07-29 15:20:11 +02:00
|
|
|
end
|
|
|
|
session = Capybara::Session.new(:schmoo, TestApp)
|
|
|
|
session.visit('/')
|
2018-07-10 14:18:39 -07:00
|
|
|
expect(session.body).to include('Hello world!')
|
2010-07-29 15:20:11 +02:00
|
|
|
end
|
|
|
|
end
|
2010-09-15 18:19:25 +02:00
|
|
|
|
2016-02-16 13:37:17 -08:00
|
|
|
describe '.register_server' do
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should add a new server' do
|
2019-07-15 14:49:21 -07:00
|
|
|
described_class.register_server :blob do |_app, _port, _host|
|
2018-04-27 11:01:47 -07:00
|
|
|
# do nothing
|
2016-02-16 13:37:17 -08:00
|
|
|
end
|
2017-08-11 11:37:15 -07:00
|
|
|
|
2019-07-15 14:49:21 -07:00
|
|
|
expect(described_class.servers).to have_key(:blob)
|
2016-02-16 13:37:17 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
describe '.server' do
|
2010-10-27 19:53:59 -07:00
|
|
|
after do
|
2019-07-15 14:49:21 -07:00
|
|
|
described_class.server = :default
|
2010-10-27 19:53:59 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should default to a proc that calls run_default_server' do
|
2018-04-27 11:01:47 -07:00
|
|
|
mock_app = Object.new
|
2019-07-15 14:49:21 -07:00
|
|
|
allow(described_class).to receive(:run_default_server).and_return(true)
|
|
|
|
described_class.server.call(mock_app, 8000)
|
|
|
|
expect(described_class).to have_received(:run_default_server).with(mock_app, 8000)
|
2010-10-27 19:53:59 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should return a custom server proc' do
|
2018-02-28 16:11:41 -08:00
|
|
|
server = ->(_app, _port) {}
|
2019-07-15 14:49:21 -07:00
|
|
|
described_class.register_server :custom, &server
|
|
|
|
described_class.server = :custom
|
|
|
|
expect(described_class.server).to eq(server)
|
2010-10-27 19:53:59 -07:00
|
|
|
end
|
2017-05-30 11:44:02 -07:00
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should have :webrick registered' do
|
2019-07-15 14:49:21 -07:00
|
|
|
expect(described_class.servers[:webrick]).not_to be_nil
|
2017-05-30 11:44:02 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should have :puma registered' do
|
2019-07-15 14:49:21 -07:00
|
|
|
expect(described_class.servers[:puma]).not_to be_nil
|
2017-08-01 16:50:05 -07:00
|
|
|
end
|
2010-10-27 19:53:59 -07:00
|
|
|
end
|
2016-05-06 10:15:59 -07:00
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
describe 'server=' do
|
2018-04-06 10:17:33 -07:00
|
|
|
after do
|
2019-07-15 14:49:21 -07:00
|
|
|
described_class.server = :default
|
2018-04-06 10:17:33 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'accepts a proc' do
|
2018-04-06 10:17:33 -07:00
|
|
|
server = ->(_app, _port) {}
|
2019-07-15 14:49:21 -07:00
|
|
|
described_class.server = server
|
|
|
|
expect(described_class.server).to eq server
|
2018-04-06 10:17:33 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-06 10:15:59 -07:00
|
|
|
describe 'app_host' do
|
|
|
|
after do
|
2019-07-15 14:49:21 -07:00
|
|
|
described_class.app_host = nil
|
2016-05-06 10:15:59 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should warn if not a valid URL' do
|
2019-07-15 14:49:21 -07:00
|
|
|
expect { described_class.app_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.app_host should be set to a url/)
|
2016-05-06 10:15:59 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should not warn if a valid URL' do
|
2019-07-15 14:49:21 -07:00
|
|
|
expect { described_class.app_host = 'http://www.example.com' }.not_to raise_error
|
2016-05-06 10:15:59 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should not warn if nil' do
|
2019-07-15 14:49:21 -07:00
|
|
|
expect { described_class.app_host = nil }.not_to raise_error
|
2016-05-06 10:15:59 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'default_host' do
|
|
|
|
around do |test|
|
2019-07-15 14:49:21 -07:00
|
|
|
old_default = described_class.default_host
|
2016-05-06 10:15:59 -07:00
|
|
|
test.run
|
2019-07-15 14:49:21 -07:00
|
|
|
described_class.default_host = old_default
|
2016-05-06 10:15:59 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should raise if not a valid URL' do
|
2019-07-15 14:49:21 -07:00
|
|
|
expect { described_class.default_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.default_host should be set to a url/)
|
2016-05-06 10:15:59 -07:00
|
|
|
end
|
|
|
|
|
2018-07-10 14:18:39 -07:00
|
|
|
it 'should not warn if a valid URL' do
|
2019-07-15 14:49:21 -07:00
|
|
|
expect { described_class.default_host = 'http://www.example.com' }.not_to raise_error
|
2016-05-06 10:15:59 -07:00
|
|
|
end
|
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|