Rspec命名空间控制器失败

时间:2013-06-26 09:18:42

标签: ruby-on-rails testing rspec rspec-rails

我想测试我的命名空间控制器,但是当我引发控制器时,没有任何提升并且测试正在通过。我没有路由错误。他们都很好。但它必须引起错误。实际上它必须调用索引操作,但事实并非如此。原因是什么?

dashboard_controller_spec.rb

require 'spec_helper'

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

的routes.rb

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

dashboard_controller.rb

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

1 个答案:

答案 0 :(得分: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