LoginSignup
0
0

More than 1 year has passed since last update.

Rspec モデルスペックの基本

Last updated at Posted at 2023-03-13

モデルスペックで行うこと

  • モデルのバリデーションの検証
  • クラスメソッド、インスタンスメソッドの検証

discribe,context,itの使い分け

  • discribe
    モデル内のモデル内の機能(メソッド)のテストをする際に使用する。
  • context
    場合分けの際に使用する(〜な時、〜じゃない時)
  • it
    テストする処理、期待する結果を記述する。
    またit一つにつき、期待する結果も一つが望ましい。
    なぜなら、テストが失敗した時に問題が起きた処理を特定することができるから。

Noteモデルの検索メソッドをテストする場合

user_spec.rb
describe '検索結果を検証' do

  context '一致するデータが存在する場合' do

    it '検索ワードに一致するデータを返すこと'
    end

  end

  context '一致するデータが存在しない場合' do

    it '空の配列を返すこと' do
    end

  end
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0