rspec `described_class` is `nil`

Viewed 585

Rails 6.0.0.beta3

rspec 3.8.0

I've just installed rspec-rails on my Rails app. I ran rails g rspec:install and it generated spec/spec_helper.rb, spec/rails_helper.rb and .rspec The only thing I changed was uncommenting the suggested settings in spec_helper

I'm using gruf to run a gRPC server, instead of a normal HTTP server.

I've also installed gruf-rspec intending to use that to test my gruf controllers.

My gruf controller is at app/rpc/controllers/users_controller.rb following the gruf documentation. Also the compiled protobuf file is at app/rpc/users_services_pb.rb

This is the class signature of the controller:

require 'users_services_pb'
require_relative 'permission_helper'

class UsersController < Gruf::Controllers::Base
  bind ::Sil::Rev79::Users::Service
  ...
end

My problem is that in my test the described_class is nil

Here is my test

# spec/rpc/users_contollers_spec.rb

require 'rails_helper'
require 'users_services_pb'

RSpec.describe 'UsersController' do

  describe 'list_users' do
    it 'succeeds' do
      expect(described_class).not_to be_nil
    end
  end

end

The test fails.

Why is described_class nil and how can I fix this?

1 Answers

Remove the quotation marks. It shouldn't be a string.

Rspec.describe UsersController do
 # insert code
end
Related