Skip to content

Commit 49ce798

Browse files
committed
Fix specs, and ensure they're up to date
1 parent bcc8fb7 commit 49ce798

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

bundler/lib/bundler/definition.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,15 @@ def dependencies_for(groups)
296296

297297
def plugins_for(groups)
298298
groups.map!(&:to_sym)
299-
current_plugins.reject do |d|
300-
(d.groups & groups).empty?
299+
plugins = current_plugins # always returns a new array
300+
plugins.select! do |d|
301+
if RUBY_VERSION >= "3.1"
302+
d.groups.intersect?(groups)
303+
else
304+
!(d.groups & groups).empty?
305+
end
301306
end
307+
plugins
302308
end
303309

304310
# Resolve all the dependencies specified in Gemfile. It ensures that

bundler/lib/bundler/dsl.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,33 @@ def plugin(name, *args)
277277
version = args || [">= 0"]
278278

279279
# We don't care to add sources for plugins in this pass over the gemfile
280-
# since we're not actually installing plugins here (they should already
281-
# be installed), just keeping track of them so that we can verify they
282-
# are actually installed. This is important because otherwise sources
280+
# since we're not installing plugins here (they should already be
281+
# installed), only keeping track of them so that we can verify they
282+
# are currently installed. This is important because otherwise sources
283283
# unique to the plugin (like a git source) would end up in the lockfile,
284284
# which we don't want.
285285
normalize_options(name, version, false, options)
286286

287287
dep = Dependency.new(name, version, options)
288288

289-
# if there's already a dependency with this name we try to prefer one
289+
# if there's already a plugin with this name we try to prefer one
290290
if current = @plugins.find {|d| d.name == dep.name }
291-
Bundler.ui.warn "Your Gemfile lists the plugin #{current.name} (#{current.requirement}) more than once.\n" \
292-
"You should keep only one of them.\n" \
293-
"Remove any duplicate entries and specify the plugin only once."
291+
if current.requirement != dep.requirement
292+
raise GemfileError, "You cannot specify the same plugin twice with different version requirements.\n" \
293+
"You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \
294+
"#{update_prompt}"
295+
end
296+
297+
if current.source != dep.source
298+
raise GemfileError, "You cannot specify the same plugin twice coming from different sources.\n" \
299+
"You specified that #{dep.name} (#{dep.requirement}) should come from " \
300+
"#{current.source || "an unspecified source"} and #{dep.source}\n"
301+
else
302+
Bundler.ui.warn "Your Gemfile lists the plugin #{current.name} (#{current.requirement}) more than once.\n" \
303+
"You should keep only one of them.\n" \
304+
"Remove any duplicate entries and specify the plugin only once." \
305+
"While it's not a problem now, it could cause errors if you change the version of one of them later."
306+
end
294307
end
295308

296309
@plugins << dep

bundler/lib/bundler/plugin.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def list
103103
# @param [Pathname] gemfile path
104104
# @param [Proc] block that can be evaluated for (inline) Gemfile
105105
def gemfile_install(gemfile = nil, unlock: false, &inline)
106+
was_deployment = Bundler.settings[:deployment]
106107
Bundler.settings.temporary(frozen: false, deployment: false) do
107108
builder = DSL.new
108109
if block_given?
@@ -113,11 +114,17 @@ def gemfile_install(gemfile = nil, unlock: false, &inline)
113114

114115
return if builder.dependencies.empty?
115116

117+
Bundler.configure_gem_home_and_path
118+
116119
lockfile_contents = index.generate_lockfile(builder.instance_variable_get(:@sources), builder.dependencies)
117120
definition = builder.to_definition(nil, unlock || {}, lockfile_contents: lockfile_contents)
118121
unless definition.no_resolve_needed?
119122
Installer.new.install_definition(definition)
120123
end
124+
# we may have cached the non-deployment gem path, so paths need to be
125+
# reset in preparation for the regular gem installation phase that
126+
# needs to use the deployment gem path
127+
Bundler.reset_paths! if was_deployment
121128

122129
plugins = definition.requested_dependencies.select(&:should_include?).map(&:name)
123130
installed_specs = plugins.to_h {|p| [p, definition.specs[p].first] }

bundler/lib/bundler/plugin/index_definition.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def platforms
88
[Bundler.local_platform]
99
end
1010

11+
def locked_checksums; end
1112
def locked_ruby_version; end
1213

1314
def bundler_version_to_lock

bundler/spec/bundler/plugin_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
end
124124

125125
it "doesn't calls installer without any plugins" do
126-
allow(definition).to receive(:dependencies) { [] }
126+
allow(builder).to receive(:dependencies) { [] }
127127
allow(installer).to receive(:install_definition).never
128128

129129
subject.gemfile_install(gemfile)
@@ -139,8 +139,13 @@
139139

140140
before do
141141
allow(index).to receive(:installed?) { nil }
142-
allow(definition).to receive(:dependencies) { [Bundler::Dependency.new("new-plugin", ">=0"), Bundler::Dependency.new("another-plugin", ">=0")] }
142+
allow(index).to receive(:generate_lockfile) { nil }
143+
allow(builder).to receive(:dependencies) { [Bundler::Dependency.new("new-plugin", ">=0"), Bundler::Dependency.new("another-plugin", ">=0")] }
144+
allow(definition).to receive(:no_resolve_needed?) { false }
145+
allow(definition).to receive(:requested_dependencies) { builder.dependencies }
146+
allow(definition).to receive(:specs) { plugin_specs.to_h {|p, s| [p, [s]] } }
143147
allow(installer).to receive(:install_definition) { plugin_specs }
148+
allow(Bundler).to receive(:configure_gem_home_and_path) {}
144149
end
145150

146151
it "should validate and register the plugins" do

bundler/spec/plugins/uninstall_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
bundle "plugin uninstall path_plugin"
5252
expect(out).to include("Uninstalled plugin path_plugin")
53+
Bundler::Plugin.reset!
5354
plugin_should_not_be_installed("path_plugin")
5455
# the actual gem still exists though
5556
expect(path).to be_a_directory

0 commit comments

Comments
 (0)