2014-08-29 76 views
0

,路線如下:爲什麼這個命名空間路由失敗?

namespace :admin do 
    get 'statistics', to: 'dashboard#statistics', as: :statistics 
end 

這裏的路由規格:

it 'routes to #statistics' do 
    expect(get: '/admin/statistics').to route_to 'admin/dashboard#statistics' 
end 

它通過完美。

然而,該控制器規範,使用上述路線,失敗:

RSpec.describe Admin::DashboardController, :type => :controller do 
    let(:user){ FactoryGirl.create :user } 
    let(:admin){ FactoryGirl.create :admin } 

    describe '#statistics:' do 
     let(:request){ get :statisitcs } 

     context 'When guest;' do 
      before { request }  

      describe 'response' do 
       subject { response }  

       its(:status){ should eq 302 } 
       its(:content_type){ should eq 'text/html' } 
       it{ should redirect_to 'new' } 
      end 
     end 
    end 
end 

的問題是:

1) Admin::DashboardController#statistics: When admin; response content_type 
    Failure/Error: let(:request){ get :statisitcs } 
    ActionController::UrlGenerationError: 
     No route matches {:action=>"statisitcs", :controller=>"admin/dashboard"} 

,但不會路由規範證明這樣的路由存在?

回答

0

看起來您的請求在控制器規範中拼寫錯誤?

let(:request){ get :statisitcs } 

,應根據要求規範和路線定義

let(:request){ get :statistics } 

。它出現在拼寫錯誤的測試中,所以...

+0

*我的臉蛋* – Starkers 2014-08-30 09:33:45