helpful error message for missing option values, closes #40

This commit is contained in:
Ben Mabey 2008-11-15 14:56:24 -07:00 committed by Bryan Helmkamp
parent d0d9ca8787
commit a381cbf17e
3 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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
<form method="get" action="/login">
<select name="month"><option value="1">January</option></select>
</form>
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