Module: TestProf::EventProf::CustomEvents::FactoryCreate

Defined in:
lib/test_prof/event_prof/custom_events/factory_create.rb

Overview

:nodoc: all

Defined Under Namespace

Modules: RunnerPatch

Class Method Summary collapse

Class Method Details

.setup!Object



17
18
19
20
# File 'lib/test_prof/event_prof/custom_events/factory_create.rb', line 17

def setup!
  @depth = 0
  TestProf::FactoryBot::FactoryRunner.prepend RunnerPatch
end

.track(factory) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/test_prof/event_prof/custom_events/factory_create.rb', line 22

def track(factory)
  @depth += 1
  res = nil
  begin
    res =
      if @depth == 1
        ActiveSupport::Notifications.instrument(
          'factory.create',
          name: factory
        ) { yield }
      else
        yield
      end
  ensure
    @depth -= 1
  end
  res
end