summaryrefslogtreecommitdiff
path: root/spec/bundler/install/gems/post_install_spec.rb
blob: 7426f5487702edd76883f827dc07c8c8abe90ff5 (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
# frozen_string_literal: true

RSpec.describe "bundle install" do
  context "with gem sources" do
    context "when gems include post install messages" do
      it "should display the post-install messages after installing" do
        gemfile <<-G
          source "#{file_uri_for(gem_repo1)}"
          gem 'rack'
          gem 'thin'
          gem 'rack-obama'
        G

        bundle :install
        expect(out).to include("Post-install message from rack:")
        expect(out).to include("Rack's post install message")
        expect(out).to include("Post-install message from thin:")
        expect(out).to include("Thin's post install message")
        expect(out).to include("Post-install message from rack-obama:")
        expect(out).to include("Rack-obama's post install message")
      end
    end

    context "when gems do not include post install messages" do
      it "should not display any post-install messages" do
        gemfile <<-G
          source "#{file_uri_for(gem_repo1)}"
          gem "activesupport"
        G

        bundle :install
        expect(out).not_to include("Post-install message")
      end
    end

    context "when a dependency includes a post install message" do
      it "should display the post install message" do
        gemfile <<-G
          source "#{file_uri_for(gem_repo1)}"
          gem 'rack_middleware'
        G

        bundle :install
        expect(out).to include("Post-install message from rack:")
        expect(out).to include("Rack's post install message")
      end
    end
  end

  context "with git sources" do
    context "when gems include post install messages" do
      it "should display the post-install messages after installing" do
        build_git "foo" do |s|
          s.post_install_message = "Foo's post install message"
        end
        gemfile <<-G
          source "#{file_uri_for(gem_repo1)}"
          gem 'foo', :git => '#{lib_path("foo-1.0")}'
        G

        bundle :install
        expect(out).to include("Post-install message from foo:")
        expect(out).to include("Foo's post install message")
      end

      it "should display the post-install messages if repo is updated" do
        build_git "foo" do |s|
          s.post_install_message = "Foo's post install message"
        end
        gemfile <<-G
          source "#{file_uri_for(gem_repo1)}"
          gem 'foo', :git => '#{lib_path("foo-1.0")}'
        G
        bundle :install

        build_git "foo", "1.1" do |s|
          s.post_install_message = "Foo's 1.1 post install message"
        end
        gemfile <<-G
          source "#{file_uri_for(gem_repo1)}"
          gem 'foo', :git => '#{lib_path("foo-1.1")}'
        G
        bundle :install

        expect(out).to include("Post-install message from foo:")
        expect(out).to include("Foo's 1.1 post install message")
      end

      it "should not display the post-install messages if repo is not updated" do
        build_git "foo" do |s|
          s.post_install_message = "Foo's post install message"
        end
        gemfile <<-G
          source "#{file_uri_for(gem_repo1)}"
          gem 'foo', :git => '#{lib_path("foo-1.0")}'
        G

        bundle :install
        expect(out).to include("Post-install message from foo:")
        expect(out).to include("Foo's post install message")

        bundle :install
        expect(out).not_to include("Post-install message")
      end
    end

    context "when gems do not include post install messages" do
      it "should not display any post-install messages" do
        build_git "foo" do |s|
          s.post_install_message = nil
        end
        gemfile <<-G
          source "#{file_uri_for(gem_repo1)}"
          gem 'foo', :git => '#{lib_path("foo-1.0")}'
        G

        bundle :install
        expect(out).not_to include("Post-install message")
      end
    end
  end

  context "when ignore post-install messages for gem is set" do
    it "doesn't display any post-install messages" do
      gemfile <<-G
        source "#{file_uri_for(gem_repo1)}"
        gem "rack"
      G

      bundle "config set ignore_messages.rack true"

      bundle :install
      expect(out).not_to include("Post-install message")
    end
  end

  context "when ignore post-install messages for all gems" do
    it "doesn't display any post-install messages" do
      gemfile <<-G
        source "#{file_uri_for(gem_repo1)}"
        gem "rack"
      G

      bundle "config set ignore_messages true"

      bundle :install
      expect(out).not_to include("Post-install message")
    end
  end
end