asdf-vm / asdf-vm/asdf-ruby

asdf does not seem to be picking up on ruby gem executables in the GEM_PATH

Open
#383 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
734
Forks
156
Avg merge
17h 6m
Merged PRs (30d)
1

Description

I've been using asdf for at least 4-5 years across languages and this is the first time I've experienced any unexpected behavior. While this report is specific to rspec, it has been observed for other bin executables like foreman.

version info:

```
asdf version 0.14.0
ruby version : 3.2.1
bundler version 2.4.21
rspec-core 3.12.2
```

asdf install via homebrew, zsh shell.

.zshrc hook

```
. /opt/homebrew/opt/asdf/libexec/asdf.sh
```

asdf info

```
% asdf info
OS:
Darwin wingmate.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103 arm64

SHELL:
zsh 5.9 (arm-apple-darwin22.1.0)

BASH VERSION:
3.2.57(1)-release

ASDF VERSION:
v0.14.0

ASDF INTERNAL VARIABLES:
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=.tool-versions
ASDF_DATA_DIR=/Users/jed/.asdf
ASDF_DIR=/opt/homebrew/opt/asdf/libexec
ASDF_CONFIG_FILE=/Users/jed/.asdfrc

ASDF INSTALLED PLUGINS:
python https://github.com/danhper/asdf-python.git master 5e277e2
ruby https://github.com/asdf-vm/asdf-ruby.git master 7a22142
terraform https://github.com/asdf-community/asdf-hashicorp.git master 197e3ec
```

# scenario

I recently began observing that gems that should exist in the bundle are not resolving on the `$PATH`. As an example, I have a rails app that is currently running ruby 3.2.1. I followed the instructions from the asdf readme to fully remove and then reinstall asdf via homebrew, add the ruby plugin, and install ruby 3.2.1. I was able to cd into my rails app, and bundle the app successfully. Then, when running rspec within the context of the bundle, I received the following output:

```
% bundle exec rspec spec
bundler: command not found: rspec
Install missing gem executables with `bundle install`
```

## ruby options in env

```
% env | grep -i ruby
RUBYOPT=-W:no-deprecated -W:no-experimental

% ruby -v
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [arm64-darwin23]
jed@wingmate src % asdf list ruby
*3.2.1
```

the command does not appear in my path:

```
% command -V rspec #=> 🚫
```

## bundler info:

```
% bundle show rspec-core
/Users/jed/.gem/ruby/3.2.0/gems/rspec-core-3.12.2

% gem which bundler
/Users/jed/.asdf/installs/ruby/3.2.1/lib/ruby/3.2.0/bundler.rb

% bundle config
Settings are listed in order of priority. The top value will be used.
deployment
Set for the current user (/Users/jed/.bundle/config): false

force_ruby_platform
Set for the current user (/Users/jed/.bundle/config): true

gem.changelog
Set for the current user (/Users/jed/.bundle/config): true

gem.ci
Set for the current user (/Users/jed/.bundle/config): "none"

gem.coc
Set for the current user (/Users/jed/.bundle/config): false

gem.linter
Set for the current user (/Users/jed/.bundle/config): "none"

gem.mit
Set for the current user (/Users/jed/.bundle/config): true

gem.test
Set for the current user (/Users/jed/.bundle/config): "rspec"

jobs
Set for the current user (/Users/jed/.bundle/config): 7

silence_root_warning
Set for the current user (/Users/jed/.bundle/config): true

% bundle info rspec-core | grep Path
Path: /Users/jed/.gem/ruby/3.2.0/gems/rspec-core-3.12.2

```

## bundler shim:

```
% cat /Users/jed/.asdf/shims/bundle
#!/usr/bin/env bash
# asdf-plugin: ruby 3.2.1
exec /opt/homebrew/opt/asdf/libexec/bin/asdf exec "bundle" "$@" # asdf_allow: ' asdf '
```

## identifying the bundler and gem exe paths:

```
% bundle exec gem contents rspec-core | grep exe
/Users/jed/.gem/ruby/3.2.0/gems/rspec-core-3.12.2/exe/rspec
```

spec runs when prefixing the whole path:

```
% /Users/jed/.gem/ruby/3.2.0/gems/rspec-core-3.12.2/exe/rspec spec/some_spec.rb # => 👍
```

and there is also a bin exe that when fully pathed works just fine

```
/Users/jed/.gem/ruby/3.2.0/bin/rspec spec/my_spec.rb # => 👍
```

# temporary solution

If I globally install the gem to the ruby version, I get a shim for the executable that will work:

```
% ls ~/.asdf/shims | grep rspec #=> 🚫

% gem install rspec-core

% cat /Users/jed/.asdf/shims/rspec
#!/usr/bin/env bash
# asdf-plugin: ruby 3.2.1
exec /opt/homebrew/opt/asdf/libexec/bin/asdf exec "rspec" "$@" # asdf_allow: ' asdf '

% bundle exec rspec spec/my_spec.rb #=> 👍
```

I was able to get to this temporary solution by groking enough of the reshim.sh in asdf to understand how it would work. The question is how the ruby asdf plugin should work in order to dynamically adjust the path to pick up on the bin executables, and if there has been something that has changed recently that would cause a change in this behavior for either this specific ruby version, the specific bundler version, or asdf as a whole, as I do not know where to target any further investigation.

Thanks in advance!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.