Capybara click_on找不到我的link_to

时间:2014-01-04 17:47:24

标签: ruby-on-rails rspec capybara

无法想出这个。任何帮助表示赞赏!在我的navigate_events_spec.rb文件中,我有:

  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

在我的show.html.erb中,我在底部有“All Events”的link_to

<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 %>

当我运行rspec spec / features / navigate_events_spec.rb时,我收到此错误:

  
    

[已弃用] I18n.enforce_available_locales将来默认为true。如果您确实想跳过语言环境的验证,可以设置I18n.enforce_available_locales = false以避免此消息。     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#导航事件允许从详细页面导航到列表页面

    
  
   Randomized with seed 30615

1 个答案:

答案 0 :(得分:1)

检查您的article HTML标记 - 结束的标记不是很正确,这会弄乱您的链接!