From 4ae94af45c7c77e39ae8ba07a67cf8a332671034 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sat, 29 Nov 2008 13:20:18 -0500 Subject: [PATCH] Extract LabelLocator --- lib/webrat/core/locators.rb | 5 ++--- lib/webrat/core/locators/label_locator.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 lib/webrat/core/locators/label_locator.rb diff --git a/lib/webrat/core/locators.rb b/lib/webrat/core/locators.rb index 834f3f3..0b52fa7 100644 --- a/lib/webrat/core/locators.rb +++ b/lib/webrat/core/locators.rb @@ -99,10 +99,9 @@ module Webrat end def find_field_id_for_label(label_text) #:nodoc: - # TODO - Convert to using elements + require "webrat/core/locators/label_locator" - label = forms.detect_mapped { |form| form.label_matching(label_text) } - if label + if (label = LabelLocator.new(self, label_text).locate) label.for_id else raise NotFoundError.new("Could not find the label with text #{label_text}") diff --git a/lib/webrat/core/locators/label_locator.rb b/lib/webrat/core/locators/label_locator.rb new file mode 100644 index 0000000..24b0835 --- /dev/null +++ b/lib/webrat/core/locators/label_locator.rb @@ -0,0 +1,19 @@ +require "webrat/core/locators/locator" + +module Webrat + module Locators + + class LabelLocator < Locator + + def locate + # TODO - Convert to using elements + + @scope.send(:forms).detect_mapped do |form| + form.label_matching(@value) + end + end + + end + + end +end \ No newline at end of file