2012-01-18 2 views
0

마이클 하트 에 의해 레일 자습서 다음 적이는 맥 OS X의 버전 3.0 레일 10.7레일스 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 적절한 제목으로 적절한 페이지를 얻으므로 테스트가 통과되어야하는 것처럼 보이게하지만 아직 그렇지는 않습니다. 또한 연락처, 집 및 테스트에 대한 정보가 전달되지만 지금은 도움을 추가했을 때 알려지지 않은 이유로 도움이되지 않습니다. 이것은 정말로 나를 괴롭 히고있다, 내가 그것이 나를 미치게 만드는 것을 간과했던 간단한 해결책은 무엇인가?

+0

변경 각각에 같은 수의 문자. 이것은 확실히 테스트 할 때 help.html.erb가 작동하지 않는 것과 관련이 있습니다. 또한 도움말의 문서 유형은 TextMate 문서이며 다른 사람들은 "문서"라고 말합니다. 이상한.. ? – Laser

+0

나는 올바른 길을 가고 있다고 생각합니다. 코드에는 실패한 것으로 보이는 것이 없습니다. help.html.erb 파일을 삭제하고 다시 만들려고합니다. –

+0

아이디어에 감사드립니다. 불행히도 도움이되지 않았습니다. 특히 레이크 루트가 다음과 같이 모순되는 오류가 발생하는 것은 이상합니다. http://stackoverflow.com/questions/8917201/my-computer-hates-me – Laser

답변

2

이 코드를 다운로드 및 실행 : 그것은 GET 'help'를 실행

........ 
8 examples, 0 failures 
Finished in 0.18184 seconds 

, 그래서 당신은 자동 측정이를 실행하고 다시로드되지 않는다 생각합니다. 가능한?

+0

감사합니다. 터미널을 종료하고 새 창을 열어 모든 것이 잘 실행되고 있습니다. 단순함은 마술 적입니다. – Laser

2

코드는 문제가 없습니다. 문제는 이전 코드가 캐싱 된 것입니다. 터미널을 종료하고 새 창을 열면 캐시를 효과적으로 삭제할 수 있습니다. 테스트 환경에서 캐싱을 끄지 않으면 같은 문제가 발생할 수 있습니다. 대한, 연락처 및 홈 .html.erb 페이지의 모든 2킬로바이트이 내 동안, 사실에도 불구하고 그들은 거의 정확한 있으며, config/environments/test.rb로 이동하여 내 help.html.erb 파일이 275 바이트 어떤 이유로 config.cache_classes = trueconfig.cache_classes = false

관련 문제