Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec may be missing when rbs_collection.yaml declares dependency #1378

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/rbs/collection/config/lockfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ def generate
end
end

gem_hash[name].dependencies.each do |dep|
if spec = gem_hash[dep.name]
assign_gem(name: dep.name, version: spec.version, src_data: nil, ignored_gems: ignored_gems)
if spec = gem_hash.fetch(name, nil)
spec.dependencies.each do |dep|
if dep_spec = gem_hash[dep.name]
assign_gem(name: dep.name, version: dep_spec.version, src_data: nil, ignored_gems: ignored_gems)
end
end
else
RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})"
end
end

Expand Down
59 changes: 59 additions & 0 deletions test/rbs/collection/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,65 @@ def test_generate_lockfile_dependency_with_platform
end
end

def test_generate_lockfile__gems_not_included_in_gemfile
mktmpdir do |tmpdir|
config_path = tmpdir / 'rbs_collection.yaml'
config_path.write [CONFIG, <<~YAML].join("\n")
sources:
- type: git
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems
path: '.gem_rbs_collection'
gems:
- name: ast
YAML
gemfile_path = tmpdir / 'Gemfile'
gemfile_path.write <<~GEMFILE
source 'https://rubygems.org'
GEMFILE
gemfile_lock_path = tmpdir / 'Gemfile.lock'
gemfile_lock_path.write <<~GEMFILE_LOCK
GEM
remote: https://rubygems.org/
specs:

PLATFORMS
x86_64-linux

DEPENDENCIES

BUNDLED WITH
2.2.0
GEMFILE_LOCK

definition = Bundler::Definition.build(gemfile_path, gemfile_lock_path, false)
_config, lockfile = RBS::Collection::Config.generate_lockfile(config_path: config_path, definition: definition)
string = YAML.dump(lockfile.to_lockfile)

assert_config <<~YAML, string
sources:
- type: git
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems
path: ".gem_rbs_collection"
gemfile_lock_path: 'Gemfile.lock'
gems:
- name: ast
version: "2.4"
source:
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems
type: git
YAML
end
end

private def assert_config(expected_str, actual_str)
assert_equal YAML.load(expected_str), YAML.load(actual_str)
end
Expand Down