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

[Fix #12975] Fix an error for gem_config_path when bundler is loaded and no Gemfile exists #12976

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Jun 9, 2024

Fixes #12975

begin
# We might not be running with `bundle exec`, so we need to pull in Bundler ourselves,
# in order to use `Bundler::LockfileParser`.
require 'bundler'
rescue LoadError
nil
end
Bundler may be loaded because the LockFile parsers needs it.

With the improvement to the isolated environment, 4 tests fail. Previously they operated on the gemfile from the project folder.

The two autogen tests relied on modified env, which now is not visible anymore.


This uses Bundler.with_unbundled_env because bundler adds some variables that would otherwise make this hard to test. Bundler.reset! is needed because a bunch of paths are memoized which would cause bundler to always return the Gemfile path of the rubocop folder instead of the tempfile/pwd. I added a test for that.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@Earlopain
Copy link
Contributor Author

:/ this might isolate a bit too much actually. Not quite sure why it passes locally.

I think it would be nice to improve isolation like this here since I would expect it to work like this already. Any ideas on that? Otherwise I will just make it isolate like that once for a test that needs this (and hope that passes on CI)

@Earlopain Earlopain force-pushed the error-for-inherit-gem-and-bundler branch 3 times, most recently from 9ad055d to b4040cb Compare June 10, 2024 08:05
@Earlopain
Copy link
Contributor Author

Sigh, bundler really wants to keep its values around somewhere. I openend #12978 for the general problem but even just this single test ended up more complicated than I really wanted it to. It does test the correct thing at least.

…s loaded and no Gemfile exists

https://github.com/rubocop/rubocop/blob/10d115f168ac61e07a3715ef3b72eb4c7518bf6e/lib/rubocop/lockfile.rb#L3-L10
Bundler may loaded because the LockFile parsers needs it.

Getting this error in tests is a bit more involved since `isolated_environment` is not isolated enough.
See rubocop#12978
@Earlopain Earlopain force-pushed the error-for-inherit-gem-and-bundler branch from b4040cb to 8716301 Compare June 10, 2024 08:10
@bbatsov bbatsov merged commit 0942395 into rubocop:master Jun 12, 2024
22 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 12, 2024

Thanks for tackling this!

@Earlopain Earlopain deleted the error-for-inherit-gem-and-bundler branch June 12, 2024 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rubocop 1.64.0 raises "Could not locate Gemfile or .bundle/ directory" error on non-Bundler environment
2 participants