Built in authentication generator errors on `rspec`

I have a basic rails app using postgres, tailwind and rspec with --skip-test and --skip-system-test. After generating the app skeleton with rails new I run the bin/rails g authentication and it always gives me the error and I’m not sure whether generator succeeded or not:

MyApp % bin/rails g authentication
      invoke  tailwindcss
      create    app/views/passwords/new.html.erb
      create    app/views/passwords/edit.html.erb
      create    app/views/sessions/new.html.erb
      create  app/models/session.rb
      create  app/models/user.rb
      create  app/models/current.rb
      create  app/controllers/sessions_controller.rb
      create  app/controllers/concerns/authentication.rb
      create  app/controllers/passwords_controller.rb
      create  app/channels/application_cable/connection.rb
      create  app/mailers/passwords_mailer.rb
      create  app/views/passwords_mailer/reset.html.erb
      create  app/views/passwords_mailer/reset.text.erb
      create  test/mailers/previews/passwords_mailer_preview.rb
      insert  app/controllers/application_controller.rb
       route  resources :passwords, param: :token
       route  resource :session
        gsub  Gemfile
      bundle  install --quiet
    generate  migration CreateUsers email_address:string!:uniq password_digest:string! --force
       rails  generate migration CreateUsers email_address:string!:uniq password_digest:string! --force 
      invoke  active_record
      create    db/migrate/20250216070657_create_users.rb
    generate  migration CreateSessions user:references ip_address:string user_agent:string --force
       rails  generate migration CreateSessions user:references ip_address:string user_agent:string --force 
      invoke  active_record
      create    db/migrate/20250216070659_create_sessions.rb
       error  rspec [not found]
MyApp % 

The rspec is there and app contains bin/rspec file. I can run rspec command and it runs successfully (0 examples, 0 failures). Running bin/rails g authentication -t rspec also fails with the same error.

What is also curious — the password mailer preview file is generated under test/mailers/previews.

The exact command used:

rails new MyApp \              
--template=./Archive/baseline.rb \
--database=postgresql \
--css=tailwind \
--skip-test \
--skip-system-test

The template file can be found in this gist.

Generated Gemfile can be found in this gist.

Also — would it make sense for me to file a bug in rails/rails repo?

I hit the same thing, and eventually found Add Rails 8 authentication generator by jeromedalbert · Pull Request #2811 · rspec/rspec-rails · GitHub

It’s merged into main, but didn’t get into 7.1.1

That said, we’re not missing much—it adds the same bare-bones User model spec the model generator does and users.yml fixtures file, roughly equivalent to what test-unit generates.

FWIW, here’s how the generator output ends with test-unit:

$ bin/rails g authentication
[...]
      create    db/migrate/20250303002744_create_sessions.rb
      invoke  test_unit
      create    test/fixtures/users.yml
      create    test/models/user_test.rb
$
1 Like