add runtime error
This commit is contained in:
parent
cbcf025c33
commit
71b97b6a38
@ -2,6 +2,7 @@ require "./mechanize/http/agent"
|
|||||||
require "./mechanize/form"
|
require "./mechanize/form"
|
||||||
require "./mechanize/node"
|
require "./mechanize/node"
|
||||||
require "./mechanize/page"
|
require "./mechanize/page"
|
||||||
|
require "./mechanize/errors/*"
|
||||||
|
|
||||||
class Mechanize
|
class Mechanize
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.0"
|
||||||
|
3
src/mechanize/errors/base_error.cr
Normal file
3
src/mechanize/errors/base_error.cr
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Base Error class
|
||||||
|
class MechanizeCr::Error < RuntimeError
|
||||||
|
end
|
13
src/mechanize/errors/element_not_found_error.cr
Normal file
13
src/mechanize/errors/element_not_found_error.cr
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
require "./base_error"
|
||||||
|
class MechanizeCr::ElementNotFoundError < MechanizeCr::Error
|
||||||
|
getter element : Symbol
|
||||||
|
getter conditions : String
|
||||||
|
|
||||||
|
def initialize(element, conditions)
|
||||||
|
@element = element
|
||||||
|
@conditions = conditions
|
||||||
|
|
||||||
|
super "Element #{element} with conditions #{conditions} was not found"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -72,15 +72,17 @@ class MechanizeCr::Form
|
|||||||
# TODO
|
# TODO
|
||||||
# when args whose type isn't String is given
|
# when args whose type isn't String is given
|
||||||
end
|
end
|
||||||
fields.select do |field|
|
f = fields.select do |field|
|
||||||
value.all? do |k,v|
|
value.all? do |k,v|
|
||||||
v === field.name
|
v === field.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
f.empty? ? nil : f
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_with(criteria)
|
def field_with(criteria)
|
||||||
f = fields_with(criteria)
|
f = fields_with(criteria)
|
||||||
f.empty? ? Array(MechanizeCr::FormContent::Field).new : f.first
|
raise MechanizeCr::ElementNotFoundError.new(:field, criteria) if f.nil?
|
||||||
|
f.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user