[3.0] Modified Gemfile to match tutorial

As in Section 2.1, our next step is to use a text editor to update the
Gemfile with the gems needed by our application. On the other hand, for
the sample application we’ll also need two gems we didn’t need before:
the gem for RSpec and the gem for the RSpec library specific to Rails.

This includes rspec-rails in development mode so that we have access to
RSpec-specific generators, and it includes it in test mode in order to
run the tests. We don’t have to install RSpec itself because it is a
dependency of rspec-rails and will thus be installed automatically. We
also include the Capybara gem, which allows us to simulate a user’s
interaction with the sample application using a natural English-like
syntax. As in Chapter 2, we also must include the PostgreSQL gem in
production for deployment to Heroku.

[Source] http://ruby.railstutorial.org/chapters/static-pages#top
[3.0] Run bundle install --without production

[Source] http://ruby.railstutorial.org/chapters/static-pages#top
[3.1.2] Generate StaticPages controller

Since we’ll be making a controller to handle static pages, we’ll call
it the StaticPages controller. We’ll also plan to make actions for a
Home page, a Help page, and an About page. The generate script takes an
optional list of actions, so we’ll include two of the initial actions
directly on the command line.

Note that we’ve used the option --no-test-framework to suppress the
generation of the default RSpec tests, which we won’t be using.
Instead, we’ll create the tests by hand starting in Section 3.2. We’ve
also intentionally left off the about action from the command line
arguments in Listing 3.4 so that we can see how to add it using
test-driven development, or TDD (Section 3.2).

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:static_pages_with_rails
[3.2.1] Add content to home and help pages

We’ll begin by adding some content to the Home page using test-driven
development, including a top-level heading (<h1>) with the content
Sample App.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:TDD
[3.2.2] Add an About page

Having seen test-driven development in action in a simple example,
we’ll use the same technique to accomplish the slightly more
complicated task of adding a new page, namely, the About page that we
intentionally left off in Section 3.1.2. By writing a test and running
RSpec at each step, we’ll see how TDD can guide us through the
development of our application code.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:adding_a_page
[3.3.1] Temporarily remove layout file

You may have noticed that the rails new command already created a layout
file. We'll learn its purpose shortly, but for now you should remove it
before proceeding.  You wouldn't normally do this in a real application,
but it's easier to understand the purpose of the layout file if we start
by disabling it.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:testing_a_title_change
[3.3.1] Modify the <title> tags of each page

Now that we’ve created the actions and views for some static pages,
we’ll make them very slightly dynamic by adding some content that
changes on a per-page basis: we’ll have the title of each page change
to reflect its content.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:testing_a_title_change
[3.3.3] Print title with embedded Ruby

Paradoxically, we’ll take the first step toward eliminating duplication
by first adding some more: we’ll make the titles of the pages, which
are currently quite similar, match exactly. This will make it much
simpler to remove all the repetition at a stroke.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:embedded_ruby
[3.3.4] Restore layout file

In order to factor out this common structure, Rails comes with a special
layout file called application.html.erb, which we removed in Section
3.3.1 and which we'll now restore.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:layouts
[3.3.4] Replace layout title with embedded Ruby version

To get the layout to work, we have to replace the default title with the
Embedded Ruby from the examples above.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:layouts
[3.0] Generate RSpec framework

Next, we need to configure Rails to use RSpec in place of Test::Unit.
This can be accomplished with rails generate rspec:install

[Source] http://ruby.railstutorial.org/chapters/static-pages#top
[3.3.4] Change views back to use layouts

Of course, the views are still filled with all the HTML structure
included in the layout, so we have to remove it, leaving only the
interior contents.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:layouts
[3.0] Improve the README

[Source] http://ruby.railstutorial.org/chapters/static-pages#top
[3.5] Add Contact page

Make a Contact page for the sample app. First write a test for the
existence of a page at the URI /static_pages/contact. (Hint: Test for
the right title.) Then write a second test for the title “Ruby on Rails
Tutorial Sample App | Contact”. Get your tests to pass, and then fill
in the Contact page with content.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:static_pages_exercises
[3.5] Reduce repetition in RSpec tests

You may have noticed some repetition in the StaticPages controller spec.
In particular, the base title, “Ruby on Rails Tutoria Sample App”, is
the same for every title test. Using the RSpec let function, which
creates a variable corresponding to its argument, verify that the tests
still pass.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:static_pages_exercises
Merge branch 'static-pages'
[3.6.1] Add binstubs to .gitignore

The first and preferred method is to use the RVM Bundler integration
to configure the Ruby Version Manager to include the proper executables
automatically in the local environment. The steps are simple if somewhat
mysterious. First, run these two commands:

    $ rvm get head && rvm reload
    $ chmod +x $rvm_path/hooks/after_cd_bundler

Then run these:

    $ cd ~/rails_projects/sample_app
    $ bundle install --without production --binstubs=./bundler_stubs

Together, these commands combine RVM and Bundler magic to ensure that
commands such as rake and rspec are automatically executed in the right
environment. Since these files are specific to your local setup, you
should add the bundler_stubs directory to your .gitignore file.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:eliminating_bundle_exec
[3.6.2] Add Guard gem for automated testing

One annoyance associated with using the rspec command is having to
switch to the command line and run the tests by hand. (A second
annoyance, the slow start-up time of the test suite, is addressed in
Section 3.6.3.) In this section, we’ll show how to use Guard to
automate the running of the tests. Guard monitors changes in the
filesystem so that, for example, when we change the static_pages_spec.rb
file only those tests get run. Even better, we can configure Guard so
that when, say, the home.html.erb file is modified, the
static_pages_spec.rb automatically runs.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:guard
[3.6.2] Set Guardfile up correctly

Now edit the resulting Guardfile so that Guard will run the right tests
when the integration tests and views are updated.

Here the line

    guard 'rspec', :version => 2, :all_after_pass => false do

ensures that Guard doesn't run all the tests after a failing test
passes (to speed up the Red-Green-Refactor cycle).

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:guard
[3.6.3] Add Spork gem for faster RSpec testing

When running bundle exec rspec, you may have noticed that it takes
several seconds just to start running the tests, but once they start
running they finish quickly. This is because each time RSpec runs the
tests it has to reload the entire Rails environment. The Spork test
server aims to solve this problem. Spork loads the environment once, and
then maintains a pool of processes for running future tests. Spork is
particularly useful when combined with Guard.

[Source] http://ruby.railstutorial.org/chapters/static-pages#sec:spork