全体的な system spec - 不定期刊 Rails App を作る(38:最終回)

RailsApp Rails RSpec Capybara 2018年 12月 27日

システム全体のエンドツーエンド(E2E)テスト

  1. それぞれのモデルに対する integration_test が終了した. 最後にシステム全体を通した E2E テストを実施する.
  2. require 'rails_helper'
    
    RSpec.describe :EventGakuseis, type: :system do
      include Devise::Test::IntegrationHelpers
      teacher_login :hkob
    
      it 'ログインしてから出席簿を付けるまでの全工程が実施できること' do
        visit kurasus_path
        click_on '編集モードに入る'
        click_on 'クラス作成'
        fill_in 'クラス名', with: '2300'
        click_on '登録'
        expect(page).to have_content 'クラスを登録しました.'
    
        click_on '学生一覧'
        click_on '編集モードに入る'
        click_on '学生の一括登録'
        page.execute_script %Q[document.getElementById('number_name').value = "2301\tABC"]
        click_on '登録'
        click_on '学生の一括登録'
        page.execute_script %Q[document.getElementById('number_name').value = "2302\tDEF"]
        click_on '登録'
        expect(page).to have_content "2301"
        expect(page).to have_content "2302"
    
        click_on 'イベント一覧'
        click_on '編集モードに入る'
        click_on 'イベント作成'
        fill_in 'イベント名', with: 'ホール行事'
        fill_in '日付', with: '2018/4/7'
        fill_in '並び順', with: '1'
        click_on '登録'
        expect(page).to have_content 'イベントを登録しました.'
    
        click_on '出席簿'
        within '.unsettled' do
          click_on '2301 ABC'
        end
        within '.shusseki' do
          expect(page).to have_content '2301 ABC'
        end
        click_on '欠席'
        within '.unsettled' do
          click_on '2302 DEF'
        end
        within '.kesseki' do
          expect(page).to have_content '2302 DEF'
        end
      end
    end
  3. それぞれのモデルの index ではモデルの表示に show を用意していた. 例えば,クラス作成後にクラス表示すると kurasus#show を描画している. しかしながら,実際にはクラス学生一覧やクラスイベント一覧へのリンクが必要である. このように各 integration_test 間のリンクを追加修正し,上記テストが通過するようにしてみる.

リンクなどの修正

  1. app/views/kurasus/index.html.haml のリンクを修正する.
  2.         = link_to t('kurasus.gakuseis.index.title'), kurasu_gakuseis_path(k)
            = link_to t('kurasus.events.index.title'), kurasu_gakuseis_path(k)
  3. app/views/kurasus/gakuseis/index.html.haml に kurasu_events_path のリンクを追加する.
  4.   %caption
        = link_to t('kurasus.events.index.title'), kurasu_events_path(@kurasu)
  5. guard の結果は以下のようになった.
  6. EventGakuseis
    Capybara starting Puma...
    * Version 3.12.0 , codename: Llamas in Pajamas
    * Min threads: 0, max threads: 4
    * Listening on tcp://127.0.0.1:56046
      ログインしてから出席簿を付けるまでの全工程が実施できること
    
    Finished in 4.49 seconds (files took 1.15 seconds to load)
    1 example, 0 failures
  7. ブラウザでも同様に描画を確認した.一部きになるところはあるが,アプリとして使えるところまで作成できた.
  8. 最終の screen shot