mirror of
https://github.com/thoughtbot/factory_bot_rails.git
synced 2022-11-09 11:49:18 -05:00
Rename all girl -> bot
* Rename files and code
* Change factory_girl dependency to factory_bot
This change will bring _rails name in line with factory_bot
c716ce01b4
This commit is contained in:
parent
dca37318f3
commit
c5d11518d7
26 changed files with 156 additions and 135 deletions
|
@ -7,7 +7,7 @@ agree to abide by the thoughtbot [code of conduct].
|
||||||
|
|
||||||
Fork, then clone the repo:
|
Fork, then clone the repo:
|
||||||
|
|
||||||
git clone git@github.com:your-username/factory_girl_rails.git
|
git clone git@github.com:your-username/factory_bot_rails.git
|
||||||
|
|
||||||
Set up your machine:
|
Set up your machine:
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ Make your change. Add tests for your change. Make the tests pass:
|
||||||
|
|
||||||
Push to your fork and [submit a pull request][pr].
|
Push to your fork and [submit a pull request][pr].
|
||||||
|
|
||||||
[pr]: https://github.com/thoughtbot/factory_girl_rails/compare/
|
[pr]: https://github.com/thoughtbot/factory_bot_rails/compare/
|
||||||
|
|
||||||
At this point you're waiting on us. We like to at least comment on pull requests
|
At this point you're waiting on us. We like to at least comment on pull requests
|
||||||
within three business days (and, typically, one business day). We may suggest
|
within three business days (and, typically, one business day). We may suggest
|
||||||
|
|
2
Gemfile
2
Gemfile
|
@ -1,6 +1,6 @@
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
gemspec
|
gemspec name: 'factory_bot_rails'
|
||||||
|
|
||||||
gem 'appraisal'
|
gem 'appraisal'
|
||||||
gem 'aruba'
|
gem 'aruba'
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
factory_girl_rails (4.8.0)
|
factory_bot_rails (4.8.0)
|
||||||
factory_girl (~> 4.8.0)
|
factory_bot (~> 4.8.2)
|
||||||
railties (>= 3.0.0)
|
railties (>= 3.0.0)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
|
@ -63,7 +63,7 @@ GEM
|
||||||
diff-lcs (1.2.5)
|
diff-lcs (1.2.5)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (2.0.2)
|
execjs (2.0.2)
|
||||||
factory_girl (4.8.0)
|
factory_bot (4.8.2)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
ffi (1.9.3)
|
ffi (1.9.3)
|
||||||
ffi (1.9.3-java)
|
ffi (1.9.3-java)
|
||||||
|
@ -129,7 +129,7 @@ DEPENDENCIES
|
||||||
aruba
|
aruba
|
||||||
coffee-rails
|
coffee-rails
|
||||||
cucumber (= 1.3.19)
|
cucumber (= 1.3.19)
|
||||||
factory_girl_rails!
|
factory_bot_rails!
|
||||||
jdbc-sqlite3
|
jdbc-sqlite3
|
||||||
jquery-rails
|
jquery-rails
|
||||||
jruby-openssl
|
jruby-openssl
|
||||||
|
|
2
NEWS
2
NEWS
|
@ -1,4 +1,4 @@
|
||||||
factory_girl_rails versioning is synced with factory_girl releases. For this reason
|
factory_bot_rails versioning is synced with factory_bot releases. For this reason
|
||||||
there might not be any notable changes in new versions of this project.
|
there might not be any notable changes in new versions of this project.
|
||||||
|
|
||||||
4.7.0 (April 1, 2016)
|
4.7.0 (April 1, 2016)
|
||||||
|
|
48
README.md
48
README.md
|
@ -1,6 +1,6 @@
|
||||||
# factory_girl_rails [![Build Status][ci-image]][ci] [![Code Climate][grade-image]][grade]
|
# factory_bot_rails [![Build Status][ci-image]][ci] [![Code Climate][grade-image]][grade]
|
||||||
|
|
||||||
[factory_girl][fg] is a fixtures replacement with a straightforward definition
|
[factory_bot][fb] is a fixtures replacement with a straightforward definition
|
||||||
syntax, support for multiple build strategies (saved instances, unsaved
|
syntax, support for multiple build strategies (saved instances, unsaved
|
||||||
instances, attribute hashes, and stubbed objects), and support for multiple
|
instances, attribute hashes, and stubbed objects), and support for multiple
|
||||||
factories for the same class (`user`, `admin_user`, and so on), including factory
|
factories for the same class (`user`, `admin_user`, and so on), including factory
|
||||||
|
@ -8,7 +8,7 @@ inheritance.
|
||||||
|
|
||||||
## Rails
|
## Rails
|
||||||
|
|
||||||
factory_girl_rails provides Rails integration for [factory_girl][fg].
|
factory_bot_rails provides Rails integration for [factory_bot][fb].
|
||||||
|
|
||||||
Currently, automatic factory definition loading is the only Rails-specific feature.
|
Currently, automatic factory definition loading is the only Rails-specific feature.
|
||||||
|
|
||||||
|
@ -17,19 +17,19 @@ Ruby versions are listed in [`.travis.yml`](.travis.yml).
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
Github: http://github.com/thoughtbot/factory_girl_rails
|
Github: http://github.com/thoughtbot/factory_bot_rails
|
||||||
|
|
||||||
Gem:
|
Gem:
|
||||||
|
|
||||||
$ gem install factory_girl_rails
|
$ gem install factory_bot_rails
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Add `factory_girl_rails` to your Gemfile:
|
Add `factory_bot_rails` to your Gemfile:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'factory_girl_rails'
|
gem 'factory_bot_rails'
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ following to your application.rb file:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.factory_girl false
|
g.factory_bot false
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -48,24 +48,24 @@ Default factories directory is `test/factories`, or `spec/factories` if
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.factory_girl dir: 'custom/dir/for/factories'
|
g.factory_bot dir: 'custom/dir/for/factories'
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
If you use factory_girl for fixture replacement, ensure that
|
If you use factory_bot for fixture replacement, ensure that
|
||||||
factory_girl_rails is available in the development group. If it's not, Rails
|
factory_bot_rails is available in the development group. If it's not, Rails
|
||||||
will generate standard .yml files instead of factory files.
|
will generate standard .yml files instead of factory files.
|
||||||
|
|
||||||
factory_girl takes an option `suffix: 'some_suffix'` to generate factories as
|
factory_bot takes an option `suffix: 'some_suffix'` to generate factories as
|
||||||
`modelname_some_suffix.rb`.
|
`modelname_some_suffix.rb`.
|
||||||
|
|
||||||
If you use factory_girl for fixture replacement and already have a
|
If you use factory_bot for fixture replacement and already have a
|
||||||
`factories.rb` file in the directory that contains your tests,
|
`factories.rb` file in the directory that contains your tests,
|
||||||
factory_girl_rails will insert new factory definitions at the top of
|
factory_bot_rails will insert new factory definitions at the top of
|
||||||
`factories.rb`.
|
`factories.rb`.
|
||||||
|
|
||||||
You may need to configure your test suite to include factory_girl methods; see
|
You may need to configure your test suite to include factory_bot methods; see
|
||||||
[configuration](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#configure-your-test-suite).
|
[configuration](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#configure-your-test-suite).
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
@ -73,22 +73,22 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
[factory_girl][fg] was originally written by Joe Ferris.
|
[factory_bot][fb] was originally written by Joe Ferris.
|
||||||
|
|
||||||
![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
|
![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
|
||||||
|
|
||||||
factory_girl is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
|
factory_bot is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
|
||||||
|
|
||||||
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
factory_girl_rails is Copyright © 2008-2016 Joe Ferris and thoughtbot. It is free
|
factory_bot_rails is Copyright © 2008-2016 Joe Ferris and thoughtbot. It is free
|
||||||
software, and may be redistributed under the terms specified in the
|
software, and may be redistributed under the terms specified in the
|
||||||
[LICENSE](LICENSE) file.
|
[LICENSE](LICENSE) file.
|
||||||
|
|
||||||
[fg]: https://github.com/thoughtbot/factory_girl
|
[fb]: https://github.com/thoughtbot/factory_bot
|
||||||
[ci]: http://travis-ci.org/thoughtbot/factory_girl_rails?branch=master
|
[ci]: http://travis-ci.org/thoughtbot/factory_bot_rails?branch=master
|
||||||
[ci-image]: https://secure.travis-ci.org/thoughtbot/factory_girl_rails.png
|
[ci-image]: https://secure.travis-ci.org/thoughtbot/factory_bot_rails.png
|
||||||
[grade]: https://codeclimate.com/github/thoughtbot/factory_girl_rails
|
[grade]: https://codeclimate.com/github/thoughtbot/factory_bot_rails
|
||||||
[grade-image]: https://codeclimate.com/github/thoughtbot/factory_girl_rails.png
|
[grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot_rails.png
|
||||||
|
|
3
Rakefile
3
Rakefile
|
@ -1,7 +1,8 @@
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
require 'bundler/gem_tasks'
|
|
||||||
require 'cucumber/rake/task'
|
require 'cucumber/rake/task'
|
||||||
|
|
||||||
|
Bundler::GemHelper.install_tasks name: 'factory_bot_rails'
|
||||||
|
|
||||||
Cucumber::Rake::Task.new(:cucumber) do |t|
|
Cucumber::Rake::Task.new(:cucumber) do |t|
|
||||||
t.fork = true
|
t.fork = true
|
||||||
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
|
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
|
||||||
|
|
20
factory_bot_rails.gemspec
Normal file
20
factory_bot_rails.gemspec
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = %q{factory_bot_rails}
|
||||||
|
s.version = '4.8.0'
|
||||||
|
s.authors = ["Joe Ferris"]
|
||||||
|
s.email = %q{jferris@thoughtbot.com}
|
||||||
|
s.homepage = "http://github.com/thoughtbot/factory_bot_rails"
|
||||||
|
s.summary = %q{factory_bot_rails provides integration between
|
||||||
|
factory_bot and rails 3 or newer}
|
||||||
|
s.description = %q{factory_bot_rails provides integration between
|
||||||
|
factory_bot and rails 3 or newer (currently just automatic factory definition
|
||||||
|
loading)}
|
||||||
|
|
||||||
|
s.files = Dir['**/*'].keep_if { |file| File.file?(file) }
|
||||||
|
s.require_paths = ["lib"]
|
||||||
|
s.executables = []
|
||||||
|
s.license = "MIT"
|
||||||
|
|
||||||
|
s.add_runtime_dependency('railties', '>= 3.0.0')
|
||||||
|
s.add_runtime_dependency('factory_bot', '~> 4.8.2')
|
||||||
|
end
|
|
@ -16,5 +16,5 @@ Gem::Specification.new do |s|
|
||||||
s.license = "MIT"
|
s.license = "MIT"
|
||||||
|
|
||||||
s.add_runtime_dependency('railties', '>= 3.0.0')
|
s.add_runtime_dependency('railties', '>= 3.0.0')
|
||||||
s.add_runtime_dependency('factory_girl', '~> 4.8.0')
|
s.add_runtime_dependency('factory_girl', '~> 4.8.2')
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
Feature:
|
Feature:
|
||||||
In order to not have to manually configure Factory Girl as the Rails testing fixture replacement by using the --fixture-replacement=factory_girl option
|
In order to not have to manually configure Factory Bot as the Rails testing fixture replacement by using the --fixture-replacement=factory_bot option
|
||||||
I would like the Factory Girl Rails gem to configure Factory Girl as the fixture replacement.
|
I would like the Factory Bot Rails gem to configure Factory Bot as the fixture replacement.
|
||||||
|
|
||||||
Background:
|
Background:
|
||||||
Given I successfully run `bundle exec rails new testapp`
|
Given I successfully run `bundle exec rails new testapp`
|
||||||
And I cd to "testapp"
|
And I cd to "testapp"
|
||||||
And I add "factory_girl_rails" from this project as a dependency
|
And I add "factory_bot_rails" from this project as a dependency
|
||||||
|
|
||||||
Scenario: Using Factory Girl and Factory Girl Rails with Test Unit generates a factory file and does not generate a fixture file
|
Scenario: Using Factory Bot and Factory Bot Rails with Test Unit generates a factory file and does not generate a fixture file
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
And I run `bundle exec rails generate model User name:string` with a clean environment
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
||||||
Then the following files should exist:
|
Then the following files should exist:
|
||||||
|
@ -15,13 +15,13 @@ Feature:
|
||||||
And the following files should not exist:
|
And the following files should not exist:
|
||||||
| test/fixtures/users.yml |
|
| test/fixtures/users.yml |
|
||||||
|
|
||||||
Scenario: Using Factory Girl and Factory Girl Rails with RSpec should generate a factory file
|
Scenario: Using Factory Bot and Factory Bot Rails with RSpec should generate a factory file
|
||||||
When I add "rspec-rails" as a dependency
|
When I add "rspec-rails" as a dependency
|
||||||
And I configure the factories as:
|
And I configure the factories as:
|
||||||
"""
|
"""
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.test_framework :rspec, fixture: true
|
g.test_framework :rspec, fixture: true
|
||||||
g.fixture_replacement :factory_girl
|
g.fixture_replacement :factory_bot
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
|
@ -32,13 +32,13 @@ Feature:
|
||||||
And the following files should not exist:
|
And the following files should not exist:
|
||||||
| spec/fixtures/users.yml |
|
| spec/fixtures/users.yml |
|
||||||
|
|
||||||
Scenario: Using Factory Girl and Factory Girl Rails with RSpec and suffix configuration should generate a factory file with suffix
|
Scenario: Using Factory Bot and Factory Bot Rails with RSpec and suffix configuration should generate a factory file with suffix
|
||||||
When I add "rspec-rails" as a dependency
|
When I add "rspec-rails" as a dependency
|
||||||
And I configure the factories as:
|
And I configure the factories as:
|
||||||
"""
|
"""
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.test_framework :rspec, fixture: true
|
g.test_framework :rspec, fixture: true
|
||||||
g.fixture_replacement :factory_girl, suffix: 'factory'
|
g.fixture_replacement :factory_bot, suffix: 'factory'
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
|
@ -49,7 +49,7 @@ Feature:
|
||||||
And the following files should not exist:
|
And the following files should not exist:
|
||||||
| spec/fixtures/users.yml |
|
| spec/fixtures/users.yml |
|
||||||
|
|
||||||
Scenario: Using Factory Girl and Factory Girl Rails does not override a manually-configured factories directory using RSpec
|
Scenario: Using Factory Bot and Factory Bot Rails does not override a manually-configured factories directory using RSpec
|
||||||
When I add "rspec-rails" as a dependency
|
When I add "rspec-rails" as a dependency
|
||||||
And I configure the factories directory as "custom/dir"
|
And I configure the factories directory as "custom/dir"
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
|
@ -61,7 +61,7 @@ Feature:
|
||||||
But the following files should exist:
|
But the following files should exist:
|
||||||
| custom/dir/users.rb |
|
| custom/dir/users.rb |
|
||||||
|
|
||||||
Scenario: Using Factory Girl and Factory Girl Rails does not override a manually-configured factories directory using Test::Unit
|
Scenario: Using Factory Bot and Factory Bot Rails does not override a manually-configured factories directory using Test::Unit
|
||||||
When I configure the factories directory as "custom/dir"
|
When I configure the factories directory as "custom/dir"
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
And I run `bundle exec rails generate model User name:string` with a clean environment
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
||||||
|
@ -71,7 +71,7 @@ Feature:
|
||||||
But the following files should exist:
|
But the following files should exist:
|
||||||
| custom/dir/users.rb |
|
| custom/dir/users.rb |
|
||||||
|
|
||||||
Scenario: Using Factory Girl Rails with MiniTest should generate a factory file
|
Scenario: Using Factory Bot Rails with MiniTest should generate a factory file
|
||||||
When I run `bundle install` with a clean environment
|
When I run `bundle install` with a clean environment
|
||||||
And I run `bundle exec rails generate model User name:string` with a clean environment
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
||||||
Then the following files should exist:
|
Then the following files should exist:
|
||||||
|
@ -79,7 +79,7 @@ Feature:
|
||||||
But the following files should not exist:
|
But the following files should not exist:
|
||||||
| spec/fixtures/users.yml |
|
| spec/fixtures/users.yml |
|
||||||
|
|
||||||
Scenario: Using Factory Girl Rails with MiniTest and a custom directory should generate a factory file
|
Scenario: Using Factory Bot Rails with MiniTest and a custom directory should generate a factory file
|
||||||
When I configure the factories directory as "custom/dir"
|
When I configure the factories directory as "custom/dir"
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
And I run `bundle exec rails generate model User name:string` with a clean environment
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
||||||
|
@ -88,11 +88,11 @@ Feature:
|
||||||
But the following files should not exist:
|
But the following files should not exist:
|
||||||
| spec/fixtures/users.yml |
|
| spec/fixtures/users.yml |
|
||||||
|
|
||||||
Scenario: Disable Factory Girl generator
|
Scenario: Disable Factory Bot generator
|
||||||
When I configure the factories as:
|
When I configure the factories as:
|
||||||
"""
|
"""
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.factory_girl false
|
g.factory_bot false
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
|
@ -101,12 +101,12 @@ Feature:
|
||||||
| test/factories/users.rb |
|
| test/factories/users.rb |
|
||||||
| spec/factories/users.rb |
|
| spec/factories/users.rb |
|
||||||
|
|
||||||
Scenario: Use a suffix with the Factory Girl generator
|
Scenario: Use a suffix with the Factory Bot generator
|
||||||
When I add "rspec-rails" as a dependency
|
When I add "rspec-rails" as a dependency
|
||||||
When I configure the factories as:
|
When I configure the factories as:
|
||||||
"""
|
"""
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.factory_girl suffix: 'suffix'
|
g.factory_bot suffix: 'suffix'
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
|
@ -116,12 +116,12 @@ Feature:
|
||||||
Then the following files should not exist:
|
Then the following files should not exist:
|
||||||
| spec/factories/users.rb |
|
| spec/factories/users.rb |
|
||||||
|
|
||||||
Scenario: Use a filename_proc with the Factory Girl generator
|
Scenario: Use a filename_proc with the Factory Bot generator
|
||||||
When I add "rspec-rails" as a dependency
|
When I add "rspec-rails" as a dependency
|
||||||
When I configure the factories as:
|
When I configure the factories as:
|
||||||
"""
|
"""
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.factory_girl filename_proc: Proc.new { |tb| "prefix_#{tb.singularize}_suffix" }
|
g.factory_bot filename_proc: Proc.new { |tb| "prefix_#{tb.singularize}_suffix" }
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
Feature:
|
Feature:
|
||||||
In order to easily generate factory files instead of fixture files when generating models
|
In order to easily generate factory files instead of fixture files when generating models
|
||||||
As a user of Rails and Factory Girl
|
As a user of Rails and Factory Bot
|
||||||
I would like to use factory_girl_rails generators.
|
I would like to use factory_bot_rails generators.
|
||||||
|
|
||||||
Background:
|
Background:
|
||||||
Given I successfully run `bundle exec rails new testapp`
|
Given I successfully run `bundle exec rails new testapp`
|
||||||
And I cd to "testapp"
|
And I cd to "testapp"
|
||||||
And I add "factory_girl_rails" from this project as a dependency
|
And I add "factory_bot_rails" from this project as a dependency
|
||||||
|
|
||||||
Scenario: The factory_girl_rails generators create a factory file for each model if there is not a factories.rb file
|
Scenario: The factory_bot_rails generators create a factory file for each model if there is not a factories.rb file
|
||||||
When I run `bundle install` with a clean environment
|
When I run `bundle install` with a clean environment
|
||||||
And I run `bundle exec rails generate model User name:string age:integer` with a clean environment
|
And I run `bundle exec rails generate model User name:string age:integer` with a clean environment
|
||||||
And I run `bundle exec rails generate model Namespaced::User name:string` with a clean environment
|
And I run `bundle exec rails generate model Namespaced::User name:string` with a clean environment
|
||||||
|
@ -16,7 +16,7 @@ Feature:
|
||||||
And the output should contain "test/factories/namespaced_users.rb"
|
And the output should contain "test/factories/namespaced_users.rb"
|
||||||
And the file "test/factories/users.rb" should contain exactly:
|
And the file "test/factories/users.rb" should contain exactly:
|
||||||
"""
|
"""
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :user do
|
factory :user do
|
||||||
name "MyString"
|
name "MyString"
|
||||||
age 1
|
age 1
|
||||||
|
@ -26,28 +26,28 @@ Feature:
|
||||||
"""
|
"""
|
||||||
And the file "test/factories/namespaced_users.rb" should contain "factory :namespaced_user, class: 'Namespaced::User' do"
|
And the file "test/factories/namespaced_users.rb" should contain "factory :namespaced_user, class: 'Namespaced::User' do"
|
||||||
|
|
||||||
Scenario: The factory_girl_rails generators add a factory in the correct spot
|
Scenario: The factory_bot_rails generators add a factory in the correct spot
|
||||||
When I run `bundle install` with a clean environment
|
When I run `bundle install` with a clean environment
|
||||||
And I write to "test/factories.rb" with:
|
And I write to "test/factories.rb" with:
|
||||||
"""
|
"""
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
And I run `bundle exec rails generate model User name:string` with a clean environment
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
||||||
Then the file "test/factories.rb" should contain exactly:
|
Then the file "test/factories.rb" should contain exactly:
|
||||||
"""
|
"""
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :user do
|
factory :user do
|
||||||
name "MyString"
|
name "MyString"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Scenario: The factory_girl_rails generators does not create a factory file for each model if there is a factories.rb file in the test directory
|
Scenario: The factory_bot_rails generators does not create a factory file for each model if there is a factories.rb file in the test directory
|
||||||
When I run `bundle install` with a clean environment
|
When I run `bundle install` with a clean environment
|
||||||
And I write to "test/factories.rb" with:
|
And I write to "test/factories.rb" with:
|
||||||
"""
|
"""
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
And I run `bundle exec rails generate model User name:string` with a clean environment
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
||||||
|
|
|
@ -3,7 +3,7 @@ Feature: automatically load step definitions
|
||||||
Background:
|
Background:
|
||||||
When I successfully run `bundle exec rails new testapp`
|
When I successfully run `bundle exec rails new testapp`
|
||||||
And I cd to "testapp"
|
And I cd to "testapp"
|
||||||
And I add "factory_girl_rails" from this project as a dependency
|
And I add "factory_bot_rails" from this project as a dependency
|
||||||
And I add "test-unit" as a dependency
|
And I add "test-unit" as a dependency
|
||||||
And I run `bundle install` with a clean environment
|
And I run `bundle install` with a clean environment
|
||||||
And I write to "db/migrate/1_create_users.rb" with:
|
And I write to "db/migrate/1_create_users.rb" with:
|
||||||
|
@ -26,7 +26,7 @@ Feature: automatically load step definitions
|
||||||
Scenario: generate a Rails application and use factory definitions
|
Scenario: generate a Rails application and use factory definitions
|
||||||
When I write to "test/factories.rb" with:
|
When I write to "test/factories.rb" with:
|
||||||
"""
|
"""
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :user do
|
factory :user do
|
||||||
name "Frank"
|
name "Frank"
|
||||||
end
|
end
|
||||||
|
@ -38,7 +38,7 @@ Feature: automatically load step definitions
|
||||||
|
|
||||||
class UserTest < ActiveSupport::TestCase
|
class UserTest < ActiveSupport::TestCase
|
||||||
test "use factory" do
|
test "use factory" do
|
||||||
user = FactoryGirl.create(:user)
|
user = FactoryBot.create(:user)
|
||||||
assert_equal 'Frank', user.name
|
assert_equal 'Frank', user.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,15 +56,15 @@ Feature: automatically load step definitions
|
||||||
module SomeRailtie
|
module SomeRailtie
|
||||||
class Railtie < ::Rails::Engine
|
class Railtie < ::Rails::Engine
|
||||||
|
|
||||||
initializer "some_railtie.factories", :after => "factory_girl.set_factory_paths" do
|
initializer "some_railtie.factories", :after => "factory_bot.set_factory_paths" do
|
||||||
FactoryGirl.definition_file_paths << File.expand_path('../factories', __FILE__)
|
FactoryBot.definition_file_paths << File.expand_path('../factories', __FILE__)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
When I write to "lib/some_railtie/factories.rb" with:
|
When I write to "lib/some_railtie/factories.rb" with:
|
||||||
"""
|
"""
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :factory_from_some_railtie, class: 'User' do
|
factory :factory_from_some_railtie, class: 'User' do
|
||||||
name 'Artem'
|
name 'Artem'
|
||||||
end
|
end
|
||||||
|
@ -76,7 +76,7 @@ Feature: automatically load step definitions
|
||||||
|
|
||||||
class UserTest < ActiveSupport::TestCase
|
class UserTest < ActiveSupport::TestCase
|
||||||
test "use factory of some_railtie" do
|
test "use factory of some_railtie" do
|
||||||
user = FactoryGirl.create(:factory_from_some_railtie)
|
user = FactoryBot.create(:factory_from_some_railtie)
|
||||||
assert_equal 'Artem', user.name
|
assert_equal 'Artem', user.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ When /^I configure the factories directory as "([^"]+)"$/ do |factory_dir|
|
||||||
append_to_file File.join('config', 'application.rb'), <<-END
|
append_to_file File.join('config', 'application.rb'), <<-END
|
||||||
class Testapp::Application
|
class Testapp::Application
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.fixture_replacement :factory_girl, :dir => "#{factory_dir}"
|
g.fixture_replacement :factory_bot, :dir => "#{factory_dir}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
END
|
END
|
||||||
|
|
|
@ -19,4 +19,4 @@ gem "sqlite3", :platforms => :ruby
|
||||||
gem "rails", "~> 3.2.21"
|
gem "rails", "~> 3.2.21"
|
||||||
gem "sass-rails"
|
gem "sass-rails"
|
||||||
|
|
||||||
gemspec :path => "../"
|
gemspec :path => "../", :name => "factory_bot_rails"
|
||||||
|
|
|
@ -20,4 +20,4 @@ gem "rails", "~> 4.1.9"
|
||||||
gem "sass-rails"
|
gem "sass-rails"
|
||||||
gem "spring"
|
gem "spring"
|
||||||
|
|
||||||
gemspec :path => "../"
|
gemspec :path => "../", :name => "factory_bot_rails"
|
||||||
|
|
|
@ -18,4 +18,4 @@ gem "jruby-openssl", :platforms => :jruby
|
||||||
gem "sqlite3", :platforms => :ruby
|
gem "sqlite3", :platforms => :ruby
|
||||||
gem "rails", "~> 4.2.0"
|
gem "rails", "~> 4.2.0"
|
||||||
|
|
||||||
gemspec :path => "../"
|
gemspec :path => "../", :name => "factory_bot_rails"
|
||||||
|
|
|
@ -19,4 +19,4 @@ gem "sqlite3", :platforms => :ruby
|
||||||
gem "activerecord", "~> 5.0.0"
|
gem "activerecord", "~> 5.0.0"
|
||||||
gem "railties", "~> 5.0.0"
|
gem "railties", "~> 5.0.0"
|
||||||
|
|
||||||
gemspec :path => "../"
|
gemspec :path => "../", :name => "factory_bot_rails"
|
||||||
|
|
4
lib/factory_bot_rails.rb
Normal file
4
lib/factory_bot_rails.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
require 'factory_bot_rails/railtie'
|
||||||
|
|
||||||
|
module FactoryBotRails
|
||||||
|
end
|
|
@ -1,8 +1,8 @@
|
||||||
require 'factory_girl_rails/generators/rspec_generator'
|
require 'factory_bot_rails/generators/rspec_generator'
|
||||||
require 'factory_girl_rails/generators/non_rspec_generator'
|
require 'factory_bot_rails/generators/non_rspec_generator'
|
||||||
require 'factory_girl_rails/generators/null_generator'
|
require 'factory_bot_rails/generators/null_generator'
|
||||||
|
|
||||||
module FactoryGirlRails
|
module FactoryBotRails
|
||||||
class Generator
|
class Generator
|
||||||
def initialize(config)
|
def initialize(config)
|
||||||
@generators = if config.respond_to?(:app_generators)
|
@generators = if config.respond_to?(:app_generators)
|
||||||
|
@ -17,7 +17,7 @@ module FactoryGirlRails
|
||||||
end
|
end
|
||||||
|
|
||||||
def generator
|
def generator
|
||||||
if factory_girl_disabled?
|
if factory_bot_disabled?
|
||||||
Generators::NullGenerator
|
Generators::NullGenerator
|
||||||
else
|
else
|
||||||
if test_framework == :rspec
|
if test_framework == :rspec
|
||||||
|
@ -32,8 +32,8 @@ module FactoryGirlRails
|
||||||
rails_options[:test_framework]
|
rails_options[:test_framework]
|
||||||
end
|
end
|
||||||
|
|
||||||
def factory_girl_disabled?
|
def factory_bot_disabled?
|
||||||
rails_options[:factory_girl] == false
|
rails_options[:factory_bot] == false
|
||||||
end
|
end
|
||||||
|
|
||||||
def rails_options
|
def rails_options
|
|
@ -1,4 +1,4 @@
|
||||||
module FactoryGirlRails
|
module FactoryBotRails
|
||||||
module Generators
|
module Generators
|
||||||
class NonRSpecGenerator
|
class NonRSpecGenerator
|
||||||
def initialize(generators)
|
def initialize(generators)
|
||||||
|
@ -6,7 +6,7 @@ module FactoryGirlRails
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
@generators.test_framework test_framework, fixture: false, fixture_replacement: :factory_girl
|
@generators.test_framework test_framework, fixture: false, fixture_replacement: :factory_bot
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
|
@ -1,4 +1,4 @@
|
||||||
module FactoryGirlRails
|
module FactoryBotRails
|
||||||
module Generators
|
module Generators
|
||||||
class NullGenerator
|
class NullGenerator
|
||||||
def initialize(generators)
|
def initialize(generators)
|
|
@ -1,4 +1,4 @@
|
||||||
module FactoryGirlRails
|
module FactoryBotRails
|
||||||
module Generators
|
module Generators
|
||||||
class RSpecGenerator
|
class RSpecGenerator
|
||||||
def initialize(generators)
|
def initialize(generators)
|
||||||
|
@ -6,17 +6,17 @@ module FactoryGirlRails
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
@generators.fixture_replacement fixture_replacement_setting, dir: factory_girl_directory
|
@generators.fixture_replacement fixture_replacement_setting, dir: factory_bot_directory
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def fixture_replacement_setting
|
def fixture_replacement_setting
|
||||||
@generators.options[:rails][:fixture_replacement] || :factory_girl
|
@generators.options[:rails][:fixture_replacement] || :factory_bot
|
||||||
end
|
end
|
||||||
|
|
||||||
def factory_girl_directory
|
def factory_bot_directory
|
||||||
@generators.options.fetch(:factory_girl, {}).fetch(:dir, 'spec/factories')
|
@generators.options.fetch(:factory_bot, {}).fetch(:dir, 'spec/factories')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
28
lib/factory_bot_rails/railtie.rb
Normal file
28
lib/factory_bot_rails/railtie.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require 'factory_bot'
|
||||||
|
require 'factory_bot_rails/generator'
|
||||||
|
require 'rails'
|
||||||
|
|
||||||
|
module FactoryBot
|
||||||
|
class Railtie < Rails::Railtie
|
||||||
|
|
||||||
|
initializer "factory_bot.set_fixture_replacement" do
|
||||||
|
FactoryBotRails::Generator.new(config).run
|
||||||
|
end
|
||||||
|
|
||||||
|
initializer "factory_bot.set_factory_paths" do
|
||||||
|
FactoryBot.definition_file_paths = [
|
||||||
|
Rails.root.join('factories'),
|
||||||
|
Rails.root.join('test', 'factories'),
|
||||||
|
Rails.root.join('spec', 'factories')
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
config.after_initialize do
|
||||||
|
FactoryBot.find_definitions
|
||||||
|
|
||||||
|
if defined?(Spring)
|
||||||
|
Spring.after_fork { FactoryBot.reload }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +0,0 @@
|
||||||
require 'factory_girl_rails/railtie'
|
|
||||||
|
|
||||||
module FactoryGirlRails
|
|
||||||
end
|
|
|
@ -1,28 +0,0 @@
|
||||||
require 'factory_girl'
|
|
||||||
require 'factory_girl_rails/generator'
|
|
||||||
require 'rails'
|
|
||||||
|
|
||||||
module FactoryGirl
|
|
||||||
class Railtie < Rails::Railtie
|
|
||||||
|
|
||||||
initializer "factory_girl.set_fixture_replacement" do
|
|
||||||
FactoryGirlRails::Generator.new(config).run
|
|
||||||
end
|
|
||||||
|
|
||||||
initializer "factory_girl.set_factory_paths" do
|
|
||||||
FactoryGirl.definition_file_paths = [
|
|
||||||
Rails.root.join('factories'),
|
|
||||||
Rails.root.join('test', 'factories'),
|
|
||||||
Rails.root.join('spec', 'factories')
|
|
||||||
]
|
|
||||||
end
|
|
||||||
|
|
||||||
config.after_initialize do
|
|
||||||
FactoryGirl.find_definitions
|
|
||||||
|
|
||||||
if defined?(Spring)
|
|
||||||
Spring.after_fork { FactoryGirl.reload }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,10 +1,10 @@
|
||||||
require 'rails/generators/named_base'
|
require 'rails/generators/named_base'
|
||||||
|
|
||||||
module FactoryGirl
|
module FactoryBot
|
||||||
module Generators
|
module Generators
|
||||||
class Base < Rails::Generators::NamedBase #:nodoc:
|
class Base < Rails::Generators::NamedBase #:nodoc:
|
||||||
def self.source_root
|
def self.source_root
|
||||||
@_factory_girl_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'factory_girl', generator_name, 'templates'))
|
@_factory_bot_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'factory_bot', generator_name, 'templates'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def explicit_class_option
|
def explicit_class_option
|
|
@ -1,7 +1,7 @@
|
||||||
require 'generators/factory_girl'
|
require 'generators/factory_bot'
|
||||||
require 'factory_girl_rails'
|
require 'factory_bot_rails'
|
||||||
|
|
||||||
module FactoryGirl
|
module FactoryBot
|
||||||
module Generators
|
module Generators
|
||||||
class ModelGenerator < Base
|
class ModelGenerator < Base
|
||||||
argument(
|
argument(
|
||||||
|
@ -43,7 +43,7 @@ module FactoryGirl
|
||||||
insert_into_file(
|
insert_into_file(
|
||||||
factories_file,
|
factories_file,
|
||||||
factory_definition,
|
factory_definition,
|
||||||
after: "FactoryGirl.define do\n"
|
after: "FactoryBot.define do\n"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ RUBY
|
||||||
|
|
||||||
def single_file_factory_definition
|
def single_file_factory_definition
|
||||||
<<-RUBY
|
<<-RUBY
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
#{factory_definition.chomp}
|
#{factory_definition.chomp}
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
@ -75,23 +75,23 @@ RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
def filename
|
def filename
|
||||||
if factory_girl_options[:filename_proc].present?
|
if factory_bot_options[:filename_proc].present?
|
||||||
factory_girl_options[:filename_proc].call(table_name)
|
factory_bot_options[:filename_proc].call(table_name)
|
||||||
else
|
else
|
||||||
[table_name, filename_suffix].compact.join('_')
|
[table_name, filename_suffix].compact.join('_')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def filename_suffix
|
def filename_suffix
|
||||||
factory_girl_options[:suffix] || options[:suffix]
|
factory_bot_options[:suffix] || options[:suffix]
|
||||||
end
|
end
|
||||||
|
|
||||||
def factory_girl_options
|
def factory_bot_options
|
||||||
generators.options[:factory_girl] || {}
|
generators.options[:factory_bot] || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def generators
|
def generators
|
||||||
config = FactoryGirl::Railtie.config
|
config = FactoryBot::Railtie.config
|
||||||
config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue