Skip to content

Instantly share code, notes, and snippets.

@malachaifrazier
Forked from patwey/rails_new.md
Created November 7, 2019 19:17
Show Gist options
  • Save malachaifrazier/f6e06ec46a6c67967025f267f44c1aac to your computer and use it in GitHub Desktop.
Save malachaifrazier/f6e06ec46a6c67967025f267f44c1aac to your computer and use it in GitHub Desktop.
Steps for creating a new rails app with a Postgres database, Haml, RSpec and FactoryGirl

Steps

  1. Create app, skipping TestUnit and specifying a Postgres db: $ rails new app_name -T --database=postgresql

  2. Update the Gemfile: Gemfile:

    gem 'haml'
    gem 'haml-rails'
    
    group :development, :test do
       gem 'rspec-rails'
       gem 'factory_girl_rails'
       gem 'shoulda-matchers', '~> 3.1'
       gem 'faker'
       gem 'database_cleaner'
  3. Bundle: $ bundle

  4. Install RSpec: $ rails g rspec:install

  5. Create spec/support/factory_girl.rb:

    RSpec.configure do |config|
      config.include FactoryGirl::Syntax::Methods
    end
  6. Update rails_helper.rb:

    require 'spec_helper'
    require 'rspec/rails'
    require 'database_cleaner'
    
    # Require support files
    Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
    
    # Configure shoulda matchers
    Shoulda::Matchers.configure do |config|
      config.integrate do |with|
        with.test_framework :rspec
        with.library :rails
      end
    end
    
    Rspec.configure do |config|
      # ...
      config.include FactoryGirl::Syntax::Methods
    
      config.before(:suite) do
        DatabaseCleaner.clean_with(:truncation)
        DatabaseCleaner.strategy = :transaction
      end
    
      config.around(:each) do |example|
        DatabaseCleaner.cleaning do
          example.run
        end
      end
  7. Convert app layout to haml: $ rails g haml:application_layout convert

  8. Set up db: $ rake db:create db:migrate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment