Module: CommandTower::Testing

Defined in:
lib/command_tower/testing.rb

Overview

Explicit host/test entry for shared FactoryBot definitions and related testing bootstrap. Not loaded in production via Railtie.

Class Method Summary collapse

Class Method Details

.ensure_endpoint_secret!Object

Ensures COMMAND_TOWER_MESSAGING_ENDPOINT_SECRET for endpoint factories in non-production test environments when unset.



44
45
46
47
48
49
# File 'lib/command_tower/testing.rb', line 44

def ensure_endpoint_secret!
  return unless ENV["COMMAND_TOWER_MESSAGING_ENDPOINT_SECRET"].to_s.empty?

  ENV["COMMAND_TOWER_MESSAGING_ENDPOINT_SECRET"] =
    "test-messaging-endpoint-secret-not-for-production"
end

.factories_loaded?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/command_tower/testing.rb', line 33

def factories_loaded?
  @factories_loaded == true
end

.factories_pathObject



51
52
53
# File 'lib/command_tower/testing.rb', line 51

def factories_path
  CommandTower::Engine.root.join("spec/factories")
end

.install!Object

Preferred host entry. Currently loads factories; reserved for future shared testing setup (helpers, config checks).



10
11
12
# File 'lib/command_tower/testing.rb', line 10

def install!
  load_factories!
end

.load_factories!Object

Load CommandTower FactoryBot definitions exactly once. Loads files under Engine.root/spec/factories explicitly (does not mutate global definition_file_paths / find_definitions).



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/command_tower/testing.rb', line 17

def load_factories!
  return if factories_loaded?

  begin
    require "factory_bot"
  rescue LoadError
    raise LoadError,
          "CommandTower::Testing requires the factory_bot gem. " \
          "Add `factory_bot` or `factory_bot_rails` to your host test group."
  end

  factory_files.each { |path| Kernel.load(path) }
  @factories_loaded = true
  true
end

.reset_factories_loaded_flag!Object

Reset loader state (specs only). Does not undefine FactoryBot factories.



38
39
40
# File 'lib/command_tower/testing.rb', line 38

def reset_factories_loaded_flag!
  @factories_loaded = false
end