diff --git a/lib/webrat/core/locators.rb b/lib/webrat/core/locators.rb index c0ccb70..827ae4a 100644 --- a/lib/webrat/core/locators.rb +++ b/lib/webrat/core/locators.rb @@ -65,20 +65,17 @@ module Webrat end def find_select_option(option_text, id_or_name_or_label) #:nodoc: - # TODO - Convert to using elements + require "webrat/core/locators/select_option_locator" + + option = SelectOptionLocator.new(self, option_text, id_or_name_or_label).locate + return option if option if id_or_name_or_label - field = field(id_or_name_or_label, SelectField) - return field.find_option(option_text) + 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 - select_option = forms.detect_mapped do |form| - form.find_select_option(option_text) - end - - return select_option if select_option + raise NotFoundError.new("Could not find option #{option_text.inspect}") end - - raise NotFoundError.new("Could not find option #{option_text.inspect}") end def find_button(value) #:nodoc: diff --git a/lib/webrat/core/locators/link_locator.rb b/lib/webrat/core/locators/link_locator.rb index 2097bc1..6bbd1ff 100644 --- a/lib/webrat/core/locators/link_locator.rb +++ b/lib/webrat/core/locators/link_locator.rb @@ -10,7 +10,7 @@ module Webrat end def link_element - matching_links.min { |a, b| Webrat::XML.inner_text(a).length <=> Webrat::XML.inner_text(b).length } + matching_links.min { |a, b| Webrat::XML.all_inner_text(a).length <=> Webrat::XML.all_inner_text(b).length } end def matching_links @@ -27,7 +27,7 @@ module Webrat matcher = /#{Regexp.escape(@value.to_s)}/i end - replace_nbsp(Webrat::XML.inner_text(link)) =~ matcher || + replace_nbsp(Webrat::XML.all_inner_text(link)) =~ matcher || replace_nbsp_ref(Webrat::XML.inner_html(link)) =~ matcher || Webrat::XML.attribute(link, "title")=~ matcher end diff --git a/lib/webrat/core/locators/select_option_locator.rb b/lib/webrat/core/locators/select_option_locator.rb new file mode 100644 index 0000000..9be1d03 --- /dev/null +++ b/lib/webrat/core/locators/select_option_locator.rb @@ -0,0 +1,30 @@ +require "webrat/core/locators/locator" + +module Webrat + module Locators + + class SelectOptionLocator < Locator + + def initialize(scope, option_text, id_or_name_or_label) + @scope = scope + @option_text = option_text + @id_or_name_or_label = id_or_name_or_label + end + + 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) + else + @scope.send(:forms).detect_mapped do |form| + form.find_select_option(@option_text) + end + end + end + + end + + end +end \ No newline at end of file diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index cf83ec2..a49c2a7 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -100,12 +100,8 @@ module Webrat # select "February", :from => "event_month" # select "February", :from => "Event Month" def select(option_text, options = {}) - if option = find_select_option(option_text, options[:from]) - option.choose - else - select_box_text = options[:from] ? " in the '#{options[:from]}' select box" : '' - raise NotFoundError.new("The '#{option_text}' option was not found#{select_box_text}") - end + option = find_select_option(option_text, options[:from]) + option.choose end webrat_deprecate :selects, :select diff --git a/spec/api/select_spec.rb b/spec/api/select_spec.rb index 7af4b3a..337e54b 100644 --- a/spec/api/select_spec.rb +++ b/spec/api/select_spec.rb @@ -11,7 +11,7 @@ describe "select" do HTML lambda { select "February", :from => "month" }.should raise_error(Webrat::NotFoundError, - "The 'February' option was not found in the 'month' select box") + "The 'February' option was not found in the \"month\" select box") end it "should fail if option not found in list specified by element name" do