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
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'])}
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