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!
Versioning
Ruby 2.7.2p & Rails 6.0.3.4
- Clone this repo
- Run
bundle install
Created with rails new shop -T --database=postgresql --skip-spring --skip-turbolinks
Configured with these gems to get started with testing
rspec-rails
- test suitefaker
- dynamic data for testingfactory_bot_rails
- factories for simpler test setupcapybara
- tools for feature testing ("drives" the screen)launchy
- has a cool snippet,save_and_open_page
simplecov
- track test coveragepry
- 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:
-
Log into Travis CI and navigate to https://travis-ci.org/account/repositories.
-
Search for your repository, and make sure it is enabled. If your repository doesn't appear click the Sync account button.
-
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.
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
- Add the above gems to a
:development, :test
group in the Gemfile. Get rid of byebug. - Install and set up RSpec from the command line.
rails g rspec:install
- Configure Simplecov by adding this snippet to the very top of
rails_helper
require 'simplecov'
SimpleCov.start
- Set up FactoryBot by creating
spec/support/factory_bot.rb
and then requiring that file inrails_helper.rb
.
# spec/support/factory_bot.rb
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
- 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
-
Add
models
,features
,factories
, andviews
to thespec
folder. -
Create a
.travis.yml
file for CI.