Prefer `type: :task` over defining :environment task in rake specs
Problem
To test rake tasks we tend to require 'rake_helper' which includes RakeHelpers and sets up hooks related to type: :task. However, this extra file is not needed and the same functionality can be achieved when using require 'spec_helper'.
Proposed solution
- Remove use of
require 'rake_helper'and usetype: :taskinstead - Include
RakeHelpersonly fortype: :taskviaconfig.include RakeHelpers type: :task - Replace instances of
Rake::Task.define_task :environmentwithtype: :task
Prior discussion
The following discussion from !131257 (merged) should be addressed:
-
@engwan started a discussion: (+1 comment) Had to add this to fix https://gitlab.com/gitlab-org/gitlab/-/jobs/5074766630
@splattael wrote in !131257 (comment 1556790880):
I see that other instances define an environment task instead:
Rake::Task.define_task :environment
Perhaps using type: :task metatag is more obvious then?
The list of users of Rake.application outside of spec/tasks:
- spec/commands/metrics_server/metrics_server_spec.rb
- spec/lib/backup/database_spec.rb
- spec/lib/backup/manager_spec.rb
- spec/migrations/add_namespaces_emails_enabled_column_data_spec.rb
- spec/migrations/add_projects_emails_enabled_column_data_spec.rb
- spec/requests/api/usage_data_queries_spec.rb
- spec/support/helpers/rake_helpers.rb
We could follow-up on that though.
Edited by Peter Leitzen