File: factory_create.rb

package info (click to toggle)
ruby-test-prof 0.12.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 508 kB
  • sloc: ruby: 4,075; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

require "test_prof/factory_bot"
require "test_prof/ext/factory_bot_strategy"

using TestProf::FactoryBotStrategy

TestProf::EventProf::CustomEvents.register("factory.create") do
  if defined?(TestProf::FactoryBot) || defined?(Fabricate)
    if defined?(TestProf::FactoryBot)
      TestProf::EventProf.monitor(
        TestProf::FactoryBot::FactoryRunner,
        "factory.create",
        :run,
        top_level: true,
        guard: ->(strategy = @strategy) { strategy.create? }
      )
    end

    if defined?(Fabricate)
      TestProf::EventProf.monitor(
        Fabricate.singleton_class,
        "factory.create",
        :create,
        top_level: true
      )
    end
  else
    TestProf.log(
      :error,
      <<~MSG
        Failed to load factory_bot / factory_girl / fabrication.

        Make sure that any of them is in your Gemfile.
      MSG
    )
  end
end