2010-09-17 19:56:32 -04:00
|
|
|
require 'spec_helper'
|
2009-11-12 11:51:31 -05:00
|
|
|
|
2009-11-16 16:02:16 -05:00
|
|
|
require 'capybara/dsl'
|
2009-11-12 11:51:31 -05:00
|
|
|
|
2009-11-16 16:02:16 -05:00
|
|
|
describe Capybara do
|
2009-11-12 11:51:31 -05:00
|
|
|
|
|
|
|
before do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.app = TestApp
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2011-01-22 15:19:42 -05:00
|
|
|
Capybara.session_name = nil
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.default_driver = nil
|
|
|
|
Capybara.use_default_driver
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#default_driver' do
|
|
|
|
it "should default to rack_test" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.default_driver.should == :rack_test
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be changeable" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.default_driver = :culerity
|
|
|
|
Capybara.default_driver.should == :culerity
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#current_driver' do
|
|
|
|
it "should default to the default driver" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.current_driver.should == :rack_test
|
|
|
|
Capybara.default_driver = :culerity
|
|
|
|
Capybara.current_driver.should == :culerity
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be changeable" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.current_driver = :culerity
|
|
|
|
Capybara.current_driver.should == :culerity
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
end
|
2009-12-12 07:33:00 -05:00
|
|
|
|
2009-11-16 14:11:42 -05:00
|
|
|
describe '#javascript_driver' do
|
|
|
|
it "should default to selenium" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.javascript_driver.should == :selenium
|
2009-11-16 14:11:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be changeable" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.javascript_driver = :culerity
|
|
|
|
Capybara.javascript_driver.should == :culerity
|
2009-11-16 14:11:42 -05:00
|
|
|
end
|
|
|
|
end
|
2009-11-12 11:51:31 -05:00
|
|
|
|
|
|
|
describe '#use_default_driver' do
|
|
|
|
it "should restore the default driver" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.current_driver = :culerity
|
|
|
|
Capybara.use_default_driver
|
|
|
|
Capybara.current_driver.should == :rack_test
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-07 09:37:33 -05:00
|
|
|
describe '#using_driver' do
|
|
|
|
before do
|
|
|
|
Capybara.current_driver.should_not == :selenium
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set the driver using Capybara.current_driver=' do
|
|
|
|
driver = nil
|
|
|
|
Capybara.using_driver(:selenium) { driver = Capybara.current_driver }
|
|
|
|
driver.should == :selenium
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should reset the driver using Capybara.use_default_driver, even if an exception occurs' do
|
|
|
|
begin
|
|
|
|
Capybara.using_driver(:selenium) { raise "ohnoes!" }
|
|
|
|
rescue Exception
|
|
|
|
end
|
|
|
|
Capybara.current_driver.should == Capybara.default_driver
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should yield the passed block' do
|
|
|
|
called = false
|
|
|
|
Capybara.using_driver(:selenium) { called = true }
|
|
|
|
called.should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-12 11:51:31 -05:00
|
|
|
describe '#app' do
|
|
|
|
it "should be changeable" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.app = "foobar"
|
|
|
|
Capybara.app.should == 'foobar'
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#current_session' do
|
|
|
|
it "should choose a session object of the current driver type" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.current_session.should be_a(Capybara::Session)
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use #app as the application" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.app = proc {}
|
|
|
|
Capybara.current_session.app.should == Capybara.app
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should change with the current driver" do
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.current_session.mode.should == :rack_test
|
2010-09-07 12:34:47 -04:00
|
|
|
Capybara.current_driver = :selenium
|
|
|
|
Capybara.current_session.mode.should == :selenium
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be persistent even across driver changes" do
|
2009-11-16 16:02:16 -05:00
|
|
|
object_id = Capybara.current_session.object_id
|
|
|
|
Capybara.current_session.object_id.should == object_id
|
2010-09-07 12:34:47 -04:00
|
|
|
Capybara.current_driver = :selenium
|
|
|
|
Capybara.current_session.mode.should == :selenium
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.current_session.object_id.should_not == object_id
|
2009-11-12 11:51:31 -05:00
|
|
|
|
2009-11-16 16:02:16 -05:00
|
|
|
Capybara.current_driver = :rack_test
|
|
|
|
Capybara.current_session.object_id.should == object_id
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should change when changing application" do
|
2009-11-16 16:02:16 -05:00
|
|
|
object_id = Capybara.current_session.object_id
|
|
|
|
Capybara.current_session.object_id.should == object_id
|
|
|
|
Capybara.app = proc {}
|
|
|
|
Capybara.current_session.object_id.should_not == object_id
|
|
|
|
Capybara.current_session.app.should == Capybara.app
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
2011-01-09 17:47:28 -05:00
|
|
|
|
2011-01-22 15:19:42 -05:00
|
|
|
it "should change when the session name changes" do
|
|
|
|
object_id = Capybara.current_session.object_id
|
|
|
|
Capybara.session_name = :administrator
|
|
|
|
Capybara.session_name.should == :administrator
|
|
|
|
Capybara.current_session.object_id.should_not == object_id
|
|
|
|
Capybara.session_name = :default
|
|
|
|
Capybara.session_name.should == :default
|
|
|
|
Capybara.current_session.object_id.should == object_id
|
2011-01-09 17:47:28 -05:00
|
|
|
end
|
2011-01-22 15:19:42 -05:00
|
|
|
end
|
2011-01-09 17:47:28 -05:00
|
|
|
|
2011-01-22 15:30:37 -05:00
|
|
|
describe "#using_session" do
|
2011-01-22 15:19:42 -05:00
|
|
|
it "should change the session name for the duration of the block" do
|
|
|
|
Capybara.session_name.should == :default
|
2011-01-22 15:30:37 -05:00
|
|
|
Capybara.using_session(:administrator) do
|
2011-01-22 15:19:42 -05:00
|
|
|
Capybara.session_name.should == :administrator
|
2011-01-09 17:47:28 -05:00
|
|
|
end
|
2011-01-22 15:19:42 -05:00
|
|
|
Capybara.session_name.should == :default
|
2011-01-09 17:47:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should reset the session to the default, even if an exception occurs" do
|
|
|
|
begin
|
2011-01-22 15:30:37 -05:00
|
|
|
Capybara.using_session(:raise) do
|
2011-01-22 15:19:42 -05:00
|
|
|
raise
|
|
|
|
end
|
2011-01-09 17:47:28 -05:00
|
|
|
rescue Exception
|
|
|
|
end
|
2011-01-22 15:19:42 -05:00
|
|
|
Capybara.session_name.should == :default
|
2011-01-09 17:47:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should yield the passed block" do
|
|
|
|
called = false
|
2011-01-22 15:30:37 -05:00
|
|
|
Capybara.using_session(:administrator) { called = true }
|
2011-01-09 17:47:28 -05:00
|
|
|
called.should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-22 15:19:42 -05:00
|
|
|
describe "#session_name" do
|
|
|
|
it "should default to :default" do
|
|
|
|
Capybara.session_name.should == :default
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-12 11:51:31 -05:00
|
|
|
describe 'the DSL' do
|
|
|
|
before do
|
2009-11-16 16:02:16 -05:00
|
|
|
@session = Capybara
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like "session"
|
2009-12-12 15:56:32 -05:00
|
|
|
it_should_behave_like "session without javascript support"
|
2009-11-12 12:09:29 -05:00
|
|
|
|
|
|
|
it "should be possible to include it in another class" do
|
|
|
|
klass = Class.new do
|
2009-11-16 16:02:16 -05:00
|
|
|
include Capybara
|
2009-11-12 12:09:29 -05:00
|
|
|
end
|
|
|
|
foo = klass.new
|
|
|
|
foo.visit('/with_html')
|
|
|
|
foo.click_link('ullamco')
|
|
|
|
foo.body.should include('Another World')
|
|
|
|
end
|
2009-12-12 07:33:00 -05:00
|
|
|
|
2009-11-14 07:51:52 -05:00
|
|
|
it "should provide a 'page' shortcut for more expressive tests" do
|
|
|
|
klass = Class.new do
|
2009-11-16 16:02:16 -05:00
|
|
|
include Capybara
|
2009-11-14 07:51:52 -05:00
|
|
|
end
|
|
|
|
foo = klass.new
|
|
|
|
foo.page.visit('/with_html')
|
|
|
|
foo.page.click_link('ullamco')
|
|
|
|
foo.page.body.should include('Another World')
|
|
|
|
end
|
2011-01-09 17:47:28 -05:00
|
|
|
|
2011-01-22 15:30:37 -05:00
|
|
|
it "should provide an 'using_session' shortcut" do
|
2011-01-09 17:47:28 -05:00
|
|
|
klass = Class.new do
|
|
|
|
include Capybara
|
|
|
|
end
|
2011-01-22 15:30:37 -05:00
|
|
|
Capybara.should_receive(:using_session).with(:name)
|
2011-01-09 17:47:28 -05:00
|
|
|
foo = klass.new
|
2011-01-22 15:30:37 -05:00
|
|
|
foo.using_session(:name)
|
2011-01-09 17:47:28 -05:00
|
|
|
end
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|