A cucumber/capybara step to test the order of elements in a list
Then /^I should see each item listed in alphabetical order in the items section$/ do
@items.each_with_index do |item, index|
find(:xpath, "//*[@id='items']/ul[@class='items']/li[#{index+1}]").inspect.should eq(find("li#item-#{item.friendly_id}").inspect)
@item = item
step "I should see the item listed in the items section"
end
end
Then /^I should( not)? see the item listed in the items section$/ do |negation|
assertion = negation ? :should_not : :should
selector = "a[href='#{item_path(@item)}']"
within(:css, "#items") do
page.send(assertion, have_selector(selector))
if !negation
find(selector).should have_content(@item.name)
end
end
end