Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paracycle committed Aug 14, 2023
1 parent 91391fb commit 6f2f432
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/tapioca/cli/annotations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AnnotationsTest < SpecWithProject
OUT

assert_success_status(result)
refute(File.directory?(@project.absolute_path("sorbet/rbi/annotations")))

repo.destroy
end
Expand Down Expand Up @@ -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)

Expand Down
34 changes: 34 additions & 0 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 60 additions & 0 deletions spec/tapioca/cli/gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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/[email protected]")
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/[email protected]")
@project.write("sorbet/rbi/gems/[email protected]")
Expand Down

0 comments on commit 6f2f432

Please sign in to comment.