Refactoring CSS searching for building Links, Areas and Forms
This commit is contained in:
parent
f2758c5d81
commit
f032a8de73
@ -1,6 +1,10 @@
|
|||||||
module Webrat
|
module Webrat
|
||||||
class Area #:nodoc:
|
class Area #:nodoc:
|
||||||
|
|
||||||
|
def self.css_search
|
||||||
|
"area"
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(session, element)
|
def initialize(session, element)
|
||||||
@session = session
|
@session = session
|
||||||
@element = element
|
@element = element
|
||||||
|
@ -5,6 +5,10 @@ module Webrat
|
|||||||
class Form #:nodoc:
|
class Form #:nodoc:
|
||||||
attr_reader :element
|
attr_reader :element
|
||||||
|
|
||||||
|
def self.css_search
|
||||||
|
"form"
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(session, element)
|
def initialize(session, element)
|
||||||
@session = session
|
@session = session
|
||||||
@element = element
|
@element = element
|
||||||
|
@ -3,6 +3,10 @@ require "webrat/core_extensions/blank"
|
|||||||
module Webrat
|
module Webrat
|
||||||
class Link #:nodoc:
|
class Link #:nodoc:
|
||||||
|
|
||||||
|
def self.css_search
|
||||||
|
"a[@href]"
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(session, element)
|
def initialize(session, element)
|
||||||
@session = session
|
@session = session
|
||||||
@element = element
|
@element = element
|
||||||
|
@ -289,9 +289,6 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def scoped_dom #:nodoc:
|
def scoped_dom #:nodoc:
|
||||||
# if @selector == "#form2"
|
|
||||||
# require "rubygems"; require "ruby-debug"; Debugger.start; debugger
|
|
||||||
# end
|
|
||||||
Webrat::XML.document("<html>" + Webrat::XML.to_html(Webrat::XML.css_search(@scope.dom, @selector).first) + "</html>")
|
Webrat::XML.document("<html>" + Webrat::XML.to_html(Webrat::XML.css_search(@scope.dom, @selector).first) + "</html>")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -309,22 +306,22 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def areas #:nodoc:
|
def areas #:nodoc:
|
||||||
Webrat::XML.css_search(dom, "area").map do |element|
|
Webrat::XML.css_search(dom, Area.css_search).map do |element|
|
||||||
Area.new(@session, element)
|
Area.new(@session, element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def links #:nodoc:
|
def links #:nodoc:
|
||||||
Webrat::XML.css_search(dom, "a[@href]").map do |link_element|
|
Webrat::XML.css_search(dom, Link.css_search).map do |element|
|
||||||
Link.new(@session, link_element)
|
Link.new(@session, element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def forms #:nodoc:
|
def forms #:nodoc:
|
||||||
return @forms if @forms
|
return @forms if @forms
|
||||||
|
|
||||||
@forms = Webrat::XML.css_search(dom, "form").map do |form_element|
|
@forms = Webrat::XML.css_search(dom, Form.css_search).map do |element|
|
||||||
Form.new(@session, form_element)
|
Form.new(@session, element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user