リスト内の記事の1つがログインしたユーザーに属しているかどうかを確認する、RSpecのテストがあります。
let(:user) { Fabricate(:user) }
before do
visit new_user_session_path
fill_in 'Email', :with => user.email
fill_in 'Password', :with => user.password
click_button 'Sign in'
end
describe 'when user has a self-authored article' do
let(:article) { Fabricate(:article, :author_id => user.id) }
before { visit articles_path }
it { should have_link('Edit article', :href => edit_article_path(article)) }
end
テストするビューは次のとおりです。
# articles/new.html.erb
<% provide(:title, 'Articles') %>
<h1>Articles</h1>
<% if user_signed_in? %>
<%= link_to 'Post article', new_article_path %>
<% end %>
<%= render @articles %>
<%= will_paginate %>
これは、テストする特定のビューです。
# articles/_article.html.erb
<% if user_signed_in? %>
<% if current_user.id == article.author.id %>
<%= link_to 'Edit article', edit_article_path(article) %>
<% end %>
<% end %>
テストを実行すると、次のエラーが発生します。
失敗/エラー:it {should have_link('Edit article'、:href => edit_article_path(article))}
expected link "Edit article" to return something
ブラウザをチェックしてテストが正しいことを確認しましたが、リンクが意図したとおりに表示されているようです。どこで私は間違えましたか?テストに合格するにはどうすればよいですか?