File: railtie_spec.rb

package info (click to toggle)
ruby-factory-bot-rails 6.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: ruby: 635; makefile: 6; sh: 4
file content (50 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

describe FactoryBotRails::Railtie do
  describe "application reloading" do
    context "when a definition file has been updated" do
      it "reloads the factory definitions" do
        allow(FactoryBot).to receive(:reload)

        touch("factories.rb")
        reload_rails!

        expect(FactoryBot).to have_received(:reload).at_least(1).times
      end
    end

    context "when a file in a definition directory has been updated" do
      it "reloads the factory definitions" do
        allow(FactoryBot).to receive(:reload)

        touch("factories/definitions.rb")
        reload_rails!

        expect(FactoryBot).to have_received(:reload).at_least(1).times
      end
    end

    context "when the factory definitions have NOT been updated" do
      it "reloads the factory definitions" do
        allow(FactoryBot).to receive(:reload)

        reload_rails!

        expect(FactoryBot).to have_received(:reload).at_least(1).times
      end
    end

    def touch(file)
      FileUtils.touch(Rails.root.join(file))
    end

    def reload_rails!
      Rails.application.reloader.reload!
      wait_for_rails_to_reload
    end

    def wait_for_rails_to_reload
      sleep 0.01
    end
  end
end