Go back Rspec, Rails test & Capybar...

exact order of items


<thead class="bg-zinc-300 ">
  <tr class="text-left">
    <th>Name</th>
    <th><%= link_to "Age", root_path(sort_by: "age") %></th>
    <th>Weight</th>
  </tr>
</thead>
<tbody>
  <% @data.each do |x| %>
    <tr>
      <td data-test="name"><%= x[:name] %></td>
      <td><%= x[:age] %></td>
      <td><%= x[:weight] %></td>
    </tr>
  <% end %>
</tbody>

it "sorts by name" do
  visit root_path

  expect(page.all('td[data-test="name"]').collect(&:text)).to eq(["David", "Bob", "Alice", "Charlie"])
end

it "sorts by name" do
  visit root_path
  click_on "Age"

  expect(page.all('td[data-test="name"]').collect(&:text)).to eq(["David", "Charlie", "Bob", "Alice"])
end