rspec-html

0.3.5
Light Mode Dark Mode

Introduction

RSpec::HTML provides a simple object interface to HTML content.

You can use RSpec::HTML to test any HTML produced by your library or application and it works out of the box with RSpec Rails request specs.

Setup

Load rspec-html in your spec_helper.rb:

# spec/spec_helper.rb

require 'rspec/html'

Quick Example

subject(:document) { parse_html(html) }

let(:html) do
  <<~HTML
  <html>
    <body>
      <div>Some other content</div>
      <div class="my-div">
        My div content
      </div>
    </body>
  </html>
  HTML
end

it 'matches "My div content"' do
  expect(document.html.body.div('.my-div')).to match_text 'My div content'
end
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
  <body>
    <div>Some other content</div>
    <div class="my-div">
      My div content
    </div>
  </body>
</html>
Some other content
My div content

Documentation generated by rspec-documentation