在adding RSpec to Rails时,我们最终可以运行rails spec
(或bundle exec rspec
)来运行RSpec测试。
但是,rails test
仍然令人困惑地尝试运行(不存在)Minitest测试。
如何将“测试” Rake任务配置为运行RSpec测试?
答案 0 :(得分:2)
您可以像这样覆盖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’])