Replace 'girl' with 'bot' everywhere (#1051)
Also: add a deprecation warning to factory_girl, asking users to switch to factory_bot https://github.com/thoughtbot/factory_girl/issues/921
This commit is contained in:
parent
f48b90a95a
commit
c716ce01b4
|
@ -1,6 +1,7 @@
|
|||
*.swp
|
||||
test.db
|
||||
factory_girl-*.gem
|
||||
factory_bot-*.gem
|
||||
doc
|
||||
.yardoc
|
||||
coverage
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Contributing to Factory Girl
|
||||
# Contributing to Factory Bot
|
||||
|
||||
We love pull requests from everyone. By participating in this project, you
|
||||
agree to abide by the thoughtbot [code of conduct].
|
||||
|
@ -17,7 +17,7 @@ Here are some ways *you* can contribute:
|
|||
* by closing [issues][]
|
||||
* by reviewing patches
|
||||
|
||||
[issues]: https://github.com/thoughtbot/factory_girl/issues
|
||||
[issues]: https://github.com/thoughtbot/factory_bot/issues
|
||||
|
||||
## Submitting an Issue
|
||||
|
||||
|
@ -52,7 +52,7 @@ already been submitted.
|
|||
asking for help. We love helping!
|
||||
* Please don't update the Gem version.
|
||||
|
||||
[repo]: https://github.com/thoughtbot/factory_girl/tree/master
|
||||
[repo]: https://github.com/thoughtbot/factory_bot/tree/master
|
||||
[fork]: https://help.github.com/articles/fork-a-repo/
|
||||
[branch]: https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
|
||||
[pr]: https://help.github.com/articles/using-pull-requests/
|
||||
|
|
|
@ -4,19 +4,19 @@ Getting Started
|
|||
Update Your Gemfile
|
||||
-------------------
|
||||
|
||||
If you're using Rails, you'll need to change the required version of `factory_girl_rails`:
|
||||
If you're using Rails, you'll need to change the required version of `factory_bot_rails`:
|
||||
|
||||
```ruby
|
||||
gem "factory_girl_rails", "~> 4.0"
|
||||
gem "factory_bot_rails", "~> 4.0"
|
||||
```
|
||||
|
||||
If you're *not* using Rails, you'll just have to change the required version of `factory_girl`:
|
||||
If you're *not* using Rails, you'll just have to change the required version of `factory_bot`:
|
||||
|
||||
```ruby
|
||||
gem "factory_girl", "~> 4.0"
|
||||
gem "factory_bot", "~> 4.0"
|
||||
```
|
||||
|
||||
JRuby users: factory_girl works with JRuby starting with 1.6.7.2 (latest stable, as per July 2012).
|
||||
JRuby users: factory_bot works with JRuby starting with 1.6.7.2 (latest stable, as per July 2012).
|
||||
JRuby has to be used in 1.9 mode, for that, use JRUBY_OPTS environment variable:
|
||||
|
||||
```bash
|
||||
|
@ -31,17 +31,17 @@ Configure your test suite
|
|||
# RSpec
|
||||
|
||||
```ruby
|
||||
# spec/support/factory_girl.rb
|
||||
# spec/support/factory_bot.rb
|
||||
RSpec.configure do |config|
|
||||
config.include FactoryGirl::Syntax::Methods
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
end
|
||||
|
||||
# RSpec without Rails
|
||||
RSpec.configure do |config|
|
||||
config.include FactoryGirl::Syntax::Methods
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
|
||||
config.before(:suite) do
|
||||
FactoryGirl.find_definitions
|
||||
FactoryBot.find_definitions
|
||||
end
|
||||
end
|
||||
```
|
||||
|
@ -49,14 +49,14 @@ end
|
|||
Remember to require the above file in your rails_helper since the support folder isn't eagerly loaded
|
||||
|
||||
```ruby
|
||||
require 'support/factory_girl'
|
||||
require 'support/factory_bot'
|
||||
```
|
||||
|
||||
# Test::Unit
|
||||
|
||||
```ruby
|
||||
class Test::Unit::TestCase
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -64,14 +64,14 @@ end
|
|||
|
||||
```ruby
|
||||
# env.rb (Rails example location - RAILS_ROOT/features/support/env.rb)
|
||||
World(FactoryGirl::Syntax::Methods)
|
||||
World(FactoryBot::Syntax::Methods)
|
||||
```
|
||||
|
||||
# Spinach
|
||||
|
||||
```ruby
|
||||
class Spinach::FeatureSteps
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -79,7 +79,7 @@ end
|
|||
|
||||
```ruby
|
||||
class Minitest::Unit::TestCase
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -87,7 +87,7 @@ end
|
|||
|
||||
```ruby
|
||||
class Minitest::Spec
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -95,11 +95,11 @@ end
|
|||
|
||||
```ruby
|
||||
class ActiveSupport::TestCase
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
end
|
||||
```
|
||||
|
||||
If you do not include `FactoryGirl::Syntax::Methods` in your test suite, then all factory_girl methods will need to be prefaced with `FactoryGirl`.
|
||||
If you do not include `FactoryBot::Syntax::Methods` in your test suite, then all factory_bot methods will need to be prefaced with `FactoryBot`.
|
||||
|
||||
Defining factories
|
||||
------------------
|
||||
|
@ -108,7 +108,7 @@ Each factory has a name and a set of attributes. The name is used to guess the c
|
|||
|
||||
```ruby
|
||||
# This will guess the User class
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
first_name "John"
|
||||
last_name "Doe"
|
||||
|
@ -129,7 +129,7 @@ It is highly recommended that you have one factory for each class that provides
|
|||
Attempting to define multiple factories with the same name will raise an error.
|
||||
|
||||
Factories can be defined anywhere, but will be automatically loaded after
|
||||
calling `FactoryGirl.find_definitions` if factories are defined in files at the
|
||||
calling `FactoryBot.find_definitions` if factories are defined in files at the
|
||||
following locations:
|
||||
|
||||
test/factories.rb
|
||||
|
@ -140,7 +140,7 @@ following locations:
|
|||
Using factories
|
||||
---------------
|
||||
|
||||
factory\_girl supports several different build strategies: build, create, attributes\_for and build\_stubbed:
|
||||
factory\_bot supports several different build strategies: build, create, attributes\_for and build\_stubbed:
|
||||
|
||||
```ruby
|
||||
# Returns a User instance that's not saved
|
||||
|
@ -198,7 +198,7 @@ end
|
|||
|
||||
Aliases
|
||||
-------
|
||||
factory_girl allows you to define aliases to existing factories to make them easier to re-use. This could come in handy when, for example, your Post object has an author attribute that actually refers to an instance of a User class. While normally factory_girl can infer the factory name from the association name, in this case it will look for a author factory in vain. So, alias your user factory so it can be used under alias names.
|
||||
factory_bot allows you to define aliases to existing factories to make them easier to re-use. This could come in handy when, for example, your Post object has an author attribute that actually refers to an instance of a User class. While normally factory_bot can infer the factory name from the association name, in this case it will look for a author factory in vain. So, alias your user factory so it can be used under alias names.
|
||||
|
||||
```ruby
|
||||
factory :user, aliases: [:author, :commenter] do
|
||||
|
@ -268,8 +268,8 @@ Static and dynamic attributes can be created as transient attributes. Transient
|
|||
attributes will be ignored within attributes\_for and won't be set on the model,
|
||||
even if the attribute exists or you attempt to override it.
|
||||
|
||||
Within factory_girl's dynamic attributes, you can access transient attributes as
|
||||
you would expect. If you need to access the evaluator in a factory_girl callback,
|
||||
Within factory_bot's dynamic attributes, you can access transient attributes as
|
||||
you would expect. If you need to access the evaluator in a factory_bot callback,
|
||||
you'll need to declare a second block argument (for the evaluator) and access
|
||||
transient attributes from there.
|
||||
|
||||
|
@ -388,7 +388,7 @@ depending on the amount of flexibility desired, but here's a surefire example
|
|||
of generating associated data.
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
|
||||
# post factory with a `belongs_to` association for the user
|
||||
factory :post do
|
||||
|
@ -437,7 +437,7 @@ Here's an example with two models that are related via
|
|||
`has_and_belongs_to_many`:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
|
||||
# language factory with a `belongs_to` association for the profile
|
||||
factory :language do
|
||||
|
@ -489,7 +489,7 @@ definition block, and values in a sequence are generated by calling
|
|||
|
||||
```ruby
|
||||
# Defines a new sequence
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
sequence :email do |n|
|
||||
"person#{n}@example.com"
|
||||
end
|
||||
|
@ -670,7 +670,7 @@ factory :user do
|
|||
end
|
||||
```
|
||||
|
||||
Traits can also be passed in as a list of symbols when you construct an instance from factory_girl.
|
||||
Traits can also be passed in as a list of symbols when you construct an instance from factory_bot.
|
||||
|
||||
```ruby
|
||||
factory :user do
|
||||
|
@ -785,12 +785,12 @@ create :invoice, :with_amount, amount: 2
|
|||
Callbacks
|
||||
---------
|
||||
|
||||
factory\_girl makes available four callbacks for injecting some code:
|
||||
factory\_bot makes available four callbacks for injecting some code:
|
||||
|
||||
* after(:build) - called after a factory is built (via `FactoryGirl.build`, `FactoryGirl.create`)
|
||||
* before(:create) - called before a factory is saved (via `FactoryGirl.create`)
|
||||
* after(:create) - called after a factory is saved (via `FactoryGirl.create`)
|
||||
* after(:stub) - called after a factory is stubbed (via `FactoryGirl.build_stubbed`)
|
||||
* after(:build) - called after a factory is built (via `FactoryBot.build`, `FactoryBot.create`)
|
||||
* before(:create) - called before a factory is saved (via `FactoryBot.create`)
|
||||
* after(:create) - called after a factory is saved (via `FactoryBot.create`)
|
||||
* after(:stub) - called after a factory is stubbed (via `FactoryBot.build_stubbed`)
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -836,10 +836,10 @@ end
|
|||
```
|
||||
|
||||
To override callbacks for all factories, define them within the
|
||||
`FactoryGirl.define` block:
|
||||
`FactoryBot.define` block:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
after(:build) { |object| puts "Built #{object}" }
|
||||
after(:create) { |object| AuditLog.create(attrs: object.attributes) }
|
||||
|
||||
|
@ -860,7 +860,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# spec/factories.rb
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
after :create, &:confirm!
|
||||
end
|
||||
|
@ -878,7 +878,7 @@ modify that factory instead of creating a child factory and adding attributes th
|
|||
If a gem were to give you a User factory:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
full_name "John Doe"
|
||||
sequence(:username) { |n| "user#{n}" }
|
||||
|
@ -890,7 +890,7 @@ end
|
|||
Instead of creating a child factory that added additional attributes:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :application_user, parent: :user do
|
||||
full_name "Jane Doe"
|
||||
date_of_birth { 21.years.ago }
|
||||
|
@ -903,7 +903,7 @@ end
|
|||
You could modify that factory instead.
|
||||
|
||||
```ruby
|
||||
FactoryGirl.modify do
|
||||
FactoryBot.modify do
|
||||
factory :user do
|
||||
full_name "Jane Doe"
|
||||
date_of_birth { 21.years.ago }
|
||||
|
@ -915,7 +915,7 @@ end
|
|||
|
||||
When modifying a factory, you can change any of the attributes you want (aside from callbacks).
|
||||
|
||||
`FactoryGirl.modify` must be called outside of a `FactoryGirl.define` block as it operates on factories differently.
|
||||
`FactoryBot.modify` must be called outside of a `FactoryBot.define` block as it operates on factories differently.
|
||||
|
||||
A caveat: you can only modify factories (not sequences or traits) and callbacks *still compound as they normally would*. So, if
|
||||
the factory you're modifying defines an `after(:create)` callback, you defining an `after(:create)` won't override it, it'll just get run after the first callback.
|
||||
|
@ -959,18 +959,18 @@ users_attrs = attributes_for_list(:user, 25) # array of attribute hashes
|
|||
Linting Factories
|
||||
-----------------
|
||||
|
||||
factory_girl allows for linting known factories:
|
||||
factory_bot allows for linting known factories:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.lint
|
||||
FactoryBot.lint
|
||||
```
|
||||
|
||||
`FactoryGirl.lint` creates each factory and catches any exceptions raised
|
||||
during the creation process. `FactoryGirl::InvalidFactoryError` is raised with
|
||||
`FactoryBot.lint` creates each factory and catches any exceptions raised
|
||||
during the creation process. `FactoryBot::InvalidFactoryError` is raised with
|
||||
a list of factories (and corresponding exceptions) for factories which could
|
||||
not be created.
|
||||
|
||||
Recommended usage of `FactoryGirl.lint`
|
||||
Recommended usage of `FactoryBot.lint`
|
||||
is to run this in a task
|
||||
before your test suite is executed.
|
||||
Running it in a `before(:suite)`,
|
||||
|
@ -981,23 +981,23 @@ when running single tests.
|
|||
Example Rake task:
|
||||
|
||||
```ruby
|
||||
# lib/tasks/factory_girl.rake
|
||||
namespace :factory_girl do
|
||||
desc "Verify that all FactoryGirl factories are valid"
|
||||
# lib/tasks/factory_bot.rake
|
||||
namespace :factory_bot do
|
||||
desc "Verify that all FactoryBot factories are valid"
|
||||
task lint: :environment do
|
||||
if Rails.env.test?
|
||||
DatabaseCleaner.cleaning do
|
||||
FactoryGirl.lint
|
||||
FactoryBot.lint
|
||||
end
|
||||
else
|
||||
system("bundle exec rake factory_girl:lint RAILS_ENV='test'")
|
||||
system("bundle exec rake factory_bot:lint RAILS_ENV='test'")
|
||||
exit $?.exitstatus
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
After calling `FactoryGirl.lint`, you'll likely want to clear out the
|
||||
After calling `FactoryBot.lint`, you'll likely want to clear out the
|
||||
database, as records will most likely be created. The provided example above
|
||||
uses the database_cleaner gem to clear out the database; be sure to add the
|
||||
gem to your Gemfile under the appropriate groups.
|
||||
|
@ -1005,11 +1005,11 @@ gem to your Gemfile under the appropriate groups.
|
|||
You can lint factories selectively by passing only factories you want linted:
|
||||
|
||||
```ruby
|
||||
factories_to_lint = FactoryGirl.factories.reject do |factory|
|
||||
factories_to_lint = FactoryBot.factories.reject do |factory|
|
||||
factory.name =~ /^old_/
|
||||
end
|
||||
|
||||
FactoryGirl.lint factories_to_lint
|
||||
FactoryBot.lint factories_to_lint
|
||||
```
|
||||
|
||||
This would lint all factories that aren't prefixed with `old_`.
|
||||
|
@ -1019,25 +1019,25 @@ and every trait of a factory generates a valid object on its own.
|
|||
This is turned on by passing `traits: true` to the `lint` method:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.lint traits: true
|
||||
FactoryBot.lint traits: true
|
||||
```
|
||||
|
||||
This can also be combined with other arguments:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.lint factories_to_lint, traits: true
|
||||
FactoryBot.lint factories_to_lint, traits: true
|
||||
```
|
||||
|
||||
You can also specify the strategy used for linting:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.lint strategy: :build
|
||||
FactoryBot.lint strategy: :build
|
||||
```
|
||||
|
||||
Custom Construction
|
||||
-------------------
|
||||
|
||||
If you want to use factory_girl to construct an object where some attributes
|
||||
If you want to use factory_bot to construct an object where some attributes
|
||||
are passed to `initialize` or if you want to do something other than simply
|
||||
calling `new` on your build class, you can override the default behavior by
|
||||
defining `initialize_with` on your factory. Example:
|
||||
|
@ -1065,7 +1065,7 @@ end
|
|||
build(:user).name # Jane Doe
|
||||
```
|
||||
|
||||
Although factory_girl is written to work with ActiveRecord out of the box, it
|
||||
Although factory_bot is written to work with ActiveRecord out of the box, it
|
||||
can also work with any Ruby class. For maximum compatibility with ActiveRecord,
|
||||
the default initializer builds all instances by calling `new` on your build class
|
||||
without any arguments. It then calls attribute writer methods to assign all the
|
||||
|
@ -1112,10 +1112,10 @@ include transient attributes, but everything else defined in the factory will be
|
|||
passed (associations, evalued sequences, etc.)
|
||||
|
||||
You can define `initialize_with` for all factories by including it in the
|
||||
`FactoryGirl.define` block:
|
||||
`FactoryBot.define` block:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
initialize_with { new("Awesome first argument") }
|
||||
end
|
||||
```
|
||||
|
@ -1125,7 +1125,7 @@ block are assigned *only* in the constructor; this equates to roughly the
|
|||
following code:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
initialize_with { new(name) }
|
||||
|
||||
|
@ -1138,11 +1138,11 @@ build(:user)
|
|||
User.new('value')
|
||||
```
|
||||
|
||||
This prevents duplicate assignment; in versions of factory_girl before 4.0, it
|
||||
This prevents duplicate assignment; in versions of factory_bot before 4.0, it
|
||||
would run this:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
initialize_with { new(name) }
|
||||
|
||||
|
@ -1159,27 +1159,27 @@ user.name = 'value'
|
|||
Custom Strategies
|
||||
-----------------
|
||||
|
||||
There are times where you may want to extend behavior of factory\_girl by
|
||||
There are times where you may want to extend behavior of factory\_bot by
|
||||
adding a custom build strategy.
|
||||
|
||||
Strategies define two methods: `association` and `result`. `association`
|
||||
receives a `FactoryGirl::FactoryRunner` instance, upon which you can call
|
||||
receives a `FactoryBot::FactoryRunner` instance, upon which you can call
|
||||
`run`, overriding the strategy if you want. The second method, `result`,
|
||||
receives a `FactoryGirl::Evaluation` instance. It provides a way to trigger
|
||||
receives a `FactoryBot::Evaluation` instance. It provides a way to trigger
|
||||
callbacks (with `notify`), `object` or `hash` (to get the result instance or a
|
||||
hash based on the attributes defined in the factory), and `create`, which
|
||||
executes the `to_create` callback defined on the factory.
|
||||
|
||||
To understand how factory\_girl uses strategies internally, it's probably
|
||||
To understand how factory\_bot uses strategies internally, it's probably
|
||||
easiest to just view the source for each of the four default strategies.
|
||||
|
||||
Here's an example of composing a strategy using
|
||||
`FactoryGirl::Strategy::Create` to build a JSON representation of your model.
|
||||
`FactoryBot::Strategy::Create` to build a JSON representation of your model.
|
||||
|
||||
```ruby
|
||||
class JsonStrategy
|
||||
def initialize
|
||||
@strategy = FactoryGirl.strategy_by_name(:create).new
|
||||
@strategy = FactoryBot.strategy_by_name(:create).new
|
||||
end
|
||||
|
||||
delegate :association, to: :@strategy
|
||||
|
@ -1190,19 +1190,19 @@ class JsonStrategy
|
|||
end
|
||||
```
|
||||
|
||||
For factory\_girl to recognize the new strategy, you can register it:
|
||||
For factory\_bot to recognize the new strategy, you can register it:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.register_strategy(:json, JsonStrategy)
|
||||
FactoryBot.register_strategy(:json, JsonStrategy)
|
||||
```
|
||||
|
||||
This allows you to call
|
||||
|
||||
```ruby
|
||||
FactoryGirl.json(:user)
|
||||
FactoryBot.json(:user)
|
||||
```
|
||||
|
||||
Finally, you can override factory\_girl's own strategies if you'd like by
|
||||
Finally, you can override factory\_bot's own strategies if you'd like by
|
||||
registering a new object in place of the strategies.
|
||||
|
||||
Custom Callbacks
|
||||
|
@ -1213,7 +1213,7 @@ Custom callbacks can be defined if you're using custom strategies:
|
|||
```ruby
|
||||
class JsonStrategy
|
||||
def initialize
|
||||
@strategy = FactoryGirl.strategy_by_name(:create).new
|
||||
@strategy = FactoryBot.strategy_by_name(:create).new
|
||||
end
|
||||
|
||||
delegate :association, to: :@strategy
|
||||
|
@ -1229,9 +1229,9 @@ class JsonStrategy
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.register_strategy(:json, JsonStrategy)
|
||||
FactoryBot.register_strategy(:json, JsonStrategy)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
before(:json) { |user| do_something_to(user) }
|
||||
after(:json) { |user_json| do_something_to(user_json) }
|
||||
|
@ -1263,10 +1263,10 @@ end
|
|||
```
|
||||
|
||||
To override `to_create` for all factories, define it within the
|
||||
`FactoryGirl.define` block:
|
||||
`FactoryBot.define` block:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
to_create { |instance| instance.persist! }
|
||||
|
||||
|
||||
|
@ -1285,7 +1285,7 @@ factories being run. One example would be to track factories based on a
|
|||
threshold of execution time.
|
||||
|
||||
```ruby
|
||||
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |name, start, finish, id, payload|
|
||||
ActiveSupport::Notifications.subscribe("factory_bot.run_factory") do |name, start, finish, id, payload|
|
||||
execution_time_in_seconds = finish - start
|
||||
|
||||
if execution_time_in_seconds >= 0.5
|
||||
|
@ -1299,19 +1299,19 @@ throughout your test suite. If you're using RSpec, it's as simple as adding a
|
|||
`before(:suite)` and `after(:suite)`:
|
||||
|
||||
```ruby
|
||||
factory_girl_results = {}
|
||||
factory_bot_results = {}
|
||||
config.before(:suite) do
|
||||
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |name, start, finish, id, payload|
|
||||
ActiveSupport::Notifications.subscribe("factory_bot.run_factory") do |name, start, finish, id, payload|
|
||||
factory_name = payload[:name]
|
||||
strategy_name = payload[:strategy]
|
||||
factory_girl_results[factory_name] ||= {}
|
||||
factory_girl_results[factory_name][strategy_name] ||= 0
|
||||
factory_girl_results[factory_name][strategy_name] += 1
|
||||
factory_bot_results[factory_name] ||= {}
|
||||
factory_bot_results[factory_name][strategy_name] ||= 0
|
||||
factory_bot_results[factory_name][strategy_name] += 1
|
||||
end
|
||||
end
|
||||
|
||||
config.after(:suite) do
|
||||
puts factory_girl_results
|
||||
puts factory_bot_results
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -1323,7 +1323,7 @@ to encounter an `ActiveRecord::AssociationTypeMismatch` error when creating a fa
|
|||
with associations, as below:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :united_states, class: Location do
|
||||
name 'United States'
|
||||
association :location_group, factory: :north_america
|
||||
|
@ -1344,11 +1344,11 @@ ActiveRecord::AssociationTypeMismatch:
|
|||
```
|
||||
|
||||
The two possible solutions are to either run the suite without the preloader, or
|
||||
to add `FactoryGirl.reload` to the RSpec configuration, like so:
|
||||
to add `FactoryBot.reload` to the RSpec configuration, like so:
|
||||
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.before(:suite) { FactoryGirl.reload }
|
||||
config.before(:suite) { FactoryBot.reload }
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -1358,31 +1358,31 @@ Using Without Bundler
|
|||
If you're not using Bundler, be sure to have the gem installed and call:
|
||||
|
||||
```ruby
|
||||
require 'factory_girl'
|
||||
require 'factory_bot'
|
||||
```
|
||||
|
||||
Once required, assuming you have a directory structure of `spec/factories` or
|
||||
`test/factories`, all you'll need to do is run
|
||||
|
||||
```ruby
|
||||
FactoryGirl.find_definitions
|
||||
FactoryBot.find_definitions
|
||||
```
|
||||
|
||||
If you're using a separate directory structure for your factories, you can
|
||||
change the definition file paths before trying to find definitions:
|
||||
|
||||
```ruby
|
||||
FactoryGirl.definition_file_paths = %w(custom_factories_directory)
|
||||
FactoryGirl.find_definitions
|
||||
FactoryBot.definition_file_paths = %w(custom_factories_directory)
|
||||
FactoryBot.find_definitions
|
||||
```
|
||||
|
||||
If you don't have a separate directory of factories and would like to define
|
||||
them inline, that's possible as well:
|
||||
|
||||
```ruby
|
||||
require 'factory_girl'
|
||||
require 'factory_bot'
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
name 'John Doe'
|
||||
date_of_birth { 21.years.ago }
|
||||
|
|
2
Gemfile
2
Gemfile
|
@ -1,6 +1,6 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gemspec
|
||||
gemspec name: 'factory_bot'
|
||||
|
||||
gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
|
||||
gem 'jdbc-sqlite3', platforms: :jruby
|
||||
|
|
97
Gemfile.lock
97
Gemfile.lock
|
@ -1,24 +1,19 @@
|
|||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
factory_girl (4.8.1)
|
||||
factory_bot (4.8.1)
|
||||
activesupport (>= 3.0.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
activemodel (5.0.0.1)
|
||||
activesupport (= 5.0.0.1)
|
||||
activerecord (5.0.0.1)
|
||||
activemodel (= 5.0.0.1)
|
||||
activesupport (= 5.0.0.1)
|
||||
arel (~> 7.0)
|
||||
activerecord-jdbc-adapter (1.3.21)
|
||||
activerecord (>= 2.2)
|
||||
activerecord-jdbcsqlite3-adapter (1.3.21)
|
||||
activerecord-jdbc-adapter (~> 1.3.21)
|
||||
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
||||
activesupport (5.0.0.1)
|
||||
activemodel (5.1.4)
|
||||
activesupport (= 5.1.4)
|
||||
activerecord (5.1.4)
|
||||
activemodel (= 5.1.4)
|
||||
activesupport (= 5.1.4)
|
||||
arel (~> 8.0)
|
||||
activesupport (5.1.4)
|
||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||
i18n (~> 0.7)
|
||||
minitest (~> 5.1)
|
||||
|
@ -27,74 +22,66 @@ GEM
|
|||
bundler
|
||||
rake
|
||||
thor (>= 0.14.0)
|
||||
arel (7.1.4)
|
||||
aruba (0.13.0)
|
||||
arel (8.0.0)
|
||||
aruba (0.14.2)
|
||||
childprocess (~> 0.5.6)
|
||||
contracts (~> 0.9)
|
||||
cucumber (>= 1.3.19)
|
||||
ffi (~> 1.9.10)
|
||||
rspec-expectations (>= 2.99)
|
||||
thor (~> 0.19)
|
||||
builder (3.2.2)
|
||||
builder (3.2.3)
|
||||
childprocess (0.5.9)
|
||||
ffi (~> 1.0, >= 1.0.11)
|
||||
concurrent-ruby (1.0.2)
|
||||
concurrent-ruby (1.0.2-java)
|
||||
contracts (0.13.0)
|
||||
concurrent-ruby (1.0.5)
|
||||
contracts (0.16.0)
|
||||
cucumber (1.3.20)
|
||||
builder (>= 2.1.2)
|
||||
diff-lcs (>= 1.1.3)
|
||||
gherkin (~> 2.12)
|
||||
multi_json (>= 1.7.5, < 2.0)
|
||||
multi_test (>= 0.1.2)
|
||||
diff-lcs (1.2.5)
|
||||
diff-lcs (1.3)
|
||||
docile (1.1.5)
|
||||
ffi (1.9.10)
|
||||
ffi (1.9.10-java)
|
||||
ffi (1.9.18)
|
||||
gherkin (2.12.2)
|
||||
multi_json (~> 1.3)
|
||||
gherkin (2.12.2-java)
|
||||
multi_json (~> 1.3)
|
||||
i18n (0.7.0)
|
||||
jdbc-sqlite3 (3.8.11.2)
|
||||
json (1.8.6)
|
||||
json (1.8.6-java)
|
||||
minitest (5.9.1)
|
||||
multi_json (1.11.2)
|
||||
i18n (0.8.6)
|
||||
json (2.1.0)
|
||||
minitest (5.10.3)
|
||||
multi_json (1.12.2)
|
||||
multi_test (0.1.2)
|
||||
rake (10.5.0)
|
||||
rspec (3.4.0)
|
||||
rspec-core (~> 3.4.0)
|
||||
rspec-expectations (~> 3.4.0)
|
||||
rspec-mocks (~> 3.4.0)
|
||||
rspec-core (3.4.2)
|
||||
rspec-support (~> 3.4.0)
|
||||
rspec-expectations (3.4.0)
|
||||
rake (12.1.0)
|
||||
rspec (3.6.0)
|
||||
rspec-core (~> 3.6.0)
|
||||
rspec-expectations (~> 3.6.0)
|
||||
rspec-mocks (~> 3.6.0)
|
||||
rspec-core (3.6.0)
|
||||
rspec-support (~> 3.6.0)
|
||||
rspec-expectations (3.6.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.4.0)
|
||||
rspec-support (~> 3.6.0)
|
||||
rspec-its (1.2.0)
|
||||
rspec-core (>= 3.0.0)
|
||||
rspec-expectations (>= 3.0.0)
|
||||
rspec-mocks (3.4.1)
|
||||
rspec-mocks (3.6.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.4.0)
|
||||
rspec-support (3.4.1)
|
||||
simplecov (0.11.2)
|
||||
rspec-support (~> 3.6.0)
|
||||
rspec-support (3.6.0)
|
||||
simplecov (0.15.1)
|
||||
docile (~> 1.1.0)
|
||||
json (~> 1.8)
|
||||
json (>= 1.8, < 3)
|
||||
simplecov-html (~> 0.10.0)
|
||||
simplecov-html (0.10.0)
|
||||
sqlite3 (1.3.12)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
thread_safe (0.3.5-java)
|
||||
timecop (0.8.0)
|
||||
tzinfo (1.2.2)
|
||||
simplecov-html (0.10.2)
|
||||
sqlite3 (1.3.13)
|
||||
thor (0.20.0)
|
||||
thread_safe (0.3.6)
|
||||
timecop (0.9.1)
|
||||
tzinfo (1.2.3)
|
||||
thread_safe (~> 0.1)
|
||||
yard (0.8.7.6)
|
||||
yard (0.9.9)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
|
@ -103,7 +90,7 @@ DEPENDENCIES
|
|||
appraisal (~> 2.1.0)
|
||||
aruba
|
||||
cucumber (~> 1.3.15)
|
||||
factory_girl!
|
||||
factory_bot!
|
||||
jdbc-sqlite3
|
||||
rspec (~> 3.0)
|
||||
rspec-its (~> 1.0)
|
||||
|
@ -113,4 +100,4 @@ DEPENDENCIES
|
|||
yard
|
||||
|
||||
BUNDLED WITH
|
||||
1.15.4
|
||||
1.15.3
|
||||
|
|
4
NEWS
4
NEWS
|
@ -111,7 +111,7 @@
|
|||
Skip to_create with skip_create
|
||||
Allow registration of custom strategies
|
||||
Deprecate alternate syntaxes
|
||||
Implicitly call factory_girl's syntax methods from dynamic attributes
|
||||
Implicitly call factory_bot's syntax methods from dynamic attributes
|
||||
|
||||
3.1.0 (April 6, 2012)
|
||||
Sequences support aliases, which reference the same block
|
||||
|
@ -206,7 +206,7 @@
|
|||
2.3.1 (November 23, 2011)
|
||||
Remove internally-used associate method from all the FactoryGirl::Proxy subclasses
|
||||
Move around requiring of files
|
||||
Consolidate errors into factory_girl.rb
|
||||
Consolidate errors into factory_bot.rb
|
||||
Refactor AttributeList to deal with priority only when iterating over
|
||||
attributes
|
||||
Refactor internals of some of the Proxy subclasses
|
||||
|
|
44
README.md
44
README.md
|
@ -1,16 +1,18 @@
|
|||
# factory_girl [![Build Status](https://travis-ci.org/thoughtbot/factory_girl.svg)](http://travis-ci.org/thoughtbot/factory_girl?branch=master) [![Dependency Status](https://gemnasium.com/thoughtbot/factory_girl.svg)](https://gemnasium.com/thoughtbot/factory_girl) [![Code Climate](https://codeclimate.com/github/thoughtbot/factory_girl/badges/gpa.svg)](https://codeclimate.com/github/thoughtbot/factory_girl)
|
||||
# factory_bot [![Build Status](https://travis-ci.org/thoughtbot/factory_bot.svg)](http://travis-ci.org/thoughtbot/factory_bot?branch=master) [![Dependency Status](https://gemnasium.com/thoughtbot/factory_bot.svg)](https://gemnasium.com/thoughtbot/factory_bot) [![Code Climate](https://codeclimate.com/github/thoughtbot/factory_bot/badges/gpa.svg)](https://codeclimate.com/github/thoughtbot/factory_bot)
|
||||
|
||||
factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.
|
||||
factory_bot is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.
|
||||
|
||||
If you want to use factory_girl with Rails, see
|
||||
[factory_girl_rails](https://github.com/thoughtbot/factory_girl_rails).
|
||||
If you want to use factory_bot with Rails, see
|
||||
[factory_bot_rails](https://github.com/thoughtbot/factory_bot_rails).
|
||||
|
||||
**A historical note:** factory_bot used to be named factory_girl. An explanation of the name change can be found in the [old factory_girl repository](https://github.com/thoughtbot/factory_girl).
|
||||
|
||||
_[Interested in the project name?](NAME.md)._
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
You should find the documentation for your version of factory_girl on [Rubygems](https://rubygems.org/gems/factory_girl).
|
||||
You should find the documentation for your version of factory_bot on [Rubygems](https://rubygems.org/gems/factory_bot).
|
||||
|
||||
See [GETTING_STARTED] for information on defining and using factories. We also
|
||||
have [a detailed introductory video][], available for free on Upcase.
|
||||
|
@ -23,7 +25,7 @@ Install
|
|||
Add the following line to Gemfile:
|
||||
|
||||
```ruby
|
||||
gem 'factory_girl'
|
||||
gem 'factory_bot'
|
||||
```
|
||||
|
||||
and run `bundle install` from your shell.
|
||||
|
@ -31,7 +33,7 @@ and run `bundle install` from your shell.
|
|||
To install the gem manually from your shell, run:
|
||||
|
||||
```shell
|
||||
gem install factory_girl
|
||||
gem install factory_bot
|
||||
```
|
||||
|
||||
**Caveat:** As of ActiveSupport 5.0 and above, Ruby 2.2.2+ is required. Because
|
||||
|
@ -39,8 +41,8 @@ of Rubygems' dependency resolution when installing gems, you may see an error
|
|||
similar to:
|
||||
|
||||
```
|
||||
$ gem install factory_girl
|
||||
ERROR: Error installing factory_girl:
|
||||
$ gem install factory_bot
|
||||
ERROR: Error installing factory_bot:
|
||||
activesupport requires Ruby version >= 2.2.2.
|
||||
```
|
||||
|
||||
|
@ -50,35 +52,37 @@ manually.
|
|||
Supported Ruby versions
|
||||
-----------------------
|
||||
|
||||
The factory_girl 3.x+ series supports MRI Ruby 1.9. Additionally, factory_girl
|
||||
The factory_bot 3.x+ series supports MRI Ruby 1.9. Additionally, factory_bot
|
||||
3.6+ supports JRuby 1.6.7.2+ while running in 1.9 mode. See [GETTING_STARTED]
|
||||
for more information on configuring the JRuby environment.
|
||||
|
||||
For versions of Ruby prior to 1.9, please use factory_girl 2.x.
|
||||
For versions of Ruby prior to 1.9, please use factory_bot 2.x.
|
||||
|
||||
More Information
|
||||
----------------
|
||||
|
||||
* [Rubygems](https://rubygems.org/gems/factory_girl)
|
||||
* [Stack Overflow](http://stackoverflow.com/questions/tagged/factory-girl)
|
||||
* [Issues](https://github.com/thoughtbot/factory_girl/issues)
|
||||
* [Rubygems](https://rubygems.org/gems/factory_bot)
|
||||
* [Stack Overflow](http://stackoverflow.com/questions/tagged/factory-bot)
|
||||
* [Issues](https://github.com/thoughtbot/factory_bot/issues)
|
||||
* [GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS](http://robots.thoughtbot.com/)
|
||||
|
||||
[GETTING_STARTED]: http://rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md
|
||||
You may also find useful information under the [factory_girl tag on Stack Overflow](http://stackoverflow.com/questions/tagged/factory-girl).
|
||||
|
||||
[GETTING_STARTED]: http://rubydoc.info/gems/factory_bot/file/GETTING_STARTED.md
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
Please see [CONTRIBUTING.md](https://github.com/thoughtbot/factory_girl/blob/master/CONTRIBUTING.md).
|
||||
Please see [CONTRIBUTING.md](https://github.com/thoughtbot/factory_bot/blob/master/CONTRIBUTING.md).
|
||||
|
||||
factory_girl was originally written by Joe Ferris and is now maintained by Josh
|
||||
factory_bot was originally written by Joe Ferris and is now maintained by Josh
|
||||
Clayton. Many improvements and bugfixes were contributed by the [open source
|
||||
community](https://github.com/thoughtbot/factory_girl/graphs/contributors).
|
||||
community](https://github.com/thoughtbot/factory_bot/graphs/contributors).
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
factory_girl is Copyright © 2008-2017 Joe Ferris and thoughtbot. It is free
|
||||
factory_bot is Copyright © 2008-2016 Joe Ferris and thoughtbot. It is free
|
||||
software, and may be redistributed under the terms specified in the
|
||||
[LICENSE](/LICENSE) file.
|
||||
|
||||
|
@ -87,7 +91,7 @@ About thoughtbot
|
|||
|
||||
![thoughtbot](http://presskit.thoughtbot.com/images/thoughtbot-logo-for-readmes.svg)
|
||||
|
||||
factory_girl is maintained and funded by thoughtbot, inc.
|
||||
factory_bot is maintained and funded by thoughtbot, inc.
|
||||
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
||||
|
||||
We love open source software!
|
||||
|
|
4
Rakefile
4
Rakefile
|
@ -6,7 +6,7 @@ require 'yard'
|
|||
require 'rspec/core/rake_task'
|
||||
require 'cucumber/rake/task'
|
||||
|
||||
Bundler::GemHelper.install_tasks
|
||||
Bundler::GemHelper.install_tasks(name: 'factory_bot')
|
||||
|
||||
desc 'Default: run the specs and features.'
|
||||
task default: %w(spec:unit spec:acceptance features)
|
||||
|
@ -14,7 +14,7 @@ task default: %w(spec:unit spec:acceptance features)
|
|||
namespace :spec do
|
||||
desc "Run unit specs"
|
||||
RSpec::Core::RakeTask.new('unit') do |t|
|
||||
t.pattern = 'spec/{*_spec.rb,factory_girl/**/*_spec.rb}'
|
||||
t.pattern = 'spec/{*_spec.rb,factory_bot/**/*_spec.rb}'
|
||||
end
|
||||
|
||||
desc "Run acceptance specs"
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
$LOAD_PATH << File.expand_path("../lib", __FILE__)
|
||||
require 'factory_bot/version'
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{factory_bot}
|
||||
s.version = FactoryBot::VERSION
|
||||
s.summary = %q{factory_bot provides a framework and DSL for defining and
|
||||
using model instance factories.}
|
||||
s.description = %q{factory_bot provides a framework and DSL for defining and
|
||||
using factories - less error-prone, more explicit, and
|
||||
all-around easier to work with than fixtures.}
|
||||
|
||||
s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(spec|features)/}) }
|
||||
|
||||
s.require_path = 'lib'
|
||||
s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
||||
|
||||
s.authors = ["Josh Clayton", "Joe Ferris"]
|
||||
s.email = ["jclayton@thoughtbot.com", "jferris@thoughtbot.com"]
|
||||
|
||||
s.homepage = "https://github.com/thoughtbot/factory_bot"
|
||||
|
||||
s.add_dependency("activesupport", ">= 3.0.0")
|
||||
|
||||
s.add_development_dependency("rspec", "~> 3.0")
|
||||
s.add_development_dependency("rspec-its", "~> 1.0")
|
||||
s.add_development_dependency("cucumber", "~> 1.3.15")
|
||||
s.add_development_dependency("timecop")
|
||||
s.add_development_dependency("simplecov")
|
||||
s.add_development_dependency("aruba")
|
||||
s.add_development_dependency("appraisal", "~> 2.1.0")
|
||||
s.add_development_dependency("activerecord", ">= 3.0.0")
|
||||
s.add_development_dependency("yard")
|
||||
|
||||
s.license = "MIT"
|
||||
end
|
|
@ -1,14 +1,16 @@
|
|||
$LOAD_PATH << File.expand_path("../lib", __FILE__)
|
||||
require 'factory_girl/version'
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{factory_girl}
|
||||
s.version = FactoryGirl::VERSION
|
||||
s.version = "4.8.1".freeze
|
||||
s.summary = %q{factory_girl provides a framework and DSL for defining and
|
||||
using model instance factories.}
|
||||
s.description = %q{factory_girl provides a framework and DSL for defining and
|
||||
using factories - less error-prone, more explicit, and
|
||||
all-around easier to work with than fixtures.}
|
||||
s.post_install_message = "The factory_girl gem has been deprecated and has "\
|
||||
"been replaced by factory_bot. Please switch to "\
|
||||
"factory_bot as soon as possible."
|
||||
|
||||
s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(spec|features)/}) }
|
||||
|
||||
|
@ -28,6 +30,8 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency("timecop")
|
||||
s.add_development_dependency("simplecov")
|
||||
s.add_development_dependency("aruba")
|
||||
s.add_development_dependency("mocha", ">= 0.12.8")
|
||||
s.add_development_dependency("bourne")
|
||||
s.add_development_dependency("appraisal", "~> 2.1.0")
|
||||
s.add_development_dependency("activerecord", ">= 3.0.0")
|
||||
s.add_development_dependency("yard")
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
Feature: FactoryGirl can find factory definitions correctly
|
||||
Feature: FactoryBot can find factory definitions correctly
|
||||
Scenario: Find definitions with a path
|
||||
Given a file named "awesome_factories.rb" with:
|
||||
"""
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :awesome_category, :class => Category do
|
||||
name "awesome!!!"
|
||||
end
|
||||
end
|
||||
"""
|
||||
When "awesome_factories.rb" is added to FactoryGirl's file definitions path
|
||||
And I create a "awesome_category" instance from FactoryGirl
|
||||
When "awesome_factories.rb" is added to FactoryBot's file definitions path
|
||||
And I create a "awesome_category" instance from FactoryBot
|
||||
Then I should find the following for the last category:
|
||||
| name |
|
||||
| awesome!!! |
|
||||
|
@ -17,14 +17,14 @@ Feature: FactoryGirl can find factory definitions correctly
|
|||
Scenario: Find definitions with an absolute path
|
||||
Given a file named "awesome_factories.rb" with:
|
||||
"""
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :another_awesome_category, :class => Category do
|
||||
name "awesome!!!"
|
||||
end
|
||||
end
|
||||
"""
|
||||
When "awesome_factories.rb" is added to FactoryGirl's file definitions path as an absolute path
|
||||
And I create a "another_awesome_category" instance from FactoryGirl
|
||||
When "awesome_factories.rb" is added to FactoryBot's file definitions path as an absolute path
|
||||
And I create a "another_awesome_category" instance from FactoryBot
|
||||
Then I should find the following for the last category:
|
||||
| name |
|
||||
| awesome!!! |
|
||||
|
@ -32,22 +32,22 @@ Feature: FactoryGirl can find factory definitions correctly
|
|||
Scenario: Find definitions with a folder
|
||||
Given a file named "nested/great_factories.rb" with:
|
||||
"""
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :great_category, :class => Category do
|
||||
name "great!!!"
|
||||
end
|
||||
end
|
||||
"""
|
||||
When "nested" is added to FactoryGirl's file definitions path
|
||||
And I create a "great_category" instance from FactoryGirl
|
||||
When "nested" is added to FactoryBot's file definitions path
|
||||
And I create a "great_category" instance from FactoryBot
|
||||
Then I should find the following for the last category:
|
||||
| name |
|
||||
| great!!! |
|
||||
|
||||
Scenario: Reload FactoryGirl
|
||||
Scenario: Reload FactoryBot
|
||||
Given a file named "nested/reload_factories.rb" with:
|
||||
"""
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
sequence(:great)
|
||||
trait :admin do
|
||||
admin true
|
||||
|
@ -58,18 +58,18 @@ Feature: FactoryGirl can find factory definitions correctly
|
|||
end
|
||||
end
|
||||
"""
|
||||
When "nested" is added to FactoryGirl's file definitions path
|
||||
When "nested" is added to FactoryBot's file definitions path
|
||||
And I append to "nested/reload_factories.rb" with:
|
||||
"""
|
||||
|
||||
FactoryGirl.modify do
|
||||
FactoryBot.modify do
|
||||
factory :handy_category do
|
||||
name "HANDY!!!"
|
||||
end
|
||||
end
|
||||
"""
|
||||
And I reload factories
|
||||
And I create a "handy_category" instance from FactoryGirl
|
||||
And I create a "handy_category" instance from FactoryBot
|
||||
Then I should find the following for the last category:
|
||||
| name |
|
||||
| HANDY!!! |
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
module FactoryBotDefinitionsHelper
|
||||
def append_file_to_factory_bot_definitions_path(path_to_file)
|
||||
FactoryBot.definition_file_paths ||= []
|
||||
FactoryBot.definition_file_paths << path_to_file
|
||||
end
|
||||
end
|
||||
|
||||
World(FactoryBotDefinitionsHelper)
|
||||
|
||||
When /^"([^"]*)" is added to FactoryBot's file definitions path$/ do |file_name|
|
||||
new_factory_file = File.join(expand_path("."), file_name.gsub(".rb", ""))
|
||||
|
||||
append_file_to_factory_bot_definitions_path(new_factory_file)
|
||||
|
||||
step %{I find definitions}
|
||||
end
|
||||
|
||||
When /^"([^"]*)" is added to FactoryBot's file definitions path as an absolute path$/ do |file_name|
|
||||
new_factory_file = File.expand_path(File.join(expand_path("."), file_name.gsub(".rb", "")))
|
||||
|
||||
append_file_to_factory_bot_definitions_path(new_factory_file)
|
||||
|
||||
step %{I find definitions}
|
||||
end
|
||||
|
||||
When /^I create a "([^"]*)" instance from FactoryBot$/ do |factory_name|
|
||||
FactoryBot.create(factory_name)
|
||||
end
|
||||
|
||||
When /^I find definitions$/ do
|
||||
FactoryBot.find_definitions
|
||||
end
|
||||
|
||||
When /^I reload factories$/ do
|
||||
FactoryBot.reload
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
module FactoryGirlDefinitionsHelper
|
||||
def append_file_to_factory_girl_definitions_path(path_to_file)
|
||||
FactoryGirl.definition_file_paths ||= []
|
||||
FactoryGirl.definition_file_paths << path_to_file
|
||||
end
|
||||
end
|
||||
|
||||
World(FactoryGirlDefinitionsHelper)
|
||||
|
||||
When /^"([^"]*)" is added to FactoryGirl's file definitions path$/ do |file_name|
|
||||
new_factory_file = File.join(expand_path("."), file_name.gsub(".rb", ""))
|
||||
|
||||
append_file_to_factory_girl_definitions_path(new_factory_file)
|
||||
|
||||
step %{I find definitions}
|
||||
end
|
||||
|
||||
When /^"([^"]*)" is added to FactoryGirl's file definitions path as an absolute path$/ do |file_name|
|
||||
new_factory_file = File.expand_path(File.join(expand_path("."), file_name.gsub(".rb", "")))
|
||||
|
||||
append_file_to_factory_girl_definitions_path(new_factory_file)
|
||||
|
||||
step %{I find definitions}
|
||||
end
|
||||
|
||||
When /^I create a "([^"]*)" instance from FactoryGirl$/ do |factory_name|
|
||||
FactoryGirl.create(factory_name)
|
||||
end
|
||||
|
||||
When /^I find definitions$/ do
|
||||
FactoryGirl.find_definitions
|
||||
end
|
||||
|
||||
When /^I reload factories$/ do
|
||||
FactoryGirl.reload
|
||||
end
|
|
@ -5,6 +5,6 @@ require "simplecov"
|
|||
$: << File.join(PROJECT_ROOT, 'lib')
|
||||
|
||||
require 'active_record'
|
||||
require 'factory_girl'
|
||||
require 'factory_bot'
|
||||
|
||||
require 'aruba/cucumber'
|
||||
|
|
|
@ -7,4 +7,4 @@ gem "jdbc-sqlite3", :platforms => :jruby
|
|||
gem "sqlite3", "~> 1.3.10", :platforms => :ruby
|
||||
gem "activerecord", :git => "https://github.com/rails/rails.git", :branch => "3-2-stable"
|
||||
|
||||
gemspec :path => "../"
|
||||
gemspec :path => "../", :name => "factory_bot"
|
||||
|
|
|
@ -18,7 +18,7 @@ GIT
|
|||
PATH
|
||||
remote: ../
|
||||
specs:
|
||||
factory_girl (4.8.1)
|
||||
factory_bot (4.8.1)
|
||||
activesupport (>= 3.0.0)
|
||||
|
||||
GEM
|
||||
|
@ -92,7 +92,7 @@ DEPENDENCIES
|
|||
appraisal (~> 2.1.0)
|
||||
aruba
|
||||
cucumber (~> 1.3.15)
|
||||
factory_girl!
|
||||
factory_bot!
|
||||
jdbc-sqlite3
|
||||
rspec (~> 3.0)
|
||||
rspec-its (~> 1.0)
|
||||
|
|
|
@ -7,4 +7,4 @@ gem "jdbc-sqlite3", :platforms => :jruby
|
|||
gem "sqlite3", "~> 1.3.10", :platforms => :ruby
|
||||
gem "activerecord", "~> 4.0.13"
|
||||
|
||||
gemspec :path => "../"
|
||||
gemspec :path => "../", :name => "factory_bot"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: ../
|
||||
specs:
|
||||
factory_girl (4.8.1)
|
||||
factory_bot (4.8.1)
|
||||
activesupport (>= 3.0.0)
|
||||
|
||||
GEM
|
||||
|
@ -92,7 +92,7 @@ DEPENDENCIES
|
|||
appraisal (~> 2.1.0)
|
||||
aruba
|
||||
cucumber (~> 1.3.15)
|
||||
factory_girl!
|
||||
factory_bot!
|
||||
jdbc-sqlite3
|
||||
rspec (~> 3.0)
|
||||
rspec-its (~> 1.0)
|
||||
|
|
|
@ -7,4 +7,4 @@ gem "jdbc-sqlite3", :platforms => :jruby
|
|||
gem "sqlite3", "~> 1.3.10", :platforms => :ruby
|
||||
gem "activerecord", "~> 4.1.14"
|
||||
|
||||
gemspec :path => "../"
|
||||
gemspec :path => "../", :name => "factory_bot"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: ../
|
||||
specs:
|
||||
factory_girl (4.8.1)
|
||||
factory_bot (4.8.1)
|
||||
activesupport (>= 3.0.0)
|
||||
|
||||
GEM
|
||||
|
@ -91,7 +91,7 @@ DEPENDENCIES
|
|||
appraisal (~> 2.1.0)
|
||||
aruba
|
||||
cucumber (~> 1.3.15)
|
||||
factory_girl!
|
||||
factory_bot!
|
||||
jdbc-sqlite3
|
||||
rspec (~> 3.0)
|
||||
rspec-its (~> 1.0)
|
||||
|
|
|
@ -7,4 +7,4 @@ gem "jdbc-sqlite3", :platforms => :jruby
|
|||
gem "sqlite3", "~> 1.3.10", :platforms => :ruby
|
||||
gem "activerecord", "~> 4.2.5.1"
|
||||
|
||||
gemspec :path => "../"
|
||||
gemspec :path => "../", :name => "factory_bot"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: ../
|
||||
specs:
|
||||
factory_girl (4.8.1)
|
||||
factory_bot (4.8.1)
|
||||
activesupport (>= 3.0.0)
|
||||
|
||||
GEM
|
||||
|
@ -91,7 +91,7 @@ DEPENDENCIES
|
|||
appraisal (~> 2.1.0)
|
||||
aruba
|
||||
cucumber (~> 1.3.15)
|
||||
factory_girl!
|
||||
factory_bot!
|
||||
jdbc-sqlite3
|
||||
rspec (~> 3.0)
|
||||
rspec-its (~> 1.0)
|
||||
|
|
|
@ -7,4 +7,4 @@ gem "jdbc-sqlite3", :platforms => :jruby
|
|||
gem "sqlite3", "~> 1.3.10", :platforms => :ruby
|
||||
gem "activerecord", "~> 5.0.0"
|
||||
|
||||
gemspec :path => "../"
|
||||
gemspec :path => "../", :name => "factory_bot"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: ../
|
||||
specs:
|
||||
factory_girl (4.8.1)
|
||||
factory_bot (4.8.1)
|
||||
activesupport (>= 3.0.0)
|
||||
|
||||
GEM
|
||||
|
@ -90,7 +90,7 @@ DEPENDENCIES
|
|||
appraisal (~> 2.1.0)
|
||||
aruba
|
||||
cucumber (~> 1.3.15)
|
||||
factory_girl!
|
||||
factory_bot!
|
||||
jdbc-sqlite3
|
||||
rspec (~> 3.0)
|
||||
rspec-its (~> 1.0)
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
require 'set'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
require 'active_support/deprecation'
|
||||
require 'active_support/notifications'
|
||||
|
||||
require 'factory_bot/definition_hierarchy'
|
||||
require 'factory_bot/configuration'
|
||||
require 'factory_bot/errors'
|
||||
require 'factory_bot/factory_runner'
|
||||
require 'factory_bot/strategy_syntax_method_registrar'
|
||||
require 'factory_bot/strategy_calculator'
|
||||
require 'factory_bot/strategy/build'
|
||||
require 'factory_bot/strategy/create'
|
||||
require 'factory_bot/strategy/attributes_for'
|
||||
require 'factory_bot/strategy/stub'
|
||||
require 'factory_bot/strategy/null'
|
||||
require 'factory_bot/registry'
|
||||
require 'factory_bot/null_factory'
|
||||
require 'factory_bot/null_object'
|
||||
require 'factory_bot/evaluation'
|
||||
require 'factory_bot/factory'
|
||||
require 'factory_bot/attribute_assigner'
|
||||
require 'factory_bot/evaluator'
|
||||
require 'factory_bot/evaluator_class_definer'
|
||||
require 'factory_bot/attribute'
|
||||
require 'factory_bot/callback'
|
||||
require 'factory_bot/callbacks_observer'
|
||||
require 'factory_bot/declaration_list'
|
||||
require 'factory_bot/declaration'
|
||||
require 'factory_bot/sequence'
|
||||
require 'factory_bot/attribute_list'
|
||||
require 'factory_bot/trait'
|
||||
require 'factory_bot/aliases'
|
||||
require 'factory_bot/definition'
|
||||
require 'factory_bot/definition_proxy'
|
||||
require 'factory_bot/syntax'
|
||||
require 'factory_bot/syntax_runner'
|
||||
require 'factory_bot/find_definitions'
|
||||
require 'factory_bot/reload'
|
||||
require 'factory_bot/decorator'
|
||||
require 'factory_bot/decorator/attribute_hash'
|
||||
require 'factory_bot/decorator/class_key_hash'
|
||||
require 'factory_bot/decorator/disallows_duplicates_registry'
|
||||
require 'factory_bot/decorator/invocation_tracker'
|
||||
require 'factory_bot/decorator/new_constructor'
|
||||
require 'factory_bot/linter'
|
||||
require 'factory_bot/version'
|
||||
|
||||
module FactoryBot
|
||||
def self.configuration
|
||||
@configuration ||= Configuration.new
|
||||
end
|
||||
|
||||
def self.reset_configuration
|
||||
@configuration = nil
|
||||
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
|
||||
def self.lint(*args)
|
||||
options = args.extract_options!
|
||||
factories_to_lint = args[0] || FactoryBot.factories
|
||||
linting_strategy = options[:traits] ? :factory_and_traits : :factory
|
||||
factory_strategy = options[:strategy] || :create
|
||||
Linter.new(factories_to_lint, linting_strategy, factory_strategy).lint!
|
||||
end
|
||||
|
||||
class << self
|
||||
delegate :factories,
|
||||
:sequences,
|
||||
:traits,
|
||||
:callbacks,
|
||||
:strategies,
|
||||
:callback_names,
|
||||
:to_create,
|
||||
:skip_create,
|
||||
:initialize_with,
|
||||
:constructor,
|
||||
:duplicate_attribute_assignment_from_initialize_with,
|
||||
:duplicate_attribute_assignment_from_initialize_with=,
|
||||
:allow_class_lookup,
|
||||
:allow_class_lookup=,
|
||||
:use_parent_strategy,
|
||||
:use_parent_strategy=,
|
||||
to: :configuration
|
||||
end
|
||||
|
||||
def self.register_factory(factory)
|
||||
factory.names.each do |name|
|
||||
factories.register(name, factory)
|
||||
end
|
||||
factory
|
||||
end
|
||||
|
||||
def self.factory_by_name(name)
|
||||
factories.find(name)
|
||||
end
|
||||
|
||||
def self.register_sequence(sequence)
|
||||
sequence.names.each do |name|
|
||||
sequences.register(name, sequence)
|
||||
end
|
||||
sequence
|
||||
end
|
||||
|
||||
def self.sequence_by_name(name)
|
||||
sequences.find(name)
|
||||
end
|
||||
|
||||
def self.register_trait(trait)
|
||||
trait.names.each do |name|
|
||||
traits.register(name, trait)
|
||||
end
|
||||
trait
|
||||
end
|
||||
|
||||
def self.trait_by_name(name)
|
||||
traits.find(name)
|
||||
end
|
||||
|
||||
def self.register_strategy(strategy_name, strategy_class)
|
||||
strategies.register(strategy_name, strategy_class)
|
||||
StrategySyntaxMethodRegistrar.new(strategy_name).define_strategy_methods
|
||||
end
|
||||
|
||||
def self.strategy_by_name(name)
|
||||
strategies.find(name)
|
||||
end
|
||||
|
||||
def self.register_default_strategies
|
||||
register_strategy(:build, FactoryBot::Strategy::Build)
|
||||
register_strategy(:create, FactoryBot::Strategy::Create)
|
||||
register_strategy(:attributes_for, FactoryBot::Strategy::AttributesFor)
|
||||
register_strategy(:build_stubbed, FactoryBot::Strategy::Stub)
|
||||
register_strategy(:null, FactoryBot::Strategy::Null)
|
||||
end
|
||||
|
||||
def self.register_default_callbacks
|
||||
register_callback(:after_build)
|
||||
register_callback(:after_create)
|
||||
register_callback(:after_stub)
|
||||
register_callback(:before_create)
|
||||
end
|
||||
|
||||
def self.register_callback(name)
|
||||
name = name.to_sym
|
||||
callback_names << name
|
||||
end
|
||||
end
|
||||
|
||||
FactoryBot.register_default_strategies
|
||||
FactoryBot.register_default_callbacks
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class << self
|
||||
attr_accessor :aliases
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
require 'factory_girl/attribute/static'
|
||||
require 'factory_girl/attribute/dynamic'
|
||||
require 'factory_girl/attribute/association'
|
||||
require 'factory_girl/attribute/sequence'
|
||||
require 'factory_bot/attribute/static'
|
||||
require 'factory_bot/attribute/dynamic'
|
||||
require 'factory_bot/attribute/association'
|
||||
require 'factory_bot/attribute/sequence'
|
||||
|
||||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class Attribute
|
||||
attr_reader :name, :ignored
|
||||
|
@ -23,7 +23,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def alias_for?(attr)
|
||||
FactoryGirl.aliases_for(attr).include?(name)
|
||||
FactoryBot.aliases_for(attr).include?(name)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -55,7 +55,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def error_message
|
||||
"factory_girl uses '#{attribute_name} value' syntax rather than '#{attribute_name} = value'"
|
||||
"factory_bot uses '#{attribute_name} value' syntax rather than '#{attribute_name} = value'"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Attribute
|
||||
# @api private
|
||||
class Association < Attribute
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Attribute
|
||||
# @api private
|
||||
class Dynamic < Attribute
|
||||
|
@ -15,7 +15,7 @@ module FactoryGirl
|
|||
when 1, -1 then instance_exec(self, &block)
|
||||
else instance_exec(&block)
|
||||
end
|
||||
raise SequenceAbuseError if FactoryGirl::Sequence === value
|
||||
raise SequenceAbuseError if FactoryBot::Sequence === value
|
||||
value
|
||||
}
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Attribute
|
||||
# @api private
|
||||
class Sequence < Attribute
|
||||
|
@ -9,7 +9,7 @@ module FactoryGirl
|
|||
|
||||
def to_proc
|
||||
sequence = @sequence
|
||||
-> { FactoryGirl.generate(sequence) }
|
||||
-> { FactoryBot.generate(sequence) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Attribute
|
||||
# @api private
|
||||
class Static < Attribute
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class AttributeAssigner
|
||||
def initialize(evaluator, build_class, &instance_builder)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class AttributeList
|
||||
include Enumerable
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Callback
|
||||
attr_reader :name
|
||||
|
||||
|
@ -27,9 +27,9 @@ module FactoryGirl
|
|||
private
|
||||
|
||||
def ensure_valid_callback_name!
|
||||
unless FactoryGirl.callback_names.include?(name)
|
||||
unless FactoryBot.callback_names.include?(name)
|
||||
raise InvalidCallbackNameError, "#{name} is not a valid callback name. " +
|
||||
"Valid callback names are #{FactoryGirl.callback_names.inspect}"
|
||||
"Valid callback names are #{FactoryBot.callback_names.inspect}"
|
||||
end
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class CallbacksObserver
|
||||
def initialize(callbacks, evaluator)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class Configuration
|
||||
attr_reader :factories, :sequences, :traits, :strategies, :callback_names
|
||||
|
@ -31,7 +31,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def duplicate_attribute_assignment_from_initialize_with=(value)
|
||||
ActiveSupport::Deprecation.warn 'Assignment of duplicate_attribute_assignment_from_initialize_with is unnecessary as this is now default behavior in FactoryGirl 4.0; this line can be removed', caller
|
||||
ActiveSupport::Deprecation.warn 'Assignment of duplicate_attribute_assignment_from_initialize_with is unnecessary as this is now default behavior in FactoryBot 4.0; this line can be removed', caller
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
require 'factory_girl/declaration/static'
|
||||
require 'factory_girl/declaration/dynamic'
|
||||
require 'factory_girl/declaration/association'
|
||||
require 'factory_girl/declaration/implicit'
|
||||
require 'factory_bot/declaration/static'
|
||||
require 'factory_bot/declaration/dynamic'
|
||||
require 'factory_bot/declaration/association'
|
||||
require 'factory_bot/declaration/implicit'
|
||||
|
||||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class Declaration
|
||||
attr_reader :name
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Declaration
|
||||
# @api private
|
||||
class Association < Declaration
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Declaration
|
||||
# @api private
|
||||
class Dynamic < Declaration
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Declaration
|
||||
# @api private
|
||||
class Implicit < Declaration
|
||||
|
@ -19,9 +19,9 @@ module FactoryGirl
|
|||
private
|
||||
|
||||
def build
|
||||
if FactoryGirl.factories.registered?(name)
|
||||
if FactoryBot.factories.registered?(name)
|
||||
[Attribute::Association.new(name, name, {})]
|
||||
elsif FactoryGirl.sequences.registered?(name)
|
||||
elsif FactoryBot.sequences.registered?(name)
|
||||
[Attribute::Sequence.new(name, name, @ignored)]
|
||||
else
|
||||
@factory.inherit_traits([name])
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Declaration
|
||||
# @api private
|
||||
class Static < Declaration
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class DeclarationList
|
||||
include Enumerable
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Decorator < BasicObject
|
||||
undef_method :==
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Decorator
|
||||
class AttributeHash < Decorator
|
||||
def initialize(component, attributes = [])
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Decorator
|
||||
class ClassKeyHash < Decorator
|
||||
def [](key)
|
||||
|
@ -18,8 +18,8 @@ module FactoryGirl
|
|||
def symbolized_key(key)
|
||||
if key.respond_to?(:to_sym)
|
||||
key.to_sym
|
||||
elsif FactoryGirl.allow_class_lookup
|
||||
ActiveSupport::Deprecation.warn "Looking up factories by class is deprecated and will be removed in 5.0. Use symbols instead and set FactoryGirl.allow_class_lookup = false", caller
|
||||
elsif FactoryBot.allow_class_lookup
|
||||
ActiveSupport::Deprecation.warn "Looking up factories by class is deprecated and will be removed in 5.0. Use symbols instead and set FactoryBot.allow_class_lookup = false", caller
|
||||
key.to_s.underscore.to_sym
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Decorator
|
||||
class DisallowsDuplicatesRegistry < Decorator
|
||||
def register(name, item)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Decorator
|
||||
class InvocationTracker < Decorator
|
||||
def initialize(component)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Decorator
|
||||
class NewConstructor < Decorator
|
||||
def initialize(component, build_class)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class Definition
|
||||
attr_reader :defined_traits, :declarations
|
||||
|
@ -94,7 +94,7 @@ module FactoryGirl
|
|||
|
||||
def callback(*names, &block)
|
||||
names.each do |name|
|
||||
FactoryGirl.register_callback(name)
|
||||
FactoryBot.register_callback(name)
|
||||
add_callback(Callback.new(name, block))
|
||||
end
|
||||
end
|
||||
|
@ -110,7 +110,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def trait_by_name(name)
|
||||
trait_for(name) || FactoryGirl.trait_by_name(name)
|
||||
trait_for(name) || FactoryBot.trait_by_name(name)
|
||||
end
|
||||
|
||||
def trait_for(name)
|
|
@ -1,15 +1,15 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class DefinitionHierarchy
|
||||
def callbacks
|
||||
FactoryGirl.callbacks
|
||||
FactoryBot.callbacks
|
||||
end
|
||||
|
||||
def constructor
|
||||
FactoryGirl.constructor
|
||||
FactoryBot.constructor
|
||||
end
|
||||
|
||||
def to_create
|
||||
FactoryGirl.to_create
|
||||
FactoryBot.to_create
|
||||
end
|
||||
|
||||
def self.build_from_definition(definition)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class DefinitionProxy
|
||||
UNPROXIED_METHODS = %w(__send__ __id__ nil? send object_id extend instance_eval initialize block_given? raise caller method)
|
||||
|
||||
|
@ -18,7 +18,7 @@ module FactoryGirl
|
|||
|
||||
def singleton_method_added(name)
|
||||
message = "Defining methods in blocks (trait or factory) is not supported (#{name})"
|
||||
raise FactoryGirl::MethodDefinitionError, message
|
||||
raise FactoryBot::MethodDefinitionError, message
|
||||
end
|
||||
|
||||
# Adds an attribute that should be assigned on generated instances for this
|
||||
|
@ -29,7 +29,7 @@ module FactoryGirl
|
|||
# instance is generated. Lazy attribute blocks will not be called if that
|
||||
# attribute is overridden for a specific instance.
|
||||
#
|
||||
# When defining lazy attributes, an instance of FactoryGirl::Strategy will
|
||||
# When defining lazy attributes, an instance of FactoryBot::Strategy will
|
||||
# be yielded, allowing associations to be built using the correct build
|
||||
# strategy.
|
||||
#
|
||||
|
@ -77,7 +77,7 @@ module FactoryGirl
|
|||
#
|
||||
# are equivalent.
|
||||
#
|
||||
# If no argument or block is given, factory_girl will look for a sequence
|
||||
# If no argument or block is given, factory_bot will look for a sequence
|
||||
# or association with the same name. This means that:
|
||||
#
|
||||
# factory :user do
|
||||
|
@ -115,7 +115,7 @@ module FactoryGirl
|
|||
# sequence(:email) { |n| "person#{n}@example.com" }
|
||||
#
|
||||
# factory :user do
|
||||
# email { FactoryGirl.generate(:email) }
|
||||
# email { FactoryBot.generate(:email) }
|
||||
# end
|
||||
#
|
||||
# Except that no globally available sequence will be defined.
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# Raised when a factory is defined that attempts to instantiate itself.
|
||||
class AssociationDefinitionError < RuntimeError; end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
require 'observer'
|
||||
|
||||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Evaluation
|
||||
include Observable
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'active_support/core_ext/hash/except'
|
||||
require 'active_support/core_ext/class/attribute'
|
||||
|
||||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class Evaluator
|
||||
class_attribute :attribute_lists
|
||||
|
@ -24,7 +24,7 @@ module FactoryGirl
|
|||
def association(factory_name, *traits_and_overrides)
|
||||
overrides = traits_and_overrides.extract_options!
|
||||
strategy_override = overrides.fetch(:strategy) do
|
||||
FactoryGirl.use_parent_strategy ? @build_strategy.class : :create
|
||||
FactoryBot.use_parent_strategy ? @build_strategy.class : :create
|
||||
end
|
||||
|
||||
traits_and_overrides += [overrides.except(:strategy)]
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class EvaluatorClassDefiner
|
||||
def initialize(attributes, parent_class)
|
|
@ -1,7 +1,7 @@
|
|||
require 'active_support/core_ext/hash/keys'
|
||||
require 'active_support/inflector'
|
||||
|
||||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class Factory
|
||||
attr_reader :name, :definition
|
||||
|
@ -59,7 +59,7 @@ module FactoryGirl
|
|||
# # ...
|
||||
# end
|
||||
#
|
||||
# FactoryGirl.create(:author).class
|
||||
# FactoryBot.create(:author).class
|
||||
# # => User
|
||||
#
|
||||
# Because an attribute defined without a value or block will build an
|
||||
|
@ -74,7 +74,7 @@ module FactoryGirl
|
|||
# author
|
||||
# end
|
||||
#
|
||||
# FactoryGirl.create(:post).author.class
|
||||
# FactoryBot.create(:post).author.class
|
||||
# # => User
|
||||
def names
|
||||
[name] + @aliases
|
||||
|
@ -145,7 +145,7 @@ module FactoryGirl
|
|||
|
||||
def parent
|
||||
if @parent
|
||||
FactoryGirl.factory_by_name(@parent)
|
||||
FactoryBot.factory_by_name(@parent)
|
||||
else
|
||||
NullFactory.new
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class FactoryRunner
|
||||
def initialize(name, strategy, traits_and_overrides)
|
||||
@name = name
|
||||
|
@ -9,7 +9,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def run(runner_strategy = @strategy, &block)
|
||||
factory = FactoryGirl.factory_by_name(@name)
|
||||
factory = FactoryBot.factory_by_name(@name)
|
||||
|
||||
factory.compile
|
||||
|
||||
|
@ -25,7 +25,7 @@ module FactoryGirl
|
|||
factory: factory
|
||||
}
|
||||
|
||||
ActiveSupport::Notifications.instrument('factory_girl.run_factory', instrumentation_payload) do
|
||||
ActiveSupport::Notifications.instrument('factory_bot.run_factory', instrumentation_payload) do
|
||||
factory.run(runner_strategy, @overrides, &block)
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class << self
|
||||
# An Array of strings specifying locations that should be searched for
|
||||
# factory definitions. By default, factory_girl will attempt to require
|
||||
# factory definitions. By default, factory_bot will attempt to require
|
||||
# "factories", "test/factories" and "spec/factories". Only the first
|
||||
# existing file will be loaded.
|
||||
attr_accessor :definition_file_paths
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Linter
|
||||
|
||||
def initialize(factories, linting_strategy, factory_strategy = :create)
|
||||
|
@ -56,7 +56,7 @@ module FactoryGirl
|
|||
def lint_factory(factory)
|
||||
result = []
|
||||
begin
|
||||
FactoryGirl.public_send(factory_strategy, factory.name)
|
||||
FactoryBot.public_send(factory_strategy, factory.name)
|
||||
rescue => error
|
||||
result |= [FactoryError.new(error, factory)]
|
||||
end
|
||||
|
@ -67,7 +67,7 @@ module FactoryGirl
|
|||
result = []
|
||||
factory.definition.defined_traits.map(&:name).each do |trait_name|
|
||||
begin
|
||||
FactoryGirl.public_send(factory_strategy, factory.name, trait_name)
|
||||
FactoryBot.public_send(factory_strategy, factory.name, trait_name)
|
||||
rescue => error
|
||||
result |=
|
||||
[FactoryTraitError.new(error, factory, trait_name)]
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class NullFactory
|
||||
attr_reader :definition
|
||||
|
@ -12,7 +12,7 @@ module FactoryGirl
|
|||
|
||||
def compile; end
|
||||
def class_name; end
|
||||
def evaluator_class; FactoryGirl::Evaluator; end
|
||||
def hierarchy_class; FactoryGirl::DefinitionHierarchy; end
|
||||
def evaluator_class; FactoryBot::Evaluator; end
|
||||
def hierarchy_class; FactoryBot::DefinitionHierarchy; end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class NullObject < ::BasicObject
|
||||
def initialize(methods_to_respond_to)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
class Registry
|
||||
include Enumerable
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
def self.reload
|
||||
reset_configuration
|
||||
register_default_strategies
|
|
@ -1,6 +1,6 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
|
||||
# Sequences are defined using sequence within a FactoryGirl.define block.
|
||||
# Sequences are defined using sequence within a FactoryBot.define block.
|
||||
# Sequence values are generated using next.
|
||||
# @api private
|
||||
class Sequence
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
module Strategy
|
||||
class AttributesFor
|
||||
def association(runner)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
module Strategy
|
||||
class Build
|
||||
def association(runner)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
module Strategy
|
||||
class Create
|
||||
def association(runner)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
module Strategy
|
||||
class Null
|
||||
def association(runner)
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
module Strategy
|
||||
class Stub
|
||||
@@next_id = 1000
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class StrategyCalculator
|
||||
def initialize(name_or_object)
|
||||
|
@ -20,7 +20,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def strategy_name_to_object
|
||||
FactoryGirl.strategy_by_name(@name_or_object)
|
||||
FactoryBot.strategy_by_name(@name_or_object)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class StrategySyntaxMethodRegistrar
|
||||
def initialize(strategy_name)
|
||||
|
@ -42,7 +42,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def define_syntax_method(name, &block)
|
||||
FactoryGirl::Syntax::Methods.module_exec do
|
||||
FactoryBot::Syntax::Methods.module_exec do
|
||||
if method_defined?(name) || private_method_defined?(name)
|
||||
undef_method(name)
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
require 'factory_bot/syntax/methods'
|
||||
require 'factory_bot/syntax/default'
|
||||
|
||||
module FactoryBot
|
||||
module Syntax
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
module Syntax
|
||||
module Default
|
||||
include Methods
|
||||
|
@ -14,10 +14,10 @@ module FactoryGirl
|
|||
class DSL
|
||||
def factory(name, options = {}, &block)
|
||||
factory = Factory.new(name, options)
|
||||
proxy = FactoryGirl::DefinitionProxy.new(factory.definition)
|
||||
proxy = FactoryBot::DefinitionProxy.new(factory.definition)
|
||||
proxy.instance_eval(&block) if block_given?
|
||||
|
||||
FactoryGirl.register_factory(factory)
|
||||
FactoryBot.register_factory(factory)
|
||||
|
||||
proxy.child_factories.each do |(child_name, child_options, child_block)|
|
||||
parent_factory = child_options.delete(:parent) || name
|
||||
|
@ -26,23 +26,23 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def sequence(name, *args, &block)
|
||||
FactoryGirl.register_sequence(Sequence.new(name, *args, &block))
|
||||
FactoryBot.register_sequence(Sequence.new(name, *args, &block))
|
||||
end
|
||||
|
||||
def trait(name, &block)
|
||||
FactoryGirl.register_trait(Trait.new(name, &block))
|
||||
FactoryBot.register_trait(Trait.new(name, &block))
|
||||
end
|
||||
|
||||
def to_create(&block)
|
||||
FactoryGirl.to_create(&block)
|
||||
FactoryBot.to_create(&block)
|
||||
end
|
||||
|
||||
def skip_create
|
||||
FactoryGirl.skip_create
|
||||
FactoryBot.skip_create
|
||||
end
|
||||
|
||||
def initialize_with(&block)
|
||||
FactoryGirl.initialize_with(&block)
|
||||
FactoryBot.initialize_with(&block)
|
||||
end
|
||||
|
||||
def self.run(block)
|
||||
|
@ -54,14 +54,14 @@ module FactoryGirl
|
|||
private
|
||||
|
||||
def configuration
|
||||
FactoryGirl.configuration
|
||||
FactoryBot.configuration
|
||||
end
|
||||
end
|
||||
|
||||
class ModifyDSL
|
||||
def factory(name, options = {}, &block)
|
||||
factory = FactoryGirl.factory_by_name(name)
|
||||
proxy = FactoryGirl::DefinitionProxy.new(factory.definition.overridable)
|
||||
factory = FactoryBot.factory_by_name(name)
|
||||
proxy = FactoryBot::DefinitionProxy.new(factory.definition.overridable)
|
||||
proxy.instance_eval(&block)
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
module Syntax
|
||||
## This module is a container for all strategy methods provided by
|
||||
## FactoryGirl. This includes all the default strategies provided ({Methods#build},
|
||||
## FactoryBot. This includes all the default strategies provided ({Methods#build},
|
||||
## {Methods#create}, {Methods#build_stubbed}, and {Methods#attributes_for}), as well as
|
||||
## the complementary *_list methods.
|
||||
## @example singular factory execution
|
||||
|
@ -30,7 +30,7 @@ module FactoryGirl
|
|||
## # factory with traits and attribute override
|
||||
## build_stubbed_list(:user, 15, :admin, :male, name: "John Doe")
|
||||
module Methods
|
||||
# @!parse FactoryGirl.register_default_strategies
|
||||
# @!parse FactoryBot.register_default_strategies
|
||||
# @!method build(name, *traits_and_overrides, &block)
|
||||
# (see #strategy_method)
|
||||
# Builds a registered factory by name.
|
||||
|
@ -88,7 +88,7 @@ module FactoryGirl
|
|||
# Returns:
|
||||
# The next value in the sequence. (Object)
|
||||
def generate(name)
|
||||
FactoryGirl.sequence_by_name(name).next
|
||||
FactoryBot.sequence_by_name(name).next
|
||||
end
|
||||
|
||||
# Generates and returns the list of values in a sequence.
|
||||
|
@ -103,7 +103,7 @@ module FactoryGirl
|
|||
# The next value in the sequence. (Object)
|
||||
def generate_list(name, count)
|
||||
(1..count).map do
|
||||
FactoryGirl.sequence_by_name(name).next
|
||||
FactoryBot.sequence_by_name(name).next
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class SyntaxRunner
|
||||
include Syntax::Methods
|
|
@ -1,4 +1,4 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
# @api private
|
||||
class Trait
|
||||
attr_reader :name, :definition
|
||||
|
@ -8,7 +8,7 @@ module FactoryGirl
|
|||
@block = block
|
||||
@definition = Definition.new(@name)
|
||||
|
||||
proxy = FactoryGirl::DefinitionProxy.new(@definition)
|
||||
proxy = FactoryBot::DefinitionProxy.new(@definition)
|
||||
proxy.instance_eval(&@block) if block_given?
|
||||
end
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
module FactoryGirl
|
||||
module FactoryBot
|
||||
VERSION = '4.8.1'.freeze
|
||||
end
|
|
@ -1,156 +1,5 @@
|
|||
require 'set'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
require 'active_support/deprecation'
|
||||
require 'active_support/notifications'
|
||||
require "factory_bot"
|
||||
|
||||
require 'factory_girl/definition_hierarchy'
|
||||
require 'factory_girl/configuration'
|
||||
require 'factory_girl/errors'
|
||||
require 'factory_girl/factory_runner'
|
||||
require 'factory_girl/strategy_syntax_method_registrar'
|
||||
require 'factory_girl/strategy_calculator'
|
||||
require 'factory_girl/strategy/build'
|
||||
require 'factory_girl/strategy/create'
|
||||
require 'factory_girl/strategy/attributes_for'
|
||||
require 'factory_girl/strategy/stub'
|
||||
require 'factory_girl/strategy/null'
|
||||
require 'factory_girl/registry'
|
||||
require 'factory_girl/null_factory'
|
||||
require 'factory_girl/null_object'
|
||||
require 'factory_girl/evaluation'
|
||||
require 'factory_girl/factory'
|
||||
require 'factory_girl/attribute_assigner'
|
||||
require 'factory_girl/evaluator'
|
||||
require 'factory_girl/evaluator_class_definer'
|
||||
require 'factory_girl/attribute'
|
||||
require 'factory_girl/callback'
|
||||
require 'factory_girl/callbacks_observer'
|
||||
require 'factory_girl/declaration_list'
|
||||
require 'factory_girl/declaration'
|
||||
require 'factory_girl/sequence'
|
||||
require 'factory_girl/attribute_list'
|
||||
require 'factory_girl/trait'
|
||||
require 'factory_girl/aliases'
|
||||
require 'factory_girl/definition'
|
||||
require 'factory_girl/definition_proxy'
|
||||
require 'factory_girl/syntax'
|
||||
require 'factory_girl/syntax_runner'
|
||||
require 'factory_girl/find_definitions'
|
||||
require 'factory_girl/reload'
|
||||
require 'factory_girl/decorator'
|
||||
require 'factory_girl/decorator/attribute_hash'
|
||||
require 'factory_girl/decorator/class_key_hash'
|
||||
require 'factory_girl/decorator/disallows_duplicates_registry'
|
||||
require 'factory_girl/decorator/invocation_tracker'
|
||||
require 'factory_girl/decorator/new_constructor'
|
||||
require 'factory_girl/linter'
|
||||
require 'factory_girl/version'
|
||||
FactoryGirl = FactoryBot
|
||||
|
||||
module FactoryGirl
|
||||
def self.configuration
|
||||
@configuration ||= Configuration.new
|
||||
end
|
||||
|
||||
def self.reset_configuration
|
||||
@configuration = nil
|
||||
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
|
||||
def self.lint(*args)
|
||||
options = args.extract_options!
|
||||
factories_to_lint = args[0] || FactoryGirl.factories
|
||||
linting_strategy = options[:traits] ? :factory_and_traits : :factory
|
||||
factory_strategy = options[:strategy] || :create
|
||||
Linter.new(factories_to_lint, linting_strategy, factory_strategy).lint!
|
||||
end
|
||||
|
||||
class << self
|
||||
delegate :factories,
|
||||
:sequences,
|
||||
:traits,
|
||||
:callbacks,
|
||||
:strategies,
|
||||
:callback_names,
|
||||
:to_create,
|
||||
:skip_create,
|
||||
:initialize_with,
|
||||
:constructor,
|
||||
:duplicate_attribute_assignment_from_initialize_with,
|
||||
:duplicate_attribute_assignment_from_initialize_with=,
|
||||
:allow_class_lookup,
|
||||
:allow_class_lookup=,
|
||||
:use_parent_strategy,
|
||||
:use_parent_strategy=,
|
||||
to: :configuration
|
||||
end
|
||||
|
||||
def self.register_factory(factory)
|
||||
factory.names.each do |name|
|
||||
factories.register(name, factory)
|
||||
end
|
||||
factory
|
||||
end
|
||||
|
||||
def self.factory_by_name(name)
|
||||
factories.find(name)
|
||||
end
|
||||
|
||||
def self.register_sequence(sequence)
|
||||
sequence.names.each do |name|
|
||||
sequences.register(name, sequence)
|
||||
end
|
||||
sequence
|
||||
end
|
||||
|
||||
def self.sequence_by_name(name)
|
||||
sequences.find(name)
|
||||
end
|
||||
|
||||
def self.register_trait(trait)
|
||||
trait.names.each do |name|
|
||||
traits.register(name, trait)
|
||||
end
|
||||
trait
|
||||
end
|
||||
|
||||
def self.trait_by_name(name)
|
||||
traits.find(name)
|
||||
end
|
||||
|
||||
def self.register_strategy(strategy_name, strategy_class)
|
||||
strategies.register(strategy_name, strategy_class)
|
||||
StrategySyntaxMethodRegistrar.new(strategy_name).define_strategy_methods
|
||||
end
|
||||
|
||||
def self.strategy_by_name(name)
|
||||
strategies.find(name)
|
||||
end
|
||||
|
||||
def self.register_default_strategies
|
||||
register_strategy(:build, FactoryGirl::Strategy::Build)
|
||||
register_strategy(:create, FactoryGirl::Strategy::Create)
|
||||
register_strategy(:attributes_for, FactoryGirl::Strategy::AttributesFor)
|
||||
register_strategy(:build_stubbed, FactoryGirl::Strategy::Stub)
|
||||
register_strategy(:null, FactoryGirl::Strategy::Null)
|
||||
end
|
||||
|
||||
def self.register_default_callbacks
|
||||
register_callback(:after_build)
|
||||
register_callback(:after_create)
|
||||
register_callback(:after_stub)
|
||||
register_callback(:before_create)
|
||||
end
|
||||
|
||||
def self.register_callback(name)
|
||||
name = name.to_sym
|
||||
callback_names << name
|
||||
end
|
||||
end
|
||||
|
||||
FactoryGirl.register_default_strategies
|
||||
FactoryGirl.register_default_callbacks
|
||||
warn "The factory_girl gem has been deprecated and has been replaced by factory_bot. Please switch to factory_bot as soon as possible."
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
require 'factory_girl/syntax/methods'
|
||||
require 'factory_girl/syntax/default'
|
||||
|
||||
module FactoryGirl
|
||||
module Syntax
|
||||
end
|
||||
end
|
|
@ -14,11 +14,11 @@ unless ActiveSupport::Notifications.respond_to?(:subscribed)
|
|||
end
|
||||
|
||||
describe "using ActiveSupport::Instrumentation to track factory interaction" do
|
||||
let(:slow_user_factory) { FactoryGirl.factory_by_name("slow_user") }
|
||||
let(:user_factory) { FactoryGirl.factory_by_name("user") }
|
||||
let(:slow_user_factory) { FactoryBot.factory_by_name("slow_user") }
|
||||
let(:user_factory) { FactoryBot.factory_by_name("user") }
|
||||
before do
|
||||
define_model("User", email: :string)
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
email "john@example.com"
|
||||
|
||||
|
@ -33,8 +33,8 @@ describe "using ActiveSupport::Instrumentation to track factory interaction" do
|
|||
it "tracks proper time of creating the record" do
|
||||
time_to_execute = 0
|
||||
callback = ->(name, start, finish, id, payload) { time_to_execute = finish - start }
|
||||
ActiveSupport::Notifications.subscribed(callback, "factory_girl.run_factory") do
|
||||
FactoryGirl.build(:slow_user)
|
||||
ActiveSupport::Notifications.subscribed(callback, "factory_bot.run_factory") do
|
||||
FactoryBot.build(:slow_user)
|
||||
end
|
||||
|
||||
expect(time_to_execute).to be >= 0.1
|
||||
|
@ -53,11 +53,11 @@ describe "using ActiveSupport::Instrumentation to track factory interaction" do
|
|||
tracked_invocations[factory_name][:factory] = factory
|
||||
end
|
||||
|
||||
ActiveSupport::Notifications.subscribed(callback, "factory_girl.run_factory") do
|
||||
FactoryGirl.build_list(:slow_user, 2)
|
||||
FactoryGirl.build_list(:user, 5)
|
||||
FactoryGirl.create_list(:user, 2)
|
||||
FactoryGirl.attributes_for(:slow_user)
|
||||
ActiveSupport::Notifications.subscribed(callback, "factory_bot.run_factory") do
|
||||
FactoryBot.build_list(:slow_user, 2)
|
||||
FactoryBot.build_list(:user, 5)
|
||||
FactoryBot.create_list(:user, 2)
|
||||
FactoryBot.attributes_for(:slow_user)
|
||||
end
|
||||
|
||||
expect(tracked_invocations[:slow_user][:build]).to eq(2)
|
||||
|
|
|
@ -2,18 +2,18 @@ require "spec_helper"
|
|||
|
||||
describe "aliases and overrides" do
|
||||
before do
|
||||
FactoryGirl.aliases << [/one/, "two"]
|
||||
FactoryBot.aliases << [/one/, "two"]
|
||||
|
||||
define_model("User", two: :string, one: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
two "set value"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl.create(:user, one: "override") }
|
||||
subject { FactoryBot.create(:user, one: "override") }
|
||||
its(:one) { should eq "override" }
|
||||
its(:two) { should be_nil }
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ describe "attribute aliases" do
|
|||
belongs_to :user
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
factory :user_with_name do
|
||||
name "John Doe"
|
||||
|
@ -26,7 +26,7 @@ describe "attribute aliases" do
|
|||
end
|
||||
|
||||
context "assigning an association by foreign key" do
|
||||
subject { FactoryGirl.build(:post, user_id: 1) }
|
||||
subject { FactoryBot.build(:post, user_id: 1) }
|
||||
|
||||
it "doesn't assign both an association and its foreign key" do
|
||||
expect(subject.user_id).to eq 1
|
||||
|
@ -34,7 +34,7 @@ describe "attribute aliases" do
|
|||
end
|
||||
|
||||
context "assigning an association by passing factory" do
|
||||
subject { FactoryGirl.create(:post_with_named_user).user }
|
||||
subject { FactoryBot.create(:post_with_named_user).user }
|
||||
|
||||
it "assigns attributes correctly" do
|
||||
expect(subject.name).to eq "John Doe"
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "declaring attributes on a Factory that are private methods on Object"
|
|||
before do
|
||||
define_model("Website", system: :boolean, link: :string, sleep: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :website do
|
||||
system false
|
||||
link "http://example.com"
|
||||
|
@ -13,7 +13,7 @@ describe "declaring attributes on a Factory that are private methods on Object"
|
|||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl.build(:website, sleep: -5) }
|
||||
subject { FactoryBot.build(:website, sleep: -5) }
|
||||
|
||||
its(:system) { should eq false }
|
||||
its(:link) { should eq "http://example.com" }
|
||||
|
@ -30,7 +30,7 @@ describe "assigning overrides that are also private methods on object" do
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :website do
|
||||
more_format { "format: #{format}" }
|
||||
end
|
||||
|
@ -41,7 +41,7 @@ describe "assigning overrides that are also private methods on object" do
|
|||
Object.send(:undef_method, :some_funky_method)
|
||||
end
|
||||
|
||||
subject { FactoryGirl.build(:website, format: "Great", y: 12345, some_funky_method: "foobar!") }
|
||||
subject { FactoryBot.build(:website, format: "Great", y: 12345, some_funky_method: "foobar!") }
|
||||
its(:format) { should eq "Great" }
|
||||
its(:y) { should eq 12345 }
|
||||
its(:more_format) { should eq "format: Great" }
|
||||
|
@ -56,13 +56,13 @@ describe "accessing methods from the instance within a dynamic attribute that is
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :website do
|
||||
more_format { "format: #{format}" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl.build(:website) }
|
||||
subject { FactoryBot.build(:website) }
|
||||
its(:more_format) { should eq "format: This is an awesome format" }
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "a generated attributes hash" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
|
@ -15,7 +15,7 @@ describe "a generated attributes hash" do
|
|||
has_many :comments
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user
|
||||
factory :comment
|
||||
|
||||
|
@ -52,12 +52,12 @@ describe "a generated attributes hash" do
|
|||
end
|
||||
|
||||
describe "calling `attributes_for` with a block" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
end
|
||||
end
|
||||
|
@ -85,13 +85,13 @@ describe "`attributes_for` for a class whose constructor has required params" do
|
|||
def initialize(arg1, arg2); end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
name "John Doe"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl.attributes_for(:user) }
|
||||
subject { FactoryBot.attributes_for(:user) }
|
||||
its([:name]) { should eq "John Doe" }
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ describe "calling methods on the model instance" do
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
age_copy { age }
|
||||
end
|
||||
|
@ -17,37 +17,37 @@ describe "calling methods on the model instance" do
|
|||
|
||||
context "without the attribute being overridden" do
|
||||
it "returns the correct value from the instance" do
|
||||
expect(FactoryGirl.build(:user).age_copy).to eq 18
|
||||
expect(FactoryBot.build(:user).age_copy).to eq 18
|
||||
end
|
||||
|
||||
it "returns nil during attributes_for" do
|
||||
expect(FactoryGirl.attributes_for(:user)[:age_copy]).to be_nil
|
||||
expect(FactoryBot.attributes_for(:user)[:age_copy]).to be_nil
|
||||
end
|
||||
|
||||
it "doesn't instantiate a record with attributes_for" do
|
||||
allow(User).to receive(:new)
|
||||
FactoryGirl.attributes_for(:user)
|
||||
FactoryBot.attributes_for(:user)
|
||||
expect(User).to_not have_received(:new)
|
||||
end
|
||||
end
|
||||
|
||||
context "with the attribute being overridden" do
|
||||
it "uses the overridden value" do
|
||||
expect(FactoryGirl.build(:user, age_copy: nil).age_copy).to be_nil
|
||||
expect(FactoryBot.build(:user, age_copy: nil).age_copy).to be_nil
|
||||
end
|
||||
|
||||
it "uses the overridden value during attributes_for" do
|
||||
expect(FactoryGirl.attributes_for(:user, age_copy: 25)[:age_copy]).to eq 25
|
||||
expect(FactoryBot.attributes_for(:user, age_copy: 25)[:age_copy]).to eq 25
|
||||
end
|
||||
end
|
||||
|
||||
context "with the referenced attribute being overridden" do
|
||||
it "uses the overridden value" do
|
||||
expect(FactoryGirl.build(:user, age: nil).age_copy).to be_nil
|
||||
expect(FactoryBot.build(:user, age: nil).age_copy).to be_nil
|
||||
end
|
||||
|
||||
it "uses the overridden value during attributes_for" do
|
||||
expect(FactoryGirl.attributes_for(:user, age: 25)[:age_copy]).to eq 25
|
||||
expect(FactoryBot.attributes_for(:user, age: 25)[:age_copy]).to eq 25
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "a generated attributes hash where order matters" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('ParentModel', static: :integer,
|
||||
|
@ -9,7 +9,7 @@ describe "a generated attributes hash where order matters" do
|
|||
evaluates_second: :integer,
|
||||
evaluates_third: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :parent_model do
|
||||
evaluates_first { static }
|
||||
evaluates_second { evaluates_first }
|
||||
|
@ -30,7 +30,7 @@ describe "a generated attributes hash where order matters" do
|
|||
end
|
||||
|
||||
context "factory with a parent" do
|
||||
subject { FactoryGirl.build(:child_model) }
|
||||
subject { FactoryBot.build(:child_model) }
|
||||
|
||||
it "assigns attributes in the order they're defined with preference to static attributes" do
|
||||
expect(subject[:evaluates_first]).to eq 1
|
||||
|
@ -40,7 +40,7 @@ describe "a generated attributes hash where order matters" do
|
|||
end
|
||||
|
||||
context "factory without a parent" do
|
||||
subject { FactoryGirl.build(:without_parent) }
|
||||
subject { FactoryBot.build(:without_parent) }
|
||||
|
||||
it "assigns attributes in the order they're defined with preference to static attributes without a parent class" do
|
||||
expect(subject[:evaluates_first]).to eq 1
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "build multiple instances" do
|
|||
before do
|
||||
define_model('Post', title: :string, position: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory(:post) do |post|
|
||||
post.title "Through the Looking Glass"
|
||||
post.position { rand(10**4) }
|
||||
|
@ -13,7 +13,7 @@ describe "build multiple instances" do
|
|||
end
|
||||
|
||||
context "without default attributes" do
|
||||
subject { FactoryGirl.build_list(:post, 20) }
|
||||
subject { FactoryBot.build_list(:post, 20) }
|
||||
|
||||
its(:length) { should eq 20 }
|
||||
|
||||
|
@ -31,7 +31,7 @@ describe "build multiple instances" do
|
|||
end
|
||||
|
||||
context "with default attributes" do
|
||||
subject { FactoryGirl.build_list(:post, 20, title: "The Hunting of the Snark") }
|
||||
subject { FactoryBot.build_list(:post, 20, title: "The Hunting of the Snark") }
|
||||
|
||||
it "overrides the default values" do
|
||||
subject.each do |record|
|
||||
|
@ -42,7 +42,7 @@ describe "build multiple instances" do
|
|||
|
||||
context "with a block" do
|
||||
subject do
|
||||
FactoryGirl.build_list(:post, 20, title: "The Listing of the Block") do |post|
|
||||
FactoryBot.build_list(:post, 20, title: "The Listing of the Block") do |post|
|
||||
post.position = post.id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "a built instance" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
|
@ -10,7 +10,7 @@ describe "a built instance" do
|
|||
belongs_to :user
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user
|
||||
|
||||
factory :post do
|
||||
|
@ -24,7 +24,7 @@ describe "a built instance" do
|
|||
it { should be_new_record }
|
||||
|
||||
context "when the :use_parent_strategy config option has not been set" do
|
||||
before { FactoryGirl.use_parent_strategy = nil }
|
||||
before { FactoryBot.use_parent_strategy = nil }
|
||||
|
||||
it "assigns and saves associations" do
|
||||
expect(subject.user).to be_kind_of(User)
|
||||
|
@ -33,7 +33,7 @@ describe "a built instance" do
|
|||
end
|
||||
|
||||
context "when the :use_parent_strategy config option has been enabled" do
|
||||
before { FactoryGirl.use_parent_strategy = true }
|
||||
before { FactoryBot.use_parent_strategy = true }
|
||||
|
||||
it "assigns but does not save associations" do
|
||||
expect(subject.user).to be_kind_of(User)
|
||||
|
@ -42,7 +42,7 @@ describe "a built instance" do
|
|||
end
|
||||
|
||||
it "assigns but does not save associations when using parent strategy" do
|
||||
FactoryGirl.use_parent_strategy = true
|
||||
FactoryBot.use_parent_strategy = true
|
||||
|
||||
expect(subject.user).to be_kind_of(User)
|
||||
expect(subject.user).to be_new_record
|
||||
|
@ -50,7 +50,7 @@ describe "a built instance" do
|
|||
end
|
||||
|
||||
describe "a built instance with strategy: :create" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
|
@ -59,7 +59,7 @@ describe "a built instance with strategy: :create" do
|
|||
belongs_to :user
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user
|
||||
|
||||
factory :post do
|
||||
|
@ -79,12 +79,12 @@ describe "a built instance with strategy: :create" do
|
|||
end
|
||||
|
||||
describe "calling `build` with a block" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "a generated stub instance" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
|
@ -13,7 +13,7 @@ describe "a generated stub instance" do
|
|||
belongs_to :user
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user
|
||||
|
||||
factory :post do
|
||||
|
@ -89,12 +89,12 @@ describe "a generated stub instance" do
|
|||
end
|
||||
|
||||
describe "calling `build_stubbed` with a block" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
end
|
||||
end
|
||||
|
@ -117,13 +117,13 @@ describe "calling `build_stubbed` with a block" do
|
|||
end
|
||||
|
||||
describe "defaulting `created_at`" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('ThingWithTimestamp', created_at: :datetime)
|
||||
define_model('ThingWithoutTimestamp')
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :thing_with_timestamp
|
||||
factory :thing_without_timestamp
|
||||
end
|
||||
|
@ -159,13 +159,13 @@ describe "defaulting `created_at`" do
|
|||
end
|
||||
|
||||
describe "defaulting `updated_at`" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model("ThingWithTimestamp", updated_at: :datetime)
|
||||
define_model("ThingWithoutTimestamp")
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :thing_with_timestamp
|
||||
factory :thing_without_timestamp
|
||||
end
|
||||
|
@ -197,12 +197,12 @@ describe 'defaulting `id`' do
|
|||
before do
|
||||
define_model('Post')
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :post
|
||||
end
|
||||
end
|
||||
|
||||
it 'allows overriding id' do
|
||||
expect(FactoryGirl.build_stubbed(:post, id: 12).id).to eq 12
|
||||
expect(FactoryBot.build_stubbed(:post, id: 12).id).to eq 12
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "callbacks" do
|
|||
before do
|
||||
define_model("User", first_name: :string, last_name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user_with_callbacks, class: :user do
|
||||
after(:stub) { |user| user.first_name = 'Stubby' }
|
||||
after(:build) { |user| user.first_name = 'Buildy' }
|
||||
|
@ -19,29 +19,29 @@ describe "callbacks" do
|
|||
end
|
||||
|
||||
it "runs the after(:stub) callback when stubbing" do
|
||||
user = FactoryGirl.build_stubbed(:user_with_callbacks)
|
||||
user = FactoryBot.build_stubbed(:user_with_callbacks)
|
||||
expect(user.first_name).to eq 'Stubby'
|
||||
end
|
||||
|
||||
it "runs the after(:build) callback when building" do
|
||||
user = FactoryGirl.build(:user_with_callbacks)
|
||||
user = FactoryBot.build(:user_with_callbacks)
|
||||
expect(user.first_name).to eq 'Buildy'
|
||||
end
|
||||
|
||||
it "runs both the after(:build) and after(:create) callbacks when creating" do
|
||||
user = FactoryGirl.create(:user_with_callbacks)
|
||||
user = FactoryBot.create(:user_with_callbacks)
|
||||
expect(user.first_name).to eq 'Buildy'
|
||||
expect(user.last_name).to eq 'Createy'
|
||||
end
|
||||
|
||||
it "runs both the after(:stub) callback on the factory and the inherited after(:stub) callback" do
|
||||
user = FactoryGirl.build_stubbed(:user_with_inherited_callbacks)
|
||||
user = FactoryBot.build_stubbed(:user_with_inherited_callbacks)
|
||||
expect(user.first_name).to eq 'Stubby'
|
||||
expect(user.last_name).to eq 'Double-Stubby'
|
||||
end
|
||||
|
||||
it "runs child callback after parent callback" do
|
||||
user = FactoryGirl.build(:user_with_inherited_callbacks)
|
||||
user = FactoryBot.build(:user_with_inherited_callbacks)
|
||||
expect(user.first_name).to eq 'Child-Buildy'
|
||||
end
|
||||
end
|
||||
|
@ -58,7 +58,7 @@ describe 'callbacks using Symbol#to_proc' do
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
after :build, &:confirm!
|
||||
end
|
||||
|
@ -66,16 +66,16 @@ describe 'callbacks using Symbol#to_proc' do
|
|||
end
|
||||
|
||||
it 'runs the callback correctly' do
|
||||
user = FactoryGirl.build(:user)
|
||||
user = FactoryBot.build(:user)
|
||||
expect(user).to be_confirmed
|
||||
end
|
||||
end
|
||||
|
||||
describe "callbacks using syntax methods without referencing FactoryGirl explicitly" do
|
||||
describe "callbacks using syntax methods without referencing FactoryBot explicitly" do
|
||||
before do
|
||||
define_model("User", first_number: :integer, last_number: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
sequence(:sequence_1)
|
||||
sequence(:sequence_2)
|
||||
sequence(:sequence_3)
|
||||
|
@ -89,16 +89,16 @@ describe "callbacks using syntax methods without referencing FactoryGirl explici
|
|||
end
|
||||
|
||||
it "works when the callback has no variables" do
|
||||
FactoryGirl.build_stubbed(:user)
|
||||
expect(FactoryGirl.generate(:sequence_3)).to eq 2
|
||||
FactoryBot.build_stubbed(:user)
|
||||
expect(FactoryBot.generate(:sequence_3)).to eq 2
|
||||
end
|
||||
|
||||
it "works when the callback has one variable" do
|
||||
expect(FactoryGirl.build(:user).first_number).to eq 1
|
||||
expect(FactoryBot.build(:user).first_number).to eq 1
|
||||
end
|
||||
|
||||
it "works when the callback has two variables" do
|
||||
expect(FactoryGirl.create(:user).last_number).to eq 1
|
||||
expect(FactoryBot.create(:user).last_number).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -140,11 +140,11 @@ describe "custom callbacks" do
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.register_strategy(:custom_before, custom_before)
|
||||
FactoryGirl.register_strategy(:custom_after, custom_after)
|
||||
FactoryGirl.register_strategy(:totally_custom, totally_custom)
|
||||
FactoryBot.register_strategy(:custom_before, custom_before)
|
||||
FactoryBot.register_strategy(:custom_after, custom_after)
|
||||
FactoryBot.register_strategy(:totally_custom, totally_custom)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
first_name "John"
|
||||
last_name "Doe"
|
||||
|
@ -160,18 +160,18 @@ describe "custom callbacks" do
|
|||
end
|
||||
|
||||
it "runs a custom before callback when the proper strategy executes" do
|
||||
expect(FactoryGirl.build(:user).name).to eq "John Doe"
|
||||
expect(FactoryGirl.custom_before(:user).name).to eq "Overridden First Doe"
|
||||
expect(FactoryBot.build(:user).name).to eq "John Doe"
|
||||
expect(FactoryBot.custom_before(:user).name).to eq "Overridden First Doe"
|
||||
end
|
||||
|
||||
it "runs a custom after callback when the proper strategy executes" do
|
||||
expect(FactoryGirl.build(:user).name).to eq "John Doe"
|
||||
expect(FactoryGirl.custom_after(:user).name).to eq "John Overridden Last"
|
||||
expect(FactoryBot.build(:user).name).to eq "John Doe"
|
||||
expect(FactoryBot.custom_after(:user).name).to eq "John Overridden Last"
|
||||
end
|
||||
|
||||
it "runs a custom callback without prepending before or after when the proper strategy executes" do
|
||||
expect(FactoryGirl.build(:user).name).to eq "John Doe"
|
||||
expect(FactoryGirl.totally_custom(:user).name).to eq "Totally Custom"
|
||||
expect(FactoryBot.build(:user).name).to eq "John Doe"
|
||||
expect(FactoryBot.totally_custom(:user).name).to eq "Totally Custom"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -179,7 +179,7 @@ describe 'binding a callback to multiple callbacks' do
|
|||
before do
|
||||
define_model('User', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
callback(:before_create, :after_stub) do |instance|
|
||||
instance.name = instance.name.upcase
|
||||
|
@ -189,26 +189,26 @@ describe 'binding a callback to multiple callbacks' do
|
|||
end
|
||||
|
||||
it 'binds the callback to creation' do
|
||||
expect(FactoryGirl.create(:user, name: 'John Doe').name).to eq 'JOHN DOE'
|
||||
expect(FactoryBot.create(:user, name: 'John Doe').name).to eq 'JOHN DOE'
|
||||
end
|
||||
|
||||
it 'does not bind the callback to building' do
|
||||
expect(FactoryGirl.build(:user, name: 'John Doe').name).to eq 'John Doe'
|
||||
expect(FactoryBot.build(:user, name: 'John Doe').name).to eq 'John Doe'
|
||||
end
|
||||
|
||||
it 'binds the callback to stubbing' do
|
||||
expect(FactoryGirl.build_stubbed(:user, name: 'John Doe').name).to eq 'JOHN DOE'
|
||||
expect(FactoryBot.build_stubbed(:user, name: 'John Doe').name).to eq 'JOHN DOE'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'global callbacks' do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User', name: :string)
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
after :build do |object|
|
||||
object.name = case object.class.to_s
|
||||
when 'User' then 'John Doe'
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "create multiple instances" do
|
|||
before do
|
||||
define_model('Post', title: :string, position: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory(:post) do |post|
|
||||
post.title "Through the Looking Glass"
|
||||
post.position { rand(10**4) }
|
||||
|
@ -13,7 +13,7 @@ describe "create multiple instances" do
|
|||
end
|
||||
|
||||
context "without default attributes" do
|
||||
subject { FactoryGirl.create_list(:post, 20) }
|
||||
subject { FactoryBot.create_list(:post, 20) }
|
||||
|
||||
its(:length) { should eq 20 }
|
||||
|
||||
|
@ -31,7 +31,7 @@ describe "create multiple instances" do
|
|||
end
|
||||
|
||||
context "with default attributes" do
|
||||
subject { FactoryGirl.create_list(:post, 20, title: "The Hunting of the Snark") }
|
||||
subject { FactoryBot.create_list(:post, 20, title: "The Hunting of the Snark") }
|
||||
|
||||
it "overrides the default values" do
|
||||
subject.each do |record|
|
||||
|
@ -42,7 +42,7 @@ describe "create multiple instances" do
|
|||
|
||||
context "with a block" do
|
||||
subject do
|
||||
FactoryGirl.create_list(:post, 20, title: "The Listing of the Block") do |post|
|
||||
FactoryBot.create_list(:post, 20, title: "The Listing of the Block") do |post|
|
||||
post.position = post.id
|
||||
end
|
||||
end
|
||||
|
@ -55,7 +55,7 @@ describe "create multiple instances" do
|
|||
end
|
||||
|
||||
context "without the count" do
|
||||
subject { FactoryGirl.create_list(:post, title: "The Hunting of the Bear") }
|
||||
subject { FactoryBot.create_list(:post, title: "The Hunting of the Bear") }
|
||||
|
||||
it "raise ArgumentError with the proper error message" do
|
||||
expect { subject }.to raise_error(ArgumentError, /count missing/)
|
||||
|
@ -73,7 +73,7 @@ describe "multiple creates and transient attributes to dynamically build attribu
|
|||
belongs_to :user
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :post do
|
||||
title "Through the Looking Glass"
|
||||
user
|
||||
|
@ -88,7 +88,7 @@ describe "multiple creates and transient attributes to dynamically build attribu
|
|||
end
|
||||
|
||||
after(:create) do |user, evaluator|
|
||||
FactoryGirl.create_list(:post, evaluator.posts_count, user: user)
|
||||
FactoryBot.create_list(:post, evaluator.posts_count, user: user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -96,10 +96,10 @@ describe "multiple creates and transient attributes to dynamically build attribu
|
|||
end
|
||||
|
||||
it "generates the correct number of posts" do
|
||||
expect(FactoryGirl.create(:user_with_posts).posts.length).to eq 5
|
||||
expect(FactoryBot.create(:user_with_posts).posts.length).to eq 5
|
||||
end
|
||||
|
||||
it "allows the number of posts to be modified" do
|
||||
expect(FactoryGirl.create(:user_with_posts, posts_count: 2).posts.length).to eq 2
|
||||
expect(FactoryBot.create(:user_with_posts, posts_count: 2).posts.length).to eq 2
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "create multiple instances" do
|
|||
before do
|
||||
define_model('Post', title: :string, position: :integer)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory(:post) do |post|
|
||||
post.title "Through the Looking Glass"
|
||||
post.position { rand(10**4) }
|
||||
|
@ -13,7 +13,7 @@ describe "create multiple instances" do
|
|||
end
|
||||
|
||||
context "without default attributes" do
|
||||
subject { FactoryGirl.create_pair(:post) }
|
||||
subject { FactoryBot.create_pair(:post) }
|
||||
|
||||
its(:length) { should eq 2 }
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "a created instance" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
|
@ -10,7 +10,7 @@ describe "a created instance" do
|
|||
belongs_to :user
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user
|
||||
|
||||
factory :post do
|
||||
|
@ -30,7 +30,7 @@ describe "a created instance" do
|
|||
end
|
||||
|
||||
describe "a created instance, specifying strategy: :build" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
|
@ -39,7 +39,7 @@ describe "a created instance, specifying strategy: :build" do
|
|||
belongs_to :user
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user
|
||||
|
||||
factory :post do
|
||||
|
@ -57,7 +57,7 @@ describe "a created instance, specifying strategy: :build" do
|
|||
end
|
||||
|
||||
describe "a custom create" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_class('User') do
|
||||
|
@ -74,7 +74,7 @@ describe "a custom create" do
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
to_create do |user|
|
||||
user.persist
|
||||
|
@ -84,7 +84,7 @@ describe "a custom create" do
|
|||
end
|
||||
|
||||
it "uses the custom create block instead of save" do
|
||||
expect(FactoryGirl.create(:user)).to be_persisted
|
||||
expect(FactoryBot.create(:user)).to be_persisted
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -94,7 +94,7 @@ describe "a custom create passing in an evaluator" do
|
|||
attr_accessor :name
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
transient { creation_name "evaluator" }
|
||||
|
||||
|
@ -106,17 +106,17 @@ describe "a custom create passing in an evaluator" do
|
|||
end
|
||||
|
||||
it "passes the evaluator to the custom create block" do
|
||||
expect(FactoryGirl.create(:user).name).to eq "evaluator"
|
||||
expect(FactoryBot.create(:user).name).to eq "evaluator"
|
||||
end
|
||||
end
|
||||
|
||||
describe "calling `create` with a block" do
|
||||
include FactoryGirl::Syntax::Methods
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "defining a child factory before a parent" do
|
|||
before do
|
||||
define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :admin, parent: :user do
|
||||
admin true
|
||||
end
|
||||
|
@ -16,6 +16,6 @@ describe "defining a child factory before a parent" do
|
|||
end
|
||||
|
||||
it "creates admin factories correctly" do
|
||||
expect(FactoryGirl.create(:admin)).to be_admin
|
||||
expect(FactoryBot.create(:admin)).to be_admin
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'defining methods inside FactoryGirl' do
|
||||
describe 'defining methods inside FactoryBot' do
|
||||
it 'raises with a meaningful message' do
|
||||
define_model('User')
|
||||
|
||||
expect do
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
def generate_name
|
||||
'John Doe'
|
||||
end
|
||||
end
|
||||
end
|
||||
end.to raise_error FactoryGirl::MethodDefinitionError, /Defining methods in blocks \(trait or factory\) is not supported \(generate_name\)/
|
||||
end.to raise_error FactoryBot::MethodDefinitionError, /Defining methods in blocks \(trait or factory\) is not supported \(generate_name\)/
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,12 +4,12 @@ describe "an instance generated by a factory named a camel case string " do
|
|||
before do
|
||||
define_model("UserModel")
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory 'UserModel', class: UserModel
|
||||
end
|
||||
end
|
||||
|
||||
it "registers the UserModel factory" do
|
||||
expect(FactoryGirl.factory_by_name('UserModel')).to be_a(FactoryGirl::Factory)
|
||||
expect(FactoryBot.factory_by_name('UserModel')).to be_a(FactoryBot::Factory)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ describe "an instance generated by a factory with a custom class name" do
|
|||
before do
|
||||
define_model("User", admin: :boolean)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user
|
||||
|
||||
factory :admin, class: User do
|
||||
|
@ -13,7 +13,7 @@ describe "an instance generated by a factory with a custom class name" do
|
|||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl.create(:admin) }
|
||||
subject { FactoryBot.create(:admin) }
|
||||
|
||||
it { should be_kind_of(User) }
|
||||
it { should be_admin }
|
||||
|
@ -23,7 +23,7 @@ describe "attributes defined using Symbol#to_proc" do
|
|||
before do
|
||||
define_model("User", password: :string, password_confirmation: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
password "foo"
|
||||
password_confirmation &:password
|
||||
|
@ -32,21 +32,21 @@ describe "attributes defined using Symbol#to_proc" do
|
|||
end
|
||||
|
||||
it "assigns values correctly" do
|
||||
user = FactoryGirl.build(:user)
|
||||
user = FactoryBot.build(:user)
|
||||
|
||||
expect(user.password).to eq "foo"
|
||||
expect(user.password_confirmation).to eq "foo"
|
||||
end
|
||||
|
||||
it "assigns value with override correctly" do
|
||||
user = FactoryGirl.build(:user, password: "bar")
|
||||
user = FactoryBot.build(:user, password: "bar")
|
||||
|
||||
expect(user.password).to eq "bar"
|
||||
expect(user.password_confirmation).to eq "bar"
|
||||
end
|
||||
|
||||
it "assigns overridden value correctly" do
|
||||
user = FactoryGirl.build(:user, password_confirmation: "bar")
|
||||
user = FactoryBot.build(:user, password_confirmation: "bar")
|
||||
|
||||
expect(user.password).to eq "foo"
|
||||
expect(user.password_confirmation).to eq "bar"
|
||||
|
|
|
@ -4,12 +4,12 @@ describe "an instance generated by a factory" do
|
|||
before do
|
||||
define_model("User")
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :user
|
||||
end
|
||||
end
|
||||
|
||||
it "registers the user factory" do
|
||||
expect(FactoryGirl.factory_by_name(:user)).to be_a(FactoryGirl::Factory)
|
||||
expect(FactoryBot.factory_by_name(:user)).to be_a(FactoryBot::Factory)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ describe 'global initialize_with' do
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
initialize_with { new("initialize_with") }
|
||||
|
||||
trait :with_initialize_with do
|
||||
|
@ -44,26 +44,26 @@ describe 'global initialize_with' do
|
|||
end
|
||||
|
||||
it 'handles base initialize_with' do
|
||||
expect(FactoryGirl.build(:user).name).to eq 'initialize_with'
|
||||
expect(FactoryGirl.build(:post).name).to eq 'initialize_with'
|
||||
expect(FactoryBot.build(:user).name).to eq 'initialize_with'
|
||||
expect(FactoryBot.build(:post).name).to eq 'initialize_with'
|
||||
end
|
||||
|
||||
it 'handles child initialize_with' do
|
||||
expect(FactoryGirl.build(:child_user).name).to eq 'initialize_with'
|
||||
expect(FactoryGirl.build(:child_post).name).to eq 'initialize_with'
|
||||
expect(FactoryBot.build(:child_user).name).to eq 'initialize_with'
|
||||
expect(FactoryBot.build(:child_post).name).to eq 'initialize_with'
|
||||
end
|
||||
|
||||
it 'handles child initialize_with with trait' do
|
||||
expect(FactoryGirl.build(:child_user_with_trait).name).to eq 'trait initialize_with'
|
||||
expect(FactoryGirl.build(:child_post_with_trait).name).to eq 'trait initialize_with'
|
||||
expect(FactoryBot.build(:child_user_with_trait).name).to eq 'trait initialize_with'
|
||||
expect(FactoryBot.build(:child_post_with_trait).name).to eq 'trait initialize_with'
|
||||
end
|
||||
|
||||
it 'handles inline trait override' do
|
||||
expect(FactoryGirl.build(:child_user, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
expect(FactoryGirl.build(:child_post, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
expect(FactoryBot.build(:child_user, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
expect(FactoryBot.build(:child_post, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
end
|
||||
|
||||
it 'uses initialize_with globally across FactoryGirl.define' do
|
||||
it 'uses initialize_with globally across FactoryBot.define' do
|
||||
define_class('Company') do
|
||||
attr_reader :name
|
||||
|
||||
|
@ -72,11 +72,11 @@ describe 'global initialize_with' do
|
|||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
end
|
||||
|
||||
expect(FactoryGirl.build(:company).name).to eq 'initialize_with'
|
||||
expect(FactoryGirl.build(:company, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
expect(FactoryBot.build(:company).name).to eq 'initialize_with'
|
||||
expect(FactoryBot.build(:company, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ describe 'global to_create' do
|
|||
define_model('User', name: :string)
|
||||
define_model('Post', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
to_create { |instance| instance.name = 'persisted!' }
|
||||
|
||||
trait :override_to_create do
|
||||
|
@ -35,34 +35,34 @@ describe 'global to_create' do
|
|||
end
|
||||
|
||||
it 'handles base to_create' do
|
||||
expect(FactoryGirl.create(:user).name).to eq 'persisted!'
|
||||
expect(FactoryGirl.create(:post).name).to eq 'persisted!'
|
||||
expect(FactoryBot.create(:user).name).to eq 'persisted!'
|
||||
expect(FactoryBot.create(:post).name).to eq 'persisted!'
|
||||
end
|
||||
|
||||
it 'handles child to_create' do
|
||||
expect(FactoryGirl.create(:child_user).name).to eq 'persisted!'
|
||||
expect(FactoryGirl.create(:child_post).name).to eq 'persisted!'
|
||||
expect(FactoryBot.create(:child_user).name).to eq 'persisted!'
|
||||
expect(FactoryBot.create(:child_post).name).to eq 'persisted!'
|
||||
end
|
||||
|
||||
it 'handles child to_create with trait' do
|
||||
expect(FactoryGirl.create(:child_user_with_trait).name).to eq 'override'
|
||||
expect(FactoryGirl.create(:child_post_with_trait).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_user_with_trait).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_post_with_trait).name).to eq 'override'
|
||||
end
|
||||
|
||||
it 'handles inline trait override' do
|
||||
expect(FactoryGirl.create(:child_user, :override_to_create).name).to eq 'override'
|
||||
expect(FactoryGirl.create(:child_post, :override_to_create).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_user, :override_to_create).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_post, :override_to_create).name).to eq 'override'
|
||||
end
|
||||
|
||||
it 'uses to_create globally across FactoryGirl.define' do
|
||||
it 'uses to_create globally across FactoryBot.define' do
|
||||
define_model('Company', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
end
|
||||
|
||||
expect(FactoryGirl.create(:company).name).to eq 'persisted!'
|
||||
expect(FactoryGirl.create(:company, :override_to_create).name).to eq 'override'
|
||||
expect(FactoryBot.create(:company).name).to eq 'persisted!'
|
||||
expect(FactoryBot.create(:company, :override_to_create).name).to eq 'override'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,7 +71,7 @@ describe 'global skip_create' do
|
|||
define_model('User', name: :string)
|
||||
define_model('Post', name: :string)
|
||||
|
||||
FactoryGirl.define do
|
||||
FactoryBot.define do
|
||||
skip_create
|
||||
|
||||
trait :override_to_create do
|
||||
|
@ -101,22 +101,22 @@ describe 'global skip_create' do
|
|||
end
|
||||
|
||||
it 'does not persist any record' do
|
||||
expect(FactoryGirl.create(:user)).to be_new_record
|
||||
expect(FactoryGirl.create(:post)).to be_new_record
|
||||
expect(FactoryBot.create(:user)).to be_new_record
|
||||
expect(FactoryBot.create(:post)).to be_new_record
|
||||
end
|
||||
|
||||
it 'does not persist child records' do
|
||||
expect(FactoryGirl.create(:child_user)).to be_new_record
|
||||
expect(FactoryGirl.create(:child_post)).to be_new_record
|
||||
expect(FactoryBot.create(:child_user)).to be_new_record
|
||||
expect(FactoryBot.create(:child_post)).to be_new_record
|
||||
end
|
||||
|
||||
it 'honors overridden to_create' do
|
||||
expect(FactoryGirl.create(:child_user_with_trait).name).to eq 'override'
|
||||
expect(FactoryGirl.create(:child_post_with_trait).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_user_with_trait).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_post_with_trait).name).to eq 'override'
|
||||
end
|
||||
|
||||
it 'honors inline trait to_create' do
|
||||
expect(FactoryGirl.create(:child_user, :override_to_create).name).to eq 'override'
|
||||
expect(FactoryGirl.create(:child_post, :override_to_create).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_user, :override_to_create).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_post, :override_to_create).name).to eq 'override'
|
||||
end
|
||||
end
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue