diff --git a/spec/tapioca/cli/annotations_spec.rb b/spec/tapioca/cli/annotations_spec.rb index 26bd57de1..40ad31902 100644 --- a/spec/tapioca/cli/annotations_spec.rb +++ b/spec/tapioca/cli/annotations_spec.rb @@ -12,6 +12,7 @@ class AnnotationsTest < SpecWithProject after do @project.remove!("sorbet/rbi/annotations") + @project.write!("Gemfile", @project.tapioca_gemfile) end it "does nothing if the repo is empty" do @@ -358,6 +359,45 @@ class AnnotationForSpoom; end repo.destroy! end + + it "filters RBI file based on gem version" do + foo = mock_gem("foo", "0.3.4") do + write!("lib/foo.rb", <<~BAR) + class Foo; end + BAR + end + + @project.require_mock_gem(foo) + @project.bundle_install! + + repo = create_repo({ + foo: <<~RBI, + # typed: false + + # @version > 0.3.5 + class AnnotationForFoo; end + class Foo; end + RBI + }) + + result = @project.tapioca("annotations --sources #{repo.absolute_path}") + + assert_stdout_includes(result, "create sorbet/rbi/annotations/foo.rbi") + + assert_project_annotation_equal("sorbet/rbi/annotations/foo.rbi", <<~RBI) + # typed: false + + # DO NOT EDIT MANUALLY + # This file was pulled from a central RBI files repository. + # Please run `bin/tapioca annotations` to update it. + + class Foo; end + RBI + + assert_success_status(result) + + repo.destroy! + end end private