1
votes

I follow M Hartl's "Ruby on Rails Tutorial", Chap 3.2.2

When I add /static_pages/about to routes.rb, even the 'about' action is NOT defined in static_pages_controller.rb, the rspec test passes.

It is driving me crazy!

I am using ruby-2.1.1, rspec-rails 2.14.2, Capybara 2.1.0

static_pages_spec.rb:

require 'spec_helper'
describe "StaticPages" do
  describe "About" do
    it "should have the content 'About'" do
      visit '/static_pages/about'
      expect(page).to have_content('About')
    end
  end
end

routes.rb:

RortSampleApp::Application.routes.draw do
  get "static_pages/about"
end

static_pages_controller.rb:

class StaticPagesController < ApplicationController
end

command running the rspec test & result:

$ rspec spec/requests/static_pages_spec.rb 
.

Finished in 0.02604 seconds
1 example, 0 failures

Randomized with seed 61832

And the test.log:

   (0.1ms)  begin transaction
Started GET "/static_pages/about" for 127.0.0.1 at 2014-04-02 01:59:45 -0700

AbstractController::ActionNotFound - The action 'about' could not be found for       StaticPagesController:
  actionpack (4.0.4) lib/abstract_controller/base.rb:131:in `process'
  actionpack (4.0.4) lib/abstract_controller/rendering.rb:44:in `process'
1

1 Answers

0
votes

In M.Hartl's Ruby on Rails Tutorial book's, 2nd edition's, Gemfile has version 1.1.2 for Capybara. I hope it works better if you change the version of Capybara in your Gemfile.

group :test do
  gem 'capybara', '1.1.2'
 ...
end

Also the rspec-rails gem version was different in the 2nd edition's Gemfile. So if the above change doesn't make it work, then please try the following rspec-rails version: 2.11.0, in addition to the Capybara version change. (I had difficulties with Capybara versions 2.1.0 and 2.2.0)

group :development, :test do
..
  gem 'rspec-rails', '2.11.0'
..
end

Gemfile for tutorial's 2nd edition