samuelgiles/rspec-sorbet

Method `eq` does not exist on <describe ...>

Closed this issue · 3 comments

Not sure if the above error falls in the scope of rspec-sorbet, but I have a simple test case:

describe Direction do
  it ".values contain all 4 basic directions" do
    expected = [
      Direction::N,
      Direction::E,
      Direction::S,
      Direction::W,
    ]
    expect(Direction.values).to eq(expected)
  end
end

And srb tc keeps failing with the error:

Method eq does not exist on <describe 'Direction'> https://srb.help/7003
    14 |    expect(Direction.values).to eq(expected)

Here's my spec_helper.rb file:

require 'sorbet-runtime'
require 'rspec/sorbet'

My question is whether rspec-sorbet is supposed to help resolve this issue? Or is it normal to get this error? Maybe I'll be better off disabling type-checking for my tests, but it'll be a bit sad to do so. Any help will be appreciated.

Errors had temporarily disappeared, but I noticed that it was because # typed had somehow become false. The problem persists.

Hey @jigarius, apologies for the delayed response I'm not sure how I missed this. Enabling # typed: true within specs isn't something the rspec-sorbet gem does just yet, I'd love it to do so but I think the DSL might make it tricky.

For the moment the gem is focused on letting you pass instance/class/object doubles into methods by semi-intelligently inspecting the Sorbet's runtime errors to check if the double is_a? double of the thing the method expects.

To anyone that finds this post in the quest to mark spec files as typed: there's a really good post here: https://stackoverflow.com/a/76548429. I managed to enable sorbet for my specs with these shims:

sorbet/rbi/shims/rspec.rbi:

# typed: strict
# frozen_string_literal: true

module RSpec
  sig do
    params(
      args: T.untyped, # rubocop:disable Sorbet/ForbidTUntyped
      example_group_block: T.proc.bind(T.untyped).void, # rubocop:disable Sorbet/ForbidTUntyped
    ).void
  end
  def self.describe(*args, &example_group_block)
  end

  sig do
    params(
      name: String,
      args: T.untyped, # rubocop:disable Sorbet/ForbidTUntyped
      block: T.proc.bind(T.untyped).void, # rubocop:disable Sorbet/ForbidTUntyped
    ).void
  end
  def self.shared_examples(name, *args, &block)
  end
end

sorbet/rbi/shims/factory_bot.rbi:

# typed: strict
# frozen_string_literal: true

module FactoryBot
  sig do
    params(
      block: T.proc.bind(T.untyped).void, # rubocop:disable Sorbet/ForbidTUntyped
    ).void
  end
  def self.define(&block)
  end
end