module ActionDispatch::Assertions::SelectorAssertions
def assert_select_encoded(element = nil, &block)
end
end
assert_select "p"
assert_select_encoded do
# Run assertions on the encoded elements.
assert_select "channel>item>description" do
# Select description element of each feed item.
assert_select_feed :rss, 2.0 do
# Selects all paragraph tags from within the description of an RSS feed
end
end
end
assert_select "b"
assert_select_encoded do
# Run assertions on the encoded title elements
assert_select "entry>title" do
# Select each entry item and then the title item
assert_select_feed :atom, 1.0 do
# Selects all bold tags from within the title of an ATOM feed's entries (perhaps to nab a section name prefix)
==== Examples
element +encoded+. It then calls the block with all un-encoded elements.
The content of each element is un-encoded, and wrapped in the root
of elements.
all currently selected elements. You can also pass an element or array
You typically call this method within another assertion to operate on
nested assertion on it.
Extracts the content of an element, treats it as encoded HTML and runs
def assert_select_encoded(element = nil, &block) case element when Array elements = element when HTML::Node elements = [element] when nil unless elements = @selected raise ArgumentError, "First argument is optional, but must be called from a nested assert_select" end else raise ArgumentError, "Argument is optional, and may be node or array of nodes" end fix_content = lambda do |node| # Gets around a bug in the Rails 1.1 HTML parser. node.content.gsub(/<!\[CDATA\[(.*)(\]\]>)?/m) { Rack::Utils.escapeHTML($1) } end selected = elements.map do |_element| text = _element.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join root = HTML::Document.new(CGI.unescapeHTML("<encoded>#{text}</encoded>")).root css_select(root, "encoded:root", &block)[0] end begin old_selected, @selected = @selected, selected assert_select ":root", &block ensure @selected = old_selected end end