Skip to content

Commit

Permalink
Merge pull request #11181 from noelblaschke/fix/asdf-tool-versions-ma…
Browse files Browse the repository at this point in the history
…y-contain-multiple-runtimes

Fix pattern to match .tool-versions files that specify multiple runtimes
  • Loading branch information
koic committed Nov 16, 2022
2 parents 60dbfdb + 8af6b7f commit 12fa5e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog/fix_fix_pattern_to_match_toolversion_files.md
@@ -0,0 +1 @@
* [#11181](https://github.com/rubocop/rubocop/pull/11181): Fix pattern to match .tool-versions files that specify multiple runtimes. ([@noelblaschke][])
2 changes: 1 addition & 1 deletion lib/rubocop/target_ruby.rb
Expand Up @@ -84,7 +84,7 @@ def version_file
# @api private
class ToolVersionsFile < RubyVersionFile
TOOL_VERSIONS_FILENAME = '.tool-versions'
TOOL_VERSIONS_PATTERN = /\Aruby (?:ruby-)?(?<version>\d+\.\d+)/.freeze
TOOL_VERSIONS_PATTERN = /^(?:ruby )(?<version>\d+\.\d+)/.freeze

def name
"`#{TOOL_VERSIONS_FILENAME}`"
Expand Down
26 changes: 20 additions & 6 deletions spec/rubocop/target_ruby_spec.rb
Expand Up @@ -104,8 +104,16 @@
create_file(File.join(dir, '.tool-versions'), tool_versions)
end

context 'when .tool-versions contains a ruby version' do
let(:tool_versions) { ['ruby 3.0.0', 'nodejs 14.9.0'] }
context 'when .tool-versions does not contain a ruby version' do
let(:tool_versions) { ['nodejs 14.9.0'] }

it 'uses the default ruby version' do
expect(target_ruby.version).to eq default_version
end
end

context 'when .tool-versions contains only a ruby version' do
let(:tool_versions) { ['ruby 3.0.0'] }
let(:ruby_version_to_f) { 3.0 }

it 'reads it to determine the target ruby version' do
Expand All @@ -119,12 +127,18 @@
end
end

context 'when .tool-versions does not contain a ruby version' do
let(:tool_versions) { ['nodejs 14.9.0'] }
context 'when .tool-versions contains different runtimes' do
let(:tool_versions) { ['nodejs 14.9.0', 'ruby 3.0.0'] }
let(:ruby_version_to_f) { 3.0 }

it 'uses the default ruby version' do
expect(target_ruby.version).to eq default_version
it 'reads it to determine the target ruby version' do
expect(target_ruby.version).to eq ruby_version_to_f
end

it 'does not read Gemfile.lock, gems.locked' do
expect(File).not_to receive(:file?).with(/Gemfile/)
expect(File).not_to receive(:file?).with(/gems\.locked/)
target_ruby.version
end
end
end
Expand Down

0 comments on commit 12fa5e1

Please sign in to comment.