下記内容のテストが実施できません
find(".relation-btn_#{other_user.id}").click_button 'フォロー解除'
上記の部分がエラーのようです。
spec/integration/relationship_spec.rb
require 'rails_helper' describe 'フォロー機能', type: :system do let!(:user){FactoryBot.create(:user,name:'一般ユーザー')} let!(:other_user){FactoryBot.create(:user,name:'その他ユーザー')} let(:active_relationship) do user.active_relationships.create( follower_id: user.id, followed_id: other_user.id ) end let(:passive_relationship) do user.passive_relationships.create( follower_id: other_user.id, followed_id: user.id ) end context 'フォロー時' do it 'フォロワー一覧に名前がある' do active_relationship visit following_user_path(user) expect do find(".relation-btn_#{other_user.id}").click_button 'フォロー解除' sleep 2 end.to change(Relationship, :count).by(-1) end end end
spec/integration/relationship_spec.rb
FactoryBot.define do factory :relationship do follower_id { 1 } followed_id { 1 } end end
エラー
1) フォロー機能 フォロー時 フォロワー一覧に名前がある Failure/Error: find(".relation-btn_#{other_user.id}").click_button 'フォロー解除' Capybara::ElementNotFound: Unable to find css ".relation-btn_4" # ./spec/integration/relationship_spec.rb:42:in `block (4 levels) in <top (required)>' # ./spec/integration/relationship_spec.rb:41:in `block (3 levels) in <top (required)>'
試したこと
save_and_open_pageを実行した際に、すべての内容が読み込まれていない気がして、
following_user_path(user)の部分のviewに記述を加えて見ました
app/views/users/show_follow.html.slim
= render 'users/profile', user:@user = render 'users/tab', user:@user div class="relation-btn_4" = render @users
すると、エラー内容が以下に変わりました。
1) フォロー機能 フォロー時 フォロワー一覧に名前がある Failure/Error: find(".relation-btn_#{other_user.id}").click_button 'フォロー解除' Capybara::ElementNotFound: Unable to find button "フォロー解除" that is not disabled within #<Capybara::Node::Element tag="div" path="/html/body/div[1]/div[2]"> # ./spec/integration/relationship_spec.rb:42:in `block (4 levels) in <top (required)>' # ./spec/integration/relationship_spec.rb:41:in `block (3 levels) in <top (required)>'
おそらく、renderの部分が読み込まれる前に、テストが実施されているのかと思うのですが、
これはそういうものなのでしょうか。
それとも、何か設定を変えることで、全て読み込まれた状態でテストができるのでしょうか。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。