Rspec and capybara selected value

capybara, rspec, ruby, ruby-on-rails

Solution

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'

Problem

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?

Original source