Skip to content

Commit

Permalink
Add failing test for gem files paths prefix matching project path
Browse files Browse the repository at this point in the history
  • Loading branch information
paracycle committed Sep 16, 2022
1 parent 703ce22 commit 26b01f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions spec/spec_with_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ def mock_project(sorbet_dependency: true, &block)
name: String,
version: String,
dependencies: T::Array[String],
path: String,
block: T.nilable(T.proc.params(gem: MockGem).bind(MockGem).void),
).returns(MockGem)
end
def mock_gem(name, version, dependencies: [], &block)
gem = MockGem.new("#{TEST_TMP_PATH}/#{spec_name}/gems/#{name}", name, version, dependencies)
def mock_gem(name, version, dependencies: [], path: default_gem_path(name), &block)
gem = MockGem.new(path, name, version, dependencies)
gem.gemspec(gem.default_gemspec_contents)
gem.instance_exec(gem, &block) if block
gem
Expand Down Expand Up @@ -139,6 +140,11 @@ def assert_stderr_includes(result, snippet)

private

sig {params(name: String).returns(String)}
def default_gem_path(name)
"#{TEST_TMP_PATH}/#{spec_name}/gems/#{name}"
end

sig { returns(String) }
def spec_name
spec_class = T.unsafe(self).class
Expand Down
14 changes: 14 additions & 0 deletions spec/tapioca/cli/gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,20 @@ class Foo::Secret; end
assert_success_status(result)
end

it "must generate RBIs for gems whose folder location starts with the same prefix as project folder" do
# Set the gem path so that the project folder is a prefix of the gem folder
gem_path = @project.path + "-gem/foo"
gem = mock_gem("foo", "0.0.1", path: gem_path)

@project.require_mock_gem(gem)

result = @project.tapioca("gem foo")

assert_stdout_includes(result, "Compiled foo")
assert_empty_stderr(result)
assert_success_status(result)
end

it "must respect exclude option" do
@project.require_mock_gem(mock_gem("foo", "0.0.1"))
@project.require_mock_gem(mock_gem("bar", "0.3.0"))
Expand Down

0 comments on commit 26b01f4

Please sign in to comment.