Skip to content
Browse files

Add using_wait_time method, closes #400

  • Loading branch information...
1 parent af2c607 commit 1d995d427c3b03c3649ae13e6f95fd95d610aec9 Jonas Nicklas and Nicklas Ramhöj committed with radar Aug 30, 2011
Showing with 54 additions and 0 deletions.
  1. +21 −0 lib/capybara/dsl.rb
  2. +33 −0 spec/dsl_spec.rb
View
21 lib/capybara/dsl.rb
@@ -58,6 +58,18 @@ def using_driver(driver)
##
#
+ # 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
#
# @return [Capybara::Session] The currently used session
@@ -117,6 +129,15 @@ def using_session(name, &block)
##
#
+ # 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
# class or module.
#
View
33 spec/dsl_spec.rb
@@ -94,6 +94,30 @@
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
it "should be changeable" do
Capybara.app = "foobar"
@@ -215,6 +239,15 @@
foo = klass.new
foo.using_session(:name)
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

0 comments on commit 1d995d4

Please sign in to comment.
Something went wrong with that request. Please try again.