LoginSignup
3
3

More than 5 years have passed since last update.

RailsプロジェクトにRSpecを導入(ほぼ最小構成)

Posted at

Gemfileに記述


rspecとテストデータ生成に使うfactory_girlを導入
ほぼ最小構成。

Gemfile
group :development, :test do
  gem 'rspec-rails', '~> 3.5'
  gem "factory_girl_rails"
end

RSpec初期化


インストールコマンドを打って初期化、ヘルパーを生成します。

$ bundle exec rails generate rspec:install

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

使ってみる


$ rspec spec/*

コラム


結果出力の設定

.rspecに --color を追加しておく
テストの成否を緑/赤で表示するようになり、赤(失敗時)のみ詳細を出すようになる

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