2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
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
|
2009-12-31 13:51:22 -05:00
|
|
|
after do
|
2015-04-14 16:56:30 -04:00
|
|
|
Capybara.default_max_wait_time = @previous_default_time
|
2009-12-31 13:51:22 -05:00
|
|
|
end
|
2010-09-15 12:19:25 -04:00
|
|
|
|
2009-12-31 13:51:22 -05:00
|
|
|
it "should be changeable" do
|
2015-04-14 16:56:30 -04:00
|
|
|
@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
|
2009-12-31 13:51:22 -05:00
|
|
|
Capybara.default_wait_time = 5
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(Capybara.default_wait_time).to eq(5)
|
2015-04-14 16:56:30 -04:00
|
|
|
expect(Capybara.default_max_wait_time).to eq(5)
|
2009-12-31 13:51:22 -05:00
|
|
|
end
|
|
|
|
end
|
2010-07-29 09:20:11 -04:00
|
|
|
|
|
|
|
describe '.register_driver' do
|
|
|
|
it "should add a new driver" do
|
|
|
|
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('/')
|
2013-11-14 12:43:36 -05: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
|
|
|
|
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
|
|
|
|
|
2010-10-27 22:53:59 -04:00
|
|
|
describe ".server" do
|
2016-02-16 16:37:17 -05:00
|
|
|
before do
|
|
|
|
@old_server = Capybara.server
|
|
|
|
end
|
|
|
|
|
2010-10-27 22:53:59 -04:00
|
|
|
after do
|
2016-02-16 16:37:17 -05:00
|
|
|
Capybara.server(&@old_server)
|
2010-10-27 22:53:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should default to a proc that calls run_default_server" do
|
2013-09-27 07:39:05 -04:00
|
|
|
mock_app = double('app')
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(Capybara).to receive(:run_default_server).with(mock_app, 8000)
|
2010-10-27 22:53:59 -04:00
|
|
|
Capybara.server.call(mock_app, 8000)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return a custom server proc" do
|
|
|
|
server = lambda {|app, port|}
|
|
|
|
Capybara.server(&server)
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(Capybara.server).to eq(server)
|
2010-10-27 22:53:59 -04:00
|
|
|
end
|
|
|
|
end
|
2016-05-06 13:15:59 -04:00
|
|
|
|
|
|
|
describe 'app_host' do
|
|
|
|
after do
|
|
|
|
Capybara.app_host = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it "should not warn if a valid URL" do
|
|
|
|
expect { Capybara.app_host = "http://www.example.com" }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it "should warn 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
|
|
|
|
|
|
|
|
it "should not warn if a valid URL" do
|
|
|
|
expect { Capybara.default_host = "http://www.example.com" }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-27 22:53:59 -04:00
|
|
|
|
2014-04-03 13:25:03 -04:00
|
|
|
RSpec.describe Capybara::Session do
|
2012-07-21 16:44:10 -04:00
|
|
|
context 'with non-existant driver' do
|
|
|
|
it "should raise an error" do
|
2012-10-30 09:26:19 -04:00
|
|
|
expect {
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::Session.new(:quox, TestApp).driver
|
2012-10-30 09:26:19 -04:00
|
|
|
}.to raise_error(Capybara::DriverNotFoundError)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2010-07-29 09:20:11 -04:00
|
|
|
end
|