Skip to content

Commit

Permalink
Abstracting access to inner_html and inner_text to Webrat::XML methods
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Nov 28, 2008
1 parent 9a344fd commit 3341080
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/webrat/core/field.rb
Expand Up @@ -159,7 +159,7 @@ def replace_param_value(params, oval, nval)
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)
Expand Down Expand Up @@ -284,7 +284,7 @@ class TextareaField < Field #:nodoc:
protected

def default_value
@element.inner_html
Webrat::XML.inner_html(@element)
end

end
Expand Down Expand Up @@ -338,7 +338,7 @@ def default_value

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

Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/core/label.rb
Expand Up @@ -11,7 +11,7 @@ def matches_text?(label_text)
end

def text
str = @element.inner_text
str = Webrat::XML.inner_text(@element)
str.gsub!("\n","")
str.strip!
str.squeeze!(" ")
Expand Down
4 changes: 2 additions & 2 deletions lib/webrat/core/link.rb
Expand Up @@ -40,11 +40,11 @@ def matches_id?(id_or_regexp)
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
Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/core/matchers/have_content.rb
Expand Up @@ -8,7 +8,7 @@ def initialize(content)

def matches?(stringlike)
@document = Webrat::XML.document(stringlike)
@element = @document.inner_text
@element = Webrat::XML.inner_text(@document)

case @content
when String
Expand Down
6 changes: 3 additions & 3 deletions lib/webrat/core/select_option.rb
Expand Up @@ -8,9 +8,9 @@ def initialize(select, element)

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

Expand All @@ -22,7 +22,7 @@ def choose
protected

def value
Webrat::XML.attribute(@element, "value") || @element.inner_html
Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
end

end
Expand Down
17 changes: 16 additions & 1 deletion lib/webrat/core/xml.rb
Expand Up @@ -6,6 +6,7 @@ def self.document(stringlike) #:nodoc:
Webrat.nokogiri_document(stringlike)
else
Webrat::XML.hpricot_document(stringlike)
# Webrat.rexml_document(Webrat::XML.hpricot_document(stringlike).to_html)
end
end

Expand All @@ -25,12 +26,26 @@ def self.hpricot_document(stringlike)
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
Expand Down

0 comments on commit 3341080

Please sign in to comment.