From 2581671fa7edf2bfe4f292611328d9c5da29080e Mon Sep 17 00:00:00 2001 From: Matheus Sales Date: Mon, 11 Dec 2023 17:30:46 -0300 Subject: [PATCH] refactor: Enhance unit test helpers loading This commit refactors the way we load unit test helpers. Instead of requiring each file individually, we now have a single file that requires all of them. This makes it easier to add new helpers and ensures that they are loaded in the correct order. --- spec/support/unit/configuration.rb | 24 ++++++++++++++++++++++++ spec/unit_spec_helper.rb | 17 ++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 spec/support/unit/configuration.rb diff --git a/spec/support/unit/configuration.rb b/spec/support/unit/configuration.rb new file mode 100644 index 000000000..9f61c408c --- /dev/null +++ b/spec/support/unit/configuration.rb @@ -0,0 +1,24 @@ +module UnitTests + class Configuration + CLASSES = [ + UnitTests::ActiveModelHelpers, + UnitTests::ActiveModelVersions, + UnitTests::ActiveModelVersions, + UnitTests::ActiveRecordVersions, + UnitTests::ClassBuilder, + UnitTests::ColumnTypeHelpers, + UnitTests::ControllerBuilder, + UnitTests::DatabaseHelpers, + UnitTests::I18nFaker, + UnitTests::MailerBuilder, + UnitTests::MessageHelpers, + UnitTests::ModelBuilder, + UnitTests::RailsVersions, + UnitTests::ValidationMatcherScenarioHelpers, + ].freeze + + def self.configure_example_groups(config) + CLASSES.each { |klass| klass.configure_example_group(config) } + end + end +end diff --git a/spec/unit_spec_helper.rb b/spec/unit_spec_helper.rb index 18a01c23f..76182097b 100644 --- a/spec/unit_spec_helper.rb +++ b/spec/unit_spec_helper.rb @@ -1,4 +1,5 @@ require_relative 'support/unit/load_environment' +require_relative 'support/unit/configuration' require 'rspec/rails' require 'rspec/matchers/fail_matchers' @@ -15,21 +16,7 @@ RSpec.configure do |config| config.include RSpec::Matchers::FailMatchers - UnitTests::ActionPackVersions.configure_example_group(config) - UnitTests::ActiveModelHelpers.configure_example_group(config) - UnitTests::ActiveModelVersions.configure_example_group(config) - UnitTests::ClassBuilder.configure_example_group(config) - UnitTests::ControllerBuilder.configure_example_group(config) - UnitTests::I18nFaker.configure_example_group(config) - UnitTests::MailerBuilder.configure_example_group(config) - UnitTests::ModelBuilder.configure_example_group(config) - UnitTests::RailsVersions.configure_example_group(config) - UnitTests::ActiveRecordVersions.configure_example_group(config) - UnitTests::ActiveModelVersions.configure_example_group(config) - UnitTests::DatabaseHelpers.configure_example_group(config) - UnitTests::ColumnTypeHelpers.configure_example_group(config) - UnitTests::ValidationMatcherScenarioHelpers.configure_example_group(config) - UnitTests::MessageHelpers.configure_example_group(config) + UnitTests::Configuration.configure_example_group(config) config.include UnitTests::Matchers