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

ber*_*kes 4 capybara

使用Capybara,可以轻松断言要找到的节点的确切数量:

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

这确保了恰好有2个这样的字段.但我想检查"至少2".就像是:

page.all("fieldset.has_many_fields input[type=file]").count should be_greater_than 2
Run Code Online (Sandbox Code Playgroud)

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

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

Don*_*ono 7

不幸的是,RobertH于2013年1月17日的答案现在是折旧语法.

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

page.all("fieldset.has_many_fields input[type=file]", :minimum => 2)
Run Code Online (Sandbox Code Playgroud)


小智 3

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

expect(page.all("fieldset.has_many_fields input[type=file]").count).to be > 2
Run Code Online (Sandbox Code Playgroud)