0
投稿と好きなものを含むrailsアプリケーションを作成しています。ページ上の1つのオブジェクトを正しくテストする方法
feature "Create like" do
include_context "user signed in"
def have_updated_likes_count
new_likes_count = bonus.likes_count
have_content("Likes #{new_likes_count}")
end
let!(:bonus) { create(:bonus) }
let(:decorated_bonus) { bonus.decorate }
before { visit root_path }
scenario "User likes bonus", js: true do
find(".like").click
expect(bonus).to have_updated_likes_count
expect(page).to have_content(current_user.full_name)
end
end
ボーナス=ポスト。あなたがボーナスを気に入っているかどうかチェックしています。しかし、このroot_path(メインページ)にはたくさんの投稿(20)があり、それぞれの投稿は好きです。私のテストではexpect(bonuses).to have_updated_likes_count
とexpect(page).to have_content(current_user.full_name)
をチェックしようとしていて、それはフルページをチェックするので、常に両方とも真ですが、私はただ1つのポスト(どこでfind(".like").click
でしたか)をチェックする必要があります。問題を解決するにはどうしたらいいですか?