2

我想测试我的命名空间控制器,但是当我提出控制器时没有提出任何东西并且测试通过了。我没有收到任何路线错误。他们都工作正常。但它必须引发错误。实际上它必须调用索引操作,但它没有。原因是什么?

dashboard_controller_spec.rb

require 'spec_helper'

describe Admin::DashboardController do
    it "gets index" do 
        get :index
    end
end

路线.rb

namespace :admin do
    match 'dashboard'    => 'dashboard#index',       :as => :dashboard
end

仪表板控制器.rb

class Admin::DashboardController < Admin::ApplicationController
    def index
        raise "asd"
    end
end
4

1 回答 1

0

嗨,您可以按如下方式编写路由路径,以便获取索引操作

describe :route do
      subject { {get: "/Admin/dashboardes"} }
      it { should route_to(controller: "Admin/dashboardes", action: "index") }
end

像例子:

  describe "#index" do
    describe :route do
      subject { {get: "/administration/users"} }
        it { should route_to(controller: "administration/users", action: "index") }
      end
    end
于 2013-06-28T08:39:10.300 回答