2

わかりました...この質問を投稿するのをためらっていましたが、ここに行きます:

それは実際にこの質問によく似ています。

私の仕様テストも失敗します...しかし、すべてのページのタイトルが含まれているだけであるということについてはあまり心配していません...(これは簡単に修正できます)

私が本当に疑問に思っているのは、ルートの問題です。

セクション 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」を付けることで、上記の 3 つのページを修正できます ...

それでもホームページの問題は解決しません。

これを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 ホーム アクションにルーティングするルート マッピングはありますが、 route のマッピングはありませんstatic_pages/home。追加するには:

   match 'static_pages/home',    to: 'static_pages#home'
于 2012-09-28T07:24:47.737 に答える