module FactoryBot
Constants
- Deprecation
- VERSION
Attributes
An Array of strings specifying locations that should be searched for factory definitions. By default, factory_bot will attempt to require “factories.rb”, “factories/*/.rb”, “test/factories.rb”, “test/factories/**.rb”, “spec/factories.rb”, and “spec/factories/**.rb”.
Public Class Methods
Source
# File lib/factory_bot/aliases.rb, line 11 def self.aliases_for(attribute) aliases.map { |(pattern, replace)| if pattern.match?(attribute) attribute.to_s.sub(pattern, replace).to_sym end }.compact << attribute end
Source
# File lib/factory_bot.rb, line 76 def self.build_stubbed_starting_id=(starting_id) Strategy::Stub.next_id = starting_id - 1 end
Set the starting value for ids when using the build_stubbed strategy
@param [Integer] starting_id The new starting id value.
Source
# File lib/factory_bot/find_definitions.rb, line 12 def self.find_definitions absolute_definition_file_paths = definition_file_paths.map { |path| File.expand_path(path) } absolute_definition_file_paths.uniq.each do |path| load("#{path}.rb") if File.exist?("#{path}.rb") if File.directory? path Dir[File.join(path, "**", "*.rb")].sort.each do |file| load file end end end end
Source
# File lib/factory_bot.rb, line 67 def self.lint(*args) options = args.extract_options! factories_to_lint = args[0] || FactoryBot.factories Linter.new(factories_to_lint, **options).lint! end
Look for errors in factories and (optionally) their traits. Parameters: factories - which factories to lint; omit for all factories options:
traits: true - to lint traits as well as factories strategy: :create - to specify the strategy for linting verbose: true - to include full backtraces for each linting error
Source
# File lib/factory_bot/reload.rb, line 2 def self.reload Internal.reset_configuration Internal.register_default_strategies find_definitions end