Module: Spree::TestingSupport

Defined in:
core/lib/spree/testing_support.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"]

Class Method Summary collapse

Class Method Details

.deprecate_cherry_picking_factory_bot_filesObject



12
13
14
15
16
17
18
19
20
# File 'core/lib/spree/testing_support.rb', line 12

def self.deprecate_cherry_picking_factory_bot_files
  # All good if the factory is being loaded by FactoryBot.
  return if caller.find { |line| line.include? "/factory_bot/find_definitions.rb" }

  Spree::Deprecation.warn(
    "Please do not cherry-pick factories, this is not well supported by FactoryBot. " \
    'Use `require "spree/testing_support/factories"` instead.', caller(2)
  )
end

.factory_bot_pathsObject



8
9
10
# File 'core/lib/spree/testing_support.rb', line 8

def self.factory_bot_paths
  @paths ||= (SEQUENCES + FACTORIES).sort.map { |path| path.sub(/.rb\z/, '') }
end

.load_all_factoriesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'core/lib/spree/testing_support.rb', line 22

def self.load_all_factories
  require 'factory_bot'
  require 'factory_bot/version'

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

  unless requirement.satisfied_by? version
    Spree::Deprecation.warn(
      "Please be aware that the supported version of FactoryBot is #{requirement}, " \
      "using version #{version} could lead to factory loading issues.", caller(2)
    )
  end

  FactoryBot.definition_file_paths.concat(factory_bot_paths).uniq!
  FactoryBot.reload
end