A platform for community discussion. Free, open, simple.
Revert "DEV: Decrease rspec startup time (#42946)" (#43147)
Martin Brennand2bbcd5f6dd6
diff --git a/Gemfile b/Gemfileindex 636de710f11..86a9655684d 100644--- a/Gemfile+++ b/Gemfile@@ -80,13 +80,13 @@ gem "loofah"gem "css_parser", require: falsegem "omniauth"-gem "omniauth-facebook", require: false-gem "omniauth-twitter", require: false-gem "omniauth-github", require: false+gem "omniauth-facebook"+gem "omniauth-twitter"+gem "omniauth-github"gem "omniauth-oauth2", require: false-gem "omniauth-google-oauth2", require: false+gem "omniauth-google-oauth2"gem "oj"@@ -114,7 +114,7 @@ gem "rack-protection" # securitygem "cbor", require: falsegem "cose", require: falsegem "addressable"-gem "json_schemer", require: false+gem "json_schemer"gem "net-smtp", require: falsegem "net-pop", require: false@@ -126,37 +126,37 @@ group :test dogem "capybara", require: falsegem "webmock", require: falsegem "simplecov", require: false- gem "test-prof", require: false+ gem "test-prof"gem "rails-dom-testing", require: falsegem "minio_runner", require: false- gem "capybara-playwright-driver", require: false+ gem "capybara-playwright-driver"gem "puma", require: falseendgroup :test, :development do- gem "rspec", require: false+ gem "rspec"gem "listen", require: falsegem "certified", require: falsegem "fabrication", require: falsegem "mocha", require: false- gem "rb-fsevent", require: false+ gem "rb-fsevent", require: RUBY_PLATFORM =~ /darwin/i ? "rb-fsevent" : false- gem "rspec-rails", require: false+ gem "rspec-rails"gem "shoulda-matchers", require: false- gem "rspec-html-matchers", require: false+ gem "rspec-html-matchers"gem "debug", ">= 1.0.0", require: "debug/prelude"gem "rubocop-discourse", require: false- gem "parallel_tests", require: false+ gem "parallel_tests"- gem "rswag-specs", require: false+ gem "rswag-specs"- gem "annotaterb", require: false+ gem "annotaterb"- gem "syntax_tree", require: false+ gem "syntax_tree"- gem "rspec-multi-mock", require: false+ gem "rspec-multi-mock"endgroup :development do@@ -175,8 +175,8 @@ if ENV["ALLOW_DEV_POPULATE"] == "1"gem "faker"elsegroup :development, :test do- gem "discourse_dev_assets", require: false- gem "faker", require: false+ gem "discourse_dev_assets"+ gem "faker"endend@@ -224,7 +224,7 @@ gem "sassc-embedded"gem "rotp", require: false-gem "rqrcode", require: false+gem "rqrcode"gem "rubyzip", require: falsediff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex c39d344f2b8..4bcb8c36da0 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -1674,7 +1674,6 @@ class UsersController < ApplicationControllerdef create_second_factor_totprequire "rotp" if !defined?(ROTP)- require "rqrcode" if !defined?(RQRCode)totp_data = ROTP::Base32.randomserver_session["staged-totp-#{current_user.id}"] = totp_dataqrcode_png =diff --git a/app/services/categories/types/base.rb b/app/services/categories/types/base.rbindex a99063444e8..604e062d1bd 100644--- a/app/services/categories/types/base.rb+++ b/app/services/categories/types/base.rb@@ -284,8 +284,6 @@ module Categories# Also validates that any site_settings keys are real SiteSettings (a# runtime check that cannot be expressed in JSON Schema).def validate_schema!- require "json_schemer" if !defined?(JSONSchemer)-# Normalize Ruby symbol keys/values to strings via JSON round-tripschema_as_json = JSON.parse(configuration_schema.to_json)diff --git a/bin/rspec b/bin/rspecindex 46f90c873b2..054240e05d5 100755--- a/bin/rspec+++ b/bin/rspec@@ -14,19 +14,14 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE_require "rubygems"require "bundler/setup"-core_spec_path = File.expand_path("../spec", __dir__)-plugin_spec_requested =- ARGV.any? do |pattern|- next false if pattern.start_with?("-")- next true if pattern.include?("plugins/")- next false if !ENV.key?("DISCOURSE_REPO_BASE_DIRECTORY")-- requested_path = File.expand_path(pattern.sub(/:\d+(?::\d+)?\z/, ""))- File.exist?(requested_path) && requested_path != core_spec_path &&- !requested_path.start_with?("#{core_spec_path}/")- end--if ENV["LOAD_PLUGINS"].nil? && plugin_spec_requested+if ENV["LOAD_PLUGINS"].nil? &&+ ARGV.any? { |pattern|+ pattern.include?("plugins/") ||+ (+ ENV.key?("DISCOURSE_REPO_BASE_DIRECTORY") &&+ !pattern.include?(ENV["DISCOURSE_REPO_BASE_DIRECTORY"] + "/spec")+ )+ }STDERR.puts "Detected plugin spec path, setting LOAD_PLUGINS to 1"ENV["LOAD_PLUGINS"] = "1"enddiff --git a/config/application.rb b/config/application.rbindex ef70bfe90fd..47937689c78 100644--- a/config/application.rb+++ b/config/application.rb@@ -56,17 +56,6 @@ if defined?(Bundler)Bundler.require(*bundler_groups)end-if Rails.env.production?- require "json_schemer"- require "omniauth-facebook"- require "omniauth-github"- require "omniauth-google-oauth2"- require "omniauth-twitter"- require "rqrcode"-end--require "discourse_dev_assets" if Rails.env.development?-require_relative "../lib/require_dependency_backward_compatibility"module Discoursediff --git a/config/initializers/009-omniauth.rb b/config/initializers/009-omniauth.rbindex 305e7e76f80..6fca1ff6ecc 100644--- a/config/initializers/009-omniauth.rb+++ b/config/initializers/009-omniauth.rb@@ -35,8 +35,6 @@ OmniAuth.config.on_failure do |env|next OmniAuth::FailureEndpoint.call(env) if !is_rescued_error # let the default behavior handle it- require "oauth" if !defined?(OAuth)-case exceptionwhen OAuth::Unauthorized# OAuth1 (i.e. Twitter) makes a web request during the setup phasediff --git a/lib/auth.rb b/lib/auth.rbindex 54b017e1411..3938f379a20 100644--- a/lib/auth.rb+++ b/lib/auth.rb@@ -9,7 +9,6 @@ require "auth/auth_provider"require "auth/result"require "auth/authenticator"require "auth/managed_authenticator"-require "omniauth-oauth2"require "auth/facebook_authenticator"require "auth/github_authenticator"require "auth/twitter_authenticator"diff --git a/lib/auth/facebook_authenticator.rb b/lib/auth/facebook_authenticator.rbindex 23f8277df71..fc3d4dac95d 100644--- a/lib/auth/facebook_authenticator.rb+++ b/lib/auth/facebook_authenticator.rb@@ -20,7 +20,6 @@ class Auth::FacebookAuthenticator < Auth::ManagedAuthenticatorenddef register_middleware(omniauth)- require "omniauth-facebook"omniauth.provider :facebook,setup:lambda { |env|diff --git a/lib/auth/github_authenticator.rb b/lib/auth/github_authenticator.rbindex 363dc617712..de70ff75e83 100644--- a/lib/auth/github_authenticator.rb+++ b/lib/auth/github_authenticator.rb@@ -56,7 +56,6 @@ class Auth::GithubAuthenticator < Auth::ManagedAuthenticatorenddef register_middleware(omniauth)- require "omniauth-github"omniauth.provider :github,setup:lambda { |env|diff --git a/lib/auth/google_oauth2_authenticator.rb b/lib/auth/google_oauth2_authenticator.rbindex c383c165994..65574204bad 100644--- a/lib/auth/google_oauth2_authenticator.rb+++ b/lib/auth/google_oauth2_authenticator.rb@@ -29,7 +29,6 @@ class Auth::GoogleOAuth2Authenticator < Auth::ManagedAuthenticatorenddef register_middleware(omniauth)- require "omniauth-google-oauth2"options = {setup:lambda do |env|diff --git a/lib/auth/twitter_authenticator.rb b/lib/auth/twitter_authenticator.rbindex 4778ef3b80c..c2b44b0e1ba 100644--- a/lib/auth/twitter_authenticator.rb+++ b/lib/auth/twitter_authenticator.rb@@ -18,7 +18,6 @@ class Auth::TwitterAuthenticator < Auth::ManagedAuthenticatorenddef healthy?- require "omniauth-twitter"consumer_key = SiteSetting.twitter_consumer_keyconsumer_secret = SiteSetting.twitter_consumer_secret@@ -41,7 +40,6 @@ class Auth::TwitterAuthenticator < Auth::ManagedAuthenticatorenddef register_middleware(omniauth)- require "omniauth-twitter"omniauth.provider :twitter,setup:lambda { |env|diff --git a/lib/tasks/api_docs.rake b/lib/tasks/api_docs.rakeindex 8f64de7b7f9..fb0fa509a6a 100644--- a/lib/tasks/api_docs.rake+++ b/lib/tasks/api_docs.rake@@ -15,8 +15,6 @@ if Rails.env.local?desc "Generate Swagger JSON files from integration specs (including plugins)"RSpec::Core::RakeTask.new("swaggerize") do |t|- require "rswag/specs"-# Automatically load plugins for API documentationENV["LOAD_PLUGINS"] = "1" unless ENV["LOAD_PLUGINS"]diff --git a/lib/tasks/parallel_tests.rake b/lib/tasks/parallel_tests.rakedeleted file mode 100644index e499471c5d0..00000000000--- a/lib/tasks/parallel_tests.rake+++ /dev/null@@ -1,3 +0,0 @@-# frozen_string_literal: true--require "parallel_tests/tasks"diff --git a/plugins/chat/spec/support/api_schema_matcher.rb b/plugins/chat/spec/support/api_schema_matcher.rbindex 89ed45fa71a..e78e158d79c 100644--- a/plugins/chat/spec/support/api_schema_matcher.rb+++ b/plugins/chat/spec/support/api_schema_matcher.rb@@ -1,7 +1,5 @@# frozen_string_literal: true-require "json-schema"-RSpec::Matchers.define :match_response_schema do |schema|match do |object|schema_directory = "#{Dir.pwd}/plugins/chat/spec/support/api/schemas"diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex 0348716c93d..eed7d46c5a6 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -3,6 +3,8 @@RSpec.describe User dosubject(:user) { Fabricate(:user, last_seen_at: 1.day.ago) }+ fab!(:group)+it_behaves_like "it has custom fields"describe "#reload" do@@ -16,9 +18,9 @@ RSpec.describe User doendit do- expect(described_class.allocate).to have_many(:pending_posts).class_name(- "ReviewableQueuedPost",- ).with_foreign_key(:target_created_by_id)+ is_expected.to have_many(:pending_posts).class_name("ReviewableQueuedPost").with_foreign_key(+ :target_created_by_id,+ )enddescribe ".in_any_groups?" do@@ -258,8 +260,6 @@ RSpec.describe User doenddescribe "when group with a same name already exists" do- fab!(:group)-it "should not be valid" donew_user = Fabricate.build(:user, username: group.name.upcase)@@ -2076,8 +2076,6 @@ RSpec.describe User doendcontext "when the user has a group" do- fab!(:group)-before dogroup.usernames = user.usernamegroup.savediff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex d51e79d5159..f3b58e1f3b5 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -15,13 +15,13 @@ if ENV["COVERAGE"]endrequire "rubygems"-require "rbtrace" if RUBY_ENGINE == "ruby" && ENV["RBTRACE"] == "1"+require "rbtrace" if RUBY_ENGINE == "ruby"+require "pry"+require "pry-rails"require "fabrication"require "mocha/api"require "certified"require "webmock/rspec"-require "rspec-html-matchers"-require "rspec-multi-mock"require_relative "support/server_error_tracking"@@ -29,28 +29,10 @@ ENV["RAILS_ENV"] ||= "test"ENV["ENABLE_LOGSTASH_LOGGER"] ||= "1"require File.expand_path("../../config/environment", __FILE__)Discourse.singleton_class.prepend(RspecWarnExceptionCapture)--spec_files = RSpec.configuration.files_to_run-system_specs_requested = spec_files.any? { |file| file.match?(%r{(^|/)spec/system/}) }-request_specs_requested = spec_files.any? { |file| file.match?(%r{(^|/)spec/requests/}) }--if system_specs_requested || request_specs_requested- require "rspec/rails"-else- capybara_path = Gem::Specification.find_by_name("capybara").full_gem_path- skipped_capybara_features =- %w[capybara/rspec.rb capybara/rails.rb].map { |file| File.join(capybara_path, "lib", file) }- skipped_capybara_features.reject! { |feature| $LOADED_FEATURES.include?(feature) }- $LOADED_FEATURES.concat(skipped_capybara_features)- begin- require "rspec/rails"- ensure- skipped_capybara_features.each { |feature| $LOADED_FEATURES.delete(feature) }- end-end-+require "rspec/rails"require "shoulda-matchers"require "sidekiq/testing"+require "capybara/rails"# The shoulda-matchers gem no longer detects the test framework# you're using or mixes itself into that framework automatically.@@ -64,48 +46,26 @@ end# Requires supporting ruby files with custom matchers and macros, etc,# in spec/support/ and its subdirectories.-system_support_files = [- Rails.root.join("spec/support/system_helpers.rb").to_s,- Rails.root.join("spec/support/theme_screenshot_marker.rb").to_s,- *Dir[Rails.root.join("spec/support/system/**/*.rb")],-]--lazy_support_files = {- DiscourseConnectHelpers:- Rails.root.join("spec/support/discourse_connect_support_helpers.rb").to_s,- FakeS3: Rails.root.join("spec/support/fake_s3.rb").to_s,- ImageOrientationHelpers: Rails.root.join("spec/support/image_orientation_helpers.rb").to_s,-}-lazy_support_files.each { |constant, file| Object.autoload(constant, file) }--(- Dir[Rails.root.join("spec/support/**/*.rb")] - system_support_files - lazy_support_files.values-).each { |f| require f }+Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }Dir[Rails.root.join("spec/requests/examples/*.rb")].each { |f| require f }-if system_specs_requested- require "capybara-playwright-driver"- system_support_files.each { |f| require f }- Dir[Rails.root.join("spec/system/helpers/**/*.rb")].each { |f| require f }- Dir[Rails.root.join("spec/system/page_objects/**/base.rb")].each { |f| require f }- Dir[Rails.root.join("spec/system/page_objects/**/*_base.rb")].each { |f| require f }- Dir[Rails.root.join("spec/system/page_objects/**/*.rb")].each { |f| require f }-end+Dir[Rails.root.join("spec/system/helpers/**/*.rb")].each { |f| require f }+Dir[Rails.root.join("spec/system/page_objects/**/base.rb")].each { |f| require f }+Dir[Rails.root.join("spec/system/page_objects/**/*_base.rb")].each { |f| require f }+Dir[Rails.root.join("spec/system/page_objects/**/*.rb")].each { |f| require f }+Dir[Rails.root.join("spec/fabricators/*.rb")].each { |f| require f }require_relative "helpers/redis_snapshot_helper"# Require plugin helpers at plugin/[plugin]/spec/plugin_helper.rb (includes symlinked plugins).if ENV["LOAD_PLUGINS"] == "1"- Dir[Rails.root.join("spec/fabricators/*.rb")].each { |f| require f }Dir[Rails.root.join("plugins/*/spec/plugin_helper.rb")].each { |f| require f }Dir[Rails.root.join("plugins/*/spec/support/**/*.rb")].sort.each { |f| require f }Dir[Rails.root.join("plugins/*/spec/fabricators/**/*.rb")].each { |f| require f }- if system_specs_requested- Dir[Rails.root.join("plugins/*/spec/system/page_objects/**/*.rb")].each { |f| require f }- end+ Dir[Rails.root.join("plugins/*/spec/system/page_objects/**/*.rb")].each { |f| require f }endRSpec.configure do |config|@@ -123,10 +83,8 @@ RSpec.configure do |config|config.include MessageBusconfig.include RSpecHtmlMatchersconfig.include IntegrationHelpers, type: :request- if system_specs_requested- config.include SystemHelpers, type: :system- config.include ThemeScreenshotMarker, type: :system- end+ config.include SystemHelpers, type: :system+ config.include ThemeScreenshotMarker, type: :systemconfig.include DiscourseWebauthnIntegrationHelpersconfig.include SiteSettingsHelpersconfig.include SidekiqHelpers@@ -213,7 +171,7 @@ RSpec.configure do |config|SiteIconManager.clear_cache!end- config.after(:suite) { Downloads.clear } if system_specs_requested+ config.after(:suite) { Downloads.clear }config.before(:each) { TestSetup.test_setup }diff --git a/spec/requests/omniauth_callbacks_controller_spec.rb b/spec/requests/omniauth_callbacks_controller_spec.rbindex e70e0854438..9c06281d8a2 100644--- a/spec/requests/omniauth_callbacks_controller_spec.rb+++ b/spec/requests/omniauth_callbacks_controller_spec.rb@@ -1,8 +1,6 @@# frozen_string_literal: truerequire "discourse_connect_base"-require "oauth"-require "omniauth-google-oauth2"RSpec.describe Users::OmniauthCallbacksController dofab!(:user)diff --git a/spec/support/ci.rb b/spec/support/ci.rbindex f8b61ef9d0f..28cd8fa074b 100644--- a/spec/support/ci.rb+++ b/spec/support/ci.rb@@ -82,24 +82,22 @@ RSpec.configure do |config|# this workaround for now where we will retry the block once before raising the error.## Potentially related: https://bugs.ruby-lang.org/issues/20172- if defined?(Capybara) && Capybara.respond_to?(:using_session)- module Capybara- class << self- def using_session_with_localhost_resolution(name, &block)- attempts = 0- _using_session(name, &block)- rescue Socket::ResolutionError- puts "Socket::ResolutionError error encountered... Current thread count: #{Thread.list.size}"- attempts += 1- attempts <= 1 ? retry : raise- end+ module Capybara+ class << self+ def using_session_with_localhost_resolution(name, &block)+ attempts = 0+ _using_session(name, &block)+ rescue Socket::ResolutionError+ puts "Socket::ResolutionError error encountered... Current thread count: #{Thread.list.size}"+ attempts += 1+ attempts <= 1 ? retry : raiseendend+ end- Capybara.singleton_class.class_eval do- alias_method :_using_session, :using_session- alias_method :using_session, :using_session_with_localhost_resolution- end+ Capybara.singleton_class.class_eval do+ alias_method :_using_session, :using_session+ alias_method :using_session, :using_session_with_localhost_resolutionendenddiff --git a/spec/support/helpers.rb b/spec/support/helpers.rbindex 380ffe57adf..1f5c980cc9c 100644--- a/spec/support/helpers.rb+++ b/spec/support/helpers.rb@@ -1,5 +1,8 @@# frozen_string_literal: true+GIT_INITIAL_BRANCH_SUPPORTED =+ Gem::Version.new(`git --version`.match(/[\d\.]+/)[0]) >= Gem::Version.new("2.28.0")+module Helpersextend ActiveSupport::Concern@@ -177,7 +180,7 @@ module Helpersdef setup_git_repo(files)repo_dir = Dir.mktmpdirsystem(- "git -C #{repo_dir} init -q . #{"--initial-branch=main" if git_initial_branch_supported?}",+ "git -C #{repo_dir} init -q . #{"--initial-branch=main" if GIT_INITIAL_BRANCH_SUPPORTED}",exception: true,)system("git -C #{repo_dir} config user.email '[email protected]'", exception: true)@@ -197,11 +200,6 @@ module Helpersrepo_dirend- def git_initial_branch_supported?- @git_initial_branch_supported ||=- Gem::Version.new(`git --version`.match(/[\d\.]+/)[0]) >= Gem::Version.new("2.28.0")- end-def setup_remote_upstream(path)system("git -C #{path} remote add origin #{path}/.git", exception: true)system("git -C #{path} fetch -q", exception: true)diff --git a/spec/support/lazy_fabricators.rb b/spec/support/lazy_fabricators.rbdeleted file mode 100644index 3563670532b..00000000000--- a/spec/support/lazy_fabricators.rb+++ /dev/null@@ -1,47 +0,0 @@-# frozen_string_literal: true--module LazyFabricators- FABRICATOR_PATTERN = /Fabricator\(\s*:([a-zA-Z0-9_]+)/-- def register(...)- @registering_fabricator = true- super- ensure- @registering_fabricator = false- end-- def [](name)- schematic = super- return schematic if schematic || @registering_fabricator-- if (file = fabricator_files[name.to_sym]) && !loading_fabricator_files.include?(file)- loading_fabricator_files << file- begin- Kernel.load(file)- ensure- loading_fabricator_files.delete(file)- end- end-- super- end-- def empty?- fabricator_files.empty? && super- end-- private-- def fabricator_files- @fabricator_files ||=- Dir[Rails.root.join("spec/fabricators/*.rb")].each_with_object({}) do |file, files|- File.read(file).scan(FABRICATOR_PATTERN).flatten.each { |name| files[name.to_sym] = file }- end- end-- def loading_fabricator_files- @loading_fabricator_files ||= Set.new- end-end--Fabrication::Schematic::Manager.prepend(LazyFabricators)diff --git a/spec/support/lazy_faker.rb b/spec/support/lazy_faker.rbdeleted file mode 100644index 79367bb53df..00000000000--- a/spec/support/lazy_faker.rb+++ /dev/null@@ -1,12 +0,0 @@-# frozen_string_literal: true--module LazyFaker- def const_missing(name)- require "faker"- return const_get(name, false) if const_defined?(name, false)-- super- end-end--Faker.singleton_class.prepend(LazyFaker)diff --git a/spec/support/lazy_pry.rb b/spec/support/lazy_pry.rbdeleted file mode 100644index f1f9ceae14b..00000000000--- a/spec/support/lazy_pry.rb+++ /dev/null@@ -1,12 +0,0 @@-# frozen_string_literal: true--module LazyPry- def pry(...)- require "pry"- require "pry-rails"- LazyPry.remove_method(:pry)- public_send(:pry, ...)- end-end--Object.prepend(LazyPry)diff --git a/spec/support/suite_setup.rb b/spec/support/suite_setup.rbindex d18f4389e3d..81543e33db7 100644--- a/spec/support/suite_setup.rb+++ b/spec/support/suite_setup.rb@@ -3,9 +3,6 @@# One-time suite bootstrap: disable expensive subsystems, check for pending# migrations, (on CI) widen INT foreign-key columns to BIGINT, quiet noisy# output, wire the test current-user provider, and reset themes.-task_specs_requested =- RSpec.configuration.files_to_run.any? { |file| file.match?(%r{(^|/)spec/(?:lib/)?tasks/}) }-RSpec.configure do |config|config.before(:suite) doCachedCounting.disable@@ -53,14 +50,14 @@ RSpec.configure do |config|SeedFu.quiet = true# json-schema's MultiJSON support is deprecated.- JSON::Validator.use_multi_json = false if defined?(JSON::Validator)+ JSON::Validator.use_multi_json = false# Ugly, but needed until we have a user creatorUser.skip_callback(:create, :after, :ensure_in_trust_level_group)DiscoursePluginRegistry.reset! if ENV["LOAD_PLUGINS"] != "1"Discourse.current_user_provider = TestCurrentUserProvider- Discourse::Application.load_tasks if task_specs_requested+ Discourse::Application.load_tasksSystemThemesManager.clear_system_theme_user_history!ThemeField.delete_alldiff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rbindex b9d2a11b772..c1df3b5b3ae 100644--- a/spec/swagger_helper.rb+++ b/spec/swagger_helper.rb@@ -1,7 +1,6 @@# frozen_string_literal: truerequire "json_schemer"-require "rswag/specs"# Require schema filesDir["./spec/requests/api/schemas/*.rb"].each { |file| require file }