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/xml"
|
||||||
require "webrat/core/nokogiri"
|
require "webrat/core/nokogiri"
|
||||||
require "webrat/core/logging"
|
require "webrat/core/logging"
|
||||||
require "webrat/core/flunk"
|
|
||||||
require "webrat/core/form"
|
require "webrat/core/form"
|
||||||
require "webrat/core/scope"
|
require "webrat/core/scope"
|
||||||
require "webrat/core/link"
|
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_with_id(*args) ||
|
||||||
find_field_named(*args) ||
|
find_field_named(*args) ||
|
||||||
field_labeled(*args) ||
|
field_labeled(*args) ||
|
||||||
flunk("Could not find field: #{args.inspect}")
|
raise(NotFoundError.new("Could not find field: #{args.inspect}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_labeled(label, *field_types)
|
def field_labeled(label, *field_types)
|
||||||
find_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
|
end
|
||||||
|
|
||||||
def field_named(name, *field_types)
|
def field_named(name, *field_types)
|
||||||
find_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
|
end
|
||||||
|
|
||||||
def field_with_id(id, *field_types)
|
def field_with_id(id, *field_types)
|
||||||
find_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
|
end
|
||||||
|
|
||||||
def find_field_labeled(label, *field_types) #:nodoc:
|
def find_field_labeled(label, *field_types) #:nodoc:
|
||||||
@ -56,7 +56,7 @@ module Webrat
|
|||||||
return select_option if select_option
|
return select_option if select_option
|
||||||
end
|
end
|
||||||
|
|
||||||
flunk("Could not find option #{option_text.inspect}")
|
raise NotFoundError.new("Could not find option #{option_text.inspect}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_button(value) #:nodoc:
|
def find_button(value) #:nodoc:
|
||||||
@ -67,13 +67,13 @@ module Webrat
|
|||||||
if button
|
if button
|
||||||
return button
|
return button
|
||||||
else
|
else
|
||||||
flunk("Could not find button #{value.inspect}")
|
raise NotFoundError.new("Could not find button #{value.inspect}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_area(area_name) #:nodoc:
|
def find_area(area_name) #:nodoc:
|
||||||
areas.detect { |area| area.matches_text?(area_name) } ||
|
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
|
end
|
||||||
|
|
||||||
def find_link(text_or_title_or_id) #:nodoc:
|
def find_link(text_or_title_or_id) #:nodoc:
|
||||||
@ -84,7 +84,7 @@ module Webrat
|
|||||||
if matching_links.any?
|
if matching_links.any?
|
||||||
matching_links.min { |a, b| a.text.length <=> b.text.length }
|
matching_links.min { |a, b| a.text.length <=> b.text.length }
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ module Webrat
|
|||||||
if label
|
if label
|
||||||
label.for_id
|
label.for_id
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,9 +2,11 @@ require "webrat/core/form"
|
|||||||
require "webrat/core/locators"
|
require "webrat/core/locators"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
|
class NotFoundError < WebratError
|
||||||
|
end
|
||||||
|
|
||||||
class Scope
|
class Scope
|
||||||
include Logging
|
include Logging
|
||||||
include Flunk
|
|
||||||
include Locators
|
include Locators
|
||||||
|
|
||||||
def self.from_page(session, response, response_body) #:nodoc:
|
def self.from_page(session, response, response_body) #:nodoc:
|
||||||
@ -96,7 +98,7 @@ module Webrat
|
|||||||
option.choose
|
option.choose
|
||||||
else
|
else
|
||||||
select_box_text = options[:from] ? " in the '#{options[:from]}' select box" : ''
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -131,7 +133,7 @@ module Webrat
|
|||||||
|
|
||||||
id_prefix = locate_id_prefix(options) do
|
id_prefix = locate_id_prefix(options) do
|
||||||
year_field = find_field_with_id(/(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/)
|
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
|
$1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ module Webrat
|
|||||||
|
|
||||||
id_prefix = locate_id_prefix(options) do
|
id_prefix = locate_id_prefix(options) do
|
||||||
hour_field = find_field_with_id(/(.*?)_#{DATE_TIME_SUFFIXES[:hour]}$/)
|
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
|
$1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user