title: Ruby on Rails tutorial: RSpec test failing when refactoring with matcher
body: <p>I'm working through <a href="http://ruby.railstutorial.org/chapters/sign-in-sign-out#sec-rspec_custom_matchers" rel="nofollow">Michael Hartl's Rails tutorial</a> and can't get one Rspec test to pass when refactoring with a matcher. </p>
  
  <p><strong>terminal output</strong></p>
  
  <pre><code>Failures:
  
    1) Authentication login with invalid information
       Failure/Error: it { should have_error_message('Invalid') }
       NoMethodError:
         undefined method `has_error_message?' for #&lt;Capybara::Session&gt;
       # ./spec/requests/authentication_pages_spec.rb:21:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p><strong>spec/support/utilities.rb</strong></p>
  
  <pre><code>RSpec::Matchers.define :have_error_message do |m|
    match do |page|
      page.should have_selector('div.alert.alert-error', text: m)
    end
  end
  </code></pre>
  
  <p><strong>spec/requests/authentication_pages_spec.rb</strong></p>
  
  <pre><code>require 'spec_helper'
  
  describe "Authentication" do 
  
    subject { page }
  
    describe "login page" do
      before { visit login_path }
  
      it { should have_selector('h1',    text: 'Login') }
      it { should have_selector('title', text: 'Login') }
    end
  
    describe "login" do
      before { visit login_path }
  
      describe "with invalid information" do
        before { click_button "Login" }
  
        it { should have_selector('title', text: 'Login') }
        it { should have_error_message('Invalid') }
      end
  
      describe "after visiting after page" do
        before { click_link "Home" }
        it { should_not have_selector('div.alert.alert-error') }
      end
  
      describe "with valid information" do
        let(:user) { FactoryGirl.create(:user) }
        before { valid_login(user) }
  
        it { should have_selector('title', text: user.name) }
        it { should have_link('Profile', href: user_path(user)) }
        it { should have_link('Logout', href: logout_path) }
        it { should_not have_link('Login', href: login_path) }
  
        describe "followed by logout" do
          before { click_link "Logout" }
  
          it { should have_link('Login') }
        end
      end
    end
  end
  </code></pre>
  
  <p>Why is it complaining about a <code>has_error_message?</code> method that's not defined anywhere? </p>
  
  <h2>Edited/added:</h2>
  
  <p><strong>spec/spec_helper.rb</strong></p>
  
  <pre><code>require 'rubygems'
  require 'spork'
  #uncomment the following line to use spork with the debugger
  #require 'spork/ext/ruby-debug'
  
  Spork.prefork do
    # Loading more in this block will cause your tests to run faster. However,
    # if you change any configuration or code from libraries loaded here, you'll
    # need to restart spork for it take effect.
    ENV["RAILS_ENV"] ||= 'test'
    require File.expand_path("../../config/environment", __FILE__)
    require 'rspec/rails'
    require 'rspec/autorun'
  
    # Requires supporting ruby files with custom matchers and macros, etc,
    # in spec/support/ and its subdirectories.
    Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  
    RSpec.configure do |config|
      # ## Mock Framework
      #
      # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
      #
      # config.mock_with :mocha
      # config.mock_with :flexmock
      # config.mock_with :rr
      config.mock_with :rspec
  
      # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
      config.fixture_path = "#{::Rails.root}/spec/fixtures"
  
      # If you're not using ActiveRecord, or you'd prefer not to run each of your
      # examples within a transaction, remove the following line or assign false
      # instead of true.
      config.use_transactional_fixtures = true
  
      # If true, the base class of anonymous controllers will be inferred
      # automatically. This will be the default behavior in future versions of
      # rspec-rails.
      config.infer_base_class_for_anonymous_controllers = false
    end
  end
  
  Spork.each_run do
    # This code will be run each time you run your specs.
  
  end
  </code></pre>