field_labeled() should disregard labels without matching fields

This commit is contained in:
Kyle Hargraves 2009-01-18 15:43:51 -06:00
parent cbd323ac37
commit 2b38b78724
3 changed files with 18 additions and 2 deletions

View File

@ -68,6 +68,7 @@
* Bug fixes * Bug fixes
* field_labeled should disregard labels without matching fields (Kyle Hargraves)
* Fixed bug where Scope was creating a new DOM rather than re-using the existing DOM. * Fixed bug where Scope was creating a new DOM rather than re-using the existing DOM.
[#105] (Zach Dennis) [#105] (Zach Dennis)
* Support Rails > v2.2 by using ActionController::RequestParser for param parsing [#107] * Support Rails > v2.2 by using ActionController::RequestParser for param parsing [#107]

View File

@ -7,7 +7,7 @@ module Webrat
class FieldLabeledLocator < Locator # :nodoc: class FieldLabeledLocator < Locator # :nodoc:
def locate def locate
matching_labels.any? && matching_labels.first.field matching_labels.any? && matching_labels.detect_mapped { |label| label.field }
end end
def matching_labels def matching_labels

View File

@ -139,4 +139,19 @@ describe "field_labeled" do
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label" should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
end end
describe "finding a field when labels without fields also match" do
using_this_html <<-HTML
<html>
<label>The Label</label>
<form>
<label for="element_42">The Label</label>
<input type="text" id="element_42">
</form>
</html>
HTML
should_return_a Webrat::TextField, :for => "The Label"
with_an_id_of "element_42", :for => "The Label"
end
end end