我有 2 个名称相同但位于不同文件夹中的 Controller 。
第一个在“controllers”中,另一个在“controllers/api/v1”中。
第一个运行顺利,但后者就是不运行。
两个测试文件都在功能测试文件夹中。
运行测试文件:
# encoding: utf-8
require 'test_helper'
require_relative '../../app/controllers/post_controller'
class PostControllerTest < ActionController::TestCase
...
没有运行测试:
# encoding: utf-8
require 'test_helper'
require_relative '../../app/controllers/api/v1/post_controller'
class ApiPostControllerTest < ActionController::TestCase
...
知道为什么吗? 谢谢
----- 注意 -----
它没有运行测试,因为它错过了文件名中的测试引用。
并且与 vimsha answer 配合得很好。
最佳答案
ActionController::TestCase 会自动从测试类名中推断出被测 Controller 。
我认为你的测试应该如下所示
class Api::V1::PostControllerTest < ActionController::TestCase
end
或
class ApiPostControllerTest < ActionController::TestCase
tests Api::V1::PostController
end
关于ruby-on-rails - Rails Minitest 没有运行测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19301186/