Module: Vault::Test::HTMLHelpers
- Defined in:
- lib/vault-test-tools/html_helpers.rb
Instance Method Summary collapse
-
#assert_css(selector, content) ⇒ Object
Assert that the content in the first element matching the CSS selector matches the specified value.
-
#assert_includes_css(selector) ⇒ Object
Assert that at least one element in the current document matches the CSS selector.
-
#css(selector) ⇒ Array
Get a list of text matches in the current document for a CSS selector.
-
#doc ⇒ Nokogiri::HTML
Get the current document or parse ‘last_response.body` into a `Nokogiri::HTML` instance.
-
#save_and_open_page(html = nil, name = 'page.html', i = 1) ⇒ Object
Save and open an HTML document in your browser.
-
#set_doc(body) ⇒ Object
Parse an HTML document into a ‘Nokogiri::HTML` instance and store it as the current document.
Instance Method Details
#assert_css(selector, content) ⇒ Object
Assert that the content in the first element matching the CSS selector matches the specified value.
55 56 57 58 59 |
# File 'lib/vault-test-tools/html_helpers.rb', line 55 def assert_css(selector, content) e = css(selector).first assert e, "Element not found: #{selector}" assert_includes e.content, content end |
#assert_includes_css(selector) ⇒ Object
Assert that at least one element in the current document matches the CSS selector.
43 44 45 46 |
# File 'lib/vault-test-tools/html_helpers.rb', line 43 def assert_includes_css(selector) exists = doc.css(selector).first assert exists, "Last response must include #{selector}" end |
#css(selector) ⇒ Array
Get a list of text matches in the current document for a CSS selector.
34 35 36 |
# File 'lib/vault-test-tools/html_helpers.rb', line 34 def css(selector) doc.css(selector) end |
#doc ⇒ Nokogiri::HTML
Get the current document or parse ‘last_response.body` into a `Nokogiri::HTML` instance.
25 26 27 |
# File 'lib/vault-test-tools/html_helpers.rb', line 25 def doc @doc || Nokogiri::HTML(last_response.body) end |
#save_and_open_page(html = nil, name = 'page.html', i = 1) ⇒ Object
Save and open an HTML document in your browser.
8 9 10 11 12 13 |
# File 'lib/vault-test-tools/html_helpers.rb', line 8 def save_and_open_page(html = nil, name = 'page.html', i = 1) html ||= last_response.body name = "page_#{i=i+1}.html" while File.exist? name File.open(name, 'w') { |f| f << html } system "open #{name}" end |
#set_doc(body) ⇒ Object
Parse an HTML document into a ‘Nokogiri::HTML` instance and store it as the current document.
17 18 19 |
# File 'lib/vault-test-tools/html_helpers.rb', line 17 def set_doc(body) @doc = Nokogiri::HTML(body) end |