ruby-on-rails - 升级到 rails 5.2.0 后无法指定测试目录

标签 ruby-on-rails ruby capybara minitest

我从 rails 5.1.1 升级到 rails 5.2.0。我的过程如下:

一切看起来都运行良好,除了我注意到我的测试套件中有一些奇怪的行为

  • 运行命令 rails test test/system 根本没有运行我的系统测试。它运行我的所有其他测试(策略、服务、模型、作业),但不运行我的系统测试。
    • 奇怪的是:运行特定的系统测试文件,例如:rails test test/system/comment_test.rb 有效。
  • 运行特定目录的测试不再有效。例如,以前我可以运行 rails test test/policiesrails test test/modelsrails test test/services,它只会在这些目录中运行测试。这不再有效。相反,它只运行所有测试(系统测试除外)。

知道 rails 5.1.1rails 5.2.0 之间发生了什么变化导致了这种行为吗?或者,也许我只是遗漏了什么?

根据Rails Guides Testing Rails Applications: 2.7 The Rails Test Runner ,它指出应该能够在每个目录的基础上运行测试:

You can also run an entire directory of tests by providing the path to the directory.

预期行为:

rails test => 运行整个测试套件

rails test test/system => 运行系统目录下的所有测试

rails test test/models => 只运行模型目录中的测试

重现行为

我可以使用以下命令重现该行为:

rails new test_app         # create demo app
cd test_app                # cd into app
rails g scaffold user name # scaffold user
rake db:migrate            # migrate
rails test test/system/    # Expect to run system tests but does not (scaffold creates 4 system tests)

最佳答案

rails -T 您可以看到可用的任务。这个问题的两个相关问题是

rails test          # Runs all tests in test folder except system ones
rails test:system   # Run system tests only

从中我们可以看到rails test不会运行系统测试。为此,您需要运行 rails test:system,iirc 正确,您可以使用 rails test:system test

运行所有测试

关于ruby-on-rails - 升级到 rails 5.2.0 后无法指定测试目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50300489/

相关文章:

ruby-on-rails - 如何将 capybara 输出html放到特定的文件夹?

ruby - 在 Capybara Webkit 测试中将 Ctrl-S 发送到浏览器

mysql - Ruby on Rails 5.2.0 Mysql2::Error::ConnectionError SSL 连接错误:未知错误号

ruby-on-rails - 使用 Rails 自定义验证来修改数据

mysql - Rails 3- 嵌套对象形式(重用地址模型)

ruby - 如何覆盖类方法

ruby - 在 MiniTest 中移除实例方法

ruby-on-rails - visit 和 current_path 与 .should 在 rails 中的使用有什么区别?

css - Rails Foundation topbar 事件元素突出显示

mysql - 无法使用 MySQL 在 Windows 上运行 Rails 服务器