đź’ľ
Cheat Sheet
  • Cheat Sheet
  • Git
    • Initialize a new project
    • Make a new commit
    • Revert the most recent commit
    • Create a new branch
    • Setup terminal prompt to show the current git branch
    • Merge a branch into the current branch
    • Push a new branch up to GitHub (if it doesn’t exist there yet)
    • Pull a new branch from to GitHub to a second computer (if it doesn’t exist there yet)
    • Go back to an older commit and re-work from there
    • Delete a git branch
  • Rails
    • Setup Rails 8 w/ SQLite & Solid Cable, Cache & Queue
    • Stripe Pay Gem
      • Running Stripe Test Mode Locally
    • Setup new Rails app
      • Start a new Rails App (v8)
      • Start a new Rails App (v7)
      • Clone Instrumental Template to a new app
    • Rails 7 Turbo/Hotwire Cheatsheet
    • ActiveStorage with AWS S3
    • Live reloading with webpack-dev-server
    • Sidekiq & Redis
      • Setup Sidekiq in a Rails 8 app
      • Clear sidekiq queue
      • Start jobs worker
    • Setup Solid Queue/Cable/Cache in Rails 8 to share a single database
    • Run rspec tests
      • ZipMessage Tests Commands
      • Can't run rspec tests: ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "thing"
    • Acts As Tenant (using Rails console)
    • Reset database & re-run migrations
    • Ultrahook for testing email to app
    • Troubleshooting
      • Manage node versions using NVM
      • Webpacker bugs
      • Tailwind updates not showing
      • Fix orphaned migrations
      • rspec error: session not created: This version of ChromeDriver only supports Chrome version
      • “PG::ConnectionBad” error when running local rails server
        • Postgres not started (PG:ConnectionBad error)
    • OLD
      • Start a new Rails app (v6)
        • Install Tailwind CSS on a Rails Project
        • Install Stimulus.js on Rails
        • Install RSpec, Capybara, FactoryBot
        • Install Devise Masqerade
    • Hosting
      • Hatchbox.io + Digital Ocean
      • Fly.io rails app hosting
      • Render rails app hosting
      • Set up a Rails site on Heroku
        • Fix Sidekiq on Heroku
        • Setup app on Heroku for a Client
    • Edit Rails Credentials
    • Run subdomains on local
  • Misc
    • Terminal shortcuts
    • ngrok for tunneling
    • Set up a new Mac
    • Mailcatcher
  • Statamic
  • Forge / Statamic
    • Run Statamic (for Clarityflow) locally
    • Set up to SSH into Forge server
    • Production deploy failed. Resolve by SSH & resolve git conflicts.
  • Old (not using anymore)
    • Heroku
      • Push to Heroku
        • Can't push to heroku. Updates were rejected because the remote contains work you dont have locally
      • Create a Heroku App from command line
      • Set up remotes for staging and production apps
      • Run the Rails Console on Heroku
      • Migrate database on Heroku
      • Make database backups
      • Restart Heroku Dynos
      • Point a root domain (non-subdomain) to heroku
    • Middleman
      • Start a new middleman site from my template
    • Jekyll
      • Start a new Jekyll site from my template
      • Run and work on my Jekyll site
    • Netlify
      • Setup a Jekyll site on Netlify
      • Push to Staging & Production on Netlify
    • Laravel
      • Start a new Laravel app
      • Setup a Mac for running Laravel
    • Design
      • Icomoon Fonts in Rails
    • Sync Sublime Text settings across macs
    • Run a rails project on a new mac for the first time
    • Customize terminal prompt for bash
  • Cursor
    • .cursorrules for Rails + Linear issue writing
  • Mac Environment
    • Install Homebrew for both arm64 and x86
    • Installing Ruby
    • Customize terminal prompt for zsh to show git branch
    • Open terminal in arm64 or Rosetta mode
    • Install Homebrew
Powered by GitBook
On this page
  • Install rspec-rails
  • Install capybara
  • Install FactoryBot
  • Rspec Configuration
  • Create Factories for user, account, account_user
  • Create an example spec
  1. Rails
  2. OLD
  3. Start a new Rails app (v6)

Install RSpec, Capybara, FactoryBot

PreviousInstall Stimulus.js on RailsNextInstall Devise Masqerade

Last updated 4 years ago

Install rspec-rails

    • Install this gem inside group :development, :test

    • NOTE: it must be gem 'rspec-rails' (not gem 'rspec' as it's github shows)

    • rails generate rspec:install

    • Generate a stub: bundle binstubs rspec-core

    • Enable --only-failures by doing the following:

      • In spec/spec_helper.rb, uncomment this line: config.example_status_persistence_file_path = "spec/examples.txt"

      • Create the file (leave it blank): spec/examples.txt

      • Add /spec/examples.txt to .gitignore

Install capybara

  • Note: If using Jumpstart, capybara is already included

    • Install this gem inside group :test

Install FactoryBot

  • Install FactoryBot:

Rspec Configuration

In spec/rails_helper.rb, inside of Rspec.configure do |config| ... add the following:

config.include Devise::Test::IntegrationHelpers, type: :feature

config.include FactoryBot::Syntax::Methods

Create Factories for user, account, account_user

This assumes you're using a fresh install of Jumpstart.

Create the following files:

spec/factories/account.rb:

FactoryBot.define do
  
  factory :account, class: Account do
    sequence(:name) { |n| "test account #{n}" }
    personal { true }
  end

end

spec/factories/user.rb:

FactoryBot.define do
  
  factory :user, class: User do
    sequence(:email) { |n| "testuser#{n}@test.com" }
    password { "testpassword" }
    admin { false }
    terms_of_service { true }
    sequence(:name) { |n| "test user #{n}" }
  end

end

spec/factories/account_user.rb:

FactoryBot.define do
  
  factory :account_user, class: AccountUser do
    user
    account
  end

end

Create an example spec

Create this in spec/features/example_spec.rb:

This example assumes you're using a fresh install of Jumpstart. You might need to adjust the content of this spec for it to work.

require "rails_helper"

RSpec.feature "Example spec", js: true, bc10820e: true do

  before do
    @user = create(:user) # creates account_user, account, user
    account_user = @user.account_users.first
    @account = @user.accounts.first

    sign_in @user
  end

  scenario "A user can log in and view announcements", bc61520:true do
    visit "/"
    click_link "What's New"
    expect(page).to have_content("Exciting stuff coming very soon!")
  end

end

https://rubygems.org/gems/rspec-rails
https://rubygems.org/gems/capybara
https://github.com/thoughtbot/factory_bot_rails