Module: FactoryGirl

Extended by:
Syntax::Default
Defined in:
lib/factory_girl.rb,
lib/factory_girl/proxy.rb,
lib/factory_girl/trait.rb,
lib/factory_girl/reload.rb,
lib/factory_girl/syntax.rb,
lib/factory_girl/aliases.rb,
lib/factory_girl/factory.rb,
lib/factory_girl/version.rb,
lib/factory_girl/callback.rb,
lib/factory_girl/registry.rb,
lib/factory_girl/sequence.rb,
lib/factory_girl/attribute.rb,
lib/factory_girl/definition.rb,
lib/factory_girl/proxy/stub.rb,
lib/factory_girl/declaration.rb,
lib/factory_girl/proxy/build.rb,
lib/factory_girl/syntax/make.rb,
lib/factory_girl/syntax/sham.rb,
lib/factory_girl/null_factory.rb,
lib/factory_girl/proxy/create.rb,
lib/factory_girl/attribute_list.rb,
lib/factory_girl/syntax/default.rb,
lib/factory_girl/syntax/methods.rb,
lib/factory_girl/syntax/vintage.rb,
lib/factory_girl/syntax/generate.rb,
lib/factory_girl/attribute/static.rb,
lib/factory_girl/declaration_list.rb,
lib/factory_girl/definition_proxy.rb,
lib/factory_girl/find_definitions.rb,
lib/factory_girl/syntax/blueprint.rb,
lib/factory_girl/attribute/dynamic.rb,
lib/factory_girl/attribute/sequence.rb,
lib/factory_girl/declaration/static.rb,
lib/factory_girl/declaration/dynamic.rb,
lib/factory_girl/declaration/implicit.rb,
lib/factory_girl/proxy/attributes_for.rb,
lib/factory_girl/attribute/association.rb,
lib/factory_girl/declaration/association.rb

Defined Under Namespace

Modules: Syntax Classes: AssociationDefinitionError, Attribute, AttributeDefinitionError, AttributeList, Callback, Declaration, DeclarationList, Definition, DefinitionProxy, DuplicateDefinitionError, Factory, InvalidCallbackNameError, NullFactory, Proxy, Registry, Sequence, SequenceAbuseError, Trait

Constant Summary collapse

VERSION =
"2.3.2"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Syntax::Default

define, modify

Methods included from Syntax::Methods

#attributes_for, #build, #build_list, #build_stubbed, #create, #create_list, #generate

Class Attribute Details

.aliasesObject

:nodoc:



3
4
5
# File 'lib/factory_girl/aliases.rb', line 3

def aliases
  @aliases
end

.definition_file_pathsObject

An Array of strings specifying locations that should be searched for factory definitions. By default, factory_girl will attempt to require “factories,” “test/factories,” and “spec/factories.” Only the first existing file will be loaded.



8
9
10
# File 'lib/factory_girl/find_definitions.rb', line 8

def definition_file_paths
  @definition_file_paths
end

Class Method Details

.aliases_for(attribute) ⇒ Object

:nodoc:



11
12
13
14
15
16
17
18
# File 'lib/factory_girl/aliases.rb', line 11

def self.aliases_for(attribute) #:nodoc:
  aliases.collect do |params|
    pattern, replace = *params
    if pattern.match(attribute.to_s)
      attribute.to_s.sub(pattern, replace).to_sym
    end
  end.compact << attribute
end

.factoriesObject



46
47
48
# File 'lib/factory_girl.rb', line 46

def self.factories
  @factories ||= Registry.new("Factory")
end

.factory_by_name(name) ⇒ Object



54
55
56
# File 'lib/factory_girl.rb', line 54

def self.factory_by_name(name)
  factories.find(name)
end

.find_definitionsObject

:nodoc:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/factory_girl/find_definitions.rb', line 12

def self.find_definitions #:nodoc:
  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.exists?("#{path}.rb")

    if File.directory? path
      Dir[File.join(path, '**', '*.rb')].sort.each do |file|
        load file
      end
    end
  end
end

.register_factory(factory) ⇒ Object



50
51
52
# File 'lib/factory_girl.rb', line 50

def self.register_factory(factory)
  factories.add(factory)
end

.register_sequence(sequence) ⇒ Object



62
63
64
# File 'lib/factory_girl.rb', line 62

def self.register_sequence(sequence)
  sequences.add(sequence)
end

.register_trait(trait) ⇒ Object



74
75
76
# File 'lib/factory_girl.rb', line 74

def self.register_trait(trait)
  traits.add(trait)
end

.reloadObject



2
3
4
5
6
7
# File 'lib/factory_girl/reload.rb', line 2

def self.reload
  self.factories.clear
  self.sequences.clear
  self.traits.clear
  self.find_definitions
end

.sequence_by_name(name) ⇒ Object



66
67
68
# File 'lib/factory_girl.rb', line 66

def self.sequence_by_name(name)
  sequences.find(name)
end

.sequencesObject



58
59
60
# File 'lib/factory_girl.rb', line 58

def self.sequences
  @sequences ||= Registry.new("Sequence")
end

.trait_by_name(name) ⇒ Object



78
79
80
# File 'lib/factory_girl.rb', line 78

def self.trait_by_name(name)
  traits.find(name)
end

.traitsObject



70
71
72
# File 'lib/factory_girl.rb', line 70

def self.traits
  @traits ||= Registry.new("Trait")
end