mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
90 lines
2.7 KiB
Ruby
90 lines
2.7 KiB
Ruby
# frozen_string_literal: true
|
|
require 'spec_helper'
|
|
|
|
RSpec.describe Capybara do
|
|
describe 'default_max_wait_time' do
|
|
after do
|
|
Capybara.default_max_wait_time = @previous_default_time
|
|
end
|
|
|
|
it "should be changeable" do
|
|
@previous_default_time = Capybara.default_max_wait_time
|
|
Capybara.default_max_wait_time = 5
|
|
expect(Capybara.default_max_wait_time).to eq(5)
|
|
end
|
|
|
|
it "should be accesible as the deprecated default_wait_time" do
|
|
expect_any_instance_of(Kernel).to receive(:warn).once.with('DEPRECATED: #default_wait_time= is deprecated, please use #default_max_wait_time= instead')
|
|
expect_any_instance_of(Kernel).to receive(:warn).once.with('DEPRECATED: #default_wait_time is deprecated, please use #default_max_wait_time instead')
|
|
@previous_default_time = Capybara.default_max_wait_time
|
|
Capybara.default_wait_time = 5
|
|
expect(Capybara.default_wait_time).to eq(5)
|
|
expect(Capybara.default_max_wait_time).to eq(5)
|
|
end
|
|
end
|
|
|
|
describe '.register_driver' do
|
|
it "should add a new driver" do
|
|
Capybara.register_driver :schmoo do |app|
|
|
Capybara::RackTest::Driver.new(app)
|
|
end
|
|
session = Capybara::Session.new(:schmoo, TestApp)
|
|
session.visit('/')
|
|
expect(session.body).to include("Hello world!")
|
|
end
|
|
end
|
|
|
|
describe '.register_server' do
|
|
before do
|
|
Capybara.reuse_server = false
|
|
@old_server = Capybara.server
|
|
end
|
|
|
|
after do
|
|
Capybara.server(&@old_server)
|
|
Capybara.reuse_server = true
|
|
end
|
|
|
|
it "should add a new server" do
|
|
Capybara.register_server :blob do |app, port, host|
|
|
Rack::Handler::WEBrick.run(app, :Host => host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
|
end
|
|
Capybara.server = :blob
|
|
session = Capybara::Session.new(:selenium, TestApp.dup)
|
|
session.visit('/')
|
|
expect(session.body).to include("Hello world!")
|
|
end
|
|
end
|
|
|
|
describe ".server" do
|
|
before do
|
|
@old_server = Capybara.server
|
|
end
|
|
|
|
after do
|
|
Capybara.server(&@old_server)
|
|
end
|
|
|
|
it "should default to a proc that calls run_default_server" do
|
|
mock_app = double('app')
|
|
expect(Capybara).to receive(:run_default_server).with(mock_app, 8000)
|
|
Capybara.server.call(mock_app, 8000)
|
|
end
|
|
|
|
it "should return a custom server proc" do
|
|
server = lambda {|app, port|}
|
|
Capybara.server(&server)
|
|
expect(Capybara.server).to eq(server)
|
|
end
|
|
end
|
|
end
|
|
|
|
RSpec.describe Capybara::Session do
|
|
context 'with non-existant driver' do
|
|
it "should raise an error" do
|
|
expect {
|
|
Capybara::Session.new(:quox, TestApp).driver
|
|
}.to raise_error(Capybara::DriverNotFoundError)
|
|
end
|
|
end
|
|
end
|