From f843ac2ae39b5791fba5ffa3dc11664de781f9fb Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sat, 29 Nov 2008 23:08:23 -0500 Subject: [PATCH] Moving locator methods --- lib/webrat/core/locators.rb | 42 ------------------- lib/webrat/core/locators/area_locator.rb | 5 +++ lib/webrat/core/locators/button_locator.rb | 5 +++ .../core/locators/field_by_id_locator.rb | 5 +++ .../core/locators/field_labeled_locator.rb | 5 +++ .../core/locators/field_named_locator.rb | 5 +++ lib/webrat/core/locators/link_locator.rb | 5 +++ .../core/locators/select_option_locator.rb | 13 +++++- 8 files changed, 42 insertions(+), 43 deletions(-) diff --git a/lib/webrat/core/locators.rb b/lib/webrat/core/locators.rb index 0501bd9..40b79a7 100644 --- a/lib/webrat/core/locators.rb +++ b/lib/webrat/core/locators.rb @@ -29,47 +29,5 @@ module Webrat raise(NotFoundError.new("Could not find field: #{args.inspect}")) end - def field_labeled(label, *field_types) - FieldLabeledLocator.new(self, label, *field_types).locate || - raise(NotFoundError.new("Could not find field labeled #{label.inspect}")) - end - - def field_named(name, *field_types) - FieldNamedLocator.new(self, name, *field_types).locate || - raise(NotFoundError.new("Could not find field named #{name.inspect}")) - end - - def field_with_id(id, *field_types) - FieldByIdLocator.new(self, id, *field_types).locate || - raise(NotFoundError.new("Could not find field with id #{id.inspect}")) - end - - def find_select_option(option_text, id_or_name_or_label) #:nodoc: - option = SelectOptionLocator.new(self, option_text, id_or_name_or_label).locate - return option if option - - if id_or_name_or_label - select_box_text = " in the #{id_or_name_or_label.inspect} select box" - raise NotFoundError.new("The '#{option_text}' option was not found#{select_box_text}") - else - raise NotFoundError.new("Could not find option #{option_text.inspect}") - end - end - - def find_button(value) #:nodoc: - ButtonLocator.new(self, value).locate || - raise(NotFoundError.new("Could not find button #{value.inspect}")) - end - - def find_area(id_or_title) #:nodoc: - AreaLocator.new(self, id_or_title).locate || - raise(NotFoundError.new("Could not find area with name #{id_or_title}")) - end - - def find_link(text_or_title_or_id) #:nodoc: - LinkLocator.new(self, text_or_title_or_id).locate || - raise(NotFoundError.new("Could not find link with text or title or id #{text_or_title_or_id.inspect}")) - end - end end diff --git a/lib/webrat/core/locators/area_locator.rb b/lib/webrat/core/locators/area_locator.rb index b4973e5..6e71758 100644 --- a/lib/webrat/core/locators/area_locator.rb +++ b/lib/webrat/core/locators/area_locator.rb @@ -26,5 +26,10 @@ module Webrat end + def find_area(id_or_title) #:nodoc: + AreaLocator.new(self, id_or_title).locate || + raise(NotFoundError.new("Could not find area with name #{id_or_title}")) + end + end end \ No newline at end of file diff --git a/lib/webrat/core/locators/button_locator.rb b/lib/webrat/core/locators/button_locator.rb index 74c236f..2bcaac6 100644 --- a/lib/webrat/core/locators/button_locator.rb +++ b/lib/webrat/core/locators/button_locator.rb @@ -42,5 +42,10 @@ module Webrat end + def find_button(value) #:nodoc: + ButtonLocator.new(self, value).locate || + raise(NotFoundError.new("Could not find button #{value.inspect}")) + end + end end \ No newline at end of file diff --git a/lib/webrat/core/locators/field_by_id_locator.rb b/lib/webrat/core/locators/field_by_id_locator.rb index d71b3eb..c254589 100644 --- a/lib/webrat/core/locators/field_by_id_locator.rb +++ b/lib/webrat/core/locators/field_by_id_locator.rb @@ -25,5 +25,10 @@ module Webrat end + def field_with_id(id, *field_types) + FieldByIdLocator.new(self, id, *field_types).locate || + raise(NotFoundError.new("Could not find field with id #{id.inspect}")) + end + end end \ No newline at end of file diff --git a/lib/webrat/core/locators/field_labeled_locator.rb b/lib/webrat/core/locators/field_labeled_locator.rb index ee76c78..369ea0f 100644 --- a/lib/webrat/core/locators/field_labeled_locator.rb +++ b/lib/webrat/core/locators/field_labeled_locator.rb @@ -14,5 +14,10 @@ module Webrat end + def field_labeled(label, *field_types) + FieldLabeledLocator.new(self, label, *field_types).locate || + raise(NotFoundError.new("Could not find field labeled #{label.inspect}")) + end + end end \ No newline at end of file diff --git a/lib/webrat/core/locators/field_named_locator.rb b/lib/webrat/core/locators/field_named_locator.rb index c13a8cd..95394b5 100644 --- a/lib/webrat/core/locators/field_named_locator.rb +++ b/lib/webrat/core/locators/field_named_locator.rb @@ -29,5 +29,10 @@ module Webrat end + def field_named(name, *field_types) + FieldNamedLocator.new(self, name, *field_types).locate || + raise(NotFoundError.new("Could not find field named #{name.inspect}")) + end + end end \ No newline at end of file diff --git a/lib/webrat/core/locators/link_locator.rb b/lib/webrat/core/locators/link_locator.rb index d75c2aa..dee2bf4 100644 --- a/lib/webrat/core/locators/link_locator.rb +++ b/lib/webrat/core/locators/link_locator.rb @@ -54,5 +54,10 @@ module Webrat end + def find_link(text_or_title_or_id) #:nodoc: + LinkLocator.new(self, text_or_title_or_id).locate || + raise(NotFoundError.new("Could not find link with text or title or id #{text_or_title_or_id.inspect}")) + end + end end \ No newline at end of file diff --git a/lib/webrat/core/locators/select_option_locator.rb b/lib/webrat/core/locators/select_option_locator.rb index 9be1d03..768617f 100644 --- a/lib/webrat/core/locators/select_option_locator.rb +++ b/lib/webrat/core/locators/select_option_locator.rb @@ -13,7 +13,6 @@ module Webrat def locate # TODO - Convert to using elements - if @id_or_name_or_label field = @scope.field(@id_or_name_or_label, SelectField) field.find_option(@option_text) @@ -26,5 +25,17 @@ module Webrat end + def find_select_option(option_text, id_or_name_or_label) #:nodoc: + option = SelectOptionLocator.new(self, option_text, id_or_name_or_label).locate + return option if option + + if id_or_name_or_label + select_box_text = " in the #{id_or_name_or_label.inspect} select box" + raise NotFoundError.new("The '#{option_text}' option was not found#{select_box_text}") + else + raise NotFoundError.new("Could not find option #{option_text.inspect}") + end + end + end end \ No newline at end of file