diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d443238b9e1..16b0b5c95e2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -143,7 +143,7 @@ Lint/MissingCopEnableDirective: Lint/NestedPercentLiteral: Exclude: - 'lib/gitlab/git/repository.rb' - - 'spec/support/email_format_shared_examples.rb' + - 'spec/support/shared_examples/email_format_shared_examples.rb' # Offense count: 1 Lint/ReturnInVoidContext: @@ -195,8 +195,8 @@ Naming/HeredocDelimiterCase: - 'spec/lib/gitlab/diff/parser_spec.rb' - 'spec/lib/json_web_token/rsa_token_spec.rb' - 'spec/models/commit_spec.rb' - - 'spec/support/repo_helpers.rb' - - 'spec/support/seed_repo.rb' + - 'spec/support/helpers/repo_helpers.rb' + - 'spec/support/helpers/seed_repo.rb' # Offense count: 112 # Configuration parameters: Blacklist. @@ -496,7 +496,7 @@ Style/EmptyLiteral: - 'spec/lib/gitlab/request_context_spec.rb' - 'spec/lib/gitlab/workhorse_spec.rb' - 'spec/requests/api/jobs_spec.rb' - - 'spec/support/chat_slash_commands_shared_examples.rb' + - 'spec/support/shared_examples/chat_slash_commands_shared_examples.rb' # Offense count: 102 # Cop supports --auto-correct. diff --git a/db/fixtures/development/17_cycle_analytics.rb b/db/fixtures/development/17_cycle_analytics.rb index d7be6f5950f..7b9a4bad449 100644 --- a/db/fixtures/development/17_cycle_analytics.rb +++ b/db/fixtures/development/17_cycle_analytics.rb @@ -1,5 +1,5 @@ require './spec/support/sidekiq' -require './spec/support/test_env' +require './spec/support/helpers/test_env' class Gitlab::Seeder::CycleAnalytics def initialize(project, perf: false) diff --git a/doc/development/testing_guide/testing_rake_tasks.md b/doc/development/testing_guide/testing_rake_tasks.md index 60163f1a230..db8ca87e9f8 100644 --- a/doc/development/testing_guide/testing_rake_tasks.md +++ b/doc/development/testing_guide/testing_rake_tasks.md @@ -9,7 +9,7 @@ At a minimum, requiring the Rake helper will redirect `stdout`, include the runtime task helpers, and include the `RakeHelpers` Spec support module. The `RakeHelpers` module exposes a `run_rake_task()` method to make -executing tasks simple. See `spec/support/rake_helpers.rb` for all available +executing tasks simple. See `spec/support/helpers/rake_helpers.rb` for all available methods. Example: diff --git a/features/support/env.rb b/features/support/env.rb index 15211995918..8fa2fcb6e3e 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -12,7 +12,11 @@ end WebMock.enable! -%w(select2_helper test_env repo_helpers wait_for_requests sidekiq project_forks_helper webmock).each do |f| +%w(select2_helper test_env repo_helpers wait_for_requests project_forks_helper).each do |f| + require Rails.root.join('spec', 'support', 'helpers', f) +end + +%w(sidekiq webmock).each do |f| require Rails.root.join('spec', 'support', f) end diff --git a/spec/factories/commits.rb b/spec/factories/commits.rb index d5d819d862a..818f7b046f6 100644 --- a/spec/factories/commits.rb +++ b/spec/factories/commits.rb @@ -1,4 +1,4 @@ -require_relative '../support/repo_helpers' +require_relative '../support/helpers/repo_helpers' FactoryBot.define do factory :commit do diff --git a/spec/factories/gpg_key_subkeys.rb b/spec/factories/gpg_key_subkeys.rb index 57eaaee345f..6c7db5379a9 100644 --- a/spec/factories/gpg_key_subkeys.rb +++ b/spec/factories/gpg_key_subkeys.rb @@ -1,5 +1,3 @@ -require_relative '../support/gpg_helpers' - FactoryBot.define do factory :gpg_key_subkey do gpg_key diff --git a/spec/factories/gpg_keys.rb b/spec/factories/gpg_keys.rb index b8aabf74221..51b8ddc9934 100644 --- a/spec/factories/gpg_keys.rb +++ b/spec/factories/gpg_keys.rb @@ -1,4 +1,4 @@ -require_relative '../support/gpg_helpers' +require_relative '../support/helpers/gpg_helpers' FactoryBot.define do factory :gpg_key do diff --git a/spec/factories/gpg_signature.rb b/spec/factories/gpg_signature.rb index 4620caff823..b89e6ffc4b3 100644 --- a/spec/factories/gpg_signature.rb +++ b/spec/factories/gpg_signature.rb @@ -1,5 +1,3 @@ -require_relative '../support/gpg_helpers' - FactoryBot.define do factory :gpg_signature do commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) } diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index 857333f222d..40f3fa7d69b 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -1,4 +1,4 @@ -require_relative '../support/repo_helpers' +require_relative '../support/helpers/repo_helpers' include ActionDispatch::TestProcess diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 1761b6e2a3b..1ae6152a1f0 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -1,4 +1,4 @@ -require_relative '../support/test_env' +require_relative '../support/helpers/test_env' FactoryBot.define do # Project without repository diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 83664bae046..53045815a6a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,42 +32,19 @@ require 'rainbow/ext/string' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. +# Requires helpers, and shared contexts/examples first since they're used in other support files +Dir[Rails.root.join("spec/support/helpers/*.rb")].each { |f| require f } +Dir[Rails.root.join("spec/support/shared_contexts/*.rb")].each { |f| require f } +Dir[Rails.root.join("spec/support/shared_examples/*.rb")].each { |f| require f } Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } RSpec.configure do |config| config.use_transactional_fixtures = false config.use_instantiated_fixtures = false - config.mock_with :rspec config.verbose_retry = true config.display_try_failure_messages = true - config.include Devise::Test::ControllerHelpers, type: :controller - config.include Devise::Test::ControllerHelpers, type: :view - config.include Devise::Test::IntegrationHelpers, type: :feature - config.include Warden::Test::Helpers, type: :request - config.include LoginHelpers, type: :feature - config.include SearchHelpers, type: :feature - config.include CookieHelper, :js - config.include InputHelper, :js - config.include SelectionHelper, :js - config.include InspectRequests, :js - config.include WaitForRequests, :js - config.include LiveDebugger, :js - config.include StubConfiguration - config.include EmailHelpers, :mailer, type: :mailer - config.include TestEnv - config.include ActiveJob::TestHelper - config.include ActiveSupport::Testing::TimeHelpers - config.include StubGitlabCalls - config.include StubGitlabData - config.include ApiHelpers, :api - config.include Gitlab::Routing, type: :routing - config.include MigrationsHelpers, :migration - config.include StubFeatureFlags - config.include StubENV - config.include ExpectOffense - config.infer_spec_type_from_file_location! config.define_derived_metadata(file_path: %r{/spec/}) do |metadata| @@ -82,7 +59,33 @@ RSpec.configure do |config| metadata[:type] = match[1].singularize.to_sym if match end - config.raise_errors_for_deprecations! + config.include ActiveJob::TestHelper + config.include ActiveSupport::Testing::TimeHelpers + config.include CycleAnalyticsHelpers + config.include ExpectOffense + config.include FactoryBot::Syntax::Methods + config.include FixtureHelpers + config.include GitlabRoutingHelper + config.include StubFeatureFlags + config.include StubGitlabCalls + config.include StubGitlabData + config.include TestEnv + config.include Devise::Test::ControllerHelpers, type: :controller + config.include Devise::Test::IntegrationHelpers, type: :feature + config.include LoginHelpers, type: :feature + config.include SearchHelpers, type: :feature + config.include EmailHelpers, :mailer, type: :mailer + config.include Warden::Test::Helpers, type: :request + config.include Gitlab::Routing, type: :routing + config.include Devise::Test::ControllerHelpers, type: :view + config.include ApiHelpers, :api + config.include CookieHelper, :js + config.include InputHelper, :js + config.include SelectionHelper, :js + config.include InspectRequests, :js + config.include WaitForRequests, :js + config.include LiveDebugger, :js + config.include MigrationsHelpers, :migration if ENV['CI'] # This includes the first try, i.e. tests will be run 4 times before failing. diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 9ddcc5f2fbf..c0ceb0f6605 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -60,6 +60,8 @@ Capybara::Screenshot.register_driver(:chrome) do |driver, path| end RSpec.configure do |config| + config.include CapybaraHelpers, type: :feature + config.before(:context, :js) do next if $capybara_server_already_started diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb deleted file mode 100644 index c7890e49c66..00000000000 --- a/spec/support/factory_bot.rb +++ /dev/null @@ -1,3 +0,0 @@ -RSpec.configure do |config| - config.include FactoryBot::Syntax::Methods -end diff --git a/spec/support/generate-seed-repo-rb b/spec/support/generate-seed-repo-rb index 876b3b8242d..44b3de23b99 100755 --- a/spec/support/generate-seed-repo-rb +++ b/spec/support/generate-seed-repo-rb @@ -8,7 +8,7 @@ # # Usage: # -# ./spec/support/generate-seed-repo-rb > spec/support/seed_repo.rb +# ./spec/support/generate-seed-repo-rb > spec/support/helpers/seed_repo.rb # # diff --git a/spec/support/gitlab-git-test.git/README.md b/spec/support/gitlab-git-test.git/README.md index f072cd421be..f757e613ee6 100644 --- a/spec/support/gitlab-git-test.git/README.md +++ b/spec/support/gitlab-git-test.git/README.md @@ -12,5 +12,5 @@ inflate the size of the gitlab-ce repository. - make changes in your local clone of gitlab-git-test - run `git push` which will push to your local source `gitlab-ce/spec/support/gitlab-git-test.git` - in gitlab-ce: run `spec/support/prepare-gitlab-git-test-for-commit` -- in gitlab-ce: `git add spec/support/seed_repo.rb spec/support/gitlab-git-test.git` +- in gitlab-ce: `git add spec/support/helpers/seed_repo.rb spec/support/gitlab-git-test.git` - commit your changes in gitlab-ce diff --git a/spec/support/api_helpers.rb b/spec/support/helpers/api_helpers.rb similarity index 100% rename from spec/support/api_helpers.rb rename to spec/support/helpers/api_helpers.rb diff --git a/spec/support/bare_repo_operations.rb b/spec/support/helpers/bare_repo_operations.rb similarity index 100% rename from spec/support/bare_repo_operations.rb rename to spec/support/helpers/bare_repo_operations.rb diff --git a/spec/support/board_helpers.rb b/spec/support/helpers/board_helpers.rb similarity index 100% rename from spec/support/board_helpers.rb rename to spec/support/helpers/board_helpers.rb diff --git a/spec/support/capybara_helpers.rb b/spec/support/helpers/capybara_helpers.rb similarity index 93% rename from spec/support/capybara_helpers.rb rename to spec/support/helpers/capybara_helpers.rb index 868233416bf..bcc2df44708 100644 --- a/spec/support/capybara_helpers.rb +++ b/spec/support/helpers/capybara_helpers.rb @@ -41,7 +41,3 @@ module CapybaraHelpers page.driver.browser.manage.delete_cookie('_gitlab_session') end end - -RSpec.configure do |config| - config.include CapybaraHelpers, type: :feature -end diff --git a/spec/support/cookie_helper.rb b/spec/support/helpers/cookie_helper.rb similarity index 100% rename from spec/support/cookie_helper.rb rename to spec/support/helpers/cookie_helper.rb diff --git a/spec/support/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb similarity index 98% rename from spec/support/cycle_analytics_helpers.rb rename to spec/support/helpers/cycle_analytics_helpers.rb index 73cc64c0b74..55359d36597 100644 --- a/spec/support/cycle_analytics_helpers.rb +++ b/spec/support/helpers/cycle_analytics_helpers.rb @@ -135,7 +135,3 @@ module CycleAnalyticsHelpers end end end - -RSpec.configure do |config| - config.include CycleAnalyticsHelpers -end diff --git a/spec/support/database_connection_helpers.rb b/spec/support/helpers/database_connection_helpers.rb similarity index 100% rename from spec/support/database_connection_helpers.rb rename to spec/support/helpers/database_connection_helpers.rb diff --git a/spec/support/devise_helpers.rb b/spec/support/helpers/devise_helpers.rb similarity index 100% rename from spec/support/devise_helpers.rb rename to spec/support/helpers/devise_helpers.rb diff --git a/spec/support/drag_to_helper.rb b/spec/support/helpers/drag_to_helper.rb similarity index 100% rename from spec/support/drag_to_helper.rb rename to spec/support/helpers/drag_to_helper.rb diff --git a/spec/support/dropzone_helper.rb b/spec/support/helpers/dropzone_helper.rb similarity index 100% rename from spec/support/dropzone_helper.rb rename to spec/support/helpers/dropzone_helper.rb diff --git a/spec/support/email_helpers.rb b/spec/support/helpers/email_helpers.rb similarity index 100% rename from spec/support/email_helpers.rb rename to spec/support/helpers/email_helpers.rb diff --git a/spec/support/fake_migration_classes.rb b/spec/support/helpers/fake_migration_classes.rb similarity index 100% rename from spec/support/fake_migration_classes.rb rename to spec/support/helpers/fake_migration_classes.rb diff --git a/spec/support/fake_u2f_device.rb b/spec/support/helpers/fake_u2f_device.rb similarity index 100% rename from spec/support/fake_u2f_device.rb rename to spec/support/helpers/fake_u2f_device.rb diff --git a/spec/support/filter_item_select_helper.rb b/spec/support/helpers/filter_item_select_helper.rb similarity index 100% rename from spec/support/filter_item_select_helper.rb rename to spec/support/helpers/filter_item_select_helper.rb diff --git a/spec/support/filter_spec_helper.rb b/spec/support/helpers/filter_spec_helper.rb similarity index 100% rename from spec/support/filter_spec_helper.rb rename to spec/support/helpers/filter_spec_helper.rb diff --git a/spec/support/filtered_search_helpers.rb b/spec/support/helpers/filtered_search_helpers.rb similarity index 100% rename from spec/support/filtered_search_helpers.rb rename to spec/support/helpers/filtered_search_helpers.rb diff --git a/spec/support/fixture_helpers.rb b/spec/support/helpers/fixture_helpers.rb similarity index 81% rename from spec/support/fixture_helpers.rb rename to spec/support/helpers/fixture_helpers.rb index 8854382dc6b..611d19f36a0 100644 --- a/spec/support/fixture_helpers.rb +++ b/spec/support/helpers/fixture_helpers.rb @@ -9,7 +9,3 @@ module FixtureHelpers File.expand_path(Rails.root.join(dir, 'spec', 'fixtures', filename)) end end - -RSpec.configure do |config| - config.include FixtureHelpers -end diff --git a/spec/support/git_http_helpers.rb b/spec/support/helpers/git_http_helpers.rb similarity index 100% rename from spec/support/git_http_helpers.rb rename to spec/support/helpers/git_http_helpers.rb diff --git a/spec/support/helpers/gitlab_verify_helpers.rb b/spec/support/helpers/gitlab_verify_helpers.rb new file mode 100644 index 00000000000..5df4bf24ec2 --- /dev/null +++ b/spec/support/helpers/gitlab_verify_helpers.rb @@ -0,0 +1,25 @@ +module GitlabVerifyHelpers + def collect_ranges(args = {}) + verifier = described_class.new(args.merge(batch_size: 1)) + + collect_results(verifier).map { |range, _| range } + end + + def collect_failures + verifier = described_class.new(batch_size: 1) + + out = {} + + collect_results(verifier).map { |_, failures| out.merge!(failures) } + + out + end + + def collect_results(verifier) + out = [] + + verifier.run_batches { |*args| out << args } + + out + end +end diff --git a/spec/support/gpg_helpers.rb b/spec/support/helpers/gpg_helpers.rb similarity index 100% rename from spec/support/gpg_helpers.rb rename to spec/support/helpers/gpg_helpers.rb diff --git a/spec/support/import_spec_helper.rb b/spec/support/helpers/import_spec_helper.rb similarity index 100% rename from spec/support/import_spec_helper.rb rename to spec/support/helpers/import_spec_helper.rb diff --git a/spec/support/input_helper.rb b/spec/support/helpers/input_helper.rb similarity index 100% rename from spec/support/input_helper.rb rename to spec/support/helpers/input_helper.rb diff --git a/spec/support/inspect_requests.rb b/spec/support/helpers/inspect_requests.rb similarity index 100% rename from spec/support/inspect_requests.rb rename to spec/support/helpers/inspect_requests.rb diff --git a/spec/support/issue_helpers.rb b/spec/support/helpers/issue_helpers.rb similarity index 100% rename from spec/support/issue_helpers.rb rename to spec/support/helpers/issue_helpers.rb diff --git a/spec/support/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb similarity index 100% rename from spec/support/javascript_fixtures_helpers.rb rename to spec/support/helpers/javascript_fixtures_helpers.rb diff --git a/spec/support/jira_service_helper.rb b/spec/support/helpers/jira_service_helper.rb similarity index 100% rename from spec/support/jira_service_helper.rb rename to spec/support/helpers/jira_service_helper.rb diff --git a/spec/support/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb similarity index 100% rename from spec/support/kubernetes_helpers.rb rename to spec/support/helpers/kubernetes_helpers.rb diff --git a/spec/support/ldap_helpers.rb b/spec/support/helpers/ldap_helpers.rb similarity index 100% rename from spec/support/ldap_helpers.rb rename to spec/support/helpers/ldap_helpers.rb diff --git a/spec/support/live_debugger.rb b/spec/support/helpers/live_debugger.rb similarity index 100% rename from spec/support/live_debugger.rb rename to spec/support/helpers/live_debugger.rb diff --git a/spec/support/login_helpers.rb b/spec/support/helpers/login_helpers.rb similarity index 100% rename from spec/support/login_helpers.rb rename to spec/support/helpers/login_helpers.rb diff --git a/spec/support/markdown_feature.rb b/spec/support/helpers/markdown_feature.rb similarity index 100% rename from spec/support/markdown_feature.rb rename to spec/support/helpers/markdown_feature.rb diff --git a/spec/support/merge_request_helpers.rb b/spec/support/helpers/merge_request_helpers.rb similarity index 100% rename from spec/support/merge_request_helpers.rb rename to spec/support/helpers/merge_request_helpers.rb diff --git a/spec/support/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb similarity index 100% rename from spec/support/migrations_helpers.rb rename to spec/support/helpers/migrations_helpers.rb diff --git a/spec/support/mobile_helpers.rb b/spec/support/helpers/mobile_helpers.rb similarity index 100% rename from spec/support/mobile_helpers.rb rename to spec/support/helpers/mobile_helpers.rb diff --git a/spec/support/project_forks_helper.rb b/spec/support/helpers/project_forks_helper.rb similarity index 100% rename from spec/support/project_forks_helper.rb rename to spec/support/helpers/project_forks_helper.rb diff --git a/spec/support/prometheus_helpers.rb b/spec/support/helpers/prometheus_helpers.rb similarity index 100% rename from spec/support/prometheus_helpers.rb rename to spec/support/helpers/prometheus_helpers.rb diff --git a/spec/support/helpers/query_recorder.rb b/spec/support/helpers/query_recorder.rb new file mode 100644 index 00000000000..28536bbef5e --- /dev/null +++ b/spec/support/helpers/query_recorder.rb @@ -0,0 +1,38 @@ +module ActiveRecord + class QueryRecorder + attr_reader :log, :cached + + def initialize(&block) + @log = [] + @cached = [] + ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block) + end + + def show_backtrace(values) + Rails.logger.debug("QueryRecorder SQL: #{values[:sql]}") + caller.each { |line| Rails.logger.debug(" --> #{line}") } + end + + def callback(name, start, finish, message_id, values) + show_backtrace(values) if ENV['QUERY_RECORDER_DEBUG'] + + if values[:name]&.include?("CACHE") + @cached << values[:sql] + elsif !values[:name]&.include?("SCHEMA") + @log << values[:sql] + end + end + + def count + @log.count + end + + def cached_count + @cached.count + end + + def log_message + @log.join("\n\n") + end + end +end diff --git a/spec/support/helpers/quick_actions_helpers.rb b/spec/support/helpers/quick_actions_helpers.rb new file mode 100644 index 00000000000..361190aa352 --- /dev/null +++ b/spec/support/helpers/quick_actions_helpers.rb @@ -0,0 +1,10 @@ +module QuickActionsHelpers + def write_note(text) + Sidekiq::Testing.fake! do + page.within('.js-main-target-form') do + fill_in 'note[note]', with: text + find('.js-comment-submit-button').click + end + end + end +end diff --git a/spec/support/rake_helpers.rb b/spec/support/helpers/rake_helpers.rb similarity index 100% rename from spec/support/rake_helpers.rb rename to spec/support/helpers/rake_helpers.rb diff --git a/spec/support/reactive_caching_helpers.rb b/spec/support/helpers/reactive_caching_helpers.rb similarity index 100% rename from spec/support/reactive_caching_helpers.rb rename to spec/support/helpers/reactive_caching_helpers.rb diff --git a/spec/support/redis_without_keys.rb b/spec/support/helpers/redis_without_keys.rb similarity index 100% rename from spec/support/redis_without_keys.rb rename to spec/support/helpers/redis_without_keys.rb diff --git a/spec/support/reference_parser_helpers.rb b/spec/support/helpers/reference_parser_helpers.rb similarity index 100% rename from spec/support/reference_parser_helpers.rb rename to spec/support/helpers/reference_parser_helpers.rb diff --git a/spec/support/repo_helpers.rb b/spec/support/helpers/repo_helpers.rb similarity index 100% rename from spec/support/repo_helpers.rb rename to spec/support/helpers/repo_helpers.rb diff --git a/spec/support/search_helpers.rb b/spec/support/helpers/search_helpers.rb similarity index 100% rename from spec/support/search_helpers.rb rename to spec/support/helpers/search_helpers.rb diff --git a/spec/support/seed_helper.rb b/spec/support/helpers/seed_helper.rb similarity index 95% rename from spec/support/seed_helper.rb rename to spec/support/helpers/seed_helper.rb index 11ef1fc477f..8fd107260cc 100644 --- a/spec/support/seed_helper.rb +++ b/spec/support/helpers/seed_helper.rb @@ -9,7 +9,7 @@ TEST_MUTABLE_REPO_PATH = 'mutable-repo.git'.freeze TEST_BROKEN_REPO_PATH = 'broken-repo.git'.freeze module SeedHelper - GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __FILE__).freeze + GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __dir__).freeze def ensure_seeds if File.exist?(SEED_STORAGE_PATH) @@ -108,11 +108,3 @@ bla/bla.txt { 'GIT_TEMPLATE_DIR' => '' } end end - -RSpec.configure do |config| - config.include SeedHelper, :seed_helper - - config.before(:all, :seed_helper) do - ensure_seeds - end -end diff --git a/spec/support/seed_repo.rb b/spec/support/helpers/seed_repo.rb similarity index 100% rename from spec/support/seed_repo.rb rename to spec/support/helpers/seed_repo.rb diff --git a/spec/support/select2_helper.rb b/spec/support/helpers/select2_helper.rb similarity index 100% rename from spec/support/select2_helper.rb rename to spec/support/helpers/select2_helper.rb diff --git a/spec/support/selection_helper.rb b/spec/support/helpers/selection_helper.rb similarity index 100% rename from spec/support/selection_helper.rb rename to spec/support/helpers/selection_helper.rb diff --git a/spec/support/helpers/sorting_helper.rb b/spec/support/helpers/sorting_helper.rb new file mode 100644 index 00000000000..577518d726c --- /dev/null +++ b/spec/support/helpers/sorting_helper.rb @@ -0,0 +1,18 @@ +# Helper allows you to sort items +# +# Params +# value - value for sorting +# +# Usage: +# include SortingHelper +# +# sorting_by('Oldest updated') +# +module SortingHelper + def sorting_by(value) + find('button.dropdown-toggle').click + page.within('.content ul.dropdown-menu.dropdown-menu-align-right li') do + click_link value + end + end +end diff --git a/spec/support/stub_configuration.rb b/spec/support/helpers/stub_configuration.rb similarity index 96% rename from spec/support/stub_configuration.rb rename to spec/support/helpers/stub_configuration.rb index a75a3eaefcb..1823099dd9c 100644 --- a/spec/support/stub_configuration.rb +++ b/spec/support/helpers/stub_configuration.rb @@ -1,3 +1,6 @@ +require 'active_support/core_ext/hash/transform_values' +require 'active_support/hash_with_indifferent_access' + module StubConfiguration def stub_application_setting(messages) add_predicates(messages) diff --git a/spec/support/stub_env.rb b/spec/support/helpers/stub_env.rb similarity index 100% rename from spec/support/stub_env.rb rename to spec/support/helpers/stub_env.rb diff --git a/spec/support/stub_feature_flags.rb b/spec/support/helpers/stub_feature_flags.rb similarity index 100% rename from spec/support/stub_feature_flags.rb rename to spec/support/helpers/stub_feature_flags.rb diff --git a/spec/support/stub_gitlab_calls.rb b/spec/support/helpers/stub_gitlab_calls.rb similarity index 100% rename from spec/support/stub_gitlab_calls.rb rename to spec/support/helpers/stub_gitlab_calls.rb diff --git a/spec/support/stub_gitlab_data.rb b/spec/support/helpers/stub_gitlab_data.rb similarity index 100% rename from spec/support/stub_gitlab_data.rb rename to spec/support/helpers/stub_gitlab_data.rb diff --git a/spec/support/stub_object_storage.rb b/spec/support/helpers/stub_object_storage.rb similarity index 98% rename from spec/support/stub_object_storage.rb rename to spec/support/helpers/stub_object_storage.rb index 6e88641da42..19d744b959a 100644 --- a/spec/support/stub_object_storage.rb +++ b/spec/support/helpers/stub_object_storage.rb @@ -1,4 +1,4 @@ -module StubConfiguration +module StubObjectStorage def stub_object_storage_uploader( config:, uploader:, diff --git a/spec/support/test_env.rb b/spec/support/helpers/test_env.rb similarity index 100% rename from spec/support/test_env.rb rename to spec/support/helpers/test_env.rb diff --git a/spec/support/upload_helpers.rb b/spec/support/helpers/upload_helpers.rb similarity index 100% rename from spec/support/upload_helpers.rb rename to spec/support/helpers/upload_helpers.rb diff --git a/spec/support/user_activities_helpers.rb b/spec/support/helpers/user_activities_helpers.rb similarity index 100% rename from spec/support/user_activities_helpers.rb rename to spec/support/helpers/user_activities_helpers.rb diff --git a/spec/support/wait_for_requests.rb b/spec/support/helpers/wait_for_requests.rb similarity index 100% rename from spec/support/wait_for_requests.rb rename to spec/support/helpers/wait_for_requests.rb diff --git a/spec/support/workhorse_helpers.rb b/spec/support/helpers/workhorse_helpers.rb similarity index 100% rename from spec/support/workhorse_helpers.rb rename to spec/support/helpers/workhorse_helpers.rb diff --git a/spec/support/json_response_helpers.rb b/spec/support/json_response.rb similarity index 66% rename from spec/support/json_response_helpers.rb rename to spec/support/json_response.rb index aa235529c56..210b0e6d867 100644 --- a/spec/support/json_response_helpers.rb +++ b/spec/support/json_response.rb @@ -1,7 +1,3 @@ -shared_context 'JSON response' do - let(:json_response) { JSON.parse(response.body) } -end - RSpec.configure do |config| config.include_context 'JSON response' config.include_context 'JSON response', type: :request diff --git a/spec/support/background_migrations_matchers.rb b/spec/support/matchers/background_migrations_matchers.rb similarity index 100% rename from spec/support/background_migrations_matchers.rb rename to spec/support/matchers/background_migrations_matchers.rb diff --git a/spec/support/query_recorder.rb b/spec/support/matchers/exceed_query_limit.rb similarity index 65% rename from spec/support/query_recorder.rb rename to spec/support/matchers/exceed_query_limit.rb index 8cf8f45a8b2..88d22a3ddd9 100644 --- a/spec/support/query_recorder.rb +++ b/spec/support/matchers/exceed_query_limit.rb @@ -1,42 +1,3 @@ -module ActiveRecord - class QueryRecorder - attr_reader :log, :cached - - def initialize(&block) - @log = [] - @cached = [] - ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block) - end - - def show_backtrace(values) - Rails.logger.debug("QueryRecorder SQL: #{values[:sql]}") - caller.each { |line| Rails.logger.debug(" --> #{line}") } - end - - def callback(name, start, finish, message_id, values) - show_backtrace(values) if ENV['QUERY_RECORDER_DEBUG'] - - if values[:name]&.include?("CACHE") - @cached << values[:sql] - elsif !values[:name]&.include?("SCHEMA") - @log << values[:sql] - end - end - - def count - @log.count - end - - def cached_count - @cached.count - end - - def log_message - @log.join("\n\n") - end - end -end - RSpec::Matchers.define :exceed_query_limit do |expected| supports_block_expectations diff --git a/spec/support/prepare-gitlab-git-test-for-commit b/spec/support/prepare-gitlab-git-test-for-commit index 3047786a599..d08e3ba5481 100755 --- a/spec/support/prepare-gitlab-git-test-for-commit +++ b/spec/support/prepare-gitlab-git-test-for-commit @@ -1,7 +1,7 @@ #!/usr/bin/env ruby abort unless [ - system('spec/support/generate-seed-repo-rb', out: 'spec/support/seed_repo.rb'), + system('spec/support/generate-seed-repo-rb', out: 'spec/support/helpers/seed_repo.rb'), system('spec/support/unpack-gitlab-git-test') ].all? diff --git a/spec/support/routing_helpers.rb b/spec/support/routing_helpers.rb deleted file mode 100644 index af1f4760804..00000000000 --- a/spec/support/routing_helpers.rb +++ /dev/null @@ -1,3 +0,0 @@ -RSpec.configure do |config| - config.include GitlabRoutingHelper -end diff --git a/spec/support/rspec.rb b/spec/support/rspec.rb new file mode 100644 index 00000000000..dffab22d8b5 --- /dev/null +++ b/spec/support/rspec.rb @@ -0,0 +1,12 @@ +require_relative "helpers/stub_configuration" +require_relative "helpers/stub_object_storage" +require_relative "helpers/stub_env" + +RSpec.configure do |config| + config.mock_with :rspec + config.raise_errors_for_deprecations! + + config.include StubConfiguration + config.include StubObjectStorage + config.include StubENV +end diff --git a/spec/support/seed.rb b/spec/support/seed.rb new file mode 100644 index 00000000000..bea2e9c3044 --- /dev/null +++ b/spec/support/seed.rb @@ -0,0 +1,7 @@ +RSpec.configure do |config| + config.include SeedHelper, :seed_helper + + config.before(:all, :seed_helper) do + ensure_seeds + end +end diff --git a/spec/support/shared_contexts/json_response_shared_context.rb b/spec/support/shared_contexts/json_response_shared_context.rb new file mode 100644 index 00000000000..df5fc288089 --- /dev/null +++ b/spec/support/shared_contexts/json_response_shared_context.rb @@ -0,0 +1,3 @@ +shared_context 'JSON response' do + let(:json_response) { JSON.parse(response.body) } +end diff --git a/spec/support/services_shared_context.rb b/spec/support/shared_contexts/services_shared_context.rb similarity index 100% rename from spec/support/services_shared_context.rb rename to spec/support/shared_contexts/services_shared_context.rb diff --git a/spec/support/chat_slash_commands_shared_examples.rb b/spec/support/shared_examples/chat_slash_commands_shared_examples.rb similarity index 100% rename from spec/support/chat_slash_commands_shared_examples.rb rename to spec/support/shared_examples/chat_slash_commands_shared_examples.rb diff --git a/spec/support/email_format_shared_examples.rb b/spec/support/shared_examples/email_format_shared_examples.rb similarity index 100% rename from spec/support/email_format_shared_examples.rb rename to spec/support/shared_examples/email_format_shared_examples.rb diff --git a/spec/support/gitlab_verify.rb b/spec/support/shared_examples/gitlab_verify.rb similarity index 59% rename from spec/support/gitlab_verify.rb rename to spec/support/shared_examples/gitlab_verify.rb index 13e2e37624d..560913ca92f 100644 --- a/spec/support/gitlab_verify.rb +++ b/spec/support/shared_examples/gitlab_verify.rb @@ -17,29 +17,3 @@ RSpec.shared_examples 'Gitlab::Verify::BatchVerifier subclass' do end end end - -module GitlabVerifyHelpers - def collect_ranges(args = {}) - verifier = described_class.new(args.merge(batch_size: 1)) - - collect_results(verifier).map { |range, _| range } - end - - def collect_failures - verifier = described_class.new(batch_size: 1) - - out = {} - - collect_results(verifier).map { |_, failures| out.merge!(failures) } - - out - end - - def collect_results(verifier) - out = [] - - verifier.run_batches { |*args| out << args } - - out - end -end diff --git a/spec/support/group_members_shared_example.rb b/spec/support/shared_examples/group_members_shared_example.rb similarity index 100% rename from spec/support/group_members_shared_example.rb rename to spec/support/shared_examples/group_members_shared_example.rb diff --git a/spec/support/issuable_shared_examples.rb b/spec/support/shared_examples/issuable_shared_examples.rb similarity index 100% rename from spec/support/issuable_shared_examples.rb rename to spec/support/shared_examples/issuable_shared_examples.rb diff --git a/spec/support/issuables_list_metadata_shared_examples.rb b/spec/support/shared_examples/issuables_list_metadata_shared_examples.rb similarity index 100% rename from spec/support/issuables_list_metadata_shared_examples.rb rename to spec/support/shared_examples/issuables_list_metadata_shared_examples.rb diff --git a/spec/support/issue_tracker_service_shared_example.rb b/spec/support/shared_examples/issue_tracker_service_shared_example.rb similarity index 100% rename from spec/support/issue_tracker_service_shared_example.rb rename to spec/support/shared_examples/issue_tracker_service_shared_example.rb diff --git a/spec/support/ldap_shared_examples.rb b/spec/support/shared_examples/ldap_shared_examples.rb similarity index 100% rename from spec/support/ldap_shared_examples.rb rename to spec/support/shared_examples/ldap_shared_examples.rb diff --git a/spec/support/legacy_path_redirect_shared_examples.rb b/spec/support/shared_examples/legacy_path_redirect_shared_examples.rb similarity index 100% rename from spec/support/legacy_path_redirect_shared_examples.rb rename to spec/support/shared_examples/legacy_path_redirect_shared_examples.rb diff --git a/spec/support/malicious_regexp_shared_examples.rb b/spec/support/shared_examples/malicious_regexp_shared_examples.rb similarity index 100% rename from spec/support/malicious_regexp_shared_examples.rb rename to spec/support/shared_examples/malicious_regexp_shared_examples.rb diff --git a/spec/support/mentionable_shared_examples.rb b/spec/support/shared_examples/mentionable_shared_examples.rb similarity index 100% rename from spec/support/mentionable_shared_examples.rb rename to spec/support/shared_examples/mentionable_shared_examples.rb diff --git a/spec/support/milestone_tabs_examples.rb b/spec/support/shared_examples/milestone_tabs_examples.rb similarity index 100% rename from spec/support/milestone_tabs_examples.rb rename to spec/support/shared_examples/milestone_tabs_examples.rb diff --git a/spec/support/notify_shared_examples.rb b/spec/support/shared_examples/notify_shared_examples.rb similarity index 100% rename from spec/support/notify_shared_examples.rb rename to spec/support/shared_examples/notify_shared_examples.rb diff --git a/spec/support/reference_parser_shared_examples.rb b/spec/support/shared_examples/reference_parser_shared_examples.rb similarity index 100% rename from spec/support/reference_parser_shared_examples.rb rename to spec/support/shared_examples/reference_parser_shared_examples.rb diff --git a/spec/support/slack_mattermost_notifications_shared_examples.rb b/spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb similarity index 100% rename from spec/support/slack_mattermost_notifications_shared_examples.rb rename to spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb diff --git a/spec/support/snippet_visibility.rb b/spec/support/shared_examples/snippet_visibility.rb similarity index 100% rename from spec/support/snippet_visibility.rb rename to spec/support/shared_examples/snippet_visibility.rb diff --git a/spec/support/snippets_shared_examples.rb b/spec/support/shared_examples/snippets_shared_examples.rb similarity index 100% rename from spec/support/snippets_shared_examples.rb rename to spec/support/shared_examples/snippets_shared_examples.rb diff --git a/spec/support/taskable_shared_examples.rb b/spec/support/shared_examples/taskable_shared_examples.rb similarity index 100% rename from spec/support/taskable_shared_examples.rb rename to spec/support/shared_examples/taskable_shared_examples.rb diff --git a/spec/support/time_tracking_shared_examples.rb b/spec/support/shared_examples/time_tracking_shared_examples.rb similarity index 100% rename from spec/support/time_tracking_shared_examples.rb rename to spec/support/shared_examples/time_tracking_shared_examples.rb diff --git a/spec/support/unique_ip_check_shared_examples.rb b/spec/support/shared_examples/unique_ip_check_shared_examples.rb similarity index 100% rename from spec/support/unique_ip_check_shared_examples.rb rename to spec/support/shared_examples/unique_ip_check_shared_examples.rb diff --git a/spec/support/update_invalid_issuable.rb b/spec/support/shared_examples/update_invalid_issuable.rb similarity index 100% rename from spec/support/update_invalid_issuable.rb rename to spec/support/shared_examples/update_invalid_issuable.rb diff --git a/spec/support/updating_mentions_shared_examples.rb b/spec/support/shared_examples/updating_mentions_shared_examples.rb similarity index 100% rename from spec/support/updating_mentions_shared_examples.rb rename to spec/support/shared_examples/updating_mentions_shared_examples.rb