Skip to content

Commit 5a3de53

Browse files
committed
Use tmpdir to avoid modifying system files
In nix environment rubylibdir is read only, so we need to use a temporary directory to test that non ruby files are not indexed.
1 parent 7eb2eb7 commit 5a3de53

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

lib/ruby_indexer/test/configuration_test.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ def test_indexable_uris_does_not_include_gems_own_installed_files
9393
end
9494

9595
def test_indexable_uris_does_not_include_non_ruby_files_inside_rubylibdir
96-
path = Pathname.new(RbConfig::CONFIG["rubylibdir"]).join("extra_file.txt").to_s
97-
FileUtils.touch(path)
96+
Dir.mktmpdir do |dir|
97+
original_rubylibdir = RbConfig::CONFIG["rubylibdir"]
98+
RbConfig::CONFIG["rubylibdir"] = dir
9899

99-
begin
100-
uris = @config.indexable_uris
101-
assert(uris.none? { |uri| uri.full_path == path })
102-
ensure
103-
FileUtils.rm(path)
100+
begin
101+
path = Pathname.new(dir).join("extra_file.txt").to_s
102+
FileUtils.touch(path)
103+
104+
uris = @config.indexable_uris
105+
assert(uris.none? { |uri| uri.full_path == path })
106+
ensure
107+
RbConfig::CONFIG["rubylibdir"] = original_rubylibdir
108+
end
104109
end
105110
end
106111

0 commit comments

Comments
 (0)