ruby-on-railsrubyauthenticationrspecrspec-rails

How to fix error in Rails Authentication generation with RSpec?


I created a new Rails 8 application. I installed RSpec for testing.

$ rails g authentication
      invoke  erb
      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/20250304151808_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/20250304151809_create_sessions.rb
       error  rspec [not found]

How do I fix error rspec [not found] when I generate authentication?


Solution

  • RSpec-Rails latest release is 7.1.1 which is still on the Rails 7 compatibility branch and thus doesn't have a generator for a feature introduced in Rails 8.

    There is a authentication generator in the master branch but I would expect it to be released with RSpec-Rails 8.x.

    If this feature is really important to you can point your gemfile to the master on GitHub.

    group :development, :test do
      gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails'
    end
    

    Otherwise you can just manually run the model / request / system generators to generate specs at each respective level.