2016-07-01 1 views
2

Michael Hartl 's Rails 튜토리얼을 수행 중이지만 Listing 5.28 (녹색 대신 RED 테스트를 얻음)에서 새로운 경로와 일치하도록 테스트를 변경했다. 모든 페이지Rails 튜토리얼 정적 페이지 경로 테스트 빨간색 (5.28)

오류 (/,/약/접촉/도움말) :

ActionController::UrlGenerationError: No route matches {:action=>"/*", :controller=>"static_pages"} 

routes.rb

Rails.application.routes.draw do 
    root 'static_pages#home' 
    get '/help', to: 'static_pages#help' 
    get '/about', to: 'static_pages#about' 
    get '/contact', to: 'static_pages#contact' 
end 

테스트/컨트롤러/static_pages_controller_test.rb

require 'test_helper' 

class StaticPagesControllerTest < ActionController::TestCase 
    test "should get home" do 
    get root_path 
    assert_response :success 
    assert_select "title", "Ruby on Rails Tutorial Sample App" 
    end 

    test "should get help" do 
    get help_path 
    assert_response :success 
    assert_select "title", "Help | Ruby on Rails Tutorial Sample App" 
    end 

    test "should get about" do 
    get about_path 
    assert_response :success 
    assert_select "title", "About | Ruby on Rails Tutorial Sample App" 
    end 

    test "should get contact" do 
    get contact_path 
    assert_response :success 
    assert_select "title", "Contact | Ruby on Rails Tutorial Sample App" 
    end 

end 

static_pages_controller.rb

class StaticPagesController < ApplicationController 
    def home 
    end 

    def help 
    end 

    def about 
    end 

    def contact 
    end 

end 

당신이 다른 어떤 코드를 볼 필요가 있다면 알려주세요! 다음과 같이 추가하려고 시도했습니다. '*'는 각 경로를 얻은 후에 발생하지만 아무런 소용이 없습니다.

Ruby/rails 버전 문제인지는 모르겠지만 IDE에서 Rails 4.2.2 및 Ruby 2.3.0을 사용하고 있지만 "Rails test"(Hartl이 사용하도록 지시 한대로)가 작동하지 않습니다 "테스트 명령을 찾을 수 없습니다"). 그것이 더 큰 문제에 대한 암시인지 또는 관련이없는 것인지 확실하지 않습니다. 미리 감사드립니다!

EDIT : 아래의 경로를 사용하는 링크가 올바르게 렌더링되어 테스트에 실패했습니다.

<%= link_to "Home", root_path %> 
<%= link_to "Help", help_path %> 

답변

3

귀하의 테스트/컨트롤러/static_pages_controller_test.rb는 문제가있다. 나는 그것을 아래 내용으로 대체 할 것을 제안 할 것이다.

require 'test_helper' 

class StaticPagesControllerTest < ActionDispatch::IntegrationTest 

    test "should get home" do 
    get root_path 
    assert_response :success 
    assert_select "title", "Ruby on Rails Tutorial Sample App" 
    end 

    test "should get help" do 
    get help_path 
    assert_response :success 
    assert_select "title", "Help | Ruby on Rails Tutorial Sample App" 
    end 

    test "should get about" do 
    get about_path 
    assert_response :success 
    assert_select "title", "About | Ruby on Rails Tutorial Sample App" 
    end 

    test "should get contact" do 
    get contact_path 
    assert_response :success 
    assert_select "title", "Contact | Ruby on Rails Tutorial Sample App" 
    end 
end 

변경 위의 파일 I 제안하고 녹색 시험을 볼 수 있습니다 $ rails test를 실행 한 것처럼. Michael Hartl 's가 rails tutorials을 레일 5.0.0으로 업그레이드 했으므로 앱을 5.0.0으로 업그레이드 할 것을 제안합니다. 장래 더 많은 것을 배울 것이고, 업그레이드하면 학습 과정에 오류가 더 많이 생길 것입니다. 쾌적한.

+1

버전이 문제가되었습니다. 이전 장에서 필자는 4.2.2를 사용하여 샘플 응용 프로그램을 작성하라고 지시 한 구형의 이전 판에있었습니다. 그런 다음 몇 가지 챕터가 나중에 5.0.0에 대한 최신 버전의 책으로 전환되었습니다. 알아 차리지 못한 채 얼마 지나지 않았는지 확신 할 수는 없지만 처음부터 앱을 시작했습니다 (Hartl의 책 5.0.0 버전에 있음을 확신합니다). 이제 모든 것이 매력처럼 작동합니다. 확실히 올바른 버전에 있는지 확인하는 소중한 교훈을 얻었습니다. 에디션! – user2521295

관련 문제