diff --git a/features/generators.feature b/features/generators.feature index d0e22c91..e7ddc2e4 100644 --- a/features/generators.feature +++ b/features/generators.feature @@ -90,3 +90,19 @@ Feature: And I run `bundle exec rails generate model User name:string age:integer` with a clean environment Then the output should not contain "test/factories/users.rb" And the output should contain "test/fixtures/users.yml" + + Scenario: The factory_bot_rails authentication generator, coupled with rspec-rails, creates a user factory file + When I add "rspec-rails" with options `github: "rspec/rspec-rails", branch: "main"` as a dependency + And I run `bundle install --verbose` with a clean environment + Then the output should contain "rspec-rails" + And I run `bundle exec rails generate authentication` with a clean environment + Then the output should contain "test/factories/users.rb" + And the file "test/factories/users.rb" should contain exactly: + """ + FactoryBot.define do + factory :user do + email_address { "john@example.com" } + password_digest { "MyString" } + end + end + """ diff --git a/features/step_definitions/rails_steps.rb b/features/step_definitions/rails_steps.rb index 3e63941a..f1274d47 100644 --- a/features/step_definitions/rails_steps.rb +++ b/features/step_definitions/rails_steps.rb @@ -28,6 +28,10 @@ append_to_file("Gemfile", %(gem "#{gem_name}"\n)) end +When(/^I add "([^"]+)" with options `(.+)` as a dependency$/) do |gem_name, options| + append_to_file("Gemfile", %(gem "#{gem_name}", #{options}\n)) +end + When(/^I print out "([^"]*)"$/) do |path| in_current_dir do File.open(path, "r") do |f| diff --git a/lib/generators/factory_bot/authentication/authentication_generator.rb b/lib/generators/factory_bot/authentication/authentication_generator.rb new file mode 100644 index 00000000..abaae92f --- /dev/null +++ b/lib/generators/factory_bot/authentication/authentication_generator.rb @@ -0,0 +1,12 @@ +require "generators/factory_bot" +require "factory_bot_rails" + +module FactoryBot + module Generators + class AuthenticationGenerator < Base + def create_fixture_file + template "users.rb", "test/factories/users.rb" + end + end + end +end diff --git a/lib/generators/factory_bot/authentication/templates/users.rb b/lib/generators/factory_bot/authentication/templates/users.rb new file mode 100644 index 00000000..5c2ac335 --- /dev/null +++ b/lib/generators/factory_bot/authentication/templates/users.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :user do + email_address { "john@example.com" } + password_digest { "MyString" } + end +end