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
|
|
|
|
2010-10-27 22:53:59 -04:00
|
|
|
describe ".server" do
|
|
|
|
after do
|
|
|
|
Capybara.server {|app, port| Capybara.run_default_server(app, port)}
|
|
|
|
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
|
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
|