Skip to content

Enable running rspec per test level based on a given list of test files

Part of #222369 (closed), we would need to be able to run rspec levels (unit/migration/integration/system), based on a list of test files.

Currently, in rspec * jobs, we run test levels by passing a pattern to knapsack. For example, a unit pattern is "spec/{bin,channels,config,db,dependencies,factories,finders,frontend,graphql,haml_lint,helpers,initializers,javascripts,lib,models,policies,presenters,rack_servers,replicators,routing,rubocop,serializers,services,sidekiq,support_specs,tasks,uploaders,validators,views,workers,elastic_integration,tooling}{,/**/}*_spec.rb".

To support #222369 (closed), we need to be able to run the respective test levels, based on a list of test files, instead of all test files in the repository.

Given the following list of test files

spec/models/user_spec.rb spec/models/project_spec.rb spec/controllers/users_controller_spec.rb  spec/controllers/projects_controller_spec.rb spec/features/users/signup_spec.rb

When we run rspec unit job, then rspec executes only test files in the unit test level:

spec/models/user_spec.rb spec/models/project_spec.rb

When we run rspec integration job, then rspec executes only test files in the integration test level:

spec/controllers/projects_controller_spec.rb

When we run rspec system job, then rspec executes only test files in the system test level:

spec/features/users/signup_spec.rb

When we run rspec migration job, then rspec executes only test files in the migration test level:

# no migration test in this example