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

File does not exist error when path is set and Gemfile inside test directory #4055

Closed
ankane opened this issue Nov 10, 2020 · 2 comments
Closed
Labels

Comments

@ankane
Copy link

ankane commented Nov 10, 2020

Hi, thanks for all the work on Bundler!

Describe the problem as clearly as you can

I'm running into a pretty odd error when Bundler's path config is set and Gemfiles are inside the test directory (using Minitest), but not when path isn't set or when Gemfiles are in a different directory with the exact same code.

Ref: ruby/setup-ruby#103

Post steps to reproduce the problem

#!/bin/bash

set -ex

mkdir /tmp/repro
cd /tmp/repro

mkdir test
cat > test/Gemfile <<EOF
source "https://rubygems.org"

gem "activerecord-import"
gem "minitest"
gem "rake"
EOF
cat > Rakefile <<EOF
require "rake/testtask"
Rake::TestTask.new do |t|
  t.libs << "test"
  t.pattern = "test/**/*_test.rb"
end
EOF
cat > test/test_helper.rb <<EOF
require "bundler/setup"
Bundler.require(:default)
require "minitest/autorun"
require "activerecord-import"
EOF

export BUNDLE_GEMFILE=test/Gemfile
bundle config --local path vendor/bundle
bundle install
bundle exec rake test

Which command did you run?

See script above.

What were you expecting to happen?

Tests run, like they do if path is not set or the Gemfile isn't inside the test directory.

What actually happened?

Errors with File does not exist: pry, which appears to be part of test/test_helper.rb in activerecord-import.

If not included with the output of your command, run bundle env and paste the output below

Seeing it on both Mac (env below) and Linux. Haven't tried Windows.

Environment

Bundler       2.1.4
  Platforms   ruby, x86_64-darwin-19
Ruby          2.7.2p137 (2020-10-01 revision 5445e0435260b449decf2ac16f9d09bae3cafe72) [x86_64-darwin19]
  Full Path   /Users/user/.rbenv/versions/2.7.2/bin/ruby
  Config Dir  /Users/user/.rbenv/versions/2.7.2/etc
RubyGems      3.1.4
  Gem Home    /Users/user/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0
  Gem Path    /Users/user/.gem/ruby/2.7.0:/Users/user/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0
  User Home   /Users/user
  User Path   /Users/user/.gem/ruby/2.7.0
  Bin Dir     /Users/user/.rbenv/versions/2.7.2/bin
Tools         
  Git         2.29.1
  RVM         not installed
  rbenv       rbenv 1.1.2
  chruby      not installed

Bundler Build Metadata

Built At          2020-01-05
Git SHA           32a4159325
Released Version  true
@ankane ankane added the Bundler label Nov 10, 2020
@deivid-rodriguez
Copy link
Member

Hello! 👋 👋

So, it turns out this error is a combination of things, but I think none of them is an issue in bundler.

Firstly, rake is swallowing a bunch of useful information about this error. I fixed this issue in ruby/rake#367.

With that fix in place, we can now see a better error that points to the actual culprit:

$ bundle exec rake test 
Traceback (most recent call last):
	11: from /home/deivid/.rbenv/versions/2.7.2/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	10: from /home/deivid/.rbenv/versions/2.7.2/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	 9: from /home/deivid/Code/ruby/rake/lib/rake/rake_test_loader.rb:5:in `<top (required)>'
	 8: from /home/deivid/Code/ruby/rake/lib/rake/rake_test_loader.rb:5:in `select'
	 7: from /home/deivid/Code/ruby/rake/lib/rake/rake_test_loader.rb:16:in `block in <top (required)>'
	 6: from /home/deivid/.rbenv/versions/2.7.2/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	 5: from /home/deivid/.rbenv/versions/2.7.2/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	 4: from /tmp/repro/test/vendor/bundle/ruby/2.7.0/gems/activerecord-import-1.0.7/test/jdbcmysql/import_test.rb:1:in `<top (required)>'
	 3: from /home/deivid/.rbenv/versions/2.7.2/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	 2: from /home/deivid/.rbenv/versions/2.7.2/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	 1: from /tmp/repro/test/vendor/bundle/ruby/2.7.0/gems/activerecord-import-1.0.7/test/test_helper.rb:13:in `<top (required)>'
/tmp/repro/test/vendor/bundle/ruby/2.7.0/gems/activerecord-import-1.0.7/test/test_helper.rb:13:in `require': cannot load such file -- pry (LoadError)
rake aborted!
Command failed with status (1)
/home/deivid/Code/ruby/rake/exe/rake:27:in `<top (required)>'
/home/deivid/.rbenv/versions/2.7.2/bin/bundle:23:in `load'
/home/deivid/.rbenv/versions/2.7.2/bin/bundle:23:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)

Your glob for test files is test/**/*_test.rb, bundler installed dependencies to a test/ folder relative to the current directory, the activerecord-import ships test files named *_test.rb. The combination of these things made rake load a test file inside the activerecord-import gem 😬.

@ankane
Copy link
Author

ankane commented Nov 12, 2020

Wow, great debugging @deivid-rodriguez (feel like I should have caught the glob issue 🤦). The rake improvement looks great. Huge thanks for looking into it and all of the work on Bundler.

@ankane ankane closed this as completed Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants