2013-07-25 5 views
0

brew install 및 rvm을 사용하여 Mac OS X 10.8에 설치된 Ruby 1.8.7을 사용하고 있습니다. 내가 bundle exec spec spec/requests/static_pages_spec.rb을 수행 할 때 내가 얻을 이러한 오류루비 1.8.7에서 Rspec 실패

FFFFF.FFF 

Failures: 

    1) Static pages Home page should have the h1 'Sample App' 
    Failure/Error: visit root_path 
    NameError: 
     undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x104b5a108> 
    # ./spec/requests/static_pages_spec.rb:8 

    2) Static pages Home page should have the base title 
    Failure/Error: visit root_path 
    NameError: 
     undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x104b45258> 
    # ./spec/requests/static_pages_spec.rb:13 

    3) Static pages Home page should not have a custom page title 
    Failure/Error: visit root_path 
    NameError: 
     undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x104b3ea48> 
    # ./spec/requests/static_pages_spec.rb:18 

    4) Static pages Help page should have the h1 'Help' 
    Failure/Error: visit help_path 
    ActionView::Template::Error: 
     undefined method `full_title' for #<#<Class:0x106d53c50>:0x106d509b0> 
    # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780' 
    # ./spec/requests/static_pages_spec.rb:26 

    5) Static pages Help page should have the title 'Help' 
    Failure/Error: visit help_path 
    ActionView::Template::Error: 
     undefined method `full_title' for #<#<Class:0x106d53c50>:0x106cde630> 
    # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780' 
    # ./spec/requests/static_pages_spec.rb:31 

    6) Static pages About page should have the title 'About Us' 
    Failure/Error: expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us") 
    NoMethodError: 
     undefined method `has_title?' for #<Capybara::Session> 
    # ./spec/requests/static_pages_spec.rb:45 

    7) Static pages Contact page should have the content 'Contact' 
    Failure/Error: visit contact_path 
    ActionView::Template::Error: 
     undefined method `full_title' for #<#<Class:0x106d53c50>:0x106c303c8> 
    # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780' 
    # ./spec/requests/static_pages_spec.rb:52 

    8) Static pages Contact page should have the title 'Contact' 
    Failure/Error: visit contact_path 
    ActionView::Template::Error: 
     undefined method `full_title' for #<#<Class:0x106d53c50>:0x106c07298> 
    # ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__291545742_2204731780' 
    # ./spec/requests/static_pages_spec.rb:57 

Finished in 0.41599 seconds 
9 examples, 8 failures 

Failed examples: 

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:12 # Static pages Home page should have the base title 
rspec ./spec/requests/static_pages_spec.rb:17 # Static pages Home page should not have a custom page title 
rspec ./spec/requests/static_pages_spec.rb:25 # Static pages Help page should have the h1 'Help' 
rspec ./spec/requests/static_pages_spec.rb:30 # Static pages Help page should have the title 'Help' 
rspec ./spec/requests/static_pages_spec.rb:43 # Static pages About page should have the title 'About Us' 
rspec ./spec/requests/static_pages_spec.rb:51 # Static pages Contact page should have the content 'Contact' 
rspec ./spec/requests/static_pages_spec.rb:56 # Static pages Contact page should have the title 'Contact' 

사람이 이러한 오류의/모든 문제를 해결하는 방법을 알고 있나요? static_pages_spec.rb 내가 관련된 내 엑스 코드, libiconv, 모든 것을 업데이트 한

require 'spec_helper' 

describe "Static pages" do 

    describe "Home page" do 

    it "should have the h1 'Sample App'" do 
     visit root_path 
     expect(page).to have_content('Sample App') 
    end 

    it "should have the base title" do 
     visit root_path 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App") 
    end 

    it "should not have a custom page title" do 
     visit root_path 
     expect(page).not_to have_title('| Home') 
    end 
    end 

    describe "Help page" do 

    it "should have the h1 'Help'" do 
     visit help_path 
     expect(page).to have_content('Help') 
    end 

    it "should have the title 'Help'" do 
     visit help_path 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help") 
    end 
    end 

    describe "About page" do 

    it "should have the h1 'About Us'" do 
     visit about_path 
     expect(page).to have_content('About Us') 
    end 

    it "should have the title 'About Us'" do 
     visit about_path 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us") 
    end 
    end 

    describe "Contact page" do 

    it "should have the content 'Contact'" do 
     visit contact_path 
     expect(page).to have_content('Contact') 
    end 

    it "should have the title 'Contact'" do 
     visit contact_path 
     expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact") 
    end 
    end 
end 

SampleApp::Application.routes.draw do 

    match '/static_pages/home', :to =>'static_pages#home' 
    match '/help' => 'static_pages#help', :via => 'get' 
    match '/about' => 'static_pages#about', :via => 'get' 
    match '/contact' => 'static_pages#contact', :via => 'get' 

    get "static_pages/home" 

    get "static_pages/help" 

    get "static_pages/about" 

    get "static_pages/contact" 

routes.rb : 여기 내 관련 파일입니다. 나는 현재 레일 튜토리얼에있는 루비 5 장을 통해 대부분의 길을 가고있다. 그리고 나 자신의 삶을 위해 무엇이이 오류를 일으키는 지 전혀 모른다. 나는 등을 완벽하게 지금까지와 같은 해시 로켓과 다른 보석 버전에 콜론 방법을 변경하는 등 사소한 예외를 제외하고 튜토리얼을 따랐다

레이크 결과 :

tatic_pages_home  /static_pages/home(.:format) static_pages#home 
       help GET /help(.:format)     static_pages#help 
       about GET /about(.:format)    static_pages#about 
      contact GET /contact(.:format)    static_pages#contact 
        GET /static_pages/home(.:format) static_pages#home 
    static_pages_help GET /static_pages/help(.:format) static_pages#help 
    static_pages_about GET /static_pages/about(.:format) static_pages#about 
static_pages_contact GET /static_pages/contact(.:format) static_pages#contact 
+0

붙여 넣은 코드를 몇 가지 최소한의 예제로 줄이려고 할 수 있습니다. –

답변

0

작성 matchget과 같은 경로를 사용하는 경우 기본적으로 help_path과 같은 이름 지정된 경로를 얻지 못합니다. rake routes을 실행하여 구성된 라우트와 이름이 지정된 헬퍼 (있을 경우)를 확인하십시오. 많은 이름의 경로가 없을 가능성이 큽니다.

당신은 당신의 경로 이름을 :as을 사용할 수 있습니다 : 당신 help_pathhelp_url을 얻을 것이다

match '/help' => 'static_pages#help', :via => 'get', :as => 'help' 

합니다. 예를 들어 경로를 정의하면 resources :help, 그 마법의 많은 당신을 위해 이루어집니다. 정적 자산으로가는 경로의 경우 :as을 사용하는 것이 가장 좋은 방법입니다.

+0

그게 말이 되네요, 나는 : as =>를 추가했지만 여전히 오류가 있습니다. 내 레이크 루트의 결과입니다 : home /static_pages/home(.:format) static_pages # home 도움말 GET /help(.:format) static_pages # help GET /about(.:format) about static_pages # about contact GET /contact(.:format) ... etc – Bhetzie

+0

서식을 사용하여 질문에 붙여 넣거나 전체 '레이크 (rake)로 [gist] (https://gist.github.com/)를 만들 수 있습니까? 노선'출력? 위의 대답은'help_path' 만 다루고 있습니다; 'root_path'와 다른 것들을 설정해야합니다. 전체'routes.rb'를 요점으로 게시 할 수 있다면 도움이 될 것입니다. –

+0

Fwiw, 내 문제를 해결하지 못했습니다. –

관련 문제