2011-12-28 38 views
6

Tôi có một bộ điều khiển như sau:Rails chức năng kiểm tra: Làm thế nào để kiểm tra quản trị :: PostsController

namespace :admin do 
    resources :posts 
end 


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

Vấn đề là tôi không biết nơi Admin::PostsControllerTest đi.

Tôi đã chờ đợi một cái gì đó giống như công việc sau:

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

Nhưng nếu tôi làm điều đó tôi nhận được lỗi sau khi tôi chạy rake test:functionals:

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

Trả lời

10

Bạn đã có vị trí bên phải. Hãy thử điều này:

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

Điều đó là đúng! Cảm ơn bạn @miked – Marcelo

Các vấn đề liên quan