Module: Vault::Test::HTMLHelpers

Defined in:
lib/vault-test-tools/html_helpers.rb

Instance Method Summary collapse

Instance Method Details

#assert_css(css_string, content) ⇒ Object



26
27
28
29
30
# File 'lib/vault-test-tools/html_helpers.rb', line 26

def assert_css(css_string, content)
  e = css(css_string).first
  assert e, "Element not found: #{css_string}"
  assert_includes e.content, content
end

#assert_includes_css(css_string) ⇒ Object



21
22
23
24
# File 'lib/vault-test-tools/html_helpers.rb', line 21

def assert_includes_css(css_string)
  exists = doc.css(css_string).first
  assert exists, "Last response must include #{css_string}"
end

#css(string) ⇒ Object



17
18
19
# File 'lib/vault-test-tools/html_helpers.rb', line 17

def css(string)
  doc.css(string)
end

#docObject



13
14
15
# File 'lib/vault-test-tools/html_helpers.rb', line 13

def doc
  @doc || Nokogiri::HTML(last_response.body)
end

#save_and_open_page(html = nil, name = 'page.html', i = 1) ⇒ Object



2
3
4
5
6
7
# File 'lib/vault-test-tools/html_helpers.rb', line 2

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



9
10
11
# File 'lib/vault-test-tools/html_helpers.rb', line 9

def set_doc(body)
  @doc = Nokogiri::HTML(body)
end