2010-07-08 25 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 

那現在應該做的伎倆?

馬塔