2

好的......在发布这个问题时有点犹豫,但这里是:

它实际上很像这个问题

我的规范测试也失败了......但我不太关心那个 b/c 它只涉及所有页面的标题......(我可以很容易地修复)

我真正想知道的是路线问题。

在遵循第 5.3.2 节铁路路线中的所有 hartl 指示之后,这就是我得到的:

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 设置

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' 

我可以通过在“/help”、“/about”和“/contact”前面加上“static_pages”来修复上面的三个页面......

它仍然没有解决主页问题。

将此添加到 spec_helper.rb 没有帮助(来自链接)

config.include Rails.application.routes.url_helpers

我在这里遗漏了什么,我需要添加哪些其他信息才能使问题更清楚?

测试由以下语句完成: bundle exec rspec spec/requests/static_pages_spec.rb

这是运行语句后的终端

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'
4

2 回答 2

0

尽管您有一个根映射,它将“/”请求路由到 StaticPagesController 主页操作,但您没有路由的映射static_pages/home。要添加它:

   match 'static_pages/home',    to: 'static_pages#home'
于 2012-09-28T07:24:47.737 回答
0

在您的计算机上使用旧版本的 Rails 时,您可能正在使用 Hartl 书籍的 Rails 4 版本。试试 Hartl 书的 Rails 3.2 版本: http ://ruby.railstutorial.org/chapters/filling-in-the-layout?version=3.2#sec-rails_routes

于 2014-01-05T07:04:17.403 回答