对于黄瓜步骤,我知道一个特定的ul
元素应该有 5 个 children li
。我如何用 Webrat 断言这一点?
我猜可能会有类似的东西:
Then ".selector" should have n ".another-selector"
或许
Then I should see n ".selector" within ".another.selector"
有没有像这样漂浮的东西,还是我应该做一个自定义步骤?
谢谢!
更新:
我采用了以下方法,这似乎工作正常:
# Check there are the correct number of items
assert_have_selector("#activity ol li:nth-child(5)")
assert_have_no_selector("#activity ol li:nth-child(6)")
另一个更新:
我对马特提供的内容做了一些改动:
Then /^I should see ([0-9]+) "([^\"]*)"$/ do |count, selector|
response.body.should have_selector(selector, :count => count.to_i)
end
工作一种享受!