Waymond
Waymond

Reputation: 257

Capybara click_on is not finding my link_to

Can't figure this one out. Any help is appreciated! In my navigate_events_spec.rb file, I have this:

  require 'spec_helper'

  describe "Navigating events" do

   it "allows navigation from the detail page to the listing page" do
event = Event.create(event_attributes)

visit event_url(event)

click_link "All Events" 

expect(current_path).to eq(events_path)
end


it "allows navigation from the listing page to the detail page" do
event = Event.create(event_attributes)

visit events_url

click_link event.name

expect(current_path).to eq(event_path(event))
end
end

and in my show.html.erb, I have the link_to at the bottom with "All Events"

<header>
<h1><%= @event.name %></h1>
</header>
<p>
<%= @event.description %>
</p>
<h3>When</h3>
<p>
<%= @event.start_at %>
</p>
<h3>Where</h3>
<p>
<%= @event.location %>
</p>
<h3>Price</h3>
<p>
<%= number_to_currency(@event.price) %>
</p>
</article

 <%= link_to "All Events", events_path %>

When I run rspec spec/features/navigate_events_spec.rb, I get this error:

[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. F.

 Failures:

 1) Navigating events allows navigation from the detail page to the listing page
 Failure/Error: click_link "All Events"
 Capybara::ElementNotFound:
   Unable to find link "All Events"
 # ./spec/features/navigate_events_spec.rb:10:in `block (2 levels) in <top (required)>'

  Finished in 0.13978 seconds
  2 examples, 1 failure

  Failed examples:

rspec ./spec/features/navigate_events_spec.rb:5 # Navigating events allows navigation from the detail page to the listing page

   Randomized with seed 30615

Upvotes: 0

Views: 708

Answers (1)

JKillian
JKillian

Reputation: 18351

Check your article HTML tags - the closing one isn't quite right and that's messing up your link!

Upvotes: 1

Related Questions