【问题标题】:retry failed tests in rspec在 rspec 中重试失败的测试
【发布时间】:2018-09-21 18:49:15
【问题描述】:

我遇到了与列出的几乎相同的问题 (Why is Rake not able to invoke multiple tasks consecutively?),但他们的解决方案对我不起作用!随着我的代码库的增长,我会定期收到误报,我希望只重新运行失败的测试。 以下内容在下一行完成后退出 Rake::Task['test:example_1'].execute (并且不会碰到 byebyg / binding.pry )。

SPEC_PATH = 'spec/platform/**/*.rb'

namespace :test do

RSpec::Core::RakeTask.new('example_1') do |t|
  t.rspec_opts = ["-Ilib","--format documentation","--color --tty"]
  t.pattern = SPEC_PATH
end

RSpec::Core::RakeTask.new('example_2') do |t|
  t.rspec_opts = ["-Ilib","--format documentation","--color --tty", "--only-failures"]
  t.pattern = SPEC_PATH
end

desc 'Run "test" task, then rerun failed tests'
  RSpec::Core::RakeTask.new('rerun') do |t|
    Rake::Task['test:example_1'].execute
    Rake::Task['test:example_2'].execute
  end
end

包括--dry-runtest:example_1 将同时运行,但显然不会产生任何故障,因此没有任何帮助。是否需要设置配置以防止完成后退出?如果是这样的话,我还没有找到。

谢谢。

*编辑: 在我的执行显示中包含--trace

** Invoke test:rerun (first_time)
** Execute test:rerun
** Execute test:test_1

开始但退出时什么都没有。

**edit:这是另一个例子,几乎完全符合我正在尝试做的事情,就像我正在尝试做的一样 (https://sourcediving.com/a-better-way-to-tame-your-randomly-failing-specs-29040dc0ed24)。 对于它的价值,我正在运行 Ruby 2.3.1 和 RSpec 3.6

【问题讨论】:

    标签: ruby testing rspec rake


    【解决方案1】:

    我发现了答案。我需要向任务t.fail_on_error = false 传递一个额外的参数。我原以为这指的是个人期望,但实际上,它指的是整个任务。

    所以,对代码的唯一更改是:

    RSpec::Core::RakeTask.new('example_1') do |t|
      t.rspec_opts = ["-Ilib","--format documentation","--color --tty"]
      t.fail_on_error = false
      t.pattern = SPEC_PATH
    end
    

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 2016-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多