パスを訪れ、そのページで新しい会話を作成するrspecテストを実行しています。しかし、私は明確にvisit conversations_path
と明記したにもかかわらず、なぜ私は以下のエラーが発生しているのか理解できません。エラーメッセージに書かれたlink_to文は、私のルートパスにあります。Rspec + Capybara webkit:テストで指定されたパスには向かわず、ルートパスの構文が検出されました
ルートパスからlink_toコードを削除すると、テストに合格します。
conversation_spec.rb
describe "Conversation" do
let!(:user) { FactoryGirl.create(:user) }
let!(:other_user) { FactoryGirl.create(:friend) }
before do
login_as(user, :scope => :user)
end
describe 'index' do
before do
visit conversations_path
end
it 'can be reached successfully' do
expect(page.status_code).to eq(200)
end
it "create a new conversation", **js: true** do
visit conversations_path
expect(current_path).to eq(conversations_path)
click_on "Compose"
expect(page).to have_css('.new_message_head')
end
end
失敗:featured_article
がnilであるので、あなたのテストのための任意の記事を作成していないので、
1) Conversation index create a new conversation
Failure/Error: <h4><%= link_to featured_article.title, article_path(featured_article) %></h4>
ActionView::Template::Error:
undefined method `title' for nil:NilClass