Skip to content

Commit 64730e9

Browse files
hsbtclaude
andcommitted
Rewrite relative path expansion test to avoid mocking Plugin internals
Replace the mock-heavy test that stubbed Plugin.root and used instance_variable_set with a direct YAML write/read approach, consistent with the other relative path tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5fc8452 commit 64730e9

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

spec/bundler/plugin/index_spec.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,24 @@
218218
expect(data["load_paths"][plugin_name]).to eq([File.join(plugin_name, "lib")])
219219
end
220220

221-
it "expands relative paths when the plugin root changes" do
222-
old_index_file = index.index_file
221+
it "expands relative paths to absolute on load" do
222+
require_relative "../../../bundler/lib/bundler/yaml_serializer"
223223

224-
new_root = tmp.join("moved_plugin_root")
225-
FileUtils.mkdir_p(new_root)
226-
FileUtils.cp(old_index_file, new_root.join("index"))
224+
plugin_root = Bundler::Plugin.root
227225

228-
Bundler::Plugin.reset!
229-
Bundler::Plugin.instance_variable_set(:@root, nil)
230-
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
231-
allow(Bundler::Plugin).to receive(:root).and_return(new_root)
232-
allow(Bundler::Plugin).to receive(:local_root).and_return(new_root)
226+
relative_index = {
227+
"commands" => {},
228+
"hooks" => {},
229+
"load_paths" => { plugin_name => [File.join(plugin_name, "lib")] },
230+
"plugin_paths" => { plugin_name => plugin_name },
231+
"sources" => {},
232+
}
233233

234-
new_index = Index.new
234+
File.open(index.index_file, "w") {|f| f.puts Bundler::YAMLSerializer.dump(relative_index) }
235235

236-
expect(new_index.plugin_path(plugin_name)).to eq(new_root.join(plugin_name))
237-
expect(new_index.load_paths(plugin_name)).to eq([new_root.join(plugin_name, "lib").to_s])
236+
new_index = Index.new
237+
expect(new_index.plugin_path(plugin_name)).to eq(plugin_root.join(plugin_name))
238+
expect(new_index.load_paths(plugin_name)).to eq([plugin_root.join(plugin_name, "lib").to_s])
238239
end
239240

240241
it "keeps paths outside the plugin root as absolute" do

0 commit comments

Comments
 (0)