【问题标题】:When switching from Minitest to RSpec in Rails, how to make `rails test` (or `rake test`) run the RSpec tests?在 Rails 中从 Minitest 切换到 RSpec 时,如何让 `rails test`(或 `rake test`)运行 RSpec 测试?
【发布时间】:2019-07-16 08:50:54
【问题描述】:

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

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

【问题讨论】:

    标签: ruby-on-rails rspec rake minitest


    【解决方案1】:

    您可以像这样覆盖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’])
    

    【讨论】:

    • 非常有趣!第二种方法似乎不起作用。第一个部分起作用:之后,rake test 工作,但rails test 仍将运行 minitest。
    猜你喜欢
    • 2022-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 2011-10-07
    相关资源
    最近更新 更多