Skip to content

Instantly share code, notes, and snippets.

@anansilva
Last active May 28, 2021 18:49
Show Gist options
  • Save anansilva/efa7f8bd8dacfbafb8c3dd7f1c034562 to your computer and use it in GitHub Desktop.
Save anansilva/efa7f8bd8dacfbafb8c3dd7f1c034562 to your computer and use it in GitHub Desktop.
New Rails 6 Project

Basic Rails setup (version 6 + postgreSQL + rspec)

1. Make sure you have rails ~> 6.0.0

$ rails -v

If you don't, install rails

$ gem install rails

2. Create a new rails project using postgres as database

$ rails new <project-name> -T --database=postgresql

-T prevents minitest from being installed, we will use rspec instead

3. Go to the app's Gemfile and check both ruby and rails versions

Rails 6 depends on ruby (>= 2.5.0)

You should see something similar to this depending on your local ruby and rails versions

ruby '3.0.1'

gem 'rails', '~> 6.0.3'

4. Add database configuration to .gitignore

# Git ignore database configuration
/config/database.yml

5. Add rspec-rails to both the :development and :test groups of your app’s Gemfile:

Run against the latest stable release

group :development, :test do
  gem 'rspec-rails', '~> 3.8'
end

Update Gemfile.lock

$ bundle

Install

$ rails generate rspec:install

This will generate .rspec, spec/rails_helper.rb, spec/spec_helper.rb

Require rails_helper in the .rspec file. This way you don't have to manually add it to every single test file. This is what your .rspec file should look like:

--require spec_helper
--require rails_helper

6. Setup db

$ rake db:setup

You're ready to go!

You can now start creating your models, controllers, views, etc

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