rspec-html

0.3.5
Light Mode Dark Mode

Request Specs

If you’re using RSpec request specs with Rails, a document object is available in all specs, wrapping the response.body of each request.

it 'generates a users table' do
  get '/users'
  expect(document.table('.users').td('.email')).to match_text 'user@example.com'
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

This is equivalent to:

let(:document) { parse_html(response.body) }

it 'generates a users table' do
  get '/users'
  expect(document.table('.users').td('.email')).to match_text 'user@example.com'
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