Skip to content

Instantly share code, notes, and snippets.

@briankung
Last active December 22, 2015 14:28
Show Gist options
  • Save briankung/6485903 to your computer and use it in GitHub Desktop.
Save briankung/6485903 to your computer and use it in GitHub Desktop.
A quick start guide for Michael Hartl's Rails Tutorial.

Rails Tutorial Quick Start Guide

Basically, this is a quick start guide for people who have some experience with Rails and Git already and just want to get to the meat of Michael Hartl's classic book, the Rails Tutorial. It boils everything down to what you'll need to start creating the sample app at Chapter 3, without any of the demo apps in the beginning, assuming you know version control with git and what you need to do to install rails.

Installing Development Environment

I'm assuming you already have a text editor or IDE.

  1. Rails Installer (Windows)
  2. Install Git
  3. Install Ruby
  4. Install RubyGems
  5. Install Rails

Setup

Create a project without the Test::Unit framework:

$ rails new -T 

Create a .ruby-version and .ruby-gemset for your project, replacing railstutorial_rails_4_0 with the project name if you're just using the Rails Tutorial setup as a quick start for your project:

$ rvm --ruby-version use ruby-2.0.0@railstutorial_rails_4_0

Use this Gemfile.

Note: Again, if your project name is different, make sure that the #ruby-gemset comment in the Gemfile is set to your project name for RVM so that RVM knows what gemset to use when you $ cd into your project. The comment looks like:

#ruby-gemset=railstutorial_rails_4_0

Ensure your dependencies are installed:

$ bundle update
$ bundle install --without production
# From now on, you can use `bundle` without the `--without production` flag

Eliminate bundle exec: http://ruby.railstutorial.org/chapters/static-pages#sec-eliminating_bundle_exec

Dynamically generate a secure token: http://ruby.railstutorial.org/chapters/static-pages#code-secret_token

Now install rspec in your project:

$ rails generate rspec:install

Ensure that Capybara is included in spec_helper: http://ruby.railstutorial.org/chapters/static-pages#code-capybara_dsl EDIT - according to this StackOverflow answer, you should prefer Capybara's installation instructions and require 'capybara/rspec'

Optionally push to GitHub and deploy to Heroku as test.

Notes

You'll probably want to do these at some point.

  • It's highly recommended to use postgresql in development (bullet point #3) to mirror the production (Heroku) environment.
  • You can use spork to speed up tests and guard to automate them. But if you're just getting into Test Driven Development, I would recommend avoiding these tools and getting used to running rspec from the command line until you become used to the workflow, then annoyed by the workflow. By then, you will have internalized the red-green-refactor process.
  • I added the removal of bundle exec to the standard setup instructions because I run bundle exec rspec spec all the time and it's a pain in the ass if you don't automate the specs with spork and guard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment