From c5d11518d7168ac28c80cee3d55e0d7e251dc49b Mon Sep 17 00:00:00 2001 From: Avielle Wolfe Date: Fri, 2 Dec 2016 10:25:09 -0500 Subject: [PATCH] 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 https://github.com/thoughtbot/factory_girl/commit/c716ce01b448ce4e0bf855c5a2c63ecb9206322e --- CONTRIBUTING.md | 4 +- Gemfile | 2 +- Gemfile.lock | 8 ++-- NEWS | 4 +- README.md | 48 +++++++++---------- Rakefile | 3 +- factory_bot_rails.gemspec | 20 ++++++++ factory_girl_rails.gemspec | 2 +- features/fixture_replacement_config.feature | 36 +++++++------- features/generators.feature | 20 ++++---- features/load_definitions.feature | 14 +++--- features/step_definitions/rails_steps.rb | 2 +- gemfiles/rails3.2.gemfile | 2 +- gemfiles/rails4.1.gemfile | 2 +- gemfiles/rails4.2.gemfile | 2 +- gemfiles/rails5.0.gemfile | 2 +- lib/factory_bot_rails.rb | 4 ++ .../generator.rb | 14 +++--- .../generators/non_rspec_generator.rb | 4 +- .../generators/null_generator.rb | 2 +- .../generators/rspec_generator.rb | 10 ++-- lib/factory_bot_rails/railtie.rb | 28 +++++++++++ lib/factory_girl_rails.rb | 4 -- lib/factory_girl_rails/railtie.rb | 28 ----------- .../{factory_girl.rb => factory_bot.rb} | 4 +- .../model/model_generator.rb | 22 ++++----- 26 files changed, 156 insertions(+), 135 deletions(-) create mode 100644 factory_bot_rails.gemspec create mode 100644 lib/factory_bot_rails.rb rename lib/{factory_girl_rails => factory_bot_rails}/generator.rb (69%) rename lib/{factory_girl_rails => factory_bot_rails}/generators/non_rspec_generator.rb (84%) rename lib/{factory_girl_rails => factory_bot_rails}/generators/null_generator.rb (84%) rename lib/{factory_girl_rails => factory_bot_rails}/generators/rspec_generator.rb (66%) create mode 100644 lib/factory_bot_rails/railtie.rb delete mode 100644 lib/factory_girl_rails.rb delete mode 100644 lib/factory_girl_rails/railtie.rb rename lib/generators/{factory_girl.rb => factory_bot.rb} (65%) rename lib/generators/{factory_girl => factory_bot}/model/model_generator.rb (79%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 10d4b53..75ff4ae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,7 +7,7 @@ agree to abide by the thoughtbot [code of conduct]. 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: @@ -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]. -[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 within three business days (and, typically, one business day). We may suggest diff --git a/Gemfile b/Gemfile index 05de785..edbe1b8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gemspec +gemspec name: 'factory_bot_rails' gem 'appraisal' gem 'aruba' diff --git a/Gemfile.lock b/Gemfile.lock index dce3f0d..53ac8bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ PATH remote: . specs: - factory_girl_rails (4.8.0) - factory_girl (~> 4.8.0) + factory_bot_rails (4.8.0) + factory_bot (~> 4.8.2) railties (>= 3.0.0) GEM @@ -63,7 +63,7 @@ GEM diff-lcs (1.2.5) erubis (2.7.0) execjs (2.0.2) - factory_girl (4.8.0) + factory_bot (4.8.2) activesupport (>= 3.0.0) ffi (1.9.3) ffi (1.9.3-java) @@ -129,7 +129,7 @@ DEPENDENCIES aruba coffee-rails cucumber (= 1.3.19) - factory_girl_rails! + factory_bot_rails! jdbc-sqlite3 jquery-rails jruby-openssl diff --git a/NEWS b/NEWS index c8ceea3..9c4309f 100644 --- a/NEWS +++ b/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. 4.7.0 (April 1, 2016) @@ -6,7 +6,7 @@ there might not be any notable changes in new versions of this project. 4.6.0 (February 1, 2016) No notable changes - + 4.5.0 (October 17, 2014) Improved README diff --git a/README.md b/README.md index f6730cf..6517951 100644 --- a/README.md +++ b/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 instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (`user`, `admin_user`, and so on), including factory @@ -8,7 +8,7 @@ inheritance. ## 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. @@ -17,19 +17,19 @@ Ruby versions are listed in [`.travis.yml`](.travis.yml). ## Download -Github: http://github.com/thoughtbot/factory_girl_rails +Github: http://github.com/thoughtbot/factory_bot_rails Gem: - $ gem install factory_girl_rails + $ gem install factory_bot_rails ## Configuration -Add `factory_girl_rails` to your Gemfile: +Add `factory_bot_rails` to your Gemfile: ```ruby group :development, :test do - gem 'factory_girl_rails' + gem 'factory_bot_rails' end ``` @@ -39,7 +39,7 @@ following to your application.rb file: ```ruby config.generators do |g| - g.factory_girl false + g.factory_bot false end ``` @@ -48,24 +48,24 @@ Default factories directory is `test/factories`, or `spec/factories` if ```ruby config.generators do |g| - g.factory_girl dir: 'custom/dir/for/factories' + g.factory_bot dir: 'custom/dir/for/factories' end ``` -If you use factory_girl for fixture replacement, ensure that -factory_girl_rails is available in the development group. If it's not, Rails +If you use factory_bot for fixture replacement, ensure that +factory_bot_rails is available in the development group. If it's not, Rails 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`. -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, -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`. -You may need to configure your test suite to include factory_girl methods; see -[configuration](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#configure-your-test-suite). +You may need to configure your test suite to include factory_bot methods; see +[configuration](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#configure-your-test-suite). ## Contributing @@ -73,22 +73,22 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md). ## 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) -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. ## 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 [LICENSE](LICENSE) file. -[fg]: https://github.com/thoughtbot/factory_girl -[ci]: http://travis-ci.org/thoughtbot/factory_girl_rails?branch=master -[ci-image]: https://secure.travis-ci.org/thoughtbot/factory_girl_rails.png -[grade]: https://codeclimate.com/github/thoughtbot/factory_girl_rails -[grade-image]: https://codeclimate.com/github/thoughtbot/factory_girl_rails.png +[fb]: https://github.com/thoughtbot/factory_bot +[ci]: http://travis-ci.org/thoughtbot/factory_bot_rails?branch=master +[ci-image]: https://secure.travis-ci.org/thoughtbot/factory_bot_rails.png +[grade]: https://codeclimate.com/github/thoughtbot/factory_bot_rails +[grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot_rails.png diff --git a/Rakefile b/Rakefile index 2797003..dfe61c2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,8 @@ require 'bundler/setup' -require 'bundler/gem_tasks' require 'cucumber/rake/task' +Bundler::GemHelper.install_tasks name: 'factory_bot_rails' + Cucumber::Rake::Task.new(:cucumber) do |t| t.fork = true t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')] diff --git a/factory_bot_rails.gemspec b/factory_bot_rails.gemspec new file mode 100644 index 0000000..5167c24 --- /dev/null +++ b/factory_bot_rails.gemspec @@ -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 diff --git a/factory_girl_rails.gemspec b/factory_girl_rails.gemspec index 28d3e6d..b27f2c5 100644 --- a/factory_girl_rails.gemspec +++ b/factory_girl_rails.gemspec @@ -16,5 +16,5 @@ Gem::Specification.new do |s| s.license = "MIT" 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 diff --git a/features/fixture_replacement_config.feature b/features/fixture_replacement_config.feature index 23d21e6..97af49f 100644 --- a/features/fixture_replacement_config.feature +++ b/features/fixture_replacement_config.feature @@ -1,13 +1,13 @@ 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 - I would like the Factory Girl Rails gem to configure Factory Girl as the fixture replacement. + 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 Bot Rails gem to configure Factory Bot as the fixture replacement. Background: Given I successfully run `bundle exec rails new 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 exec rails generate model User name:string` with a clean environment Then the following files should exist: @@ -15,13 +15,13 @@ Feature: And the following files should not exist: | 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 And I configure the factories as: """ config.generators do |g| g.test_framework :rspec, fixture: true - g.fixture_replacement :factory_girl + g.fixture_replacement :factory_bot end """ And I run `bundle install` with a clean environment @@ -32,13 +32,13 @@ Feature: And the following files should not exist: | 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 And I configure the factories as: """ config.generators do |g| g.test_framework :rspec, fixture: true - g.fixture_replacement :factory_girl, suffix: 'factory' + g.fixture_replacement :factory_bot, suffix: 'factory' end """ And I run `bundle install` with a clean environment @@ -49,7 +49,7 @@ Feature: And the following files should not exist: | 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 And I configure the factories directory as "custom/dir" And I run `bundle install` with a clean environment @@ -61,7 +61,7 @@ Feature: But the following files should exist: | 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" And I run `bundle install` 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: | 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 And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should exist: @@ -79,7 +79,7 @@ Feature: But the following files should not exist: | 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" And I run `bundle install` 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: | spec/fixtures/users.yml | - Scenario: Disable Factory Girl generator + Scenario: Disable Factory Bot generator When I configure the factories as: """ config.generators do |g| - g.factory_girl false + g.factory_bot false end """ And I run `bundle install` with a clean environment @@ -101,12 +101,12 @@ Feature: | test/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 configure the factories as: """ config.generators do |g| - g.factory_girl suffix: 'suffix' + g.factory_bot suffix: 'suffix' end """ And I run `bundle install` with a clean environment @@ -116,12 +116,12 @@ Feature: Then the following files should not exist: | 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 configure the factories as: """ 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 """ And I run `bundle install` with a clean environment diff --git a/features/generators.feature b/features/generators.feature index dc0ef9c..2227e2c 100644 --- a/features/generators.feature +++ b/features/generators.feature @@ -1,14 +1,14 @@ Feature: In order to easily generate factory files instead of fixture files when generating models - As a user of Rails and Factory Girl - I would like to use factory_girl_rails generators. + As a user of Rails and Factory Bot + I would like to use factory_bot_rails generators. Background: Given I successfully run `bundle exec rails new 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 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 @@ -16,7 +16,7 @@ Feature: And the output should contain "test/factories/namespaced_users.rb" And the file "test/factories/users.rb" should contain exactly: """ - FactoryGirl.define do + FactoryBot.define do factory :user do name "MyString" age 1 @@ -26,28 +26,28 @@ Feature: """ 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 And I write to "test/factories.rb" with: """ - FactoryGirl.define do + FactoryBot.define do end """ And I run `bundle exec rails generate model User name:string` with a clean environment Then the file "test/factories.rb" should contain exactly: """ - FactoryGirl.define do + FactoryBot.define do factory :user do name "MyString" 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 And I write to "test/factories.rb" with: """ - FactoryGirl.define do + FactoryBot.define do end """ And I run `bundle exec rails generate model User name:string` with a clean environment diff --git a/features/load_definitions.feature b/features/load_definitions.feature index a307fe6..85f0d58 100644 --- a/features/load_definitions.feature +++ b/features/load_definitions.feature @@ -3,7 +3,7 @@ Feature: automatically load step definitions Background: When I successfully run `bundle exec rails new 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 run `bundle install` with a clean environment 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 When I write to "test/factories.rb" with: """ - FactoryGirl.define do + FactoryBot.define do factory :user do name "Frank" end @@ -38,7 +38,7 @@ Feature: automatically load step definitions class UserTest < ActiveSupport::TestCase test "use factory" do - user = FactoryGirl.create(:user) + user = FactoryBot.create(:user) assert_equal 'Frank', user.name end end @@ -56,15 +56,15 @@ Feature: automatically load step definitions module SomeRailtie class Railtie < ::Rails::Engine - initializer "some_railtie.factories", :after => "factory_girl.set_factory_paths" do - FactoryGirl.definition_file_paths << File.expand_path('../factories', __FILE__) + initializer "some_railtie.factories", :after => "factory_bot.set_factory_paths" do + FactoryBot.definition_file_paths << File.expand_path('../factories', __FILE__) end end end """ When I write to "lib/some_railtie/factories.rb" with: """ - FactoryGirl.define do + FactoryBot.define do factory :factory_from_some_railtie, class: 'User' do name 'Artem' end @@ -76,7 +76,7 @@ Feature: automatically load step definitions class UserTest < ActiveSupport::TestCase 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 end end diff --git a/features/step_definitions/rails_steps.rb b/features/step_definitions/rails_steps.rb index 299f785..2fa0653 100644 --- a/features/step_definitions/rails_steps.rb +++ b/features/step_definitions/rails_steps.rb @@ -26,7 +26,7 @@ When /^I configure the factories directory as "([^"]+)"$/ do |factory_dir| append_to_file File.join('config', 'application.rb'), <<-END class Testapp::Application config.generators do |g| - g.fixture_replacement :factory_girl, :dir => "#{factory_dir}" + g.fixture_replacement :factory_bot, :dir => "#{factory_dir}" end end END diff --git a/gemfiles/rails3.2.gemfile b/gemfiles/rails3.2.gemfile index dc3e2fa..e95b3c1 100644 --- a/gemfiles/rails3.2.gemfile +++ b/gemfiles/rails3.2.gemfile @@ -19,4 +19,4 @@ gem "sqlite3", :platforms => :ruby gem "rails", "~> 3.2.21" gem "sass-rails" -gemspec :path => "../" +gemspec :path => "../", :name => "factory_bot_rails" diff --git a/gemfiles/rails4.1.gemfile b/gemfiles/rails4.1.gemfile index e007b3a..d220822 100644 --- a/gemfiles/rails4.1.gemfile +++ b/gemfiles/rails4.1.gemfile @@ -20,4 +20,4 @@ gem "rails", "~> 4.1.9" gem "sass-rails" gem "spring" -gemspec :path => "../" +gemspec :path => "../", :name => "factory_bot_rails" diff --git a/gemfiles/rails4.2.gemfile b/gemfiles/rails4.2.gemfile index a006cbb..dc06fd9 100644 --- a/gemfiles/rails4.2.gemfile +++ b/gemfiles/rails4.2.gemfile @@ -18,4 +18,4 @@ gem "jruby-openssl", :platforms => :jruby gem "sqlite3", :platforms => :ruby gem "rails", "~> 4.2.0" -gemspec :path => "../" +gemspec :path => "../", :name => "factory_bot_rails" diff --git a/gemfiles/rails5.0.gemfile b/gemfiles/rails5.0.gemfile index b57a975..0f48cce 100644 --- a/gemfiles/rails5.0.gemfile +++ b/gemfiles/rails5.0.gemfile @@ -19,4 +19,4 @@ gem "sqlite3", :platforms => :ruby gem "activerecord", "~> 5.0.0" gem "railties", "~> 5.0.0" -gemspec :path => "../" +gemspec :path => "../", :name => "factory_bot_rails" diff --git a/lib/factory_bot_rails.rb b/lib/factory_bot_rails.rb new file mode 100644 index 0000000..a25d277 --- /dev/null +++ b/lib/factory_bot_rails.rb @@ -0,0 +1,4 @@ +require 'factory_bot_rails/railtie' + +module FactoryBotRails +end diff --git a/lib/factory_girl_rails/generator.rb b/lib/factory_bot_rails/generator.rb similarity index 69% rename from lib/factory_girl_rails/generator.rb rename to lib/factory_bot_rails/generator.rb index cd27922..c1ed00c 100644 --- a/lib/factory_girl_rails/generator.rb +++ b/lib/factory_bot_rails/generator.rb @@ -1,8 +1,8 @@ -require 'factory_girl_rails/generators/rspec_generator' -require 'factory_girl_rails/generators/non_rspec_generator' -require 'factory_girl_rails/generators/null_generator' +require 'factory_bot_rails/generators/rspec_generator' +require 'factory_bot_rails/generators/non_rspec_generator' +require 'factory_bot_rails/generators/null_generator' -module FactoryGirlRails +module FactoryBotRails class Generator def initialize(config) @generators = if config.respond_to?(:app_generators) @@ -17,7 +17,7 @@ module FactoryGirlRails end def generator - if factory_girl_disabled? + if factory_bot_disabled? Generators::NullGenerator else if test_framework == :rspec @@ -32,8 +32,8 @@ module FactoryGirlRails rails_options[:test_framework] end - def factory_girl_disabled? - rails_options[:factory_girl] == false + def factory_bot_disabled? + rails_options[:factory_bot] == false end def rails_options diff --git a/lib/factory_girl_rails/generators/non_rspec_generator.rb b/lib/factory_bot_rails/generators/non_rspec_generator.rb similarity index 84% rename from lib/factory_girl_rails/generators/non_rspec_generator.rb rename to lib/factory_bot_rails/generators/non_rspec_generator.rb index e261d9a..0aa7d5d 100644 --- a/lib/factory_girl_rails/generators/non_rspec_generator.rb +++ b/lib/factory_bot_rails/generators/non_rspec_generator.rb @@ -1,4 +1,4 @@ -module FactoryGirlRails +module FactoryBotRails module Generators class NonRSpecGenerator def initialize(generators) @@ -6,7 +6,7 @@ module FactoryGirlRails end 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 private diff --git a/lib/factory_girl_rails/generators/null_generator.rb b/lib/factory_bot_rails/generators/null_generator.rb similarity index 84% rename from lib/factory_girl_rails/generators/null_generator.rb rename to lib/factory_bot_rails/generators/null_generator.rb index e1868fb..964f0f5 100644 --- a/lib/factory_girl_rails/generators/null_generator.rb +++ b/lib/factory_bot_rails/generators/null_generator.rb @@ -1,4 +1,4 @@ -module FactoryGirlRails +module FactoryBotRails module Generators class NullGenerator def initialize(generators) diff --git a/lib/factory_girl_rails/generators/rspec_generator.rb b/lib/factory_bot_rails/generators/rspec_generator.rb similarity index 66% rename from lib/factory_girl_rails/generators/rspec_generator.rb rename to lib/factory_bot_rails/generators/rspec_generator.rb index dd3fc29..c97809d 100644 --- a/lib/factory_girl_rails/generators/rspec_generator.rb +++ b/lib/factory_bot_rails/generators/rspec_generator.rb @@ -1,4 +1,4 @@ -module FactoryGirlRails +module FactoryBotRails module Generators class RSpecGenerator def initialize(generators) @@ -6,17 +6,17 @@ module FactoryGirlRails end def run - @generators.fixture_replacement fixture_replacement_setting, dir: factory_girl_directory + @generators.fixture_replacement fixture_replacement_setting, dir: factory_bot_directory end private def fixture_replacement_setting - @generators.options[:rails][:fixture_replacement] || :factory_girl + @generators.options[:rails][:fixture_replacement] || :factory_bot end - def factory_girl_directory - @generators.options.fetch(:factory_girl, {}).fetch(:dir, 'spec/factories') + def factory_bot_directory + @generators.options.fetch(:factory_bot, {}).fetch(:dir, 'spec/factories') end end end diff --git a/lib/factory_bot_rails/railtie.rb b/lib/factory_bot_rails/railtie.rb new file mode 100644 index 0000000..f7af2b0 --- /dev/null +++ b/lib/factory_bot_rails/railtie.rb @@ -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 diff --git a/lib/factory_girl_rails.rb b/lib/factory_girl_rails.rb deleted file mode 100644 index b03895a..0000000 --- a/lib/factory_girl_rails.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'factory_girl_rails/railtie' - -module FactoryGirlRails -end diff --git a/lib/factory_girl_rails/railtie.rb b/lib/factory_girl_rails/railtie.rb deleted file mode 100644 index d247130..0000000 --- a/lib/factory_girl_rails/railtie.rb +++ /dev/null @@ -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 diff --git a/lib/generators/factory_girl.rb b/lib/generators/factory_bot.rb similarity index 65% rename from lib/generators/factory_girl.rb rename to lib/generators/factory_bot.rb index acbba81..963cc36 100644 --- a/lib/generators/factory_girl.rb +++ b/lib/generators/factory_bot.rb @@ -1,10 +1,10 @@ require 'rails/generators/named_base' -module FactoryGirl +module FactoryBot module Generators class Base < Rails::Generators::NamedBase #:nodoc: 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 def explicit_class_option diff --git a/lib/generators/factory_girl/model/model_generator.rb b/lib/generators/factory_bot/model/model_generator.rb similarity index 79% rename from lib/generators/factory_girl/model/model_generator.rb rename to lib/generators/factory_bot/model/model_generator.rb index 21a25b3..95e993a 100644 --- a/lib/generators/factory_girl/model/model_generator.rb +++ b/lib/generators/factory_bot/model/model_generator.rb @@ -1,7 +1,7 @@ -require 'generators/factory_girl' -require 'factory_girl_rails' +require 'generators/factory_bot' +require 'factory_bot_rails' -module FactoryGirl +module FactoryBot module Generators class ModelGenerator < Base argument( @@ -43,7 +43,7 @@ module FactoryGirl insert_into_file( factories_file, factory_definition, - after: "FactoryGirl.define do\n" + after: "FactoryBot.define do\n" ) end @@ -62,7 +62,7 @@ RUBY def single_file_factory_definition <<-RUBY -FactoryGirl.define do +FactoryBot.define do #{factory_definition.chomp} end RUBY @@ -75,23 +75,23 @@ RUBY end def filename - if factory_girl_options[:filename_proc].present? - factory_girl_options[:filename_proc].call(table_name) + if factory_bot_options[:filename_proc].present? + factory_bot_options[:filename_proc].call(table_name) else [table_name, filename_suffix].compact.join('_') end end def filename_suffix - factory_girl_options[:suffix] || options[:suffix] + factory_bot_options[:suffix] || options[:suffix] end - def factory_girl_options - generators.options[:factory_girl] || {} + def factory_bot_options + generators.options[:factory_bot] || {} end def generators - config = FactoryGirl::Railtie.config + config = FactoryBot::Railtie.config config.respond_to?(:app_generators) ? config.app_generators : config.generators end end