断言找到的节点数量大于N.

时间:2013-01-17 17:54:08

标签: capybara

使用Capybara,可以很容易地确定要找到的节点的确切数量:

page.should have_selector("fieldset.has_many_fields input[type=file]", :count => 2)

这确保了正好有2个这样的字段。但我想检查"至少2"。类似的东西:

page.all("fieldset.has_many_fields input[type=file]").count should be_greater_than 2

这是一个例子,因为它会抛出undefined method 'greater_than?' for 3:Fixnum'

有这样的匹配器吗?或者另一个技巧,允许我检查"至少N个节点"?

2 个答案:

答案 0 :(得分:6)

不幸的是,RobertH在2013年1月17日的回答现在是折旧语法。

对于这个精确的场景,您需要这样做:

page.all("fieldset.has_many_fields input[type=file]", :minimum => 2)

答案 1 :(得分:2)

我认为你只是有一个错字。尝试:

expect(page.all("fieldset.has_many_fields input[type=file]").count).to be > 2
相关问题