summaryrefslogtreecommitdiff
path: root/spec/commands/add_spec.rb
blob: d6b9b46f942a05100485ce4a5b2252463947ba3e (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
# frozen_string_literal: true
require "spec_helper"

describe "bundle add" do
  before :each do
    build_repo2

    gemfile <<-G
      source "file://#{gem_repo2}"
    G
  end

  context "when version number is set" do
    it "adds gem with provided version" do
      bundle "add activesupport 2.3.5"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '~> 2.3.5'")
    end

    it "adds gem with provided version and version operator" do
      update_repo2 do
        build_gem "activesupport", "3.0.0"
      end

      bundle "add activesupport '> 2.3.5'"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '> 2.3.5'")
    end
  end

  context "when version number is not set" do
    it "adds gem with last stable version" do
      bundle "add activesupport"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '~> 2.3.5'")
    end

    it "`--pre` flag adds the gem with the latest prerelease version" do
      update_repo2 do
        build_gem "activesupport", "3.0.0.beta"
      end

      bundle "add activesupport --pre"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '~> 3.0.0.beta'")
    end

    it "`--pre` flag adds the gem with the latest non-prerelease version if it is available" do
      update_repo2 do
        build_gem "activesupport", "3.0.0.beta"
        build_gem "activesupport", "3.0.0"
      end

      bundle "add activesupport --pre"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '~> 3.0.0'")
    end
  end

  context "when group is set" do
    it "adds the gem with the specified groups" do
      bundle "add activesupport --group development test"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '~> 2.3.5', :group => [:development, :test]")
    end
  end

  context "when source is set" do
    it "adds the gem with a specified source" do
      bundle "add activesupport --source file://#{gem_repo2}"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '~> 2.3.5', :source => 'file:\/\/#{gem_repo2}'")
    end
  end

  context "when multiple options are set" do
    before :each do
      update_repo2 do
        build_gem "activesupport", "3.0.0"
      end
    end

    it "adds the gem with a specified group and source" do
      bundle "add activesupport --group test --source file://#{gem_repo2}"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '~> 3.0.0', :group => [:test], :source => 'file:\/\/#{gem_repo2}'")
    end

    it "adds the gem with a specified version, group, and source" do
      bundle "add activesupport 2.3.5 --group development --source file://#{gem_repo2}"
      expect(bundled_app("Gemfile").read).to include("gem 'activesupport', '~> 2.3.5', :group => [:development], :source => 'file:\/\/#{gem_repo2}'")
    end
  end
end