ruby-on-rails – Rails功能测试:如何测试Admin :: PostsController

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails功能测试:如何测试Admin :: 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.

解决方法

你有合适的位置.试试这个:
class Admin::PostsControllerTest < ActionController::TestCase
  #put your tests here
end

猜你在找的Ruby相关文章