factory_bot_rails 4.10.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/NEWS.md +88 -0
- data/README.md +116 -31
- data/lib/factory_bot_rails.rb +1 -1
- data/lib/factory_bot_rails/definition_file_paths.rb +27 -0
- data/lib/factory_bot_rails/generator.rb +9 -15
- data/lib/factory_bot_rails/generators/non_rspec_generator.rb +5 -1
- data/lib/factory_bot_rails/generators/rspec_generator.rb +9 -2
- data/lib/factory_bot_rails/railtie.rb +19 -13
- data/lib/factory_bot_rails/reloader.rb +40 -0
- data/lib/generators/factory_bot.rb +16 -3
- data/lib/generators/factory_bot/model/model_generator.rb +14 -21
- data/lib/generators/factory_bot/model/templates/factories.erb +3 -0
- metadata +22 -43
- data/Appraisals +0 -21
- data/Gemfile +0 -20
- data/Gemfile.lock +0 -144
- data/NEWS +0 -30
- data/Rakefile +0 -24
- data/bin/setup +0 -16
- data/factory_bot_rails.gemspec +0 -20
- data/factory_girl_rails.gemspec +0 -20
- data/features/fixture_replacement_config.feature +0 -132
- data/features/generators.feature +0 -54
- data/features/load_definitions.feature +0 -85
- data/features/step_definitions/appraisal.rb +0 -5
- data/features/step_definitions/rails_steps.rb +0 -42
- data/features/support/env.rb +0 -21
- data/gemfiles/rails3.2.gemfile +0 -22
- data/gemfiles/rails3.2.gemfile.lock +0 -186
- data/gemfiles/rails4.1.gemfile +0 -23
- data/gemfiles/rails4.1.gemfile.lock +0 -181
- data/gemfiles/rails4.2.gemfile +0 -21
- data/gemfiles/rails4.2.gemfile.lock +0 -189
- data/gemfiles/rails5.0.gemfile +0 -22
- data/gemfiles/rails5.0.gemfile.lock +0 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c54ddb791dcf6eccf0e7ffe73cad7294a72b7d84a7c9b1c8be1b858e6ff0f209
|
4
|
+
data.tar.gz: 5c5b2bd9f09413c8a2cbbf5bba8c46f927c717de9caa798f3dd161cc464961cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fa8bcf45b0a9ac5bf032676109d341b7ec773479f53e71e3606a39b52a307b60c49d31ada524f25e77822a97724849a475afb5da0fffcefe7a91bb23d01f5cf
|
7
|
+
data.tar.gz: 7c78b5c2c241080b9bdbc59f402cb68034df1efe26ede947cc620118b67389272c14f063442946a1f5ea28c64204c273791c276c7b3c363b4cfa3b253bfdf611
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2008-
|
1
|
+
Copyright (c) 2008-2020 Joe Ferris and thoughtbot, inc.
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
data/NEWS.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
factory\_bot\_rails versioning is synced with factory\_bot releases. For this reason
|
2
|
+
there might not be any notable changes in new versions of this project.
|
3
|
+
|
4
|
+
# NEWS
|
5
|
+
|
6
|
+
## 6.1.0 (July 8, 2020)
|
7
|
+
|
8
|
+
* Changed: factory\_bot dependency to ~> 6.1.0
|
9
|
+
|
10
|
+
## 6.0.0 (June 18, 2020)
|
11
|
+
|
12
|
+
* Fixed: generate a plural factory name when the --force-plural flag is provided
|
13
|
+
* Changed: factory\_bot dependency to ~> 6.0.0
|
14
|
+
* Removed: `"factory_bot.register_reloader"` initializer, now registering the
|
15
|
+
reloader after application initialization
|
16
|
+
* Removed: support for EOL versions of Ruby (2.3, 2.4) and Rails (4.2)
|
17
|
+
|
18
|
+
## 5.1.1 (September 24, 2019)
|
19
|
+
|
20
|
+
* Fixed: Ensure definitions do not load before I18n is initialized
|
21
|
+
|
22
|
+
## 5.1.0 (September 24, 2019)
|
23
|
+
|
24
|
+
* Changed: factory\_bot dependency to ~> 5.1.0
|
25
|
+
|
26
|
+
## 5.0.2 (April 14, 2019)
|
27
|
+
|
28
|
+
* Bugfix: Reload factory\_bot whenever the application changes to avoid holding
|
29
|
+
onto stale object references
|
30
|
+
* Bugfix: Avoid watching project root when no factory definitions exist
|
31
|
+
|
32
|
+
## 5.0.1 (February 9, 2019)
|
33
|
+
|
34
|
+
* Bugfix: Avoid watching files and directories that don't exist (to avoid a
|
35
|
+
file watching bug in Rails https://github.com/rails/rails/issues/32700)
|
36
|
+
|
37
|
+
## 5.0.0 (February 1, 2019)
|
38
|
+
|
39
|
+
* Added: calling reload! in the Rails console will reload any factory definition files that have changed
|
40
|
+
* Added: support for custom generator templates
|
41
|
+
* Added: `definition_file_paths` configuration option, making it easier to place factories in custom locations
|
42
|
+
* Changed: namespaced models are now generated inside a directory matching the namespace
|
43
|
+
* Changed: added newline between factories generated into the same file
|
44
|
+
* Removed: support for EOL version of Ruby and Rails
|
45
|
+
|
46
|
+
## 4.11.1 (September 7, 2018)
|
47
|
+
|
48
|
+
* Update generator to use dynamic attributes instead of deprecated static attributes
|
49
|
+
|
50
|
+
## 4.11.0 (August 16, 2018)
|
51
|
+
|
52
|
+
* No notable changes
|
53
|
+
|
54
|
+
## 4.10.0 (May 25, 2018)
|
55
|
+
|
56
|
+
* No notable changes
|
57
|
+
|
58
|
+
## 4.8.2 (October 20, 2017)
|
59
|
+
|
60
|
+
* Rename factory\_girl\_rails to factory\_bot\_rails
|
61
|
+
|
62
|
+
## 4.7.0 (April 1, 2016)
|
63
|
+
|
64
|
+
* No notable changes
|
65
|
+
|
66
|
+
## 4.6.0 (February 1, 2016)
|
67
|
+
|
68
|
+
* No notable changes
|
69
|
+
|
70
|
+
## 4.5.0 (October 17, 2014)
|
71
|
+
|
72
|
+
* Improved README
|
73
|
+
|
74
|
+
## 4.4.1 (February 26, 2014)
|
75
|
+
|
76
|
+
* Support Spring
|
77
|
+
|
78
|
+
## 4.2.1 (February 8, 2013)
|
79
|
+
|
80
|
+
* Fix bug when configuring FG and RSpec fixture directory
|
81
|
+
* Remove debugging
|
82
|
+
* Require factory\_girl\_rails explicitly in generator
|
83
|
+
|
84
|
+
## 4.2.0 (January 25, 2013)
|
85
|
+
|
86
|
+
* Add appraisal and get test suite working reliably with turn gem
|
87
|
+
* Support MiniTest
|
88
|
+
* Allow a custom directory for factories to be specified
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# factory_bot_rails [![Build Status][ci-image]][ci] [![Code Climate][grade-image]][grade]
|
1
|
+
# factory_bot_rails [![Build Status][ci-image]][ci] [![Code Climate][grade-image]][grade] [![Gem Version][version-image]][version]
|
2
2
|
|
3
3
|
[factory_bot][fb] is a fixtures replacement with a straightforward definition
|
4
4
|
syntax, support for multiple build strategies (saved instances, unsaved
|
@@ -12,9 +12,7 @@ Check out the [guide](https://github.com/thoughtbot/factory_bot/blob/4-9-0-stabl
|
|
12
12
|
|
13
13
|
## Rails
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
Currently, automatic factory definition loading is the only Rails-specific feature.
|
15
|
+
factory\_bot\_rails provides Rails integration for [factory_bot][fb].
|
18
16
|
|
19
17
|
Supported Rails versions are listed in [`Appraisals`](Appraisals). Supported
|
20
18
|
Ruby versions are listed in [`.travis.yml`](.travis.yml).
|
@@ -29,7 +27,7 @@ Gem:
|
|
29
27
|
|
30
28
|
## Configuration
|
31
29
|
|
32
|
-
Add `factory_bot_rails` to your Gemfile:
|
30
|
+
Add `factory_bot_rails` to your Gemfile in both the test and development groups:
|
33
31
|
|
34
32
|
```ruby
|
35
33
|
group :development, :test do
|
@@ -37,9 +35,61 @@ group :development, :test do
|
|
37
35
|
end
|
38
36
|
```
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
You may want to configure your test suite to include factory\_bot methods; see
|
39
|
+
[configuration](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#configure-your-test-suite).
|
40
|
+
|
41
|
+
### Automatic Factory Definition Loading
|
42
|
+
|
43
|
+
By default, factory\_bot\_rails will automatically load factories
|
44
|
+
defined in the following locations,
|
45
|
+
relative to the root of the Rails project:
|
46
|
+
|
47
|
+
```
|
48
|
+
factories.rb
|
49
|
+
test/factories.rb
|
50
|
+
spec/factories.rb
|
51
|
+
factories/*.rb
|
52
|
+
test/factories/*.rb
|
53
|
+
spec/factories/*.rb
|
54
|
+
```
|
55
|
+
|
56
|
+
You can configure by adding the following to `config/application.rb` or the
|
57
|
+
appropriate environment configuration in `config/environments`:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
config.factory_bot.definition_file_paths = ["custom/factories"]
|
61
|
+
```
|
62
|
+
|
63
|
+
This will cause factory\_bot\_rails to automatically load factories in
|
64
|
+
`custom/factories.rb` and `custom/factories/*.rb`.
|
65
|
+
|
66
|
+
It is possible to use this setting to share factories from a gem:
|
67
|
+
|
68
|
+
```rb
|
69
|
+
begin
|
70
|
+
require 'factory_bot_rails'
|
71
|
+
rescue LoadError
|
72
|
+
end
|
73
|
+
|
74
|
+
class MyEngine < ::Rails::Engine
|
75
|
+
config.factory_bot.definition_file_paths +=
|
76
|
+
[File.expand_path('../factories', __FILE__)] if defined?(FactoryBotRails)
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
You can also disable automatic factory definition loading entirely by
|
81
|
+
using an empty array:
|
82
|
+
|
83
|
+
```rb
|
84
|
+
config.factory_bot.definition_file_paths = []
|
85
|
+
```
|
86
|
+
|
87
|
+
### Generators
|
88
|
+
|
89
|
+
Including factory\_bot\_rails in the development group of your Gemfile
|
90
|
+
will cause Rails to generate factories instead of fixtures.
|
91
|
+
If you want to disable this feature, you can either move factory\_bot\_rails out
|
92
|
+
of the development group of your Gemfile, or add the following configuration:
|
43
93
|
|
44
94
|
```ruby
|
45
95
|
config.generators do |g|
|
@@ -47,8 +97,15 @@ config.generators do |g|
|
|
47
97
|
end
|
48
98
|
```
|
49
99
|
|
50
|
-
|
51
|
-
`
|
100
|
+
If fixture replacement is enabled and you already have a `test/factories.rb`
|
101
|
+
file (or `spec/factories.rb` if using rspec_rails), generated factories will be
|
102
|
+
inserted at the top of the existing file.
|
103
|
+
Otherwise, factories will be generated in the
|
104
|
+
`test/factories` directory (`spec/factories` if using rspec_rails),
|
105
|
+
in a file matching the name of the table (e.g. `test/factories/users.rb`).
|
106
|
+
|
107
|
+
To generate factories in a different directory, you can use the following
|
108
|
+
configuration:
|
52
109
|
|
53
110
|
```ruby
|
54
111
|
config.generators do |g|
|
@@ -56,43 +113,71 @@ config.generators do |g|
|
|
56
113
|
end
|
57
114
|
```
|
58
115
|
|
59
|
-
|
60
|
-
|
61
|
-
|
116
|
+
Note that factory\_bot\_rails will not automatically load files in custom
|
117
|
+
locations unless you add them to `config.factory_bot.definition_file_paths` as
|
118
|
+
well.
|
62
119
|
|
63
|
-
|
64
|
-
|
120
|
+
The suffix option allows you to customize the name of the generated file with a
|
121
|
+
suffix:
|
65
122
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
123
|
+
```ruby
|
124
|
+
config.generators do |g|
|
125
|
+
g.factory_bot suffix: "factory"
|
126
|
+
end
|
127
|
+
```
|
70
128
|
|
71
|
-
|
72
|
-
|
129
|
+
This will generate `test/factories/users_factory.rb` instead of
|
130
|
+
`test/factories/users.rb`.
|
73
131
|
|
74
|
-
|
132
|
+
For even more customization, use the `filename_proc` option:
|
75
133
|
|
76
|
-
|
134
|
+
```ruby
|
135
|
+
config.generators do |g|
|
136
|
+
g.factory_bot filename_proc: ->(table_name) { "prefix_#{table_name}_suffix" }
|
137
|
+
end
|
138
|
+
```
|
77
139
|
|
78
|
-
|
140
|
+
To override the [default factory template][], define your own template in
|
141
|
+
`lib/templates/factory_bot/model/factories.erb`. This template will have
|
142
|
+
access to any methods available in `FactoryBot::Generators::ModelGenerator`.
|
143
|
+
Note that factory\_bot\_rails will only use this custom template if you are
|
144
|
+
generating each factory in a separate file; it will have no effect if you are
|
145
|
+
generating all of your factories in `test/factories.rb` or `spec/factories.rb`.
|
79
146
|
|
80
|
-
[
|
147
|
+
[default factory template]: https://github.com/thoughtbot/factory_bot_rails/tree/master/lib/generators/factory_bot/model/templates/factories.erb
|
81
148
|
|
82
|
-
|
149
|
+
## Contributing
|
83
150
|
|
84
|
-
|
151
|
+
Please see [CONTRIBUTING.md](CONTRIBUTING.md).
|
85
152
|
|
86
|
-
|
153
|
+
factory_bot_rails was originally written by Joe Ferris and is maintained by thoughtbot. Many improvements and bugfixes were contributed by the [open source
|
154
|
+
community](https://github.com/thoughtbot/factory_bot_rails/graphs/contributors).
|
87
155
|
|
88
156
|
## License
|
89
157
|
|
90
|
-
factory_bot_rails is Copyright © 2008-
|
158
|
+
factory_bot_rails is Copyright © 2008-2020 Joe Ferris and thoughtbot. It is free
|
91
159
|
software, and may be redistributed under the terms specified in the
|
92
160
|
[LICENSE](LICENSE) file.
|
93
161
|
|
162
|
+
## About thoughtbot
|
163
|
+
|
164
|
+

|
165
|
+
|
166
|
+
factory_bot_rails is maintained and funded by thoughtbot, inc.
|
167
|
+
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
168
|
+
|
169
|
+
We are passionate about open source software.
|
170
|
+
See [our other projects][community].
|
171
|
+
We are [available for hire][hire].
|
172
|
+
|
94
173
|
[fb]: https://github.com/thoughtbot/factory_bot
|
95
174
|
[ci]: http://travis-ci.org/thoughtbot/factory_bot_rails?branch=master
|
96
|
-
[ci-image]: https://secure.travis-ci.org/thoughtbot/factory_bot_rails.
|
175
|
+
[ci-image]: https://secure.travis-ci.org/thoughtbot/factory_bot_rails.svg
|
97
176
|
[grade]: https://codeclimate.com/github/thoughtbot/factory_bot_rails
|
98
|
-
[grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot_rails.
|
177
|
+
[grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot_rails.svg
|
178
|
+
[community]: https://thoughtbot.com/community?utm_source=github
|
179
|
+
[hire]: https://thoughtbot.com/hire-us?utm_source=github
|
180
|
+
[version-image]: https://badge.fury.io/rb/factory_bot_rails.svg
|
181
|
+
[version]: https://badge.fury.io/rb/factory_bot_rails
|
182
|
+
[hound-image]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
|
183
|
+
[hound]: https://houndci.com
|
data/lib/factory_bot_rails.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FactoryBotRails
|
4
|
+
class DefinitionFilePaths
|
5
|
+
def initialize(definition_file_paths)
|
6
|
+
@files = []
|
7
|
+
@directories = {}
|
8
|
+
|
9
|
+
definition_file_paths.each do |path|
|
10
|
+
@files << "#{path}.rb"
|
11
|
+
@directories[path.to_s] = [:rb]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def directories
|
16
|
+
@directories.select { |path| Dir.exist?(path) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def files
|
20
|
+
@files.select { |file| File.exist?(file) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def any?
|
24
|
+
directories.any? || files.any?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,15 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "factory_bot_rails/generators/rspec_generator"
|
2
|
+
require "factory_bot_rails/generators/non_rspec_generator"
|
3
|
+
require "factory_bot_rails/generators/null_generator"
|
4
4
|
|
5
5
|
module FactoryBotRails
|
6
6
|
class Generator
|
7
7
|
def initialize(config)
|
8
|
-
@generators =
|
9
|
-
config.app_generators
|
10
|
-
else
|
11
|
-
config.generators
|
12
|
-
end
|
8
|
+
@generators = config.app_generators
|
13
9
|
end
|
14
10
|
|
15
11
|
def run
|
@@ -17,14 +13,12 @@ module FactoryBotRails
|
|
17
13
|
end
|
18
14
|
|
19
15
|
def generator
|
20
|
-
if factory_bot_disabled?
|
21
|
-
|
16
|
+
return Generators::NullGenerator if factory_bot_disabled?
|
17
|
+
|
18
|
+
if test_framework == :rspec
|
19
|
+
Generators::RSpecGenerator
|
22
20
|
else
|
23
|
-
|
24
|
-
Generators::RSpecGenerator
|
25
|
-
else
|
26
|
-
Generators::NonRSpecGenerator
|
27
|
-
end
|
21
|
+
Generators::NonRSpecGenerator
|
28
22
|
end
|
29
23
|
end
|
30
24
|
|
@@ -6,7 +6,11 @@ module FactoryBotRails
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def run
|
9
|
-
@generators.test_framework
|
9
|
+
@generators.test_framework(
|
10
|
+
test_framework,
|
11
|
+
fixture: false,
|
12
|
+
fixture_replacement: :factory_bot
|
13
|
+
)
|
10
14
|
end
|
11
15
|
|
12
16
|
private
|
@@ -6,7 +6,10 @@ module FactoryBotRails
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def run
|
9
|
-
@generators.fixture_replacement
|
9
|
+
@generators.fixture_replacement(
|
10
|
+
fixture_replacement_setting,
|
11
|
+
dir: factory_bot_directory
|
12
|
+
)
|
10
13
|
end
|
11
14
|
|
12
15
|
private
|
@@ -16,7 +19,11 @@ module FactoryBotRails
|
|
16
19
|
end
|
17
20
|
|
18
21
|
def factory_bot_directory
|
19
|
-
|
22
|
+
factory_bot_options.fetch(:dir, "spec/factories")
|
23
|
+
end
|
24
|
+
|
25
|
+
def factory_bot_options
|
26
|
+
@generators.options.fetch(:factory_bot, {})
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
@@ -1,27 +1,33 @@
|
|
1
|
-
|
2
|
-
require 'factory_bot_rails/generator'
|
3
|
-
require 'rails'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
3
|
+
require "factory_bot"
|
4
|
+
require "factory_bot_rails/generator"
|
5
|
+
require "factory_bot_rails/reloader"
|
6
|
+
require "rails"
|
7
|
+
|
8
|
+
module FactoryBotRails
|
6
9
|
class Railtie < Rails::Railtie
|
10
|
+
config.factory_bot = ActiveSupport::OrderedOptions.new
|
11
|
+
config.factory_bot.definition_file_paths = FactoryBot.definition_file_paths
|
7
12
|
|
8
13
|
initializer "factory_bot.set_fixture_replacement" do
|
9
|
-
|
14
|
+
Generator.new(config).run
|
10
15
|
end
|
11
16
|
|
12
17
|
initializer "factory_bot.set_factory_paths" do
|
13
|
-
FactoryBot.definition_file_paths =
|
14
|
-
Rails.root.join('factories'),
|
15
|
-
Rails.root.join('test', 'factories'),
|
16
|
-
Rails.root.join('spec', 'factories')
|
17
|
-
]
|
18
|
+
FactoryBot.definition_file_paths = definition_file_paths
|
18
19
|
end
|
19
20
|
|
20
|
-
config.after_initialize do
|
21
|
+
config.after_initialize do |app|
|
21
22
|
FactoryBot.find_definitions
|
23
|
+
Reloader.new(app).run
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
22
27
|
|
23
|
-
|
24
|
-
|
28
|
+
def definition_file_paths
|
29
|
+
config.factory_bot.definition_file_paths.map do |path|
|
30
|
+
Rails.root.join(path)
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|