1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
# frozen_string_literal: true
RSpec.describe "bundler plugin install" do
before do
build_repo2 do
build_plugin "foo"
build_plugin "kung-foo"
end
end
it "shows proper message when gem in not found in the source" do
bundle "plugin install no-foo --source #{file_uri_for(gem_repo1)}", raise_on_error: false
expect(err).to include("Could not find")
plugin_should_not_be_installed("no-foo")
end
it "installs from rubygems source" do
bundle "plugin install foo --source #{file_uri_for(gem_repo2)}"
expect(out).to include("Installed plugin foo")
plugin_should_be_installed("foo")
end
it "installs from rubygems source in frozen mode" do
bundle "plugin install foo --source #{file_uri_for(gem_repo2)}", env: { "BUNDLE_DEPLOYMENT" => "true" }
expect(out).to include("Installed plugin foo")
plugin_should_be_installed("foo")
end
it "installs from sources configured as Gem.sources without any flags" do
bundle "plugin install foo", env: { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s }
expect(out).to include("Installed plugin foo")
plugin_should_be_installed("foo")
end
it "shows help when --help flag is given" do
bundle "plugin install --help"
# The help message defined in ../../lib/bundler/man/bundle-plugin.1.ronn will be output.
expect(out).to include("You can install, uninstall, and list plugin(s)")
end
context "plugin is already installed" do
before do
bundle "plugin install foo --source #{file_uri_for(gem_repo2)}"
end
it "doesn't install plugin again" do
bundle "plugin install foo --source #{file_uri_for(gem_repo2)}"
expect(out).not_to include("Installing plugin foo")
expect(out).not_to include("Installed plugin foo")
end
end
it "installs multiple plugins" do
bundle "plugin install foo kung-foo --source #{file_uri_for(gem_repo2)}"
expect(out).to include("Installed plugin foo")
expect(out).to include("Installed plugin kung-foo")
plugin_should_be_installed("foo", "kung-foo")
end
it "uses the same version for multiple plugins" do
update_repo2 do
build_plugin "foo", "1.1"
build_plugin "kung-foo", "1.1"
end
bundle "plugin install foo kung-foo --version '1.0' --source #{file_uri_for(gem_repo2)}"
expect(out).to include("Installing foo 1.0")
expect(out).to include("Installing kung-foo 1.0")
plugin_should_be_installed("foo", "kung-foo")
end
it "installs the latest version if not installed" do
update_repo2 do
build_plugin "foo", "1.1"
end
bundle "plugin install foo --version 1.0 --source #{file_uri_for(gem_repo2)} --verbose"
expect(out).to include("Installing foo 1.0")
bundle "plugin install foo --source #{file_uri_for(gem_repo2)} --verbose"
expect(out).to include("Installing foo 1.1")
bundle "plugin install foo --source #{file_uri_for(gem_repo2)} --verbose"
expect(out).to include("Using foo 1.1")
end
it "raises an error when when --branch specified" do
bundle "plugin install foo --branch main --source #{file_uri_for(gem_repo2)}", raise_on_error: false
expect(out).not_to include("Installed plugin foo")
expect(err).to include("--branch can only be used with git sources")
end
it "raises an error when --ref specified" do
bundle "plugin install foo --ref v1.2.3 --source #{file_uri_for(gem_repo2)}", raise_on_error: false
expect(err).to include("--ref can only be used with git sources")
end
it "raises error when both --branch and --ref options are specified" do
bundle "plugin install foo --source #{file_uri_for(gem_repo2)} --branch main --ref v1.2.3", raise_on_error: false
expect(out).not_to include("Installed plugin foo")
expect(err).to include("You cannot specify `--branch` and `--ref` at the same time.")
end
it "works with different load paths" do
build_repo2 do
build_plugin "testing" do |s|
s.write "plugins.rb", <<-RUBY
require "fubar"
class Test < Bundler::Plugin::API
command "check2"
def exec(command, args)
puts "mate"
end
end
RUBY
s.require_paths = %w[lib src]
s.write("src/fubar.rb")
end
end
bundle "plugin install testing --source #{file_uri_for(gem_repo2)}"
bundle "check2", "no-color" => false
expect(out).to eq("mate")
end
context "malformatted plugin" do
it "fails when plugins.rb is missing" do
update_repo2 do
build_plugin "foo", "1.1"
build_plugin "kung-foo", "1.1"
end
bundle "plugin install foo kung-foo --version '1.0' --source #{file_uri_for(gem_repo2)}"
expect(out).to include("Installing foo 1.0")
expect(out).to include("Installing kung-foo 1.0")
plugin_should_be_installed("foo", "kung-foo")
build_repo2 do
build_gem "charlie"
end
bundle "plugin install charlie --source #{file_uri_for(gem_repo2)}", raise_on_error: false
expect(err).to include("Failed to install plugin `charlie`, due to Bundler::Plugin::MalformattedPlugin (plugins.rb was not found in the plugin.)")
expect(global_plugin_gem("charlie-1.0")).not_to be_directory
plugin_should_be_installed("foo", "kung-foo")
plugin_should_not_be_installed("charlie")
end
it "fails when plugins.rb throws exception on load" do
build_repo2 do
build_plugin "chaplin" do |s|
s.write "plugins.rb", <<-RUBY
raise "I got you man"
RUBY
end
end
bundle "plugin install chaplin --source #{file_uri_for(gem_repo2)}", raise_on_error: false
expect(global_plugin_gem("chaplin-1.0")).not_to be_directory
plugin_should_not_be_installed("chaplin")
end
end
context "git plugins" do
it "installs form a git source" do
build_git "foo" do |s|
s.write "plugins.rb"
end
bundle "plugin install foo --git #{file_uri_for(lib_path("foo-1.0"))}"
expect(out).to include("Installed plugin foo")
plugin_should_be_installed("foo")
end
it "installs form a local git source" do
build_git "foo" do |s|
s.write "plugins.rb"
end
bundle "plugin install foo --git #{lib_path("foo-1.0")}"
expect(out).to include("Installed plugin foo")
plugin_should_be_installed("foo")
end
it "raises an error when both git and local git sources are specified", bundler: "< 3" do
bundle "plugin install foo --git /phony/path/project --local_git [email protected]:/repo/project", raise_on_error: false
expect(exitstatus).not_to eq(0)
expect(err).to eq("Remote and local plugin git sources can't be both specified")
end
end
it "installs from a path source" do
build_lib "path_plugin" do |s|
s.write "plugins.rb"
end
bundle "plugin install path_plugin --path #{lib_path("path_plugin-1.0")}"
expect(out).to include("Installed plugin path_plugin")
plugin_should_be_installed("path_plugin")
end
context "Gemfile eval" do
before do
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "installs plugins listed in gemfile" do
gemfile <<-G
source '#{file_uri_for(gem_repo2)}'
plugin 'foo'
gem 'rack', "1.0.0"
G
bundle "install"
expect(out).to include("Installed plugin foo")
expect(out).to include("Bundle complete!")
expect(the_bundle).to include_gems("rack 1.0.0")
plugin_should_be_installed("foo")
end
it "accepts plugin version" do
update_repo2 do
build_plugin "foo", "1.1.0"
end
gemfile <<-G
source '#{file_uri_for(gem_repo2)}'
plugin 'foo', "1.0"
G
bundle "install"
expect(out).to include("Installing foo 1.0")
plugin_should_be_installed("foo")
expect(out).to include("Bundle complete!")
end
it "accepts git sources" do
build_git "ga-plugin" do |s|
s.write "plugins.rb"
end
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
plugin 'ga-plugin', :git => "#{lib_path("ga-plugin-1.0")}"
G
expect(out).to include("Installed plugin ga-plugin")
plugin_should_be_installed("ga-plugin")
end
it "accepts path sources" do
build_lib "ga-plugin" do |s|
s.write "plugins.rb"
end
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
plugin 'ga-plugin', :path => "#{lib_path("ga-plugin-1.0")}"
G
expect(out).to include("Installed plugin ga-plugin")
plugin_should_be_installed("ga-plugin")
end
context "in deployment mode" do
it "installs plugins" do
install_gemfile <<-G
source '#{file_uri_for(gem_repo2)}'
gem 'rack', "1.0.0"
G
bundle "config set --local deployment true"
install_gemfile <<-G
source '#{file_uri_for(gem_repo2)}'
plugin 'foo'
gem 'rack', "1.0.0"
G
expect(out).to include("Installed plugin foo")
expect(out).to include("Bundle complete!")
expect(the_bundle).to include_gems("rack 1.0.0")
plugin_should_be_installed("foo")
end
end
end
context "inline gemfiles" do
it "installs the listed plugins" do
code = <<-RUBY
require "bundler/inline"
gemfile do
source '#{file_uri_for(gem_repo2)}'
plugin 'foo'
end
RUBY
ruby code, env: { "BUNDLER_VERSION" => Bundler::VERSION }
expect(local_plugin_gem("foo-1.0", "plugins.rb")).to exist
end
end
describe "local plugin" do
it "is installed when inside an app" do
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
gemfile ""
bundle "plugin install foo --source #{file_uri_for(gem_repo2)}"
plugin_should_be_installed("foo")
expect(local_plugin_gem("foo-1.0")).to be_directory
end
context "conflict with global plugin" do
before do
update_repo2 do
build_plugin "fubar" do |s|
s.write "plugins.rb", <<-RUBY
class Fubar < Bundler::Plugin::API
command "shout"
def exec(command, args)
puts "local_one"
end
end
RUBY
end
end
# inside the app
gemfile "source '#{file_uri_for(gem_repo2)}'\nplugin 'fubar'"
bundle "install"
update_repo2 do
build_plugin "fubar", "1.1" do |s|
s.write "plugins.rb", <<-RUBY
class Fubar < Bundler::Plugin::API
command "shout"
def exec(command, args)
puts "global_one"
end
end
RUBY
end
end
# outside the app
bundle "plugin install fubar --source #{file_uri_for(gem_repo2)}", dir: tmp
end
it "inside the app takes precedence over global plugin" do
bundle "shout"
expect(out).to eq("local_one")
end
it "outside the app global plugin is used" do
bundle "shout", dir: tmp
expect(out).to eq("global_one")
end
end
end
end
|