1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rspec ~ インストールから準備まで~

Posted at

備忘録。

Rspec Install

今回は、Gemfileに記述してRspecのRails用の機能を追加します。

Gemfileに記述

gem 'rspec-rails', '~> 5.0' # (2021/3/11時点で最新)


バージョンはお好みで、

[RubyGems.org](https://rubygems.org/)でrspec-railsを検索して、バージョンを確認しましょう。


> ```
$ bundle 

実行してgemをインストール。

Rspecに必要なもの

gemのインストールが終わったら、

$ bin/rails g rspec:install


> を実行。

> このgenarateコマンドを実行することで、設定ファイルなどを作成します。

---

1.Rails標準のMinitestを今後使わない。
     &
2.Railsアプリケーションを作成した時、自動でtestディレクトリが作られている場合は、

$ rm -r ./test

を実行。

もしくは、直接テキストエディタからtestフォルダを消しましょう。

### Rspecを使っていくなら、specディレクトリ下にテストファイルが格納される。

### Minitest用のtestというフォルダは要らないです。

---

# Rspecのフォーマット


```ruby


require 'rails_helper'
# Rails特有の設定。


describe[ ✖︎✖︎✖︎ 機能 ], type: [ スペックの種類 ] do
    context: [ 条件 (▲▲▲ の場合) ] do
        [ 事前準備 (contextの中身を確認するのに必要な準備) ]
    end

    it [ 期待値の概要 ( 〇〇しますよ〜 ) ] do
        [ 期待する動作 ]
    end
end

他にもFactoryBotなどテスト作成を支援してくれるgemなど色々あるので、調べてみてください!!!


1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?