Hi i am doing rspec testing now, Basically the test is allow navigating
from detail page to listing page, this part it passes, but when it comes
to listing page to detail page, it keep showing me this Ambiguous match,
found 5 elements matching link “BugSmash”, and there’s a error at this
Failure/Error: click_link event.name
my spec is located at rspec spec/features/navigate_events_spec.rb
routes.rb
Rails.application.routes.draw do
get “events” => “events#index”
get “events/:id” => “events#show”, as: “event”
end
nagivate_events_spec.rb
require “rails_helper”
describe “Navigating events” do
it “Allow nagivation from the detail page to the listing page” do
event = Event.create(name:“BugSmash”,
location:“Denver”,
price:10.00,
description:“A fun evening of bug smashing!”,
starts_at: 10.days.from_now)
visit event_url(event)
click_link “All Events”
expect(current_path).to eq(events_path)
end
it “Allow nagivation from the listing page to the detail page” do
event = Event.create(name:“BugSmash”,
location:“Denver”,
price:10.00,
description:“A fun evening of bug smashing!”,
starts_at: 10.days.from_now)
visit events_url
click_link event.name
expect(current_path).to eq(event_path(event))
end
end
index.html.erb
<%= pluralize(@events.size,"Event") %>
<% @events.each do |event| %><%= link_to(event.name,event) %>
<%= truncate(event.description,length:35,separator: " ") %>
<table>
<tr>
<th>When</th>
<td><%= event.starts_at %></td>
</tr>
<tr>
<th>Where</th>
<td><%= event.location %></td>
</tr>
<tr>
<th>Price</th>
<td><%= number_to_currency(event.price) %></td>
</tr>
</table>