1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Within now accepts same args as other finders. closes #227

This commit is contained in:
Jonas Nicklas 2010-12-22 16:15:06 +01:00 committed by Your Name
parent 2b78681d07
commit 86491cb060
2 changed files with 14 additions and 7 deletions

View file

@ -151,11 +151,11 @@ module Capybara
# fill_in('Street', :with => '12 Main Street')
# end
#
# @param [:css, :xpath, String] kind The type of selector or the selector if the second argument is blank
# @param [String] selector The selector within which to execute the given block
# @param (see Capybara::Node::Finders#all)
# @raise [Capybara::ElementNotFound] If the scope can't be found before time expires
#
def within(kind, selector=nil)
new_scope = find(kind, selector, :message => "scope '#{selector || kind}' not found on page")
def within(*args)
new_scope = find(*args)
begin
scopes.push(new_scope)
yield

View file

@ -1,4 +1,4 @@
shared_examples_for "within" do
shared_examples_for "within" do
describe '#within' do
before do
@session.visit('/with_scope')
@ -11,6 +11,13 @@ shared_examples_for "within" do
end
@session.body.should include('Bar')
end
it "should accept additional options" do
@session.within(:css, "ul li", :text => 'With Simple HTML') do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
end
context "with XPath selector" do
@ -32,14 +39,14 @@ shared_examples_for "within" do
end
context "with the default selector set to CSS" do
before { Capybara.default_selector = :css }
before { Capybara.default_selector = :css }
it "should use CSS" do
@session.within("ul li[contains('With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
after { Capybara.default_selector = :xpath }
after { Capybara.default_selector = :xpath }
end
context "with click_link" do