rspec should have_select('cars', :options => ['volvo', 'saab'] not working

rspec, ruby, ruby-on-rails

Solution

As you can see in this question most people trying to solve a similar problem would use `#cars` to locate their `select`, but the capybara docs for `has_select?` say it will (as usual) find the correct label, name or id. Looking at the examples there I would suggest you try to use the visible (capitalized) option names instead of the internal option values.

The third answer in the question I linked to has an example of verifying the internal values (with the exact same options you use which seems a very tough piece of a coincidence :-).

So you could try

it { should have_select('#cars', :options => ['Volvo', 'Saab', 'Mercedes', 'Audi'])}

Problem

In home page I have: Cars: ``` <select id="cars"> <option value="volvo">Volvo </option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi </option> </select> ``` The test code in static_pages_spec.rb: ``` it "should have the right select" do visit home_path it { should have_select('cars', :options => ['volvo', 'saab','mercedes','audi'])} end ``` The response is ``` rspec ./spec/requests/static_pages_spec.rb:21 # Static pages Home page should have the right select ```

Original source

Related problems