[rspec-users] Cucumber + capybara: checking list items

Michael Schuerig michael at schuerig.de
Fri Apr 23 18:54:57 EDT 2010

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")

For checking existing articles like this

<ul id="articles">
    <span class="title">Article 1</span>
    <span class="abstract">foo bar</span>

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) }

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 Schuerig
mailto:michael at schuerig.de

More information about the rspec-users mailing list