Skip to content

Instantly share code, notes, and snippets.

@chrisbloom7
Created March 20, 2012 21:15
Show Gist options
  • Save chrisbloom7/2141370 to your computer and use it in GitHub Desktop.
Save chrisbloom7/2141370 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment