Raise Webrat::NotFoundErrors instead of RuntimeErrors to make error catching easier
This commit is contained in:
parent
df9d8179c0
commit
10d5d7695f
@ -2,7 +2,6 @@ require "webrat/core/configuration"
|
||||
require "webrat/core/xml"
|
||||
require "webrat/core/nokogiri"
|
||||
require "webrat/core/logging"
|
||||
require "webrat/core/flunk"
|
||||
require "webrat/core/form"
|
||||
require "webrat/core/scope"
|
||||
require "webrat/core/link"
|
||||
|
@ -1,7 +0,0 @@
|
||||
module Flunk
|
||||
|
||||
def flunk(message) #:nodoc:
|
||||
raise message
|
||||
end
|
||||
|
||||
end
|
@ -8,22 +8,22 @@ module Webrat
|
||||
find_field_with_id(*args) ||
|
||||
find_field_named(*args) ||
|
||||
field_labeled(*args) ||
|
||||
flunk("Could not find field: #{args.inspect}")
|
||||
raise(NotFoundError.new("Could not find field: #{args.inspect}"))
|
||||
end
|
||||
|
||||
def field_labeled(label, *field_types)
|
||||
find_field_labeled(label, *field_types) ||
|
||||
flunk("Could not find field labeled #{label.inspect}")
|
||||
raise(NotFoundError.new("Could not find field labeled #{label.inspect}"))
|
||||
end
|
||||
|
||||
def field_named(name, *field_types)
|
||||
find_field_named(name, *field_types) ||
|
||||
flunk("Could not find field named #{name.inspect}")
|
||||
raise(NotFoundError.new("Could not find field named #{name.inspect}"))
|
||||
end
|
||||
|
||||
def field_with_id(id, *field_types)
|
||||
find_field_with_id(id, *field_types) ||
|
||||
flunk("Could not find field with id #{id.inspect}")
|
||||
raise(NotFoundError.new("Could not find field with id #{id.inspect}"))
|
||||
end
|
||||
|
||||
def find_field_labeled(label, *field_types) #:nodoc:
|
||||
@ -56,7 +56,7 @@ module Webrat
|
||||
return select_option if select_option
|
||||
end
|
||||
|
||||
flunk("Could not find option #{option_text.inspect}")
|
||||
raise NotFoundError.new("Could not find option #{option_text.inspect}")
|
||||
end
|
||||
|
||||
def find_button(value) #:nodoc:
|
||||
@ -67,13 +67,13 @@ module Webrat
|
||||
if button
|
||||
return button
|
||||
else
|
||||
flunk("Could not find button #{value.inspect}")
|
||||
raise NotFoundError.new("Could not find button #{value.inspect}")
|
||||
end
|
||||
end
|
||||
|
||||
def find_area(area_name) #:nodoc:
|
||||
areas.detect { |area| area.matches_text?(area_name) } ||
|
||||
flunk("Could not find area with name #{area_name}")
|
||||
raise(NotFoundError.new("Could not find area with name #{area_name}"))
|
||||
end
|
||||
|
||||
def find_link(text_or_title_or_id) #:nodoc:
|
||||
@ -84,7 +84,7 @@ module Webrat
|
||||
if matching_links.any?
|
||||
matching_links.min { |a, b| a.text.length <=> b.text.length }
|
||||
else
|
||||
flunk("Could not find link with text or title or id #{text_or_title_or_id.inspect}")
|
||||
raise NotFoundError.new("Could not find link with text or title or id #{text_or_title_or_id.inspect}")
|
||||
end
|
||||
end
|
||||
|
||||
@ -93,7 +93,7 @@ module Webrat
|
||||
if label
|
||||
label.for_id
|
||||
else
|
||||
flunk("Could not find the label with text #{label_text}")
|
||||
raise NotFoundError.new("Could not find the label with text #{label_text}")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,9 +2,11 @@ require "webrat/core/form"
|
||||
require "webrat/core/locators"
|
||||
|
||||
module Webrat
|
||||
class NotFoundError < WebratError
|
||||
end
|
||||
|
||||
class Scope
|
||||
include Logging
|
||||
include Flunk
|
||||
include Locators
|
||||
|
||||
def self.from_page(session, response, response_body) #:nodoc:
|
||||
@ -96,7 +98,7 @@ module Webrat
|
||||
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}")
|
||||
raise NotFoundError.new("The '#{option_text}' option was not found#{select_box_text}")
|
||||
end
|
||||
end
|
||||
|
||||
@ -131,7 +133,7 @@ module Webrat
|
||||
|
||||
id_prefix = locate_id_prefix(options) do
|
||||
year_field = find_field_with_id(/(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/)
|
||||
flunk("No date fields were found") unless year_field && year_field.id =~ /(.*?)_1i/
|
||||
raise NotFoundError.new("No date fields were found") unless year_field && year_field.id =~ /(.*?)_1i/
|
||||
$1
|
||||
end
|
||||
|
||||
@ -165,7 +167,7 @@ module Webrat
|
||||
|
||||
id_prefix = locate_id_prefix(options) do
|
||||
hour_field = find_field_with_id(/(.*?)_#{DATE_TIME_SUFFIXES[:hour]}$/)
|
||||
flunk("No time fields were found") unless hour_field && hour_field.id =~ /(.*?)_4i/
|
||||
raise NotFoundError.new("No time fields were found") unless hour_field && hour_field.id =~ /(.*?)_4i/
|
||||
$1
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user