diff --git a/History.txt b/History.txt index da96e37..1899022 100644 --- a/History.txt +++ b/History.txt @@ -8,6 +8,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 cfdb931..3edf5d0 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 7da2d5f..a9f0433 100644 --- a/spec/api/selects_spec.rb +++ b/spec/api/selects_spec.rb @@ -7,14 +7,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