我正在一个实验性开源项目(ruby_crystal_codemod)中试用 Sorbet。我不知道如何让类型检查与嵌套测试项目中的一些 RSpec 测试一起工作。当我运行时srb tc
,我看到一些类型检查错误,如下所示:
spec/src/example_class_annotated_spec.rb:6: Method it does not exist on T.class_of(<root>) https://srb.help/7003
6 | it 'should add @foo and @bar' do
7 | instance = ExampleClass.new(2, 3, 4)
8 | expect(instance.add).to eq 5
9 | end
spec/src/example_class_annotated_spec.rb:8: Method expect does not exist on T.class_of(<root>) https://srb.help/7003
8 | expect(instance.add).to eq 5
^^^^^^^^^^^^^^^^^^^^
https://github.com/sorbet/sorbet/tree/67cd17f5168252fdec1ad04839b31fdda8bc6155/rbi/core/kernel.rbi#L2662: Did you mean: Kernel#exec?
2662 | def exec(*args); end
^^^^^^^^^^^^^^^
spec/src/example_class_annotated_spec.rb:8: Method eq does not exist on T.class_of(<root>) https://srb.help/7003
8 | expect(instance.add).to eq 5
^^^^
# etc.
您应该能够运行以下命令来重现类型错误:
cd /tmp
git clone https://github.com/DocSpring/ruby_crystal_codemod.git
cd ruby_crystal_codemod
git checkout sorbet-rspec-type-checking-error
cd spec/fixtures/rspec_project/
bundle install
bundle exec srb tc
您应该会看到以下类型错误:
spec/src/example_class_annotated_spec.rb:6: Method it does not exist on T.class_of(<root>) https://srb.help/7003
6 | it 'should add @foo and @bar' do
7 | instance = ExampleClass.new(2, 3, 4)
8 | expect(instance.add).to eq 5
9 | end
# etc.
spec/fixtures/rspec_project/sorbet/rbi/gems/rspec-core.rbi
等处的 RBI 文件有问题吗?