summaryrefslogtreecommitdiff
path: root/spec/other/major_deprecation_spec.rb
blob: c59c08f93c3a785225ccfa2833d7df2af19297f9 (plain)
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
# frozen_string_literal: true

RSpec.describe "major deprecations" do
  let(:warnings) { err }

  describe "Bundler" do
    before do
      create_file "gems.rb", <<-G
        source "file:#{gem_repo1}"
        ruby #{RUBY_VERSION.dump}
        gem "rack"
      G
      bundle! "install"
    end

    describe ".clean_env" do
      before do
        source = "Bundler.clean_env"
        bundle "exec ruby -e #{source.dump}"
      end

      it "is not deprecated", :bundler => "< 2" do
        expect(deprecations).to be_empty
      end

      it "is deprecated in favor of .unbundled_env", :bundler => "2" do
        expect(deprecations).to include \
          "`Bundler.clean_env` has been deprecated in favor of `Bundler.unbundled_env`. " \
          "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`"
      end
    end

    describe ".environment" do
      before do
        source = "Bundler.environment"
        bundle "exec ruby -e #{source.dump}"
      end

      it "is not deprecated", :bundler => "< 2" do
        expect(deprecations).to be_empty
      end

      it "is deprecated in favor of .load", :bundler => "2" do
        expect(deprecations).to include "Bundler.environment has been removed in favor of Bundler.load"
      end
    end

    describe "bundle update --quiet" do
      it "does not print any deprecations" do
        bundle :update, :quiet => true
        expect(deprecations).to be_empty
      end
    end

    describe "bundle update" do
      before do
        bundle! "install"
      end

      it "does not warn when no options are given", :bundler => "< 2" do
        bundle! "update"
        expect(deprecations).to be_empty
      end

      it "warns when no options are given", :bundler => "2" do
        bundle! "update"
        expect(deprecations).to include("Pass --all to `bundle update` to update everything")
      end

      it "does not warn when --all is passed" do
        bundle! "update --all"
        expect(deprecations).to be_empty
      end
    end

    describe "bundle install --binstubs" do
      xit "should output a deprecation warning" do
        bundle :install, :binstubs => true
        expect(deprecations).to include("The --binstubs option will be removed")
      end
    end
  end

  context "when bundle install is run" do
    it "should not warn about gems.rb" do
      create_file "gems.rb", <<-G
        source "file://#{gem_repo1}"
        gem "rack"
      G

      bundle :install
      expect(deprecations).to be_empty
    end

    it "should print a proper warning when both gems.rb and Gemfile present, and use Gemfile", :bundler => "< 2" do
      create_file "gems.rb"
      install_gemfile! <<-G
        source "file://#{gem_repo1}"
        gem "rack"
      G

      expect(warnings).to include(
        "Multiple gemfiles (gems.rb and Gemfile) detected. The gems.rb and gems.rb.locked files are currently ignored, but they will get used as soon as you delete your Gemfile and Gemfile.lock files."
      )

      expect(the_bundle).to include_gem "rack 1.0"
    end

    it "should print a proper warning when both gems.rb and Gemfile present, and use gems.rb", :bundler => "2" do
      create_file "gems.rb"
      install_gemfile! <<-G
        source "file://#{gem_repo1}"
        gem "rack"
      G

      expect(warnings).to include(
        "Multiple gemfiles (gems.rb and Gemfile) detected. Make sure you remove Gemfile and Gemfile.lock since bundler is ignoring them in favor of gems.rb and gems.rb.locked."
      )

      expect(the_bundle).not_to include_gem "rack 1.0"
    end

    context "with flags" do
      before do
        install_gemfile <<-G, :path => "vendor/bundle"
          source "file://#{gem_repo1}"
          gem "rack"
        G
      end

      {
        :clean => true,
        :deployment => true,
        :frozen => true,
        :"no-cache" => true,
        :"no-prune" => true,
        :path => "vendor/bundle",
        :shebang => "ruby27",
        :system => true,
        :without => "development",
        :with => "development",
      }.each do |name, value|
        flag_name = "--#{name}"

        context "with the #{flag_name} flag", :bundler => "2" do
          it "should print a deprecation warning" do
            bundle "install #{flag_name} #{value}"

            expect(deprecations).to include(
              "The `#{flag_name}` flag is deprecated because it relies on " \
              "being remembered accross bundler invokations, which bundler " \
              "will no longer do in future versions. Instead please use " \
              "`bundle config #{name} '#{value}'`, and stop using this flag"
            )
          end
        end

        context "with the #{flag_name} flag", :bundler => "< 2" do
          it "should not print a deprecation warning" do
            bundle "install #{flag_name} #{value}"

            expect(deprecations).to be_empty
          end
        end
      end
    end
  end

  context "when Bundler.setup is run in a ruby script" do
    before do
      create_file "gems.rb"
      install_gemfile! <<-G
        source "file://#{gem_repo1}"
        gem "rack", :group => :test
      G

      ruby <<-RUBY
        require 'rubygems'
        require 'bundler'
        require 'bundler/vendored_thor'

        Bundler.ui = Bundler::UI::Shell.new
        Bundler.setup
        Bundler.setup
      RUBY
    end

    it "should print a single deprecation warning", :bundler => "< 2" do
      expect(warnings).to include(
        "Multiple gemfiles (gems.rb and Gemfile) detected. The gems.rb and gems.rb.locked files are currently ignored, but they will get used as soon as you delete your Gemfile and Gemfile.lock files."
      )
    end

    it "should print a single deprecation warning", :bundler => "2" do
      expect(warnings).to include(
        "Multiple gemfiles (gems.rb and Gemfile) detected. Make sure you remove Gemfile and Gemfile.lock since bundler is ignoring them in favor of gems.rb and gems.rb.locked."
      )
    end
  end

  context "when `bundler/deployment` is required in a ruby script" do
    before do
      ruby(<<-RUBY)
        require 'bundler/deployment'
      RUBY
    end

    it "should not print a capistrano deprecation warning", :bundler => "< 2" do
      expect(deprecations).to be_empty
    end

    it "should print a capistrano deprecation warning", :bundler => "2" do
      expect(deprecations).to include("Bundler no longer integrates " \
                             "with Capistrano, but Capistrano provides " \
                             "its own integration with Bundler via the " \
                             "capistrano-bundler gem. Use it instead.")
    end
  end

  describe Bundler::Dsl do
    let(:msg) do
      <<-EOS
The :github git source is deprecated, and will be removed in the future. Change any "reponame" :github sources to "username/reponame". Add this code to the top of your Gemfile to ensure it continues to work:

    git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" }

      EOS
    end

    before do
      @rubygems = double("rubygems")
      allow(Bundler::Source::Rubygems).to receive(:new) { @rubygems }
    end

    context "with github gems" do
      it "warns about the https change if people are opting out" do
        Bundler.settings.temporary "github.https" => false
        expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg)
        expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, "Setting `github.https` to false is deprecated and won't be supported in the future.")
        subject.gem("sparks", :github => "indirect/sparks")
      end

      it "upgrades to https by default", :bundler => "2" do
        expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg)
        subject.gem("sparks", :github => "indirect/sparks")
        github_uri = "https://github.com/indirect/sparks.git"
        expect(subject.dependencies.first.source.uri).to eq(github_uri)
      end

      it "upgrades to https on request", :bundler => "< 2" do
        Bundler.settings.temporary "github.https" => true
        expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg)
        subject.gem("sparks", :github => "indirect/sparks")
        github_uri = "https://github.com/indirect/sparks.git"
        expect(subject.dependencies.first.source.uri).to eq(github_uri)
      end
    end

    context "with bitbucket gems" do
      it "warns about removal" do
        allow(Bundler.ui).to receive(:deprecate)
        msg = <<-EOS
The :bitbucket git source is deprecated, and will be removed in the future. Add this code to the top of your Gemfile to ensure it continues to work:

    git_source(:bitbucket) do |repo_name|
      user_name, repo_name = repo_name.split("/")
      repo_name ||= user_name
      "https://\#{user_name}@bitbucket.org/\#{user_name}/\#{repo_name}.git"
    end

        EOS
        expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg)
        subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails")
      end
    end

    context "with gist gems" do
      it "warns about removal" do
        allow(Bundler.ui).to receive(:deprecate)
        msg = <<-EOS
The :gist git source is deprecated, and will be removed in the future. Add this code to the top of your Gemfile to ensure it continues to work:

    git_source(:gist) {|repo_name| "https://gist.github.com/\#{repo_name}.git" }

        EOS
        expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg)
        subject.gem("not-really-a-gem", :gist => "1234")
      end
    end
  end

  context "bundle show" do
    before do
      install_gemfile! <<-G
        source "file://#{gem_repo1}"
        gem "rack"
      G

      bundle! :show
    end

    it "does not print a deprecation warning", :bundler => "< 2" do
      expect(deprecations).to be_empty
    end

    it "prints a deprecation warning", :bundler => "2" do
      expect(deprecations).to include("use `bundle list` instead of `bundle show`")
    end
  end

  context "bundle console" do
    before do
      bundle "console"
    end

    it "does not print a deprecation warning", :bundler => "< 2" do
      expect(deprecations).to be_empty
    end

    it "prints a deprecation warning", :bundler => "2" do
      expect(deprecations).to include \
        "bundle console will be replaced by `bin/console` generated by `bundle gem <name>`"
    end
  end

  context "bundle viz" do
    let(:ruby_graphviz) do
      graphviz_glob = base_system_gems.join("cache/ruby-graphviz*")
      Pathname.glob(graphviz_glob).first
    end

    before do
      system_gems ruby_graphviz
      create_file "gems.rb"
      bundle "viz"
    end

    it "does not print a deprecation warning", :bundler => "< 2" do
      expect(deprecations).to be_empty
    end

    it "prints a deprecation warning", :bundler => "2" do
      expect(deprecations).to include "The `viz` command has been moved to the `bundle-viz` gem, see https://github.com/bundler/bundler-viz"
    end
  end
end