rspec-html

0.3.5
Light Mode Dark Mode

match_text

The match_text matcher filters out any tags and compacts whitespace to make matching strings within your HTML more straightforward.

Strings

subject(:document) do
  parse_html '<div>Some     <span>text</span> with   <span>whitespace</span></div>'
end

it 'matches simple strings' do
  expect(document.div).to match_text 'Some text with whitespace'
end
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
    <div>Some     <span>text</span> with   <span>whitespace</span>
    </div>
  </body></html>
Some text with whitespace

Regular Expressions

subject(:document) do
  parse_html '<div>Some     <span>text</span> with   <span>whitespace</span></div>'
end

it 'matches simple strings' do
  expect(document.div).to match_text /text.*whitespace/
end
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
    <div>Some     <span>text</span> with   <span>whitespace</span>
    </div>
  </body></html>
Some text with whitespace

Documentation generated by rspec-documentation