Skip to content

Commit

Permalink
handle missing rbenv-aliases plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dastra-mak committed Jan 3, 2024
1 parent 42167bb commit 1751262
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

### Compatible changes

-
- handle missing rbenv-aliases plugin


## 0.8.2 - 2023-07-13
Expand Down
11 changes: 8 additions & 3 deletions lib/gemika/matrix.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'open3'
require 'yaml'
require 'gemika/errors'
require 'gemika/env'
Expand Down Expand Up @@ -89,11 +90,15 @@ def find_aliased_ruby(requested_version, aliased_versions)
end

##
# Returns the list of rbenv aliases, if rbenv is installed.
# Returns the list of rbenv aliases, if rbenv is installed with rbenv-aliases plugin.
#
def rbenv_aliases
if `which rbenv` != ''
`rbenv alias --list`
_output, status = Open3.capture2e('which', 'rbenv')
return '' unless status.success?

output, status = Open3.capture2e('rbenv', 'alias', '--list')
if status.success?
output
else
''
end
Expand Down
13 changes: 13 additions & 0 deletions spec/gemika/matrix/row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@
end
end

context 'when rbenv is installed without rbenv-aliases plugin' do
before do
allow(Open3).to receive(:capture2e).with('which', 'rbenv').and_return(['/path/to/rbenv', double(success?: true, exitstatus: 0)])
allow(Open3).to receive(:capture2e).with('rbenv', 'alias', '--list').and_return(['rbenv: no such command `alias', double(success?: false, exitstatus: 1)])
end

it 'does not crash and does not print errors' do
expect do
expect(subject.compatible_with_ruby?('3.0.3')).to eq(true)
end.to output('').to_stdout_from_any_process.and output('').to_stderr_from_any_process
end
end

end

end

0 comments on commit 1751262

Please sign in to comment.