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

Improve irb_spec's home setup #1141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Mar 7, 2024

Before v1.12, IRB avoids loading ~/.irbrc if the project folder has a .irbrc file. So to avoid loading dev's ~/.irbrc, cfe908c added an empty irbrc fixture as a workaround.

However, because IRB v1.12 starts loading ~/.irbrc even if the project folder has a .irbrc file, the workaround no longer works.

This commit removes the workaround and uses altering HOME environment variable to avoid loading .irbrc from devs' home directory instead.

Before v1.12, IRB avoids loading `~/.irbrc` if the project folder has
a `.irbrc` file. So to avoid loading dev's `~/.irbrc`, cfe908c added an
empty irbrc fixture as a workaround.

However, because IRB v1.12 starts loading `~/.irbrc` even if the project
folder has a `.irbrc` file, the workaround no longer works.

This commit removes the workaround and uses altering `HOME` environment
variable to avoid loading `.irbrc` from devs' home directory instead.
@nobu
Copy link
Member

nobu commented Mar 9, 2024

Don't IRBRC and XDG_CONFIG_HOME need to be set or cleared too?

@@ -1,11 +1,19 @@
require_relative '../../spec_helper'

describe "Binding#irb" do
before :each do
@env_home = ENV["HOME"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@env_home = ENV["HOME"]
@envs = ["IRBRC", "XDG_CONFIG_HOME", "HOME"].map {|e| [e, ENV.delete(e)]}.to_h

end

after :each do
ENV["HOME"] = @env_home
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ENV["HOME"] = @env_home
ENV.update(@envs)


out = IO.popen([{"IRBRC"=>irbrc_fixture}, *ruby_exe, irb_fixture], "r+") do |pipe|
out = IO.popen([*ruby_exe, irb_fixture], "r+") do |pipe|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather how about to change states only in the IO.popen-ed process?

Suggested change
out = IO.popen([*ruby_exe, irb_fixture], "r+") do |pipe|
dir = CODE_LOADING_DIR
envs = {"IRBRC" => nil, "XDG_CONFIG_HOME" => nil, "HOME" => dir}
out = IO.popen([envs, *ruby_exe, irb_fixture, chdir: dir], "r+") do |pipe|

@eregon
Copy link
Member

eregon commented Mar 11, 2024

Could we use irb's -f flag or similar to skip irbrc's?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants