Skip to content

Commit

Permalink
Fix the ability to override Gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
paracycle committed Jun 5, 2019
1 parent a5511c9 commit e864294
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
15 changes: 11 additions & 4 deletions lib/tapioca/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def initialize(gemfile:)
@gemfile = T.let(File.new(gemfile.to_s), File)
@lockfile = T.let(File.new(lockfile.to_s), File)
@dependencies = T.let(nil, T.nilable(T::Array[Gem]))
@definition = T.let(nil, T.nilable(Bundler::Definition))
end

sig { returns(T::Array[Gem]) }
def dependencies
@dependencies ||= begin
bundler = Bundler::Dsl.evaluate(gemfile, lockfile, {})
specs = bundler.specs.to_a
specs = definition.specs.to_a

bundler
definition
.resolve
.materialize(specs)
.reject { |spec| ignore_gem_spec?(spec) }
Expand All @@ -43,7 +43,6 @@ def gem(gem_name)
def require_bundle(initialize_file, require_file)
require(initialize_file) if initialize_file && File.exist?(initialize_file)

definition = Bundler::Dsl.evaluate(gemfile, lockfile, {})
runtime = Bundler::Runtime.new(File.dirname(gemfile.path), definition)
groups = Bundler.definition.groups
runtime.setup(*groups).require(*groups)
Expand All @@ -58,6 +57,14 @@ def require_bundle(initialize_file, require_file)
sig { returns(File) }
attr_reader(:gemfile, :lockfile)

sig { returns(Bundler::Definition) }
def definition
@definition ||= begin
ENV["BUNDLE_GEMFILE"] = gemfile.path
Bundler::Dsl.evaluate(gemfile, lockfile, {})
end
end

sig { params(spec: Spec).returns(T::Boolean) }
def ignore_gem_spec?(spec)
spec.name == "sorbet" ||
Expand Down
6 changes: 3 additions & 3 deletions spec/support/repo/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
PATH
remote: ../gems/bar
remote: spec/support/gems/bar
specs:
bar (0.3.0)

PATH
remote: ../gems/baz
remote: spec/support/gems/baz
specs:
baz (0.0.2)

PATH
remote: ../gems/foo
remote: spec/support/gems/foo
specs:
foo (0.0.1)

Expand Down
31 changes: 16 additions & 15 deletions spec/tapioca/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
RSpec.describe(Tapioca::Cli) do
let(:outdir) { @outdir }
let(:repo_path) { Pathname.new(__dir__) / ".." / "support" / "repo" }
let(:exe_path) { Pathname.new(__dir__) / ".." / ".." / "exe" }
let(:exec_command) { @exec_command.join(" ") }

def run(command, args = [], flags = {})
Dir.chdir(exe_path) do
flags = {
outdir: outdir,
gemfile: (repo_path / "Gemfile").to_s,
}.merge(flags)

@exec_command = [
"tapioca",
command,
*flags.flat_map { |k, v| ["--#{k}", v] },
*args,
]
IO.popen(@exec_command).read
end
flags = {
outdir: outdir,
gemfile: (repo_path / "Gemfile").to_s,
}.merge(flags).flat_map { |k, v| ["--#{k}", v] }

@exec_command = [
"tapioca",
command,
*flags,
*args,
]

IO.popen(
@exec_command,
chdir: Pathname.new(__dir__) / ".." / ".." / "exe"
).read
end

around(:each) do |example|
Expand Down

0 comments on commit e864294

Please sign in to comment.