mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Add using_wait_time method, closes #400
This commit is contained in:
parent
1a56611d4b
commit
e9b8a45f84
2 changed files with 54 additions and 0 deletions
|
@ -56,6 +56,18 @@ module Capybara
|
||||||
@current_driver = previous_driver
|
@current_driver = previous_driver
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
#
|
||||||
|
# Yield a block using a specific wait time
|
||||||
|
#
|
||||||
|
def using_wait_time(seconds)
|
||||||
|
previous_wait_time = Capybara.default_wait_time
|
||||||
|
Capybara.default_wait_time = seconds
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
Capybara.default_wait_time = previous_wait_time
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
# The current Capybara::Session base on what is set as Capybara.app and Capybara.current_driver
|
# The current Capybara::Session base on what is set as Capybara.app and Capybara.current_driver
|
||||||
|
@ -115,6 +127,15 @@ module Capybara
|
||||||
Capybara.using_session(name, &block)
|
Capybara.using_session(name, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
#
|
||||||
|
# Shortcut to working in a different session. This is useful when Capybara is included
|
||||||
|
# in a class or module.
|
||||||
|
#
|
||||||
|
def using_wait_time(seconds, &block)
|
||||||
|
Capybara.using_wait_time(seconds, &block)
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
# Shortcut to accessing the current session. This is useful when Capybara is included in a
|
# Shortcut to accessing the current session. This is useful when Capybara is included in a
|
||||||
|
|
|
@ -94,6 +94,30 @@ describe Capybara::DSL do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#using_wait_time' do
|
||||||
|
it "should switch the wait time and switch it back" do
|
||||||
|
in_block = nil
|
||||||
|
Capybara.using_wait_time 6 do
|
||||||
|
in_block = Capybara.default_wait_time
|
||||||
|
end
|
||||||
|
in_block.should == 6
|
||||||
|
Capybara.default_wait_time.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should ensure wait time is reset" do
|
||||||
|
expect do
|
||||||
|
Capybara.using_wait_time 6 do
|
||||||
|
raise "hell"
|
||||||
|
end
|
||||||
|
end.to raise_error
|
||||||
|
Capybara.default_wait_time.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
Capybara.default_wait_time = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#app' do
|
describe '#app' do
|
||||||
it "should be changeable" do
|
it "should be changeable" do
|
||||||
Capybara.app = "foobar"
|
Capybara.app = "foobar"
|
||||||
|
@ -215,6 +239,15 @@ describe Capybara::DSL do
|
||||||
foo = klass.new
|
foo = klass.new
|
||||||
foo.using_session(:name)
|
foo.using_session(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should provide a 'using_wait_time' shortcut" do
|
||||||
|
klass = Class.new do
|
||||||
|
include Capybara::DSL
|
||||||
|
end
|
||||||
|
Capybara.should_receive(:using_wait_time).with(6)
|
||||||
|
foo = klass.new
|
||||||
|
foo.using_wait_time(6)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue