summaryrefslogtreecommitdiff
path: root/spec/other/install_path_spec.rb
blob: 64b271aca585c5d1650e7a1d40ecc42b6b6cdbfb (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
require 'pathname'
require Pathname(__FILE__).ascend { |d| h=d+'spec_helper.rb'; break h if h.file? }

describe "Bundler config " do
  context "with a Gemfile" do
    it "recognizes the install-path setting in a config file" do
      gemfile <<-G
        source "file://#{gem_repo1}"
        gem "rack"
      G
      config({'BUNDLE_INSTALL_PATH' => 'found_installed_path'})
      Dir.chdir(bundled_app('.bundle')) do
        bundle "config install-path", "no-color" => false
        out.should match /Settings for `install-path`(.+)\n(.+)found_installed_path/
      end
    end
  end
  context "without a Gemfile" do
    it "only complains about the missing Gemfile" do
      config({'BUNDLE_INSTALL_PATH' => 'found_installed_path'})
      Dir.chdir(bundled_app('.bundle')) do
        bundle "config install-path", "no-color" => false
        out.should match /Settings for `install-path`(.+)\n(.+)Could not locate Gemfile/
      end
    end
  end
end

describe "Bundler's full install path can point anywhere" do

  {:global => 'global Bundler install_path config', :env => 'environment variable BUNDLE_INSTALL_PATH'}.each do |type, desc|

    describe "running bundle install" do
      describe "when the #{desc} is set" do
        before :each do
          build_lib "rack", "1.0.0", :to_system => true do |s|
            s.write "lib/rack.rb", "raise 'FAIL'"
          end

          gemfile <<-G
            source "file://#{gem_repo1}"
            gem "rack"
          G
          @install_folder=[Array.new(6){rand(50).chr}.join].pack("m").chomp
        end

        after :each do
          clean_config
        end

        it "installs gems' when given a gemfile path (sans Gemfile) and install path" do
          ipath = make_install_path(@install_folder)
          Dir.chdir(ipath) do
            env              = set_bundle_install_path(type, @install_folder)
            env['gemfile']    = bundled_app.to_s
            env[:exitstatus] = true
            bundle "install", env
            check exitstatus.should == 0
          end
        end

        it "installs gems' when given a Gemfile and install path" do
          ipath = make_install_path(@install_folder)
          Dir.chdir(ipath) do
            env              = set_bundle_install_path(type, @install_folder)
            env['gemfile']    = (bundled_app + 'Gemfile').to_s
            env[:exitstatus] = true
            bundle "install", env
            check exitstatus.should == 0
          end
        end

        it "installs gems' when gemfile is in working dir and given the same gemfile path (sans Gemfile) and install path" do
          env              = set_bundle_install_path(type, @install_folder)
          env['gemfile']    = bundled_app.to_s
          env[:exitstatus] = true
          bundle "install", env
          check exitstatus.should == 0
        end

        it "installs gems' when gemfile is in working dir and given the same given a Gemfile and install path" do
          env              = set_bundle_install_path(type, @install_folder)
          env['gemfile']    = (bundled_app + 'Gemfile').to_s
          env[:exitstatus] = true
          bundle "install", env
          check exitstatus.should == 0
        end

        it "outputs an error when Gemfile is not pointed to nor is in working directory" do
          ipath = make_install_path(@install_folder)
          Dir.chdir(ipath) do
            env              = set_bundle_install_path(type, @install_folder)
            env[:exitstatus] = true
            bundle "install", env
            check exitstatus.should == 10
            out.should match /Could not locate Gemfile/
          end
        end

        it "outputs an error when Gemfile is pointed to but is not installed" do
          ipath = make_install_path(@install_folder)
          Dir.chdir(ipath) do
            bundle :check, :exitstatus => true, 'gemfile' => bundled_app.to_s
            check @exitstatus.should == 1
            out.should match /Your Gemfile's dependencies could not be satisfied\nInstall missing gems with `bundle install`/
          end
        end
      end
    end

    describe "requiring the installed library" do
      describe "when the #{desc} is set" do
        before :each do
          build_lib "rack", "1.0.0", :to_system => true do |s|
            s.write "lib/rack.rb", "raise 'FAIL'"
          end
          @install_folder = [Array.new(6){rand(50).chr}.join].pack("m").chomp
          @env = {'no-color' => false}
          @env['gemfile']    = bundled_app.to_s
          @env = @env.merge set_bundle_install_path(type, @install_folder, @env)
          ipath           = build_install_path(@install_folder)
          @installed_path   = File.join(ipath, 'gems','rack-1.0.0','lib')
          gemfile <<-G
            source "file://#{gem_repo1}"
            gem "rack"
          G
          bundle "install", @env
        end

        after :each do
          clean_config
        end

        it "installs nothing to the typical vendor path" do
          vendored_gems("gems/rack-1.0.0").should_not be_directory
        end

        it "installs nothing to the typical Bundler app path" do
          bundled_app("gems/rack-1.0.0").should_not be_directory
        end

        it "installs nothing to the typical Bundler app vendor path" do
          bundled_app('vendor/gems/rack-1.0.0').should_not be_directory
        end

        it "installs nothing to the typical Bundler app system gem path" do
          system_gem_path('gems/rack-1.0.0').should_not be_directory
        end

        it "installs nothing to the install folder under the typical Bundler app path" do
          bundled_app("#{@install_folder}/gems/rack-1.0.0").should_not be_directory
        end

        it "installs to the install path directly" do
          Dir.entries(@installed_path).size.should == 3
        end

##    it "installs gems's contents to BUNDLE_INSTALL_PATH relative to root when relative" do
##      set_bundle_install_path(type, "../#{@install_path}")
##
##      FileUtils.mkdir_p bundled_app('lol')
##      Dir.chdir(bundled_app('lol')) do
##        bundle :install
##      end
##
##      bundled_app('vendor/gems/rack-1.0.0').should_not be_directory
##      puts File.expand_path(File.join(bundled_app("#{@install_path}"),"**", "*"))
##      bundled_app("../#{@install_path}/gems/rack-1.0.0").should be_directory
##      should_be_installed "rack 1.0.0"
##    end

#        it "necessitates the full path be given to require the library" do
#          opts = set_bundle_install_path(type, @install_folder)
#          should_be_installed "rack 1.0.0", opts
#        end

#        it "installs gems' contents to BUNDLE_INSTALL_PATH with #{type}" do
#          set_bundle_install_path(type, bundled_app(@install_path).to_s)
#
#          bundle :install
#
          # bundled_app('vendor/gems/rack-1.0.0').should_not be_directory
#          puts File.expand_path(File.join(bundled_app("#{@install_path}").to_s,"**", "*"))
#          puts Dir.glob(File.join(bundled_app("#{@install_path}").to_s,"**", "*"))
#          bundled_app("#{@install_path}/gems/rack-1.0.0").should be_directory
#          should_be_installed "rack 1.0.0"
#        end

      end
    end

    describe "Bundler show <gem>" do
      context "with a Gemfile" do
        it "shows the installed location of an bundled gem is the given install-path" do
          build_lib "rack", "1.0.0", :to_system => true do |s|
            s.write "lib/rack.rb", "raise 'FAIL'"
          end
          install_folder = [Array.new(6){rand(50).chr}.join].pack("m").chomp
          env = {'no-color' => true}
          env['gemfile']    = bundled_app.to_s
          env = env.merge set_bundle_install_path(type, install_folder, env)
          ipath           = build_install_path(install_folder)
          installed_path   = File.join(ipath, 'gems','rack-1.0.0','lib')
          gemfile <<-G
            source "file://#{gem_repo1}"
            gem "rack"
          G
          bundle "install", env
          pending "spec's that are not Pixie Dust (TM, Bundler 2011)" do
            bundle 'show rack'  # TODO This should point to the installed path
            out.should match /Some success message/
          end
        end
      end

      context "without a Gemfile" do
        it "complains about the missing Gemfile" do
          build_lib "rack", "1.0.0", :to_system => true do |s|
            s.write "lib/rack.rb", "raise 'FAIL'"
          end
          install_folder = [Array.new(6){rand(50).chr}.join].pack("m").chomp
          env = {'no-color' => true}
          env['gemfile']    = bundled_app.to_s
          env = env.merge set_bundle_install_path(type, install_folder, env)
          ipath           = build_install_path(install_folder)
          installed_path   = File.join(ipath, 'gems','rack-1.0.0','lib')
          gemfile <<-G
            source "file://#{gem_repo1}"
            gem "rack"
          G
          bundle "install", env
          Dir.chdir(installed_path) do
            bundle 'show rack'
            out.should match /Could not locate Gemfile/
          end
        end
      end
    end

  end # each
end