Labels should only search for fields within the current scope

This commit is contained in:
Kyle Hargraves 2009-01-19 10:50:54 -06:00
parent 14d114ce1d
commit 6529a016d1
2 changed files with 22 additions and 1 deletions

View File

@ -23,7 +23,7 @@ module Webrat
if for_id.blank? if for_id.blank?
Webrat::XML.xpath_at(@element, *Field.xpath_search) Webrat::XML.xpath_at(@element, *Field.xpath_search)
else else
Webrat::XML.css_search(@session.dom, "#" + for_id).first Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
end end
end end

View File

@ -124,6 +124,27 @@ describe "within" do
end end
end end
it "should not find fields outside of the scope" do
with_html <<-HTML
<html>
<form id="form1" action="/form1">
<label for="email">Email</label><input id="email" type="text" name="email" />
<input type="submit" value="Add" />
</form>
<form id="form2" action="/form2">
<label for="email">Email</label><input id="email" type="text" name="email" />
<input type="submit" value="Add" />
</form>
</html>
HTML
webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
within "#form2" do
fill_in "Email", :with => "test@example.com"
click_button "Add"
end
end
it "should not find buttons outside of the scope" do it "should not find buttons outside of the scope" do
with_html <<-HTML with_html <<-HTML
<html> <html>