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.0"

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


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

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

.factory_by_name(name) ⇒ Object


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

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


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

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

.register_sequence(sequence) ⇒ Object


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

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

.register_trait(trait) ⇒ Object


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

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


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

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

.sequencesObject


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

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

.trait_by_name(name) ⇒ Object


83
84
85
# File 'lib/factory_girl.rb', line 83

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

.traitsObject


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

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