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

RSpecの導入

Last updated at Posted at 2019-09-13

ユーザー認証の単体テスト

ユーザーモデルクラスが単体で正常に動作するかテストを行う

RSpecを導入する

Gemfileに gem 'rspec-rails' を追記する

Gemfile
group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri

  gem 'capistrano'
  gem 'capistrano-rbenv'
  gem 'capistrano-bundler'
  gem 'capistrano-rails'
  gem 'capistrano3-unicorn'
  gem 'rspec-rails'

end

追記したらbundle intallを行う

RSpec用の設定ファイルを作成する

$ rails g rspec:install

ターミナルで実行すると、以下のようにファイルが作成される

   create  .rspec
   create  spec
   create  spec/spec_helper.rb
   create  spec/rails_helper.rb

.rspecに追記する

.rspec
--format documentation

これで設定ファイルの準備は完了♩

RSpecが正常に利用できるかの確認

$ bundle exec rspec

ターミナルで上記を実行して、次の通り表示されれば利用できます。

No examples found.


Finished in 0.00058 seconds (files took 0.20912 seconds to load)
0 examples, 0 failures
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?