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 2581671
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
24 changes: 24 additions & 0 deletions spec/support/unit/configuration.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 2 additions & 15 deletions spec/unit_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'support/unit/load_environment'
require_relative 'support/unit/configuration'

require 'rspec/rails'
require 'rspec/matchers/fail_matchers'
Expand All @@ -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

Expand Down

0 comments on commit 2581671

Please sign in to comment.