diff --git a/spec/tapioca/cli/annotations_spec.rb b/spec/tapioca/cli/annotations_spec.rb index cf729941e..68bceb661 100644 --- a/spec/tapioca/cli/annotations_spec.rb +++ b/spec/tapioca/cli/annotations_spec.rb @@ -27,6 +27,7 @@ class AnnotationsTest < SpecWithProject OUT assert_success_status(result) + refute(File.directory?(@project.absolute_path("sorbet/rbi/annotations"))) repo.destroy end @@ -94,6 +95,9 @@ class AnnotationForRBI; end class AnnotationForSpoom; end RBI + assert_project_file_equal("sorbet/rbi/annotations/.gitattributes", <<~CONTENT) + **/*.rbi linguist-vendored=true + CONTENT refute_project_file_exist("sorbet/rbi/annotations/foo.rbi") assert_success_status(result) diff --git a/spec/tapioca/cli/dsl_spec.rb b/spec/tapioca/cli/dsl_spec.rb index 6797e65f8..1a2f53f23 100644 --- a/spec/tapioca/cli/dsl_spec.rb +++ b/spec/tapioca/cli/dsl_spec.rb @@ -72,6 +72,40 @@ def self.application @project.remove("sorbet/rbi/dsl") end + it "must generate a .gitattributes file in the output folder" do + @project.write("lib/post.rb", <<~RB) + require "smart_properties" + + class Post + include SmartProperties + property :title, accepts: String + end + RB + + result = @project.tapioca("dsl Post --outdir output") + + assert_empty_stderr(result) + assert_success_status(result) + + assert_project_file_equal("output/.gitattributes", <<~CONTENT) + **/*.rbi linguist-generated=true + CONTENT + ensure + @project.remove("output") + end + + it "must not generate a .gitattributes file if the output folder is not created" do + result = @project.tapioca("dsl --outdir output") + + assert_equal(<<~ERR, result.err) + No classes/modules can be matched for RBI generation. + Please check that the requested classes/modules include processable DSL methods. + ERR + refute_project_file_exist("output/.gitattributes") + ensure + @project.remove("output") + end + it "respects the Gemfile and Gemfile.lock" do gem = mock_gem("foo", "1.0.0") do write("lib/foo.rb", <<~RB) diff --git a/spec/tapioca/cli/gem_spec.rb b/spec/tapioca/cli/gem_spec.rb index fedf114fc..1caaaf095 100644 --- a/spec/tapioca/cli/gem_spec.rb +++ b/spec/tapioca/cli/gem_spec.rb @@ -213,6 +213,52 @@ class << self project.remove("config/application.rb") end + it "must generate a .gitattributes file in the output folder" do + foo = mock_gem("foo", "0.0.1") do + write("lib/foo.rb", FOO_RB) + end + + @project.require_mock_gem(foo) + @project.bundle_install + result = @project.tapioca("gem foo --outdir output") + + assert_stdout_includes(result, <<~OUT) + Compiled foo + OUT + + assert_empty_stderr(result) + assert_success_status(result) + + assert_project_file_equal("output/.gitattributes", <<~CONTENT) + **/*.rbi linguist-generated=true + CONTENT + ensure + @project.remove("output") + end + + it "must not generate a .gitattributes file if the output folder is not created" do + foo = mock_gem("foo", "0.0.1") do + write("lib/foo.rb", FOO_RB) + end + + @project.require_mock_gem(foo) + @project.bundle_install + + # Generate for `foo` but exclude it as well, so that we don't create the output folder + result = @project.tapioca("gem foo --outdir output --exclude foo") + + assert_stdout_includes(result, <<~OUT) + Nothing to do. + OUT + + assert_empty_stderr(result) + assert_success_status(result) + + refute_project_file_exist("output/.gitattributes") + ensure + @project.remove("output") + end + it "must generate a single gem RBI" do foo = mock_gem("foo", "0.0.1") do write("lib/foo.rb", FOO_RB) @@ -1598,6 +1644,20 @@ def baz; end @project.remove("../gems") end + it "must generate a .gitattributes file in the output folder" do + result = @project.tapioca("gem --outdir output") + + assert_stdout_includes(result, "create output/foo@0.0.1.rbi") + assert_empty_stderr(result) + assert_success_status(result) + + assert_project_file_equal("output/.gitattributes", <<~CONTENT) + **/*.rbi linguist-generated=true + CONTENT + ensure + @project.remove("output") + end + it "must perform no operations if everything is up-to-date" do @project.write("sorbet/rbi/gems/foo@0.0.1.rbi") @project.write("sorbet/rbi/gems/bar@0.3.0.rbi")