Module: Spree::TestingSupport::FactoryBot

Defined in:
lib/spree/testing_support/factory_bot.rb

Constant Summary collapse

SEQUENCES =
["#{::Spree::Core::Engine.root}/lib/spree/testing_support/sequences.rb"]
FACTORIES =
Dir["#{::Spree::Core::Engine.root}/lib/spree/testing_support/factories/**/*_factory.rb"].sort
PATHS =
SEQUENCES + FACTORIES

Class Method Summary collapse

Class Method Details

.add_definitions!Object



35
36
37
# File 'lib/spree/testing_support/factory_bot.rb', line 35

def self.add_definitions!
  ::FactoryBot.definition_file_paths.unshift(*definition_file_paths).uniq!
end

.add_paths_and_load!Object



39
40
41
42
# File 'lib/spree/testing_support/factory_bot.rb', line 39

def self.add_paths_and_load!
  add_definitions!
  ::FactoryBot.reload
end

.check_versionObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/spree/testing_support/factory_bot.rb', line 20

def self.check_version
  require "factory_bot/version"

  requirement = Gem::Requirement.new(">= 4.8")
  version = Gem::Version.new(::FactoryBot::VERSION)

  unless requirement.satisfied_by? version
    raise <<~MSG
      Please be aware that the supported version of FactoryBot is #{requirement},
      using version #{version} could lead to factory loading issues.
    MSG
  end
end

.definition_file_pathsObject



16
17
18
# File 'lib/spree/testing_support/factory_bot.rb', line 16

def self.definition_file_paths
  @paths ||= PATHS.map { |path| path.sub(/.rb\z/, '') }
end