作業の流れ
- Gemfile 追記
- bundle install
- rails generate rspec install
- application.rb にジェネレータ追加
- bundle binstubs spec-core
- 確認
手順
1. Gemfile 追記
Gemfile に下記を追記。
# Use RSpec3 group :development, :test do gem "rspec-rails", "~> 3.1.0" gem "factory_girl_rails", "~> 4.4.1" end group :test do gem "faker", "~> 1.4.3" gem "capybara", "~> 2.4.3" gem "database_cleaner", "~> 1.3.0" gem "launchy", "~> 2.4.2" gem "selenium-webdriver", "~> 2.43.0" end
2. bundle install
bundle install 実行。
要すればbundle update も行う。
bundle install
3. rails generate rspec:install
RSpec 用のディレクトリ他用意。
rails generate rspec:install
4. application.rb にジェネレータ追加
config/application.rb のclass Application < Rails::Application 内に下記を追記。
# Use RSpec3 config.generators do |g| g.test_framework :rspec, fixtures: true, view_specs: false, helper_specs: false, routing_specs: false, controller_specs: true, request_specs: false g.fixture_replacement :factory_girl, dir: "spec/factories" end
5. bundle binstubs spec-core
bin ディレクトリ内にrspec 実行ファイルを作成
bundle binstubs rspec-core
6. 確認
bin/rspec