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!'
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">
    <div class="welcome-message">Welcome to our website!</div>
Welcome to our website!

Documentation generated by rspec-documentation