2
3

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 5 years have passed since last update.

[Rails5.2] rspecの導入

Last updated at Posted at 2018-05-27

railsの開発にrspecを導入しました。
導入手順を残しておこうと思います。

環境

Rails 5.2.0
ruby 2.5.1
mysql 5.7.20

インストール

Gemfileを編集して「bundle install」
そして「bin/rails g rspec:install」
にて初期設定ファイル等を作成します。

Gemfile
group :development, :test do
  ()
  gem 'rspec-rails'
end
$ bundle install
$ bin/rails g rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb
      create  spec/rails_helper.rb

bin/rspecで実行できるように & 確認

しかしエラーが...。

$ bundle binstubs rspec-core
$ bin/rspec
Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.

エラーメッセージの通りにコマンドを実行 & 確認

エラーメッセージにある通り「bundle binstubs bundler --force」
にて再度「bin/rspec」を実行したところ実行ができました。

$ bundle binstubs bundler --force
$ bin/rspec
No examples found.

Finished in 0.00038 seconds (files took 0.15095 seconds to load)
0 examples, 0 failures

rails genarate コマンドを使った際にspecファイルも作成するように

application.rb
config.generators do |g|
  g.test_framework :rspec,
  fixtures: false,
  view_specs: false,
  helper_specs: false,
  routing_specs: false,
  request_specs: false
end

RSpecの出力を見やすくする

.rspecに以下を追加してください

.rspec
+ --format documentation

参考

Rails RSpecの基本 ~導入編~
Rails5へのRspec導入から実行確認まで

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?