File: factory_all_stub.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 (32 lines) | stat: -rw-r--r-- 740 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
# frozen_string_literal: true

require "test_prof/factory_bot"
require "test_prof/factory_all_stub/factory_bot_patch"

module TestProf
  # FactoryAllStub inject into FactoryBot to make
  # all strategies be `build_stubbed` strategy.
  module FactoryAllStub
    LOCAL_NAME = :__factory_bot_stub_all__

    class << self
      def init
        # Monkey-patch FactoryBot / FactoryGirl
        TestProf::FactoryBot::FactoryRunner.prepend(FactoryBotPatch) if
          defined?(TestProf::FactoryBot)
      end

      def enabled?
        Thread.current[LOCAL_NAME] == true
      end

      def enable!
        Thread.current[LOCAL_NAME] = true
      end

      def disable!
        Thread.current[LOCAL_NAME] = false
      end
    end
  end
end