I’m trying to use Capybara to test that a list contains the correct items. For example:
<table id="rodents">
<tr><td class="rodent_id">1</td><td class="rodent_name">Hamster</td></tr>
<tr><td class="rodent_id">2</td><td class="rodent_name">Gerbil</td></tr>
</table>
This list should contain ids 1 and 2, but should not include 3.
What I’d like is something like:
ids = ? # get the contents of each row's first cell
ids.should include(1)
ids.should include(2)
ids.should_not include(3)
How might I do something like that?
I’m answering with a couple of unsatisfactory solutions I’ve found, but I’d love to see a better one.
Here is a slightly simplified expression:
From there, you can do your comparisons.