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

标签 ruby-on-rails testing rubymine minitest

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

相关文章:

java - 在没有 xml 的情况下测试 spring 上下文

testing - Karma + AngularJS 场景测试运行器和表单的问题

ruby-on-rails - RubyMine Debugger.start 尚未调用

ruby-on-rails - rails : Why am I getting the ActiveRecord error "missing FROM-clause entry for table"?

unit-testing - 我应该对验证代码进行单元测试吗?似乎不切实际

ruby-on-rails - heroku 不显示自定义错误页面

ruby-on-rails - RubyMine 使用不正确/不同的 Ruby 版本 - Ubuntu

ruby - 设置 RubyMine2 以运行和调试 Sinatra 应用程序

css - simple_form_for rails 内联单选按钮

ruby-on-rails - Ruby 将十进制持续时间(日|周|月|年)转换为结束日期