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-02-25 18:50:24 -05:00
|
|
|
before { @previous_default_time = Capybara.default_max_wait_time }
|
|
|
|
|
|
|
|
after { Capybara.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-02-25 18:50:24 -05:00
|
|
|
expect(Capybara.default_max_wait_time).not_to eq(5)
|
2015-04-14 16:56:30 -04:00
|
|
|
Capybara.default_max_wait_time = 5
|
|
|
|
expect(Capybara.default_max_wait_time).to eq(5)
|
|
|
|
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
|
2010-07-29 09:20:11 -04:00
|
|
|
Capybara.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
|
2018-02-28 19:11:41 -05:00
|
|
|
Capybara.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
|
|
|
|
|
|
|
expect(Capybara.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
|
2016-08-17 16:21:21 -04:00
|
|
|
Capybara.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
|
2018-05-01 16:36:42 -04:00
|
|
|
allow(Capybara).to receive(:run_default_server).and_return(true)
|
2010-10-27 22:53:59 -04:00
|
|
|
Capybara.server.call(mock_app, 8000)
|
2018-04-27 14:01:47 -04:00
|
|
|
expect(Capybara).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) {}
|
2016-08-17 16:21:21 -04:00
|
|
|
Capybara.register_server :custom, &server
|
|
|
|
Capybara.server = :custom
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(Capybara.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
|
2018-03-23 16:41:42 -04:00
|
|
|
expect(Capybara.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
|
2018-03-23 16:41:42 -04:00
|
|
|
expect(Capybara.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
|
|
|
|
Capybara.server = :default
|
|
|
|
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) {}
|
|
|
|
Capybara.server = server
|
|
|
|
expect(Capybara.server).to eq server
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-06 13:15:59 -04:00
|
|
|
describe 'app_host' do
|
|
|
|
after do
|
|
|
|
Capybara.app_host = nil
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should warn if not a valid URL' do
|
|
|
|
expect { Capybara.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
|
|
|
|
expect { Capybara.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
|
2016-05-06 13:15:59 -04:00
|
|
|
expect { Capybara.app_host = nil }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'default_host' do
|
|
|
|
around do |test|
|
|
|
|
old_default = Capybara.default_host
|
|
|
|
test.run
|
|
|
|
Capybara.default_host = old_default
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should raise if not a valid URL' do
|
|
|
|
expect { Capybara.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
|
|
|
|
expect { Capybara.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
|