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

  • Article 1 foo bar
  • ...

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 S.
mailto:[email protected]
http://www.schuerig.de/michael/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs