gpt4 book ai didi

ruby-on-rails - Rails Minitest 没有运行测试类

转载 作者:行者123 更新时间:2023-11-28 21:31:36 25 4
gpt4 key购买 nike

我有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com