在Rails中从Minitest切换到RSpec时,如何使“ rails test”(或“ rake test”)运行RSpec测试?

时间:2019-07-16 08:50:54

标签: ruby-on-rails rspec rake minitest

adding RSpec to Rails时,我们最终可以运行rails spec(或bundle exec rspec)来运行RSpec测试。

但是,rails test仍然令人困惑地尝试运行(不存在)Minitest测试。 如何将“测试” Rake任务配置为运行RSpec测试?

1 个答案:

答案 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’])