0

对于黄瓜步骤,我知道一个特定的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

工作一种享受!

4

1 回答 1

1

我就是这样做的:

Then /^"([^\"]*)" should have ([0-9]+) "([^\"]*)"$/ do |selector1, count, selector2|
  within(selector1) do |content|
       content.should have_selector(selector2, :count => count.to_i)
  end
end

这应该行吗?

马塔

于 2010-07-08T22:53:42.457 回答