1

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! 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.

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. 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:

** 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 ). For what its worth, I'm running Ruby 2.3.1 and RSpec 3.6

1 Answers1

0

I discovered the answer. I needed to pass an additional argument to the task 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