マウント可能な Rails 3.1 エンジンのルーティング仕様をいくつか記述しようとしています。動作するモデルとコントローラーの仕様はありますが、ルートを指定する方法がわかりません。
サンプル エンジン「testy」の場合、試したすべてのアプローチは同じエラーで終わります。
ActionController::RoutingError: No route matches "/testy"
Rspec と Test::Unit 構文 (spec/routing/index_routing_spec.rb) の両方を試しました。
describe "test controller routing" do
it "Routs the root to the test controller's index action" do
{ :get => '/testy/' }.should route_to(:controller => 'test', :action => 'index')
end
it "tries the same thing using Test::Unit syntax" do
assert_routing({:method => :get, :path => '/testy/', :use_route => :testy}, {:controller => 'test', :action => 'index'})
end
end
ルートを正しくレイアウトしました (config/routes.rb):
Testy::Engine.routes.draw do
root :to => 'test#index'
end
そして、それらをダミー アプリ (spec/dummy/config/routes.rb) にマウントしました。
Rails.application.routes.draw do
mount Testy::Engine => "/testy"
end
実行rails server
とリクエストはhttp://localhost:3000/testy/
問題なく動作します。
何か明らかなことを見逃しているのでしょうか、それともまだフレームワークに適切に組み込まれていないだけなのでしょうか?
アップデート:@andrerobot が指摘しているように、rspec の開発者はバージョン 2.14 でこの問題を修正したので、それに応じて承認済みの回答を変更しました。
ベストアンサー1
RSpec 2.14 以降では以下を使用できます。
describe "test controller routing" do
routes { Testy::Engine.routes }
# ...
end