Railsルートのテスト:ActionController :: Assertions :: RoutingAssertionsメソッドが見つかりません

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アプリでシナリオを再作成した場合にも発生します。これらのモジュールをテストケースに含める必要があるとは思わない。ここで何が間違っているのでしょうか?

他のヒント

ルーティングテストは、統合テストの一部として実行する必要があります。

これらは、 script / generate script / generate integration_test routes

を使用して生成できます

例:

class RoutesTest < ActionController::IntegrationTest
  fixtures :all

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

Rails 2.3.2以降、ルーティングユニットテストファイルには ActionController :: Assertions :: RoutingAssertions モジュールを含める必要があります。

scroll top