2011-12-28 75 views
6

我有一個控制器類似如下:Rails的功能測試:如何測試管理:: PostsController

namespace :admin do 
    resources :posts 
end 


# app/controllers/admin_posts_controller.rb 
module Admin 
    class PostsController < ApplicationController 
    end 
end 

問題是我不知道哪裏去Admin::PostsControllerTest

我期待像以下工作:

# test/functional/admin/posts_controller_test.rb 
module Admin 
    class PostsControllerTest < ActionController::TestCase 
    end 
end 

但如果我這樣做,我得到以下錯誤,當我運行rake test:functionals

RuntimeError: @controller is nil: make sure you set it in your test's setup method. 

回答

10

你已經得到了正確的位置。試試這個:

class Admin::PostsControllerTest < ActionController::TestCase 
    #put your tests here 
end 
+0

這是正確的!謝謝@miked – Marcelo 2011-12-28 18:55:48