このエラーは、コントローラーのいずれかのアクション メソッドの名前を想定しているメソッドに URL 全体を渡しているために発生します。私の理解が正しければ、あなたは一度に複数のことをテストしようとしています。
ルートに名前があることをテストすることは、ルートをテストすることと、コントローラー アクションをテストすることとは異なります。コントローラーのアクションをテストする方法は次のとおりです (これはおそらく当然のことです)。私が使用するものを推奨するのではなく、あなたの命名に一致していることに注意してください。
spec/controllers/articles_controller_spec.rb で、
describe ArticlesController do
describe '#permalink' do
it "renders the page" do
# The action and its parameter are both named permalink
get :permalink :permalink => 666
response.should be_success
# etc.
end
end
end
rspec-rails のみを使用して名前付きルートをテストする方法は次のとおりです。
spec/routing/articles_routing_spec.rb で、
describe ArticlesController do
describe 'permalink' do
it 'has a named route' do
articles_permalink(666).should == '/permalink/666'
end
it 'is routed to' do
{ :get => '/permalink/666' }.should route_to(
:controller => 'articles', :action => 'permalink', :id => '666')
end
end
end
Shoulda のルート マッチャーはより簡潔ですが、適切な説明と失敗メッセージを提供します。
describe ArticlesController do
describe 'permalink' do
it 'has a named route' do
articles_permalink(666).should == '/permalink/666'
end
it { should route(:get, '/permalink/666').to(
:controller => 'articles', :action => 'permalink', :id => '666' })
end
end
私の知る限り、RSpec も Shoulda も名前付きルートをテストする具体的で簡潔な方法を持っていませんが、独自のマッチャーを作成することはできます。