class Bezel::Testing::Doc
A parsed HTML page for tests to query (Testing.html_response): its
elements as a tree, found by a small selector language:
tag, "#id", ".class",[attr],[attr=value](quoted or not), combined (form.search[method=get]);- descendants, separated by spaces (
form input[type=hidden]); - several selectors separated by commas (
h1, h2).
doc = Bezel::Testing::Doc.parse("<form action=\"/users\"><input name=\"user[email]\" value=\"a&b\"></form>")
doc.has_element?("form[action=\"/users\"] input") # => true
doc.select("input")[0].attr("value") # => "a&b"
doc.has_text?("nothing") # => false
The parser reads well-formed HTML as Bezel.html writes it, and is
forgiving with the rest: void elements need no end tag, an end tag
closes up to its element, entities are decoded, comments and the
doctype are skipped, script, style, textarea and title hold
text.
Class methods
def self.parse(source: String) -> Bezel::Testing::Doc
The document of source.
Methods
def root -> Bezel::Testing::Node
The document's root (a node without a tag).
def select(selector: String) -> Array[Bezel::Testing::Node]
The elements selector matches, in document order.
def at(selector: String) -> Bezel::Testing::Node?
The first element selector matches, or nil.
def has_element?(selector: String) -> Bool
Whether an element matches selector.
def text -> String
The text of the page, whitespace collapsed.
def has_text?(text: String) -> Bool
Whether the page's text has text (whitespace collapsed in both).