2010-07-08 26 views
0

对于黄瓜步骤的具体数目,我知道某个ul元素应该有5个孩子li。我怎样才能用Webrat声明这一点?使用Webrat检查列表有li元素

我猜有可能是这样的:

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 

作品一种享受!

回答

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 

那现在应该做的伎俩?

马塔