ruby-on-rails - 在 Rails 中从 Minitest 切换到 RSpec 时,如何让 `rails test`(或 `rake test`)运行 RSpec 测试?
问题描述
将RSpec 添加到 Rails时,我们最终可以运行rails spec
(或bundle exec rspec
)运行 RSpec 测试。
然而,rails test
令人困惑的是,仍然尝试运行(不存在的)Minitest 测试。如何将“测试” rake 任务配置为运行 RSpec 测试?
解决方案
您可以像这样覆盖test
任务:
# Add the code below in the Rakefile
require File.expand_path(‘config/application’, __dir__)
Rails.application.load_tasks
Rake::Task['test'].clear
task :test do
Rake::Task['rspec’].invoke
end
另一种方式(我只在我的控制台中尝试了一个放置一些东西但它应该与 rspec 一起使用的任务):
# Add the code below in the Rakefile
require File.expand_path(‘config/application’, __dir__)
Rails.application.load_tasks
task(:test).clear.enhance([‘rspec’])
推荐阅读
- gitlab - 如何在 GitLab 中为使用 Java 的 Docker 映像运行 Trivy stable?
- scala - 如果选项已定义,如何将 Option[Long] 推送或附加到 Seq[Long]?
- javascript - 我收到此错误 MongoClient 必须连接才能执行此操作
- android - 如何为多模块项目创建汇总的 Jacoco 报告?
- javascript - 如何在 Firestore 中创建自定义 id 文档(Firebase 模块化 SDK (v9))
- sql - 如何计算一天内重叠的最大预订量?
- javascript - 如何在 react-map-gl (mapbox) 中获取 long/lat 用户位置
- blockchain - Corda - 关于交易规模的信息
- excel - Excel VBA排序功能错误地对一列进行排序
- python - OperatorNotAllowedInGraphError:不允许使用 `tf.Tensor` 作为 Python `bool`