は、マイケル・ハート でRailsのチュートリアルを追ってありは、Mac OS X上でバージョン3.0をレール10.7Rails pages_controller_spec.rbテストは失敗してはいけませんが、エラーですか?
$のRSpecのスペック/
......FF
Failures:
1) PagesController GET 'help' should be successful
Failure/Error: get 'help'
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>"help"}
# ./spec/controllers/pages_controller_spec.rb:45:in `block (3 levels) in <top (required)>'
2) PagesController GET 'help' should have the right title
Failure/Error: get 'help'
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>"help"}
# ./spec/controllers/pages_controller_spec.rb:49:in `block (3 levels) in <top (required)>'
Finished in 0.14686 seconds
8 examples, 2 failures
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:44 # PagesController GET 'help' should be successful
rspec ./spec/controllers/pages_controller_spec.rb:48 # PagesController GET 'help' should have the right title
テストはこのようになります
:
require 'spec_helper'
describe PagesController do
render_views
describe "GET 'home'" do
it "should be successful" do
get 'home'
response.should be_success
end
it "should have the right title" do
get 'home'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | Home")
end
end
describe "GET 'contact'" do
it "should be successful" do
get 'contact'
response.should be_success
end
it "should have the right title" do
get 'contact'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | Contact")
end
end
describe "GET 'about'" do
it "should be successful" do
get 'about'
response.should be_success
end
it "should have the right title" do
get 'about'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | About")
end
end
describe "GET 'help'" do
it "should be successful" do
get 'help'
response.should be_success
end
it "should have the right title" do
get 'help'
response.should have_selector("title",
:content => "Ruby on Rails Tutorial Sample App | Help")
end
end
end
そして、私は持っていますin pages_controller.rb
class PagesController < ApplicationController
def home
@title = "Home"
end
def contact
@title = "Contact"
end
def about
@title = "About"
end
def help
@title = "Help"
end
end
そしてroutes.rbをして、私は
SampleApp::Application.routes.draw do
get "pages/home"
get "pages/contact"
get "pages/about"
get "pages/help"
end
を持っているそしてもちろん私も、私はレールのサーバを実行して、ローカルホストに行くとき奇妙なことがあるアプリ/ビュー/ページ でhelp.html.erbページを作成しました:3000/pages/help適切なタイトルを持つ適切なページが表示され、テストが合格したように見えるようになりますが、そうではありません。さらに、連絡先、家庭、およびテストについては、私はちょうど今、いくつかの未知の理由ではないヘルプを追加したときに渡します。これは本当に私を悩ましています、私はそれが私を狂ってしまうのを見落とした単純な解決策は何ですか?
に変更します。私のhelp.html.erbファイルは275バイトですが、about、contact、およびhome .html.erbページはすべてほぼ2KBですが、ほぼ正確ですそれぞれに同じ文字数。これは確かに、テスト時にhelp.html.erbが機能しないことと関係があります。また、ヘルプのドキュメントタイプはTextMateドキュメントであり、他のドキュメントタイプは「ドキュメント」です。奇妙な..? – Laser
あなたは正しい方向に進んでいると思います。コードには失敗するようなものは何もありません。 help.html.erbファイルを削除して再作成してみます。 –
アイデアに感謝し、残念ながらそれは役に立たなかった。レイクルートがここで説明されているように矛盾しているという私にエラーを与えるのは特に奇妙です:http://stackoverflow.com/questions/8917201/my-computer-hates-me – Laser