書籍「Everyday Rails - RSpecによるRailsテスト入門」の環境構築
書籍「Everyday Rails - RSpecによるRailsテスト入門」に記載されているものと同じバージョンで進めるために以下手順で構築を行った。
以下のバージョンで設定
Rubyバージョン2.4.9をインストール
$ rbenv install 2.4.9
ローカル環境に「Everyday Rails」のコードをクローン
$ git clone URL
クローンしたディレクトリに移動してカレントディレクトリのRubyバージョンを2.4.9にする
$ cd クローンしたディレクトリ名
$ rbenv local 2.4.9
※もしバンドラーがインストールされていなければ
$ gem install bundler
バンドルインストール
$ bundle install
以下のエラーが発生が発生した場合の対処
Your bundle is locked to mimemagic (0.3.2) from rubygems repository https://rubygems.org/ or installed locally, but that version can no longer be found in that source. That means the author of mimemagic (0.3.2) has removed it. You'll need to update your bundle to a version other than mimemagic (0.3.2) that hasn't been removed in order to install.
Gemfileに gem "mimemagic", "~> 0.3.10"
と記述した後に
$ bundle install
※それでも上手くいかない場合は
$ bundle update
参考
クローンしたアプリが立ち上がるか確認
$ rails db:migrate
$ rails s
立ち上げたサーバURLにアクセスしてアプリ画面が表示されればOK
テストが通るか確認
以下のコマンドでテストを実行
$ bin/rspec
テストが通ればOK
※ライブラリ内の警告を表示したくない場合は、.rspec
ファイルの--warning
を消す