Skip to content

Commit 8e79cb9

Browse files
committed
Merge pull request #1378 from ruby/skip-dependency
Spec may be missing when `rbs_collection.yaml` declares dependency
1 parent 2de653d commit 8e79cb9

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

lib/rbs/collection/config/lockfile_generator.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ def generate
133133
end
134134
end
135135

136-
gem_hash[name].dependencies.each do |dep|
137-
if spec = gem_hash[dep.name]
138-
assign_gem(name: dep.name, version: spec.version, src_data: nil, ignored_gems: ignored_gems)
136+
if spec = gem_hash.fetch(name, nil)
137+
spec.dependencies.each do |dep|
138+
if dep_spec = gem_hash[dep.name]
139+
assign_gem(name: dep.name, version: dep_spec.version, src_data: nil, ignored_gems: ignored_gems)
140+
end
139141
end
142+
else
143+
RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})"
140144
end
141145
end
142146

test/rbs/collection/config_test.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,65 @@ def test_generate_lockfile_dependency_with_platform
702702
end
703703
end
704704

705+
def test_generate_lockfile__gems_not_included_in_gemfile
706+
mktmpdir do |tmpdir|
707+
config_path = tmpdir / 'rbs_collection.yaml'
708+
config_path.write [CONFIG, <<~YAML].join("\n")
709+
sources:
710+
- type: git
711+
name: ruby/gem_rbs_collection
712+
remote: https://github.com/ruby/gem_rbs_collection.git
713+
revision: cde6057e7546843ace6420c5783dd945c6ccda54
714+
repo_dir: gems
715+
path: '.gem_rbs_collection'
716+
gems:
717+
- name: ast
718+
YAML
719+
gemfile_path = tmpdir / 'Gemfile'
720+
gemfile_path.write <<~GEMFILE
721+
source 'https://rubygems.org'
722+
GEMFILE
723+
gemfile_lock_path = tmpdir / 'Gemfile.lock'
724+
gemfile_lock_path.write <<~GEMFILE_LOCK
725+
GEM
726+
remote: https://rubygems.org/
727+
specs:
728+
729+
PLATFORMS
730+
x86_64-linux
731+
732+
DEPENDENCIES
733+
734+
BUNDLED WITH
735+
2.2.0
736+
GEMFILE_LOCK
737+
738+
definition = Bundler::Definition.build(gemfile_path, gemfile_lock_path, false)
739+
_config, lockfile = RBS::Collection::Config.generate_lockfile(config_path: config_path, definition: definition)
740+
string = YAML.dump(lockfile.to_lockfile)
741+
742+
assert_config <<~YAML, string
743+
sources:
744+
- type: git
745+
name: ruby/gem_rbs_collection
746+
remote: https://github.com/ruby/gem_rbs_collection.git
747+
revision: cde6057e7546843ace6420c5783dd945c6ccda54
748+
repo_dir: gems
749+
path: ".gem_rbs_collection"
750+
gemfile_lock_path: 'Gemfile.lock'
751+
gems:
752+
- name: ast
753+
version: "2.4"
754+
source:
755+
name: ruby/gem_rbs_collection
756+
remote: https://github.com/ruby/gem_rbs_collection.git
757+
revision: cde6057e7546843ace6420c5783dd945c6ccda54
758+
repo_dir: gems
759+
type: git
760+
YAML
761+
end
762+
end
763+
705764
private def assert_config(expected_str, actual_str)
706765
assert_equal YAML.load(expected_str), YAML.load(actual_str)
707766
end

0 commit comments

Comments
 (0)