Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert amount of found nodes greater than N

Tags:

capybara

With Capybara, one can easily assert the exact amount of nodes to be found:

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

This ensures that there are exactly 2 such fields. But I want to check for "at least 2". Something like:

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

This is an example, because it throws undefined method 'greater_than?' for 3:Fixnum'

Is there a matcher like this? Or another trick that allows me to check for "at least N nodes"?

like image 366
berkes Avatar asked Jan 17 '13 17:01

berkes


2 Answers

Unfortunately the answer from RobertH on 17th Jan 2013 is now depreciated syntax.

For this precise scenario you would need to do:

page.all("fieldset.has_many_fields input[type=file]", :minimum => 2)
like image 200
Dono Avatar answered Sep 30 '22 06:09

Dono


I think you just have a typo. Try:

expect(page.all("fieldset.has_many_fields input[type=file]").count).to be > 2
like image 35
RobertH Avatar answered Sep 30 '22 06:09

RobertH