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 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
before { @previous_default_time = Capybara.default_max_wait_time }
after { Capybara.default_max_wait_time = @previous_default_time } # rubocop:disable RSpec/InstanceVariable
2018-07-10 17:18:39 -04:00
it 'should be changeable' do
expect(Capybara.default_max_wait_time).not_to eq(5)
Capybara.default_max_wait_time = 5
expect(Capybara.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
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
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|
# do nothing
2016-02-16 16:37:17 -05:00
end
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
after do
Capybara.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
allow(Capybara).to receive(:run_default_server).and_return(true)
Capybara.server.call(mock_app, 8000)
expect(Capybara).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) {}
Capybara.register_server :custom, &server
Capybara.server = :custom
expect(Capybara.server).to eq(server)
end
2018-07-10 17:18:39 -04:00
it 'should have :webrick registered' do
expect(Capybara.servers[:webrick]).not_to be_nil
end
2018-07-10 17:18:39 -04:00
it 'should have :puma registered' do
expect(Capybara.servers[:puma]).not_to be_nil
end
end
2018-07-10 17:18:39 -04:00
describe 'server=' do
after do
Capybara.server = :default
end
2018-07-10 17:18:39 -04:00
it 'accepts a proc' do
server = ->(_app, _port) {}
Capybara.server = server
expect(Capybara.server).to eq server
end
end
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/)
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
end
2018-07-10 17:18:39 -04:00
it 'should not warn if nil' do
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/)
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
end
end
end