Module: TestProf::FactoryDefault

Defined in:
lib/test_prof/factory_default.rb,
lib/test_prof/factory_default/factory_bot_patch.rb

Overview

:nodoc: all

Defined Under Namespace

Modules: DefaultSyntax, RunnerExt, StrategyExt

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.preserve_traitsObject

Returns the value of attribute preserve_traits.



25
26
27
# File 'lib/test_prof/factory_default.rb', line 25

def preserve_traits
  @preserve_traits
end

Class Method Details

.get(name, traits = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/test_prof/factory_default.rb', line 45

def get(name, traits = nil)
  record = store[name]
  return unless record

  if traits && !traits.empty?
    return if FactoryDefault.preserve_traits || record[:preserve_traits]
  end
  record[:object]
end

.initObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/test_prof/factory_default.rb', line 27

def init
  TestProf::FactoryBot::Syntax::Methods.include DefaultSyntax
  TestProf::FactoryBot.extend DefaultSyntax
  TestProf::FactoryBot::Strategy::Create.prepend StrategyExt
  TestProf::FactoryBot::Strategy::Build.prepend StrategyExt
  TestProf::FactoryBot::Strategy::Stub.prepend StrategyExt

  @store = {}
  # default is false to retain backward compatibility
  @preserve_traits = false
end

.register(name, obj, **options) ⇒ Object



39
40
41
42
43
# File 'lib/test_prof/factory_default.rb', line 39

def register(name, obj, **options)
  options[:preserve_traits] = true if FactoryDefault.preserve_traits
  store[name] = { object: obj, **options }
  obj
end

.remove(name) ⇒ Object



55
56
57
# File 'lib/test_prof/factory_default.rb', line 55

def remove(name)
  store.delete(name)
end

.resetObject



59
60
61
# File 'lib/test_prof/factory_default.rb', line 59

def reset
  @store.clear
end