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