rspec-html

0.3.5
Light Mode Dark Mode

Usage

RSpec::HTML uses method chaining to traverse the Document Object Model (DOM).

Implicit Navigation

Access a <td> tag anywhere in the document:

it 'renders a user name' do
  get '/users'
  expect(document.td('.name')).to match_text 'Example User #1'
end
<table id="users-table" class="table users">
  <thead>
    <tr>
      <th>Email</th>
      <th>Name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="email">
        user@example.org
      </td>
      <td class="name">
        Example User #1
      </td>
    </tr>
    <tr>
      <td class="email">
        user@example.com
      </td>
      <td class="name">
        Example User #2
      </td>
    </tr>
  </tbody>
</table>
Email Name
Example User #1
Example User #2

Explicit Navigation

Or specify the full node tree explicitly to ensure your document’s structure:

it 'renders a user name' do
  get '/users'
  expect(document.body.table.tbody.tr.td('.name')).to match_text 'Example User #1'
end
<table id="users-table" class="table users">
  <thead>
    <tr>
      <th>Email</th>
      <th>Name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="email">
        user@example.org
      </td>
      <td class="name">
        Example User #1
      </td>
    </tr>
    <tr>
      <td class="email">
        user@example.com
      </td>
      <td class="name">
        Example User #2
      </td>
    </tr>
  </tbody>
</table>
Email Name
Example User #1
Example User #2

Documentation generated by rspec-documentation