I am writing a test for a navigation menu. This test worked until I changed the options in the <li>
in the rails view from hard-coded options to be retrieved from the database. How should I setup this test so it mimics the user choosing the selection from the navigation drop-down?
my spec:
feature "user can navigate to a restaurant page" do
scenario "views a restaurant page" do
visit root_path
within('#restaurants'){
click_on 'Corner Pub'
}
end
end
My test fails with:
1) user can navigate to a restaurant page views a restaurant page
Failure/Error: click_on 'Corner Pub'
Capybara::ElementNotFound:
Unable to find link or button "Corner Pub"
from the navigation partial:
<li class="nav-link more" id="restaurants"><a href="/restaurants/">restaurants</a>
<ul class="submenu">
<% Restaurant.reviewed_restaurants.each do |restaurant| %>
<li><%= link_to restaurant.name, restaurant %></li>
<% end %>
</ul>
</li>
From the html:
<li class="nav-link more" id="restaurants"><a href="/restaurants/">restaurants</a>
<ul class="submenu">
<li><a href="/restaurants/corner-pub">Corner Pub</a></li>
</ul>
</li>