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

113 lines
3.2 KiB
Ruby
Raw Normal View History

2016-03-07 19:52:19 -05:00
# frozen_string_literal: true
2018-02-28 19:11:41 -05:00
require 'spec_helper'
RSpec.describe Capybara do
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-07-15 17:49:21 -04:00
after { described_class.default_max_wait_time = @previous_default_time } # rubocop:disable RSpec/InstanceVariable
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)
end
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
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|
# do nothing
2016-02-16 16:37:17 -05:00
end
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
after do
2019-07-15 17:49:21 -04:00
described_class.server = :default
end
2018-07-10 17:18:39 -04:00
it 'should default to a proc that calls run_default_server' do
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)
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)
end
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
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
end
end
2018-07-10 17:18:39 -04:00
describe 'server=' do
after do
2019-07-15 17:49:21 -04:00
described_class.server = :default
end
2018-07-10 17:18:39 -04:00
it 'accepts a proc' do
server = ->(_app, _port) {}
2019-07-15 17:49:21 -04:00
described_class.server = server
expect(described_class.server).to eq server
end
end
describe 'app_host' do
after do
2019-07-15 17:49:21 -04:00
described_class.app_host = nil
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/)
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
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
end
end
describe 'default_host' do
around do |test|
2019-07-15 17:49:21 -04:00
old_default = described_class.default_host
test.run
2019-07-15 17:49:21 -04:00
described_class.default_host = old_default
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/)
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
end
end
end