Skip to content

Instantly share code, notes, and snippets.

@fernandollisboa
Last active January 16, 2024 01:44
Show Gist options
  • Save fernandollisboa/cc8e35ad295d4fed008b068e6e9fa6c3 to your computer and use it in GitHub Desktop.
Save fernandollisboa/cc8e35ad295d4fed008b068e6e9fa6c3 to your computer and use it in GitHub Desktop.

Create Rails Project

  1. Run rails new
    rails new [name] --api -T
  2. Copy your Gemfile
  3. Copy your .gitignore
  4. Copy your .rubocop.yml
  5. Install Rspec
      rails generate rspec:install
  6. Install Shoulda
    # spec/rails_helper.rb
    Shoulda::Matchers.configure do |config|
       config.integrate do |with|
         with.test_framework :rspec
         with.library :rails
       end
     end
  7. Install Guard (1/2)
      bundle exec guard init rspec
  8. Install Guard (2/2)
    # Guardfile
     watch(rails.controller) do 
        ...
        rspec.spec.call("requests/#{m[1]}")
  9. Install Simplecov
    # At the very top of your `spec/spec_helper.rb`
    require 'simplecov'
    SimpleCov.start
  10. Install Factory Bot
    # spec/rails_helper.rb, 
     RSpec.configure do |config|
        ...
        config.include FactoryBot::Syntax::Methods
  11. Create FactoryBot Test
    # spec/factories_spec.rb
    require 'rails_helper'
    
    describe 'ModelFactories' do
      FactoryBot.factories.map(&:name).each do |factory_name|
        describe "the #{factory_name} factory" do
          it 'is valid' do
            expect(FactoryBot.create(factory_name)).to be_valid
          end
        end
      end
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment