Skip to content

Instantly share code, notes, and snippets.

@Automatic365
Forked from ryanflach/rails_setup.md
Created August 29, 2016 23:04
Show Gist options
  • Save Automatic365/250545727d2a425fe91b8c40ff60681b to your computer and use it in GitHub Desktop.
Save Automatic365/250545727d2a425fe91b8c40ff60681b to your computer and use it in GitHub Desktop.
Common setup for a new Rails project
  1. rails new <project_name> -d postgresql --skip-test-unit --skip-turbolinks --skip-spring
  • -d postgresql sets up the project to use PostgreSQL
  • --skip-test-unit skips the creation of the test directory
  • --skip-turbolinks & --skip-spring creates a project that does not use turbolinks or spring
  1. In the Gemfile:
  • inside of group :development, :test:
    • gem 'rspec-rails'
      • bundle
      • rails g rspec:install
    • gem 'capybara
      • inside of rails_helper.rb: require 'capybara/rails'
    • gem 'launchy - for running save_and_open_page
    • gem 'shoulda-matchers' - easy model testing
      • inside of rails_helper.rb:
      Shoulda::Matchers.configure do |config|
        config.integrate do |with|
          with.test_framework :rspec
          with.library :rails
        end
      end
      
  • gem 'unicorn' - slightly faster web server
  • gem 'rails_12factor', group: :production - If publishing on Heroku
  • gem 'database_cleaner' (test only)
  • (optional) gem 'factory_girl_rails' (test only)
    • touch spec/support/factory_girl.rb:
    RSpec.configure do |config|
      config.include FactoryGirl::Syntax::Methods
      
      config.before(:suite) do
        begin
          DatabaseCleaner.start
          FactoryGirl.link
        ensure
          DatabaseCleaner.clean
        end
      end
    end
    
    • In rails_helper.rb uncomment `Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
    • touch spec/support/factories.rb
    FactoryGirl.define do
      <factories for each model go here>
    end
    
  • (if not using FactoryGirl)
  • gem 'figaro'
    • bundle exec figaro install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment