factory_bot 1.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +9 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.simplecov +4 -0
- data/.travis.yml +41 -0
- data/.yardopts +5 -0
- data/Appraisals +19 -0
- data/CONTRIBUTING.md +60 -0
- data/GETTING_STARTED.md +1387 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +123 -0
- data/LICENSE +19 -0
- data/NAME.md +11 -0
- data/NEWS +285 -0
- data/README.md +102 -0
- data/Rakefile +36 -0
- data/cucumber.yml +1 -0
- data/factory_bot.gemspec +38 -0
- data/factory_girl.gemspec +41 -0
- data/gemfiles/3.2.gemfile +10 -0
- data/gemfiles/3.2.gemfile.lock +112 -0
- data/gemfiles/4.0.gemfile +10 -0
- data/gemfiles/4.0.gemfile.lock +112 -0
- data/gemfiles/4.1.gemfile +10 -0
- data/gemfiles/4.1.gemfile.lock +111 -0
- data/gemfiles/4.2.gemfile +10 -0
- data/gemfiles/4.2.gemfile.lock +111 -0
- data/gemfiles/5.0.gemfile +10 -0
- data/gemfiles/5.0.gemfile.lock +110 -0
- data/lib/factory_bot.rb +154 -0
- data/lib/factory_bot/aliases.rb +18 -0
- data/lib/factory_bot/attribute.rb +62 -0
- data/lib/factory_bot/attribute/association.rb +27 -0
- data/lib/factory_bot/attribute/dynamic.rb +24 -0
- data/lib/factory_bot/attribute/sequence.rb +16 -0
- data/lib/factory_bot/attribute/static.rb +16 -0
- data/lib/factory_bot/attribute_assigner.rb +97 -0
- data/lib/factory_bot/attribute_list.rb +67 -0
- data/lib/factory_bot/callback.rb +40 -0
- data/lib/factory_bot/callbacks_observer.rb +21 -0
- data/lib/factory_bot/configuration.rb +37 -0
- data/lib/factory_bot/declaration.rb +23 -0
- data/lib/factory_bot/declaration/association.rb +28 -0
- data/lib/factory_bot/declaration/dynamic.rb +26 -0
- data/lib/factory_bot/declaration/implicit.rb +33 -0
- data/lib/factory_bot/declaration/static.rb +26 -0
- data/lib/factory_bot/declaration_list.rb +49 -0
- data/lib/factory_bot/decorator.rb +21 -0
- data/lib/factory_bot/decorator/attribute_hash.rb +16 -0
- data/lib/factory_bot/decorator/class_key_hash.rb +28 -0
- data/lib/factory_bot/decorator/disallows_duplicates_registry.rb +13 -0
- data/lib/factory_bot/decorator/invocation_tracker.rb +19 -0
- data/lib/factory_bot/decorator/new_constructor.rb +12 -0
- data/lib/factory_bot/definition.rb +136 -0
- data/lib/factory_bot/definition_hierarchy.rb +48 -0
- data/lib/factory_bot/definition_proxy.rb +174 -0
- data/lib/factory_bot/errors.rb +25 -0
- data/lib/factory_bot/evaluation.rb +23 -0
- data/lib/factory_bot/evaluator.rb +82 -0
- data/lib/factory_bot/evaluator_class_definer.rb +20 -0
- data/lib/factory_bot/factory.rb +162 -0
- data/lib/factory_bot/factory_runner.rb +33 -0
- data/lib/factory_bot/find_definitions.rb +25 -0
- data/lib/factory_bot/linter.rb +97 -0
- data/lib/factory_bot/null_factory.rb +18 -0
- data/lib/factory_bot/null_object.rb +24 -0
- data/lib/factory_bot/registry.rb +38 -0
- data/lib/factory_bot/reload.rb +8 -0
- data/lib/factory_bot/sequence.rb +62 -0
- data/lib/factory_bot/strategy/attributes_for.rb +13 -0
- data/lib/factory_bot/strategy/build.rb +15 -0
- data/lib/factory_bot/strategy/create.rb +18 -0
- data/lib/factory_bot/strategy/null.rb +11 -0
- data/lib/factory_bot/strategy/stub.rb +108 -0
- data/lib/factory_bot/strategy_calculator.rb +26 -0
- data/lib/factory_bot/strategy_syntax_method_registrar.rb +54 -0
- data/lib/factory_bot/syntax.rb +7 -0
- data/lib/factory_bot/syntax/default.rb +76 -0
- data/lib/factory_bot/syntax/methods.rb +111 -0
- data/lib/factory_bot/syntax_runner.rb +6 -0
- data/lib/factory_bot/trait.rb +30 -0
- data/lib/factory_bot/version.rb +3 -0
- data/lib/factory_girl.rb +5 -0
- data/lib/factory_girl/version.rb +1 -0
- metadata +302 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
6
|
+
gem "jdbc-sqlite3", :platforms => :jruby
|
7
|
+
gem "sqlite3", "~> 1.3.10", :platforms => :ruby
|
8
|
+
gem "activerecord", "~> 4.1.14"
|
9
|
+
|
10
|
+
gemspec :path => "../"
|
@@ -0,0 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
factory_girl (4.8.0)
|
5
|
+
activesupport (>= 3.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (4.1.15)
|
11
|
+
activesupport (= 4.1.15)
|
12
|
+
builder (~> 3.1)
|
13
|
+
activerecord (4.1.15)
|
14
|
+
activemodel (= 4.1.15)
|
15
|
+
activesupport (= 4.1.15)
|
16
|
+
arel (~> 5.0.0)
|
17
|
+
activesupport (4.1.15)
|
18
|
+
i18n (~> 0.6, >= 0.6.9)
|
19
|
+
json (~> 1.7, >= 1.7.7)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
thread_safe (~> 0.1)
|
22
|
+
tzinfo (~> 1.1)
|
23
|
+
appraisal (2.1.0)
|
24
|
+
bundler
|
25
|
+
rake
|
26
|
+
thor (>= 0.14.0)
|
27
|
+
arel (5.0.1.20140414130214)
|
28
|
+
aruba (0.14.1)
|
29
|
+
childprocess (~> 0.5.6)
|
30
|
+
contracts (~> 0.9)
|
31
|
+
cucumber (>= 1.3.19)
|
32
|
+
ffi (~> 1.9.10)
|
33
|
+
rspec-expectations (>= 2.99)
|
34
|
+
thor (~> 0.19)
|
35
|
+
bourne (1.6.0)
|
36
|
+
mocha (~> 1.1)
|
37
|
+
builder (3.2.2)
|
38
|
+
childprocess (0.5.9)
|
39
|
+
ffi (~> 1.0, >= 1.0.11)
|
40
|
+
contracts (0.14.0)
|
41
|
+
cucumber (1.3.20)
|
42
|
+
builder (>= 2.1.2)
|
43
|
+
diff-lcs (>= 1.1.3)
|
44
|
+
gherkin (~> 2.12)
|
45
|
+
multi_json (>= 1.7.5, < 2.0)
|
46
|
+
multi_test (>= 0.1.2)
|
47
|
+
diff-lcs (1.2.5)
|
48
|
+
docile (1.1.5)
|
49
|
+
ffi (1.9.10)
|
50
|
+
gherkin (2.12.2)
|
51
|
+
multi_json (~> 1.3)
|
52
|
+
i18n (0.7.0)
|
53
|
+
json (1.8.3)
|
54
|
+
metaclass (0.0.4)
|
55
|
+
minitest (5.9.0)
|
56
|
+
mocha (1.1.0)
|
57
|
+
metaclass (~> 0.0.1)
|
58
|
+
multi_json (1.12.1)
|
59
|
+
multi_test (0.1.2)
|
60
|
+
rake (11.2.2)
|
61
|
+
rspec (3.4.0)
|
62
|
+
rspec-core (~> 3.4.0)
|
63
|
+
rspec-expectations (~> 3.4.0)
|
64
|
+
rspec-mocks (~> 3.4.0)
|
65
|
+
rspec-core (3.4.4)
|
66
|
+
rspec-support (~> 3.4.0)
|
67
|
+
rspec-expectations (3.4.0)
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
+
rspec-support (~> 3.4.0)
|
70
|
+
rspec-its (1.2.0)
|
71
|
+
rspec-core (>= 3.0.0)
|
72
|
+
rspec-expectations (>= 3.0.0)
|
73
|
+
rspec-mocks (3.4.1)
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
+
rspec-support (~> 3.4.0)
|
76
|
+
rspec-support (3.4.1)
|
77
|
+
simplecov (0.11.2)
|
78
|
+
docile (~> 1.1.0)
|
79
|
+
json (~> 1.8)
|
80
|
+
simplecov-html (~> 0.10.0)
|
81
|
+
simplecov-html (0.10.0)
|
82
|
+
sqlite3 (1.3.11)
|
83
|
+
thor (0.19.1)
|
84
|
+
thread_safe (0.3.5)
|
85
|
+
timecop (0.8.1)
|
86
|
+
tzinfo (1.2.2)
|
87
|
+
thread_safe (~> 0.1)
|
88
|
+
yard (0.8.7.6)
|
89
|
+
|
90
|
+
PLATFORMS
|
91
|
+
ruby
|
92
|
+
|
93
|
+
DEPENDENCIES
|
94
|
+
activerecord (~> 4.1.14)
|
95
|
+
activerecord-jdbcsqlite3-adapter
|
96
|
+
appraisal (~> 2.1.0)
|
97
|
+
aruba
|
98
|
+
bourne
|
99
|
+
cucumber (~> 1.3.15)
|
100
|
+
factory_girl!
|
101
|
+
jdbc-sqlite3
|
102
|
+
mocha (>= 0.12.8)
|
103
|
+
rspec (~> 3.0)
|
104
|
+
rspec-its (~> 1.0)
|
105
|
+
simplecov
|
106
|
+
sqlite3 (~> 1.3.10)
|
107
|
+
timecop
|
108
|
+
yard
|
109
|
+
|
110
|
+
BUNDLED WITH
|
111
|
+
1.13.6
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
6
|
+
gem "jdbc-sqlite3", :platforms => :jruby
|
7
|
+
gem "sqlite3", "~> 1.3.10", :platforms => :ruby
|
8
|
+
gem "activerecord", "~> 4.2.5.1"
|
9
|
+
|
10
|
+
gemspec :path => "../"
|
@@ -0,0 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
factory_girl (4.8.0)
|
5
|
+
activesupport (>= 3.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (4.2.5.1)
|
11
|
+
activesupport (= 4.2.5.1)
|
12
|
+
builder (~> 3.1)
|
13
|
+
activerecord (4.2.5.1)
|
14
|
+
activemodel (= 4.2.5.1)
|
15
|
+
activesupport (= 4.2.5.1)
|
16
|
+
arel (~> 6.0)
|
17
|
+
activesupport (4.2.5.1)
|
18
|
+
i18n (~> 0.7)
|
19
|
+
json (~> 1.7, >= 1.7.7)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
22
|
+
tzinfo (~> 1.1)
|
23
|
+
appraisal (2.1.0)
|
24
|
+
bundler
|
25
|
+
rake
|
26
|
+
thor (>= 0.14.0)
|
27
|
+
arel (6.0.3)
|
28
|
+
aruba (0.14.1)
|
29
|
+
childprocess (~> 0.5.6)
|
30
|
+
contracts (~> 0.9)
|
31
|
+
cucumber (>= 1.3.19)
|
32
|
+
ffi (~> 1.9.10)
|
33
|
+
rspec-expectations (>= 2.99)
|
34
|
+
thor (~> 0.19)
|
35
|
+
bourne (1.6.0)
|
36
|
+
mocha (~> 1.1)
|
37
|
+
builder (3.2.2)
|
38
|
+
childprocess (0.5.9)
|
39
|
+
ffi (~> 1.0, >= 1.0.11)
|
40
|
+
contracts (0.14.0)
|
41
|
+
cucumber (1.3.20)
|
42
|
+
builder (>= 2.1.2)
|
43
|
+
diff-lcs (>= 1.1.3)
|
44
|
+
gherkin (~> 2.12)
|
45
|
+
multi_json (>= 1.7.5, < 2.0)
|
46
|
+
multi_test (>= 0.1.2)
|
47
|
+
diff-lcs (1.2.5)
|
48
|
+
docile (1.1.5)
|
49
|
+
ffi (1.9.10)
|
50
|
+
gherkin (2.12.2)
|
51
|
+
multi_json (~> 1.3)
|
52
|
+
i18n (0.7.0)
|
53
|
+
json (1.8.3)
|
54
|
+
metaclass (0.0.4)
|
55
|
+
minitest (5.9.0)
|
56
|
+
mocha (1.1.0)
|
57
|
+
metaclass (~> 0.0.1)
|
58
|
+
multi_json (1.12.1)
|
59
|
+
multi_test (0.1.2)
|
60
|
+
rake (11.2.2)
|
61
|
+
rspec (3.4.0)
|
62
|
+
rspec-core (~> 3.4.0)
|
63
|
+
rspec-expectations (~> 3.4.0)
|
64
|
+
rspec-mocks (~> 3.4.0)
|
65
|
+
rspec-core (3.4.4)
|
66
|
+
rspec-support (~> 3.4.0)
|
67
|
+
rspec-expectations (3.4.0)
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
+
rspec-support (~> 3.4.0)
|
70
|
+
rspec-its (1.2.0)
|
71
|
+
rspec-core (>= 3.0.0)
|
72
|
+
rspec-expectations (>= 3.0.0)
|
73
|
+
rspec-mocks (3.4.1)
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
+
rspec-support (~> 3.4.0)
|
76
|
+
rspec-support (3.4.1)
|
77
|
+
simplecov (0.11.2)
|
78
|
+
docile (~> 1.1.0)
|
79
|
+
json (~> 1.8)
|
80
|
+
simplecov-html (~> 0.10.0)
|
81
|
+
simplecov-html (0.10.0)
|
82
|
+
sqlite3 (1.3.11)
|
83
|
+
thor (0.19.1)
|
84
|
+
thread_safe (0.3.5)
|
85
|
+
timecop (0.8.1)
|
86
|
+
tzinfo (1.2.2)
|
87
|
+
thread_safe (~> 0.1)
|
88
|
+
yard (0.8.7.6)
|
89
|
+
|
90
|
+
PLATFORMS
|
91
|
+
ruby
|
92
|
+
|
93
|
+
DEPENDENCIES
|
94
|
+
activerecord (~> 4.2.5.1)
|
95
|
+
activerecord-jdbcsqlite3-adapter
|
96
|
+
appraisal (~> 2.1.0)
|
97
|
+
aruba
|
98
|
+
bourne
|
99
|
+
cucumber (~> 1.3.15)
|
100
|
+
factory_girl!
|
101
|
+
jdbc-sqlite3
|
102
|
+
mocha (>= 0.12.8)
|
103
|
+
rspec (~> 3.0)
|
104
|
+
rspec-its (~> 1.0)
|
105
|
+
simplecov
|
106
|
+
sqlite3 (~> 1.3.10)
|
107
|
+
timecop
|
108
|
+
yard
|
109
|
+
|
110
|
+
BUNDLED WITH
|
111
|
+
1.13.6
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
6
|
+
gem "jdbc-sqlite3", :platforms => :jruby
|
7
|
+
gem "sqlite3", "~> 1.3.10", :platforms => :ruby
|
8
|
+
gem "activerecord", "~> 5.0.0"
|
9
|
+
|
10
|
+
gemspec :path => "../"
|
@@ -0,0 +1,110 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
factory_girl (4.8.0)
|
5
|
+
activesupport (>= 3.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (5.0.0)
|
11
|
+
activesupport (= 5.0.0)
|
12
|
+
activerecord (5.0.0)
|
13
|
+
activemodel (= 5.0.0)
|
14
|
+
activesupport (= 5.0.0)
|
15
|
+
arel (~> 7.0)
|
16
|
+
activesupport (5.0.0)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (~> 0.7)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
appraisal (2.1.0)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
thor (>= 0.14.0)
|
25
|
+
arel (7.0.0)
|
26
|
+
aruba (0.14.1)
|
27
|
+
childprocess (~> 0.5.6)
|
28
|
+
contracts (~> 0.9)
|
29
|
+
cucumber (>= 1.3.19)
|
30
|
+
ffi (~> 1.9.10)
|
31
|
+
rspec-expectations (>= 2.99)
|
32
|
+
thor (~> 0.19)
|
33
|
+
bourne (1.6.0)
|
34
|
+
mocha (~> 1.1)
|
35
|
+
builder (3.2.2)
|
36
|
+
childprocess (0.5.9)
|
37
|
+
ffi (~> 1.0, >= 1.0.11)
|
38
|
+
concurrent-ruby (1.0.2)
|
39
|
+
contracts (0.14.0)
|
40
|
+
cucumber (1.3.20)
|
41
|
+
builder (>= 2.1.2)
|
42
|
+
diff-lcs (>= 1.1.3)
|
43
|
+
gherkin (~> 2.12)
|
44
|
+
multi_json (>= 1.7.5, < 2.0)
|
45
|
+
multi_test (>= 0.1.2)
|
46
|
+
diff-lcs (1.2.5)
|
47
|
+
docile (1.1.5)
|
48
|
+
ffi (1.9.10)
|
49
|
+
gherkin (2.12.2)
|
50
|
+
multi_json (~> 1.3)
|
51
|
+
i18n (0.7.0)
|
52
|
+
json (1.8.3)
|
53
|
+
metaclass (0.0.4)
|
54
|
+
minitest (5.9.0)
|
55
|
+
mocha (1.1.0)
|
56
|
+
metaclass (~> 0.0.1)
|
57
|
+
multi_json (1.12.1)
|
58
|
+
multi_test (0.1.2)
|
59
|
+
rake (11.2.2)
|
60
|
+
rspec (3.4.0)
|
61
|
+
rspec-core (~> 3.4.0)
|
62
|
+
rspec-expectations (~> 3.4.0)
|
63
|
+
rspec-mocks (~> 3.4.0)
|
64
|
+
rspec-core (3.4.4)
|
65
|
+
rspec-support (~> 3.4.0)
|
66
|
+
rspec-expectations (3.4.0)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.4.0)
|
69
|
+
rspec-its (1.2.0)
|
70
|
+
rspec-core (>= 3.0.0)
|
71
|
+
rspec-expectations (>= 3.0.0)
|
72
|
+
rspec-mocks (3.4.1)
|
73
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
+
rspec-support (~> 3.4.0)
|
75
|
+
rspec-support (3.4.1)
|
76
|
+
simplecov (0.11.2)
|
77
|
+
docile (~> 1.1.0)
|
78
|
+
json (~> 1.8)
|
79
|
+
simplecov-html (~> 0.10.0)
|
80
|
+
simplecov-html (0.10.0)
|
81
|
+
sqlite3 (1.3.11)
|
82
|
+
thor (0.19.1)
|
83
|
+
thread_safe (0.3.5)
|
84
|
+
timecop (0.8.1)
|
85
|
+
tzinfo (1.2.2)
|
86
|
+
thread_safe (~> 0.1)
|
87
|
+
yard (0.8.7.6)
|
88
|
+
|
89
|
+
PLATFORMS
|
90
|
+
ruby
|
91
|
+
|
92
|
+
DEPENDENCIES
|
93
|
+
activerecord (~> 5.0.0)
|
94
|
+
activerecord-jdbcsqlite3-adapter
|
95
|
+
appraisal (~> 2.1.0)
|
96
|
+
aruba
|
97
|
+
bourne
|
98
|
+
cucumber (~> 1.3.15)
|
99
|
+
factory_girl!
|
100
|
+
jdbc-sqlite3
|
101
|
+
mocha (>= 0.12.8)
|
102
|
+
rspec (~> 3.0)
|
103
|
+
rspec-its (~> 1.0)
|
104
|
+
simplecov
|
105
|
+
sqlite3 (~> 1.3.10)
|
106
|
+
timecop
|
107
|
+
yard
|
108
|
+
|
109
|
+
BUNDLED WITH
|
110
|
+
1.13.6
|
data/lib/factory_bot.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
3
|
+
require 'active_support/deprecation'
|
4
|
+
require 'active_support/notifications'
|
5
|
+
|
6
|
+
require 'factory_bot/definition_hierarchy'
|
7
|
+
require 'factory_bot/configuration'
|
8
|
+
require 'factory_bot/errors'
|
9
|
+
require 'factory_bot/factory_runner'
|
10
|
+
require 'factory_bot/strategy_syntax_method_registrar'
|
11
|
+
require 'factory_bot/strategy_calculator'
|
12
|
+
require 'factory_bot/strategy/build'
|
13
|
+
require 'factory_bot/strategy/create'
|
14
|
+
require 'factory_bot/strategy/attributes_for'
|
15
|
+
require 'factory_bot/strategy/stub'
|
16
|
+
require 'factory_bot/strategy/null'
|
17
|
+
require 'factory_bot/registry'
|
18
|
+
require 'factory_bot/null_factory'
|
19
|
+
require 'factory_bot/null_object'
|
20
|
+
require 'factory_bot/evaluation'
|
21
|
+
require 'factory_bot/factory'
|
22
|
+
require 'factory_bot/attribute_assigner'
|
23
|
+
require 'factory_bot/evaluator'
|
24
|
+
require 'factory_bot/evaluator_class_definer'
|
25
|
+
require 'factory_bot/attribute'
|
26
|
+
require 'factory_bot/callback'
|
27
|
+
require 'factory_bot/callbacks_observer'
|
28
|
+
require 'factory_bot/declaration_list'
|
29
|
+
require 'factory_bot/declaration'
|
30
|
+
require 'factory_bot/sequence'
|
31
|
+
require 'factory_bot/attribute_list'
|
32
|
+
require 'factory_bot/trait'
|
33
|
+
require 'factory_bot/aliases'
|
34
|
+
require 'factory_bot/definition'
|
35
|
+
require 'factory_bot/definition_proxy'
|
36
|
+
require 'factory_bot/syntax'
|
37
|
+
require 'factory_bot/syntax_runner'
|
38
|
+
require 'factory_bot/find_definitions'
|
39
|
+
require 'factory_bot/reload'
|
40
|
+
require 'factory_bot/decorator'
|
41
|
+
require 'factory_bot/decorator/attribute_hash'
|
42
|
+
require 'factory_bot/decorator/class_key_hash'
|
43
|
+
require 'factory_bot/decorator/disallows_duplicates_registry'
|
44
|
+
require 'factory_bot/decorator/invocation_tracker'
|
45
|
+
require 'factory_bot/decorator/new_constructor'
|
46
|
+
require 'factory_bot/linter'
|
47
|
+
require 'factory_bot/version'
|
48
|
+
|
49
|
+
module FactoryBot
|
50
|
+
def self.configuration
|
51
|
+
@configuration ||= Configuration.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.reset_configuration
|
55
|
+
@configuration = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
# Look for errors in factories and (optionally) their traits.
|
59
|
+
# Parameters:
|
60
|
+
# factories - which factories to lint; omit for all factories
|
61
|
+
# options:
|
62
|
+
# traits : true - to lint traits as well as factories
|
63
|
+
def self.lint(*args)
|
64
|
+
options = args.extract_options!
|
65
|
+
factories_to_lint = args[0] || FactoryBot.factories
|
66
|
+
strategy = options[:traits] ? :factory_and_traits : :factory
|
67
|
+
Linter.new(factories_to_lint, strategy).lint!
|
68
|
+
end
|
69
|
+
|
70
|
+
class << self
|
71
|
+
delegate :factories,
|
72
|
+
:sequences,
|
73
|
+
:traits,
|
74
|
+
:callbacks,
|
75
|
+
:strategies,
|
76
|
+
:callback_names,
|
77
|
+
:to_create,
|
78
|
+
:skip_create,
|
79
|
+
:initialize_with,
|
80
|
+
:constructor,
|
81
|
+
:duplicate_attribute_assignment_from_initialize_with,
|
82
|
+
:duplicate_attribute_assignment_from_initialize_with=,
|
83
|
+
:allow_class_lookup,
|
84
|
+
:allow_class_lookup=,
|
85
|
+
:use_parent_strategy,
|
86
|
+
:use_parent_strategy=,
|
87
|
+
to: :configuration
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.register_factory(factory)
|
91
|
+
factory.names.each do |name|
|
92
|
+
factories.register(name, factory)
|
93
|
+
end
|
94
|
+
factory
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.factory_by_name(name)
|
98
|
+
factories.find(name)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.register_sequence(sequence)
|
102
|
+
sequence.names.each do |name|
|
103
|
+
sequences.register(name, sequence)
|
104
|
+
end
|
105
|
+
sequence
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.sequence_by_name(name)
|
109
|
+
sequences.find(name)
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.register_trait(trait)
|
113
|
+
trait.names.each do |name|
|
114
|
+
traits.register(name, trait)
|
115
|
+
end
|
116
|
+
trait
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.trait_by_name(name)
|
120
|
+
traits.find(name)
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.register_strategy(strategy_name, strategy_class)
|
124
|
+
strategies.register(strategy_name, strategy_class)
|
125
|
+
StrategySyntaxMethodRegistrar.new(strategy_name).define_strategy_methods
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.strategy_by_name(name)
|
129
|
+
strategies.find(name)
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.register_default_strategies
|
133
|
+
register_strategy(:build, FactoryBot::Strategy::Build)
|
134
|
+
register_strategy(:create, FactoryBot::Strategy::Create)
|
135
|
+
register_strategy(:attributes_for, FactoryBot::Strategy::AttributesFor)
|
136
|
+
register_strategy(:build_stubbed, FactoryBot::Strategy::Stub)
|
137
|
+
register_strategy(:null, FactoryBot::Strategy::Null)
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.register_default_callbacks
|
141
|
+
register_callback(:after_build)
|
142
|
+
register_callback(:after_create)
|
143
|
+
register_callback(:after_stub)
|
144
|
+
register_callback(:before_create)
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.register_callback(name)
|
148
|
+
name = name.to_sym
|
149
|
+
callback_names << name
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
FactoryBot.register_default_strategies
|
154
|
+
FactoryBot.register_default_callbacks
|