2012-12-06 2 views
0

작동하지 :레일 사용자 정의 경로 때 테스트를 찾았지만, 설정/routes.rb에서

match 'app_config/:version' => "application#appconfig" 

시험/기능/application_controller_test.rb :

require 'test_helper' 
class ApplicationControllerTest < ActionController::TestCase 
    test "app config" do 
    get "/app_config/v2" 
    assert_response :success 
    end 
end 

rake test :

1) Error: 
test_app_config(ApplicationControllerTest): 
ActionController::RoutingError: No route matches {:controller=>"application", :action=>"/app_config/v2"} 

하지만 $ curl localhost:3000/app_config/v2이 작동하고 예상 한 응답을 반환하며 rake routes은 r 예상과 다르게 어떤 일이 벌어지고 있는지, 또 어떻게 조사 할 생각인가? 이것은 기본적으로 프로젝트의 유일한 코드입니다.

답변

1

get 메서드는 경로를 사용하지 않습니다. 액션 이름과 매개 변수의 해시를 사용합니다. 당신이 작업을 테스트하려면

, 당신의 검사 결과는 다음과 같아야합니다

test "for success" do 
    get :appconfig, :version => "v2" 
    assert_response :success 
end 

을 당신이 tutorial here in the documentation이 라우팅 테스트합니다.

test "should route to appconfig" do 
    assert_routing '/app_config/v2', { :controller => "application", :action => "appconfig", :version => "v2" } 
end 
+0

고마워요! 나는'get '이 생성 된 성능 테스트에서'get /''때문에 경로를 취할 수 있다고 생각했다. – Narfanator