sharoa
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 【第20週】パRails輪読会🚂 \(2024\-01\-04\~ 2024\-01\-05\) ###### tags: `パRails🚂` - [開催概要](https://hackmd.io/4A_8ahJtQNi5hz713N5Y7w?view) - [パRails輪読会 ノートまとめ](https://hackmd.io/jsgA8Pf_RVioOgSL_VOR4g) - サンプルコード・正誤表:[サポートページ:パーフェクトRuby on Rails【増補改訂版】:|技術評論社](https://gihyo.jp/book/2020/978-4-297-11462-6/support) - **サンプルコードをダウンロードしただけでは、すぐに`rails s`できない可能性が高い**です。 以下のページに環境構築の手順をまとめたので、ドライバーをやってくださるという方は、こちらに沿って環境構築をお願いします🙏 ⏩ [環境構築の手順 2022年版](https://hackmd.io/y7qb2BRMT2Wd4tAtKYObcQ) ⏩ [環境構築の手順 2023年版](https://hackmd.io/3_lnn8_QRD6wEjwFbWcBzQ) 💁‍♀️ [更新の手順 2章編](https://hackmd.io/pZAmF2EjSmyQ38lUtJ_CqA) ## 目次 [TOC] ------ ## 2024\-01\-04(木) ### ファシリ @shodan ### ドライバー @motohiro-mm ### 読んだところ 7-4-3 「システムテストを失敗させる」から 7-4-6 「ログインが必要なページのテストを書く」まで。 PR:https://github.com/PerfectRubyonRails-Rindoku/Perfect_Ruby_on_Rails_Ch6/pull/19 ### 次回 7-4-7 「データを入力して登録するテストを書く」から。🚂 ### 学んだこと・感想 - @sharoa - 久しぶりの輪読会で、前回までやっていたOmniAuthやFactoryBotの定義など忘れている部分があった。 - テストコードで失敗するとスクリーンショットされて、なぜ失敗したかの情報を得るのに有力な情報になる。 - 作成したログインヘルパーを使うために、 test_helper.rbやapplication_system_test_case.rbに追記をしないといけない。 - モック化というのが急に出てきてなんだ?と思ったけど、shodanさんの説明でなんとなくだけどわかった。急にわからん単語出てくるの、本当に多いw - @hiromisugie - 前回部分ですが、`application_system_test_case.rb`で`using: headless_chrome`とするとヘッドレスブラウザでChromeを起動せずにシステムテストを行うことができる(Chromeを使うときは`using: chrome`) - テスト内で`sleep 5`とすると5秒停止してくれる。Chrome起動で画面を見るときに一瞬で画面が変わってしまう時などに便利。 - ログインヘルパーを作ることで、複数のシステムテストでもログイン処理がサッとできるようになる - `setup`メソッドは、いくつかのテストをするにあたって共通で先に行う動作をすることができる - `teardown`メソッドは、最後に行う動作を共通化して書ける - @shodan - 失敗時にスクショが取られるのはそういうものかな〜と思っていたけれど、実は`take_faild_screenshot`というメソッドがテスト終了時に呼び出されているからだった。 - さらに`take_screenshot`メソッドを使えばいつでも好きなタイミングでスクショを撮れるというのは知れてよかった気がします。 - OmniAuthのモック化の設定方法を覚えておくのは無理そうだけど、自分で使うときになったらパRailsのこのページに戻って来れるよう、ふわっとインデックスしておきたいです。 - @moegi29 - FactoryBotで定義したファイルを使ってuserをcreateしたりする様子を確認できた。やっぱりheadlessじゃなくブラウザ上でみれたほうがわかりやすいなぁと感じました。 - プロダクトコードがある状態→事前に作ったプロダクトのコードがあって後からテストをする状態のこと。 - OmniAuth.config OmniAuthを使う場合特有のメソッドがあるということを覚えておきたい - @motohiro-mm - テストコードだけを後から作成したいときは`bin/rails g test_unit:scaffold モデル名` - 失敗時にスクショが撮られる:`take_failed_screenshot`メソッド、常にスクショを撮る:`take_screenshot`メソッド - モック化:テストに必要な部品の値を擬似的に設定するもの - `require_relative`や`include`のところは、言われて「なるほどな〜」ととても思いました - `setup`:テストの前に行う共通動作、`teardown`:テストが終わった後に行う共通動作 ----- ## 2024\-01\-05(金) ### ファシリ @motohiro-mm ### ドライバー @ayu-0505 ### 読んだところ 7-4-7 「データを入力して登録するテストを書く」から 7-4-8 「ダイアログを操作するテストを書く」まで。 PR:https://github.com/PerfectRubyonRails-Rindoku/Perfect_Ruby_on_Rails_Ch6/pull/20 ### 次回 7-5 「コントローラに対する機能テスト」から。🚂 ### 学んだこと・感想 - @sharoa - `fill_in`メソッドと`select`メソッドを使ってフォームにデータを入力して登録するテストを書くことができる。 - テストを実行した時の`run`と`assertions`の数が違うのがなんか気になる。。。。 - 削除ボタンを押した時に出てくる「本当に削除してもいいですか?」と言ったダイアログを操作するテストを書くこともできる。 - テストで時刻を制御することもできる。`travel_to`メソッド覚えておこう。(メソッド名が素敵ですねw) - テストで結構なんでもできる?!すごっ。 - @hiromisugie - システムテストで`fill_in`や`select`などのメソッドを使って画面に入力したり、`click_on`メソッドで画面を進んでいくのを設定して実際に画面が動くのを見るのは、なんというか楽しい(書籍で既に書かれたものを見る分には楽しいけど、自分でゼロから書くとなるとかなりモタつきそうだなとも思った) - `assert_difference`というのを初めて知った。assertなんちゃらは画面上で表示されているものに対して行うものだと思っていたのですが、イベントの数が1つ減った、みたいなこともテストできることを知った。 - 時間を移動するためのヘルパーが`travel_to`という名前なのが、洒落ているなと思った - @moegi29 - travel_toヘルパーを使って現在時刻を変更するテストができる。また、FactoryBot.createメソッドで指定するstart_atの値を変更してテストを書くこともできる。今日でシステムテスト終わり、いろんなテストの書き方がある - JSの画面書き換えを待たずにテストが失敗する場合がある。assert_text や assert_selector に置き換えて回避することができるらしい。shodanさんが貼ってくれた解説をちゃんと読んでおきたいです。 - @shodan - Capybaraの`select`メソッドで、セレクトフォームへの入力ができる - `accept_confirm`メソッドにブロックを渡すと、そのブロックの操作の中で出現したダイアログに対してOKボタンを押させることができる - `travel_to`メソッドに時刻とブロックを渡すと、その時刻を現在時刻として、ブロック内の操作を行なってテストすることができる(テスト実行時の時刻を制御するヘルパー) - `assert_difference`の第一引数の処理が「文字列」であることが地味にハマりポイントだったことがあります - `assert_difference("Event.count", -1)`の第一引数が「文字列」 - 第一引数に渡した「式の文字列」を内部処理でRubyのコードとして実行するという、メタプログラミング(通称:黒魔術)というのをやっているそうです - @ayu-0505 - `fill_in`メソッドと`select`メソッドを使ってフォームにデータ入力を行う。 - ダイアログ操作をする際は`accept_confirm`メソッドを使用すると、渡されたブロック内で表示されたダイアログに対してOKボタンをクリックしてくれる。(ということはキャンセルボタンをクリックするメソッドもあるかも?) - `assert_difference`メソッドでは渡したブロック内の処理の前後の変化を確認できる。 - `travel_to`メソッドを使用するとブロックで引き渡した時刻に現在時刻が差し代わる。 - `assert〜`系のメソッドはJSの表示を最短時間で待ってくれるらしいので、色々活用したい。 - @motohiro-mm - `fill_in`メソッドと`select`メソッドでフォームにデータを入力できる - 時刻の入力が大変そうだなと思いました - ダイアログの操作は`accept_confirm do ~ end`で書く - `assert_difference`渡したブロック中の処理の前後で結果が変わっていることをみている - `travel_to`ヘルパーでタイムスリップできる -----

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully