Moving around XML code

This commit is contained in:
Bryan Helmkamp 2008-11-30 01:38:55 -05:00
parent f3ff8d4ad2
commit 53539eda09
10 changed files with 40 additions and 44 deletions

View File

@ -17,7 +17,7 @@ module Webrat
require "rexml/document"
else
require "nokogiri"
require "webrat/core/nokogiri"
require "webrat/core/xml/nokogiri"
end
end

View File

@ -1,6 +1,6 @@
require "webrat/core/configuration"
require "webrat/core/xml"
require "webrat/core/nokogiri"
require "webrat/core/xml/nokogiri"
require "webrat/core/logging"
require "webrat/core/elements/form"
require "webrat/core/scope"

View File

@ -11,13 +11,6 @@ module Webrat
".//form"
end
def initialize(*args)
super
fields # preload
labels # preload
end
def find_select_option(option_text)
select_fields = fields_by_type([SelectField])
@ -30,15 +23,7 @@ module Webrat
end
def fields
@fields ||= Webrat::XML.xpath_search(@element, *Field.xpath_search).map do |element|
@session.element_to_webrat_element(element)
end
end
def labels
@labels ||= Webrat::XML.css_search(element, "label").map do |element|
@session.element_to_webrat_element(element)
end
@fields ||= Field.load_all(@session, @element)
end
def submit

View File

@ -10,7 +10,7 @@ module Webrat
if Webrat.configuration.parse_with_nokogiri?
@document = Webrat.nokogiri_document(stringlike)
else
@document = Webrat::XML.hpricot_document(stringlike)
@document = Webrat.hpricot_document(stringlike)
end
@element = Webrat::XML.inner_text(@document)

View File

@ -1,5 +1,5 @@
require "webrat/core/nokogiri"
require "webrat/core/rexml"
require "webrat/core/xml/nokogiri"
require "webrat/core/xml/rexml"
module Webrat
module Matchers

View File

@ -29,11 +29,8 @@ module Webrat
@session = session
instance_eval(&block) if block_given?
labels
fields
forms # preload
areas # preload
links # preload
# preload
load_elements
end
# Verifies an input field or textarea exists on the current page, and stores a value for
@ -283,6 +280,14 @@ module Webrat
protected
def load_elements
labels
fields
forms
areas
links
end
def page_dom #:nodoc:
return @response.dom if @response.respond_to?(:dom)
dom = Webrat::XML.document(@response_body)

View File

@ -1,3 +1,7 @@
require "webrat/core/xml/nokogiri"
require "webrat/core/xml/hpricot"
require "webrat/core/xml/rexml"
module Webrat #:nodoc:
module XML #:nodoc:
@ -5,24 +9,7 @@ module Webrat #:nodoc:
if Webrat.configuration.parse_with_nokogiri?
Webrat.nokogiri_document(stringlike)
else
# Webrat::XML.hpricot_document(stringlike)
Webrat.rexml_document(Webrat::XML.hpricot_document(stringlike).to_html)
end
end
def self.hpricot_document(stringlike)
return stringlike.dom if stringlike.respond_to?(:dom)
if Hpricot::Doc === stringlike
stringlike
elsif Hpricot::Elements === stringlike
stringlike
elsif StringIO === stringlike
Hpricot(stringlike.string)
elsif stringlike.respond_to?(:body)
Hpricot(stringlike.body.to_s)
else
Hpricot(stringlike.to_s)
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
end
end

View File

@ -0,0 +1,19 @@
module Webrat
def self.hpricot_document(stringlike)
return stringlike.dom if stringlike.respond_to?(:dom)
if Hpricot::Doc === stringlike
stringlike
elsif Hpricot::Elements === stringlike
stringlike
elsif StringIO === stringlike
Hpricot(stringlike.string)
elsif stringlike.respond_to?(:body)
Hpricot(stringlike.body.to_s)
else
Hpricot(stringlike.to_s)
end
end
end