I want to assert if certain select has certain value and not text. This works if I assert by text :
it 'should be true' do
should have_select("country", :selected => 'Brazil')
end
My select html is like this :
<select name="user[country]" id="country">
<option value="BR">Brazil</option>
...
</select>
I want to assert does page have select with selected value, how can I do that?
I do not believe there is a built-in matcher for checking the select list by value.
You can however, get the select list's value (ie selected option's value) by using the value
method:
find(:css, 'select#country').value
You could compare this to the expected value, using the expect syntax:
expect( find(:css, 'select#country').value ).to eq('BR')
Or using the should syntax:
find(:css, 'select#country').value.should == 'BR'
Or if you prefer to stay away from CSS selectors:
find_field("country").value.must_equal "BR"
This assumes you name the label for this field country
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With