Michael Schuerig
2010-Apr-23 22:54 UTC
[rspec-users] Cucumber + capybara: checking list items
I''m unsure how to check a few things related to lists of items. In this specific case, I have a articles with title and abstract. When there are no articles, I''d like to ensure that there *is* a list on the page, but that it does not contain any articles. When there are articles, they should be displayed in such a way that their attributes are not mixed. For the empty list check I''ve come up with this, however, I noticed that the capybara README advises against "x.should_not have_y". Is there a better way? Then /^I should see an empty article list$/ do with_scope("#articles") do page.should_not have_css("li") end end For checking existing articles like this <ul id="articles"> <li> <span class="title">Article 1</span> <span class="abstract">foo bar</span> </li> <li> ... </li> </ul> I have this broken step Then /^I should see an article with title "([^\"]*)" and abstract "([^\"]*)"$/ do |title, abstract| with_scope(''#articles li'') do with_scope(''.title'') { page.should have_content(title) } with_scope(''.abstract'') { page.should have_content(abstract) } end end It is broken in that it does not ensure that corresponding titles and abstracts are within the same LI. I understand why it doesn''t work, for with_scope just builds up a scope chain. Unfortunately, I don''t see how to get the check I want. Michael -- Michael Schuerig mailto:michael at schuerig.de http://www.schuerig.de/michael/