rspec-html

0.3.5
Light Mode Dark Mode

The document Object

For RSpec Rails request specs the document object is already defined by RSpec::HTML as the parsed response body.

If you are testing HTML in any other context, e.g. for parsing ActionMailer emails, simply define document with a let or subject block that calls the provided parse_html helper:

subject(:document) { parse_html(ActionMailer::Base.deliveries.last.body.decoded) }

it 'contains a welcome message' do
  expect(document.div('.welcome-message')).to match_text 'Welcome to our website!'
end
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
    <div class="welcome-message">Welcome to our website!</div>
  </body></html>
Welcome to our website!

Documentation generated by rspec-documentation