samuelgiles / rspec-sorbet

A small gem consisting of helpers for using Sorbet & RSpec together.
MIT License
39 stars 9 forks source link

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

Closed jigarius closed 3 years ago

jigarius commented 3 years ago

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.

jigarius commented 3 years ago

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

samuelgiles commented 3 years ago

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.

jgrau commented 7 months ago

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