【问题标题】:Rails Functional Test: How to test Admin::PostsControllerRails 功能测试:如何测试 Admin::PostsController
【发布时间】:2011-12-28 18:36:20
【问题描述】:

我有一个如下控制器:

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.

【问题讨论】:

    标签: ruby-on-rails testing tdd


    【解决方案1】:

    您找到了正确的位置。试试这个:

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

    【讨论】:

      猜你喜欢
      • 2012-05-30
      • 2011-04-04
      • 2020-05-26
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-08
      • 2011-04-05
      相关资源
      最近更新 更多