mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Allow #within to take a node in addition to a selector
This commit is contained in:
parent
0858c26d94
commit
363e87c862
2 changed files with 22 additions and 2 deletions
|
@ -173,11 +173,20 @@ module Capybara
|
|||
# fill_in('Street', :with => '12 Main Street')
|
||||
# end
|
||||
#
|
||||
# @param (see Capybara::Node::Finders#all)
|
||||
# @overload within(*find_args)
|
||||
# @param (see Capybara::Node::Finders#all)
|
||||
#
|
||||
# @overload within(a_node)
|
||||
# @param [Capybara::Node::Base] a_node The node in whose scope the block should be evaluated
|
||||
#
|
||||
# @raise [Capybara::ElementNotFound] If the scope can't be found before time expires
|
||||
#
|
||||
def within(*args)
|
||||
new_scope = find(*args)
|
||||
new_scope = if args.size == 1 && Capybara::Node::Base === args.first
|
||||
args.first
|
||||
else
|
||||
find(*args)
|
||||
end
|
||||
begin
|
||||
scopes.push(new_scope)
|
||||
yield
|
||||
|
|
|
@ -38,6 +38,17 @@ shared_examples_for "within" do
|
|||
end
|
||||
end
|
||||
|
||||
context "with Node rather than selector" do
|
||||
it "should click links in the given scope" do
|
||||
node_of_interest = @session.find(:css, "ul li[contains('With Simple HTML')]")
|
||||
|
||||
@session.within(node_of_interest) do
|
||||
@session.click_link('Go')
|
||||
end
|
||||
@session.body.should include('Bar')
|
||||
end
|
||||
end
|
||||
|
||||
context "with the default selector set to CSS" do
|
||||
before { Capybara.default_selector = :css }
|
||||
it "should use CSS" do
|
||||
|
|
Loading…
Reference in a new issue