Skip to content

Commit

Permalink
Add using_wait_time method, closes teamcapybara#400
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Nicklas and Nicklas Ramhöj committed Aug 30, 2011
1 parent 1a56611 commit e9b8a45
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/capybara/dsl.rb
Expand Up @@ -56,6 +56,18 @@ def using_driver(driver)
@current_driver = previous_driver
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
Expand Down Expand Up @@ -115,6 +127,15 @@ def using_session(name, &block)
Capybara.using_session(name, &block)
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
Expand Down
33 changes: 33 additions & 0 deletions spec/dsl_spec.rb
Expand Up @@ -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"
Expand Down Expand Up @@ -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 e9b8a45

Please sign in to comment.