From c99f658a9ed8e63859ffa3f067aedd17e6ec449e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= <1108771+megothss@users.noreply.github.com> Date: Tue, 2 Aug 2022 23:52:53 -0300 Subject: [PATCH] DEV: Allow to specify seed on rake task plugin:spec (#17770) Allow users to specify the seed of the tests using the env variable RSPEC_SEED Example: bundle exec rake "plugin:spec[plugin-name]" RSPEC_SEED=65536 This is useful while fixing flaky tests. --- lib/tasks/plugin.rake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/tasks/plugin.rake b/lib/tasks/plugin.rake index 451c7e23097..7b29c264e90 100644 --- a/lib/tasks/plugin.rake +++ b/lib/tasks/plugin.rake @@ -170,11 +170,15 @@ end desc 'run plugin specs' task 'plugin:spec', :plugin do |t, args| args.with_defaults(plugin: "*") - params = ENV['RSPEC_FAILFAST'] ? '--profile --fail-fast' : '--profile' + + params = ['--profile'] + params << '--fail-fast' if ENV['RSPEC_FAILFAST'] + params << "--seed #{ENV['RSPEC_SEED']}" if Integer(ENV['RSPEC_SEED'], exception: false) + ruby = `which ruby`.strip files = Dir.glob("./plugins/#{args[:plugin]}/spec/**/*_spec.rb").sort if files.length > 0 - sh "LOAD_PLUGINS=1 #{ruby} -S rspec #{files.join(' ')} #{params}" + sh "LOAD_PLUGINS=1 #{ruby} -S rspec #{files.join(' ')} #{params.join(' ')}" else abort "No specs found." end