FactoryBot

forked from FactoryBot

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)
TDD fixtures 1,196 2


y.fkhar
y.fkhar

Jun 18, 2020

Copy and paste this code into your terminal

DISCLAIMER: You should always review templates before running them. By running the template, you are agreeing to the terms of use.

The contents of this script as show. Any updates will be reflected in the below code and the snippet.

if !defined? RSpec
  say "RSpec was not installed. Adding it now..."
  gem "rspec-rails" , group: [:development, :test]
  run "bundle install"
  generate "rspec:install"
end

gem "factory_bot_rails", group: [:development, :test]

run "bundle install"

create_file "spec/support/factory_bot.rb", <<~EOF
  RSpec.configure do |config|
    config.include FactoryBot::Syntax::Methods
  end
EOF

gsub_file 'spec/rails_helper.rb', "# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }\n", "Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }\n"

A place where you can thank the author, post problems, give constructive feedback, etc. Be nice!