我从 rails 5.1.1
升级到 rails 5.2.0
。我的过程如下:
- 升级了 rails gem 并解决了依赖问题
- 查看了 railsdiff between 5.1.1 and 5.2.0并根据需要更新文件
一切看起来都运行良好,除了我注意到我的测试套件中有一些奇怪的行为
- 运行命令
rails test test/system
根本没有运行我的系统测试。它运行我的所有其他测试(策略、服务、模型、作业),但不运行我的系统测试。- 奇怪的是:运行特定的系统测试文件,例如:
rails test test/system/comment_test.rb
有效。
- 奇怪的是:运行特定的系统测试文件,例如:
- 运行特定目录的测试不再有效。例如,以前我可以运行
rails test test/policies
、rails test test/models
和rails test test/services
,它只会在这些目录中运行测试。这不再有效。相反,它只运行所有测试(系统测试除外)。
知道 rails 5.1.1
和 rails 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/