You need an rspec-retry gem. Here are some examples from the docs on how to implement them:
Apply it in the configure
block covering the entire test package ...
RSpec.configure do |config| config.verbose_retry = true
Or apply it individually ...
it 'should randomly succeed', :retry => 3 do expect(rand(2)).to eq(1) end
source share