简体   繁体   English

重试rspec中失败的测试

[英]retry failed tests in rspec

I'm having a nearly identical issue as listed ( Why is Rake not able to invoke multiple tasks consecutively? ) but their solutions aren't working for me! 我遇到了一个与列出的问题几乎相同的问题( 为什么Rake无法连续调用多个任务? ),但是它们的解决方案对我不起作用! As my codebase has grown, I periodically get false-negatives, and I would love to rerun only failed tests. 随着我的代码库的增长,我会定期得到假阴性,并且我希望仅重新运行失败的测试。 The below exits out on completion of line Rake::Task['test:example_1'].execute ( and wont hit a byebyg / binding.pry ) on the next line down. 下面在下一行的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

Including --dry-run to test:example_1 will run both, but obviously, no failures are generated, so it isn't helpful. 包括--dry-runtest:example_1将同时运行,但是显然不会产生任何故障,因此没有帮助。 Is there a config I need to set to prevent exit upon completion? 我是否需要设置一个配置以防止完成时退出? I haven't been able to find it if so. 如果是这样,我还找不到。

Thanks. 谢谢。

*edit: Including --trace on my execution displays: *编辑:在我的执行中包括--trace显示:

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

at the beginning but nothing on exit. 一开始,但退出时一无所有。

**edit: here is another example of pretty much exactly what I'm trying to do in the same way that I'm trying to do it ( https://sourcediving.com/a-better-way-to-tame-your-randomly-failing-specs-29040dc0ed24 ). **编辑:这是我尝试以与尝试相同的方式进行操作的另一个示例( https://sourcediving.com/a-better-way-to-tame- your-randomly-failing-specs-29040dc0ed24 )。 For what its worth, I'm running Ruby 2.3.1 and RSpec 3.6 对于它的价值,我正在运行Ruby 2.3.1和RSpec 3.6

I discovered the answer. 我找到了答案。 I needed to pass an additional argument to the task t.fail_on_error = false . 我需要将其他参数传递给任务t.fail_on_error = false I had assumed that that referred to individual expectations, but, in fact, it refers to the entire task. 我以为那是指个人的期望,但实际上,它指的是整个任务。

so, the only change to the code is: 因此,对代码的唯一更改是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM