/create_rails_app

Create Rails App creates a standard Rails app with the best testing and development practices configured. Create Rails App is the easiest way to start a new Rails application.

Primary LanguageRuby

Create Rails App

A boilerplate Test Driven Development environment for Rails. Clone the repo down and delete ./.git. Maybe try the rename gem. Write some tests. Do the things!

Installation

Versioning

Ruby 2.7.2p & Rails 6.0.3.4

  • Clone this repo
  • Run bundle install

Configuration details

Created with rails new shop -T --database=postgresql --skip-spring --skip-turbolinks

Configured with these gems to get started with testing

  • rspec-rails - test suite
  • faker - dynamic data for testing
  • factory_bot_rails - factories for simpler test setup
  • capybara - tools for feature testing ("drives" the screen)
  • launchy - has a cool snippet, save_and_open_page
  • simplecov - track test coverage
  • pry - powerful, interactive debugger

Configured with a .travis.yml to get up and running with CI/CD

After using this starter pack, make sure to delete the ./.git directory and add your own remote repository. Push your local to remote. Then you are ready to start with CI:

  1. Log into Travis CI and navigate to https://travis-ci.org/account/repositories.

  2. Search for your repository, and make sure it is enabled. If your repository doesn't appear click the Sync account button.

  3. Navigate to your project and trigger a build. Alternatively, make a new commit and push to GitHub to trigger a new build.

If you're using Heroku you can use GitHub as your deployment method and enable automatic deployments, but have it configured to wait for the CI to pass first.

TODO: add instructions for Heroku CD.

Testing DSL

This repo is configured with extra helper methods to make writing tests way cooler. Helper methods are described in spec/support/helpers.rb. Here's a common pattern for a feature test, using the included DSL:

# spec/features/welcome/index_spec.rb

require 'rails_helper'

feature 'Welcome Page' do
  background do
    visit root_path
  end

  scenario 'has a page header' do
    within '.page-header' do
      page_has_text 'Home'
    end
  end
  
  scenario 'has a nav bar' do
    home_link = ['Home', href: root_path]
    articles_link = ['Articles', href: '/articles']
    links = [home_link, articles_link]

    within '#nav-bar' do
      page_has_links links
    end
  end
end

Setup (These Steps were done so you don't have to)

  1. Add the above gems to a :development, :test group in the Gemfile. Get rid of byebug.
  2. Install and set up RSpec from the command line.
rails g rspec:install
  1. Configure Simplecov by adding this snippet to the very top of rails_helper
require 'simplecov'
SimpleCov.start
  1. Set up FactoryBot by creating spec/support/factory_bot.rb and then requiring that file in rails_helper.rb.
# spec/support/factory_bot.rb

RSpec.configure do |config|
  config.include FactoryBot::Syntax::Methods
end

FactoryBot documentation

  1. Configure Capybara by adding this to (the top?) of spec_helper.rb
require 'capybara/rspec'

Examples of how to write tests - Using Capybara with RSpec

  1. Add models, features, factories, and views to the spec folder.

  2. Create a .travis.yml file for CI.