diff --git a/History.txt b/History.txt index 70dd07b..5d7853b 100644 --- a/History.txt +++ b/History.txt @@ -4,6 +4,7 @@ * Allow clicking links by id and id regexp (gaffo) * Raise Webrat::PageLoadError when a failure occurs so that application exceptions can be more accurately tested (Ryan Briones) + * Helpful error message for missing option in select box. (Ben Mabey, Ticket #40) == 0.3.2 / 2008-11-08 diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index 187e81a..a9fb725 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -87,7 +87,12 @@ module Webrat # selects "February", :from => "event_month" # selects "February", :from => "Event Month" def selects(option_text, options = {}) - find_select_option(option_text, options[:from]).choose + if option = find_select_option(option_text, options[:from]) + option.choose + else + select_box_text = options[:from] ? " in the '#{options[:from]}' select box" : '' + flunk("The '#{option_text}' option was not found#{select_box_text}") + end end alias_method :select, :selects diff --git a/spec/api/selects_spec.rb b/spec/api/selects_spec.rb index e2a1d24..2ee4ae0 100644 --- a/spec/api/selects_spec.rb +++ b/spec/api/selects_spec.rb @@ -5,14 +5,15 @@ describe "selects" do @session = Webrat::TestSession.new end - it "should fail if option not found" do + it "should fail with a helpful message when option not found" do @session.response_body = <<-EOS
EOS - lambda { @session.selects "February", :from => "month" }.should raise_error + lambda { @session.selects "February", :from => "month" }.should raise_error( + Exception, "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