레일 경로 테스트 : ActionController :: Assertions :: RoutingAssertions Methods를 찾을 수 없습니다.

StackOverflow https://stackoverflow.com/questions/1806351

문제

레일 2.3.4 응용 프로그램의 경로를 테스트하려고합니다. Rails 문서를 포함하여 경로를 테스트하는 방법을 설명하는 여러 사이트가 있지만 지침에 따라 오류가 발생합니다.

먼저, 이러한 테스트는 관련 단위 테스트 파일에서 수행 할 수 있다고 가정합니다. 더 명백한 장소는없고 문서 중 어느 것도 지정하지 않습니다.

즉, 이것은 응축 된 버전입니다 test/unit/TitlesTest.rb

require File.dirname(__FILE__) + '/../test_helper'

class TitleTest < Test::Unit::TestCase
  # include ActionController::Assertions::RoutingAssertions

  def test_routes
    assert_routing "games", { :controller => "titles", :section => "games", :action => "index", :id => nil }
  end
end

rake test:units 오류로 실패합니다.

NoMethodError: undefined method `assert_routing' for #<TitleTest:0x7f387232ec98>
    /test/unit/title_test.rb:7:in `test_routes'

Rails API에서 assert_routing이 정의 된 것을 보았습니다. ActionController::Assertions::RoutingAssertions, 그래서 나는 해당 모듈을 포함 시키려고 시도했지만 다른 곳에서만 실패하도록했습니다.

댓글을 달았습니다 include 위의 코드 예제에서 줄

NoMethodError: undefined method `clean_backtrace' for #<TitleTest:0x7fd895fadf00>
    /test/unit/title_test.rb:7:in `test_routes'

clean_backtrace ActionController :: TestCase :: Assertions에서 정의 된 또 다른 테스트 방법입니다.

이러한 오류에 대한 Google 검색 결과를 얻지 못합니다. 다른 사람 이이 문제를 겪고있는 것 같습니다. 새로 생성 된 레일 앱에서 시나리오를 재현하면 문제가 발생합니다. 테스트 사례에 이러한 모듈을 포함시켜야한다고 생각하지 않습니다. 여기서 무엇이 잘못되었을 수 있습니까?

도움이 되었습니까?

해결책

목록이 있습니다 Rails Gotchas 업그레이드 거대한 로봇에. 분명히 라우팅 테스트는 클래스를 사용해야합니다 ActionController::TestCase, 아니다 ActiveSupport::TestCase.

다른 팁

라우팅 테스트는 통합 테스트의 일부로 수행해야합니다.

이들은 사용하여 생성 할 수 있습니다 script/generate script/generate integration_test routes

An example:

class RoutesTest < ActionController::IntegrationTest
  fixtures :all

  def test_resources_route
    assert_routing "titles/15", { :controller => "titles", :action => "show", :id => "15" }
  end
end

라우팅 장치 테스트 파일을 포함해야합니다 ActionController::Assertions::RoutingAssertions 레일 이후 모듈 2.3.2.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top