2
votes

ok ... sort of have been dithering on posting this question but here goes:

it's actually lot like this question.

my spec tests fail too ... but i'm not too concerned about that b/c it just involves the title for all pages... (which i can easily fix)

what i'm really wondering about are the routes issue.

after following all of hartl's directions in section 5.3.2 rail routes, this is what i get:

No route matches [GET] "/static_pages/about"
No route matches [GET] "/static_pages/home"
No route matches [GET] "/static_pages/help"
No route matches [GET] "/static_pages/contact"

config/routes.rb settings

SampleApp::Application.routes.draw do
   root to: 'static_pages#home'
   match '/help',    to: 'static_pages#help'
   match '/about',   to: 'static_pages#about'
   match '/contact', to: 'static_pages#contact' 

I can fix three of the pages above by prefixing the '/help,' '/about,' and '/contact' with 'static_pages' ...

it still doesn't solve the home page problem.

adding this to spec_helper.rb didn't help (from the link)

config.include Rails.application.routes.url_helpers

what am i missing here, and what other information do i need to add to make the question clearer?

tests are done by this statement: bundle exec rspec spec/requests/static_pages_spec.rb

here is the terminal out after running the statement

Failures:

1) Static pages About page should have the h1 'About Us'
 Failure/Error: visit '/static_pages/about'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/about"
 # ./spec/requests/static_pages_spec.rb:46:in `block (3 levels) in <top (required)>'

 2) Static pages About page should not have a custom page title
 Failure/Error: visit '/static_pages/about'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/about"
 # ./spec/requests/static_pages_spec.rb:57:in `block (3 levels) in <top (required)>'

 3) Static pages About page should have the base title
 Failure/Error: visit '/static_pages/about'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/about"
 # ./spec/requests/static_pages_spec.rb:51:in `block (3 levels) in <top (required)>'

 4) Static pages Home page should have the h1 'Sample App'
 Failure/Error: visit '/static_pages/home'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/home"
 # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

 5) Static pages Home page should not have a custom page title
 Failure/Error: visit '/static_pages/home'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/home"
 # ./spec/requests/static_pages_spec.rb:19:in `block (3 levels) in <top (required)>'

 6) Static pages Home page should have the base title
 Failure/Error: visit '/static_pages/home'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/home"
 # ./spec/requests/static_pages_spec.rb:13:in `block (3 levels) in <top (required)>'

 7) Static pages Help page should have the h1 'Help'
 Failure/Error: visit '/static_pages/help'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/help"
 # ./spec/requests/static_pages_spec.rb:27:in `block (3 levels) in <top (required)>'

 8) Static pages Help page should not have a custom page title
 Failure/Error: visit '/static_pages/help'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/help"
 # ./spec/requests/static_pages_spec.rb:38:in `block (3 levels) in <top (required)>'

 9) Static pages Help page should have the base title
 Failure/Error: visit '/static_pages/help'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/help"
 # ./spec/requests/static_pages_spec.rb:32:in `block (3 levels) in <top (required)>'

 10) Static pages Contact page should have the h1 'Contact'
 Failure/Error: visit '/static_pages/contact'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/contact"
 # ./spec/requests/static_pages_spec.rb:65:in `block (3 levels) in <top (required)>'

 11) Static pages Contact page should have the title 'Contact'
 Failure/Error: visit '/static_pages/contact'
 ActionController::RoutingError:
   No route matches [GET] "/static_pages/contact"
 # ./spec/requests/static_pages_spec.rb:70:in `block (3 levels) in <top (required)>'

 Finished in 0.14305 seconds
 11 examples, 11 failures

 Failed examples:

 rspec ./spec/requests/static_pages_spec.rb:45 # Static pages About page should have the h1 'About Us'
 rspec ./spec/requests/static_pages_spec.rb:56 # Static pages About page should not have a custom page title
 rspec ./spec/requests/static_pages_spec.rb:50 # Static pages About page should have the base title
 rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the h1 'Sample App'
 rspec ./spec/requests/static_pages_spec.rb:18 # Static pages Home page should not have a custom page title
 rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the base title
 rspec ./spec/requests/static_pages_spec.rb:26 # Static pages Help page should have the h1 'Help'
 rspec ./spec/requests/static_pages_spec.rb:37 # Static pages Help page should not have a custom page title
 rspec ./spec/requests/static_pages_spec.rb:31 # Static pages Help page should have the base title
 rspec ./spec/requests/static_pages_spec.rb:64 # Static pages Contact page should have the h1 'Contact'
  rspec ./spec/requests/static_pages_spec.rb:69 # Static pages Contact page should have the title 'Contact'
2

2 Answers

0
votes

Although you have a root mapping, which routes '/' requests to StaticPagesController home action, you have no mapping for the route static_pages/home. To add it:

   match 'static_pages/home',    to: 'static_pages#home'
0
votes

You might have be using the Rails 4 version of the Hartl book while using an older version of Rails on your computer. Try the Rails 3.2 version of the Hartl book: http://ruby.railstutorial.org/chapters/filling-in-the-layout?version=3.2#sec-rails_routes