2

How do I use Webrat to check that a select box has certain values listed as options? I currently have field_named(field).value.should contain(value) but that only passes for the first selected value and not for the unselected values. How do I check that the unselected options are present? And how do I check the number of options available in a select box?

I believe I need something akin to field_named(field).element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{value}/ except that I don't actually care about what's selected - only what exists.

Can you also provide a source on where your answer comes from? I find documentation on using Webrat beyond the basics terribly difficult to find.

WheresAlice
  • 188
  • 8

1 Answers1

1

I had similar problem, I found this useful

 Then /^"([^"]*)" should be seen within "([^"]*)"$/ do |value, field|
  find_by_id(field).text.should =~ /#{value}/ 
end

where value is the text you want to check and field is the id of the select box.

Hope it is useful to you too!

Sadiksha Gautam
  • 5,032
  • 6
  • 40
  • 71