Class: Boring::FactoryBot::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/boring/factory_bot/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_factory_bot_gemObject



14
15
16
17
18
19
# File 'lib/generators/boring/factory_bot/install/install_generator.rb', line 14

def add_factory_bot_gem
  log :adding, "FactoryBot"
  Bundler.with_unbundled_env do
    run "bundle add factory_bot_rails --group='development,test'"
  end
end

#add_factory_bot_helper_methodObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/boring/factory_bot/install/install_generator.rb', line 28

def add_factory_bot_helper_method
  log :adding, "factory_bot helper"
  data = <<~RUBY
    include FactoryBot::Syntax::Methods
  RUBY

  inject_into_file "test/test_helper.rb", optimize_indentation(data, 2),
                                          after: /ActiveSupport::TestCase*\n/,
                                          verbose: false
end

#add_faker_gemObject



39
40
41
42
43
# File 'lib/generators/boring/factory_bot/install/install_generator.rb', line 39

def add_faker_gem
  return if options[:skip_faker]

  Rails::Command.invoke :generate, ["boring:faker:install"]
end

#add_sample_factoryObject



21
22
23
24
25
26
# File 'lib/generators/boring/factory_bot/install/install_generator.rb', line 21

def add_sample_factory
  return if options[:skip_factory]

  log :adding, "Sample users factory"
  copy_file "users.rb", "test/factories/users.rb"
end