Abstracting access to inner_html and inner_text to Webrat::XML methods
This commit is contained in:
parent
9a344fdc2b
commit
334108015f
|
@ -159,7 +159,7 @@ module Webrat
|
|||
class ButtonField < Field #:nodoc:
|
||||
|
||||
def matches_text?(text)
|
||||
@element.inner_html =~ /#{Regexp.escape(text.to_s)}/i
|
||||
Webrat::XML.inner_html(@element) =~ /#{Regexp.escape(text.to_s)}/i
|
||||
end
|
||||
|
||||
def matches_value?(value)
|
||||
|
@ -284,7 +284,7 @@ module Webrat
|
|||
protected
|
||||
|
||||
def default_value
|
||||
@element.inner_html
|
||||
Webrat::XML.inner_html(@element)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -338,7 +338,7 @@ module Webrat
|
|||
|
||||
selected_options.map do |option|
|
||||
return "" if option.nil?
|
||||
Webrat::XML.attribute(option, "value") || option.inner_html
|
||||
Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ module Webrat
|
|||
end
|
||||
|
||||
def text
|
||||
str = @element.inner_text
|
||||
str = Webrat::XML.inner_text(@element)
|
||||
str.gsub!("\n","")
|
||||
str.strip!
|
||||
str.squeeze!(" ")
|
||||
|
|
|
@ -40,11 +40,11 @@ module Webrat
|
|||
end
|
||||
|
||||
def inner_html
|
||||
@element.inner_html
|
||||
Webrat::XML.inner_html(@element)
|
||||
end
|
||||
|
||||
def text
|
||||
@element.inner_text
|
||||
Webrat::XML.inner_text(@element)
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -8,7 +8,7 @@ module Webrat
|
|||
|
||||
def matches?(stringlike)
|
||||
@document = Webrat::XML.document(stringlike)
|
||||
@element = @document.inner_text
|
||||
@element = Webrat::XML.inner_text(@document)
|
||||
|
||||
case @content
|
||||
when String
|
||||
|
|
|
@ -8,9 +8,9 @@ module Webrat
|
|||
|
||||
def matches_text?(text)
|
||||
if text.is_a?(Regexp)
|
||||
@element.inner_html =~ text
|
||||
Webrat::XML.inner_html(@element) =~ text
|
||||
else
|
||||
@element.inner_html == text.to_s
|
||||
Webrat::XML.inner_html(@element) == text.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -22,7 +22,7 @@ module Webrat
|
|||
protected
|
||||
|
||||
def value
|
||||
Webrat::XML.attribute(@element, "value") || @element.inner_html
|
||||
Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ module Webrat #:nodoc:
|
|||
Webrat.nokogiri_document(stringlike)
|
||||
else
|
||||
Webrat::XML.hpricot_document(stringlike)
|
||||
# Webrat.rexml_document(Webrat::XML.hpricot_document(stringlike).to_html)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -25,12 +26,26 @@ module Webrat #:nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
def self.inner_html(element)
|
||||
element.inner_html
|
||||
end
|
||||
|
||||
def self.inner_text(element)
|
||||
element.inner_text
|
||||
end
|
||||
|
||||
def self.attribute(element, attribute_name)
|
||||
element[attribute_name]
|
||||
# case element
|
||||
# when Nokogiri::XML::Element, Hash
|
||||
element[attribute_name]
|
||||
# else
|
||||
# element.attributes[attribute_name]
|
||||
# end
|
||||
end
|
||||
|
||||
def self.xpath_search(element, *searches)
|
||||
searches.flatten.map do |search|
|
||||
# REXML::XPath.match(element, search)
|
||||
element.xpath(search)
|
||||
end.flatten.compact
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue