Skip to content

Commit

Permalink
refactor: Enhance unit test helpers loading
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matsales28 committed Dec 11, 2023
1 parent f2db1f2 commit 871f4e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
27 changes: 27 additions & 0 deletions spec/support/unit/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module UnitTests
class Configuration
CLASSES = %i[
ActionPackVersions
ActiveModelHelpers
ActiveModelVersions
ActiveRecordVersions
ClassBuilder
ColumnTypeHelpers
ControllerBuilder
DatabaseHelpers
I18nFaker
MailerBuilder
MessageHelpers
ModelBuilder
RailsVersions
ValidationMatcherScenarioHelpers
].freeze

def self.configure_example_groups(config)
CLASSES.each do |class_name|
constantized_class = "UnitTests::#{class_name}"
Object.const_get(constantized_class).configure_example_group(config)
end
end
end
end
16 changes: 1 addition & 15 deletions spec/unit_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,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_groups(config)

config.include UnitTests::Matchers

Expand Down

0 comments on commit 871f4e1

Please sign in to comment.