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

handle missing rbenv-aliases plugin #21

Merged
merged 1 commit into from
Jan 4, 2024
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
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