rails new <project_name> -d postgresql --skip-turbolinks --skip-spring -T
-d postgresql
sets up the project to use PostgreSQL--skip-turbolinks
&--skip-spring
creates a project that does not use turbolinks or spring-T
skips the creation of the test directory and use ofTest::Unit
- In the Gemfile:
- Available to all environments:
gem 'figaro'
- store environment variables securely across your app (docs)
- Inside of
group :test
:gem 'rspec-rails'
- user rspec in place of minitest (docs)gem 'capybara'
- act as a user navigating your site in tests (docs)gem 'launchy'
- for running save_and_open_page (docs)gem 'shoulda-matchers'
- easier model testing (docs)gem 'database_cleaner'
- clean your database between tests (docs)gem 'factory_girl_rails'
- easily generate database objects without repetitive code in tests (docs)gem 'simplecov', require: false
- generate reports on your test coverage (docs)
- inside of
group :production
:gem 'rails_12factor', group: :production
- If publishing on Heroku (docs)
- Bundle and install (
bundle exec
orrails g
) where required, create additional required files
bundle
rails g rspec:install
bundle exec figaro install
mkdir spec/support
touch spec/support/factory_girl.rb
touch spec/support/factories.rb
- Add config data
- In
spec/rails_helper.rb
require 'capybara/rails' Shoulda::Matchers.configure do |config| config.integrate do |with| with.test_framework :rspec with.library :rails end end
- Uncomment
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
- Uncomment
- In
spec/support/factory_girl.rb
RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.before(:suite) do begin DatabaseCleaner.start FactoryGirl.lint ensure DatabaseCleaner.clean end end end
- In
spec/support/factories.rb
FactoryGirl.define do <factories for each model go here> end
- In
spec/spec_helper.rb
- Note: this must appear at the very top of this file
require 'simplecov' SimpleCov.start 'rails'
- In
.gitignore
coverage
- (Optional) If working with an external API:
- In
Gemfile
bundle
- In
spec/rails_helper.rb
require 'vcr' VCR.configure do |config| config.cassette_library_dir = "spec/vcr_cassettes" config.hook_into :webmock end
- In
.gitignore
# Ignore vcr cassettes /spec/vcr_cassettes
Note: If you are not using FactoryGirl, disregard the steps above for FactoryGirl and follow the instructions here for configuring DatabaseCleaner.