Я использую следующее, пока не придумаю что-нибудь более элегантное:
# controller_macros.rb
def it_should_recognize_and_generate_routes_for(controller, routes)
describe "routing" do
routes.each do |route|
action = route[:action].to_s
method = route[:method] || :get
url = controller + (route[:url] || '')
params = route.reject {|k, v| [:action, :method, :url].include?(k) }
expected = { :controller => controller, :action => action }.merge(params)
it "should recognize and generate '#{action}'" do
{ method => url }.should route_to(expected)
end
end
end
end
# posts_controller_spec.rb
describe Forum::PostsController do
it_should_recognize_and_generate_routes_for('forum/posts', [
{ :action => :new, :url => '/new' },
{ :action => :create, :method => :post },
{ :action => :show, :url => '/1', :id => '1' },
{ :action => :index },
{ :action => :edit, :url => '/1/edit', :id => '1' },
{ :action => :update, :method => :put, :url => '/1', :id => '1' },
{ :action => :destroy, :method => :delete, :url => '/1', :id => '1' }
])
end
Кстати, мне еще нужно расширить его для работы с маршрутами, такими как:
get 'login' => 'user_sessions#new'