为什么这个命名空间路由失败了?

时间:2014-08-29 23:37:05

标签: ruby-on-rails rspec routes

这是路线:

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"}

但路由规范是否证明这样的路由存在?

1 个答案:

答案 0 :(得分:0)

看起来您的请求在控制器规范中拼写错误了吗?

let(:request){ get :statisitcs }

应该是

let(:request){ get :statistics }

基于请求规范和路由定义。它在失败的测试中也显示出拼写错误,所以...