bovender
bovender

Reputation: 1960

RSpec and Capybara: Test position of content on page

In Rails testing with RSpec and Capybara, is it possible to test the position of a certain content on a page?

I have a page that lists orders in different sections 'Pending' and 'Received', and I would like to test that a particular order can move from the 'Pending' to the 'Received' section on the page.

It would help if I could test that the content is inside a particular div.

Upvotes: 1

Views: 1059

Answers (1)

Jon M
Jon M

Reputation: 11705

I'd say the easiest way is to build this right into your selectors, and assert the presence of the element in the correct section, and the absence of it in the old section. The following example assumes you're keeping the order ID in a data attribute:

page.should have_selector '#received-orders .order[data-order-id="12345"]'
page.should_not have_selector '#pending-orders .order[data-order-id="12345"]'

Upvotes: 2

Related Questions