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.
This commit is contained in:
Sérgio Saquetim 2022-08-02 23:52:53 -03:00 committed by GitHub
parent d4dda2c93a
commit c99f658a9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -170,11 +170,15 @@ end
desc 'run plugin specs' desc 'run plugin specs'
task 'plugin:spec', :plugin do |t, args| task 'plugin:spec', :plugin do |t, args|
args.with_defaults(plugin: "*") 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 ruby = `which ruby`.strip
files = Dir.glob("./plugins/#{args[:plugin]}/spec/**/*_spec.rb").sort files = Dir.glob("./plugins/#{args[:plugin]}/spec/**/*_spec.rb").sort
if files.length > 0 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 else
abort "No specs found." abort "No specs found."
end end