bundler_package_git 1.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/.gitignore +22 -0
  2. data/.rvmrc +1 -0
  3. data/CHANGELOG.md +659 -0
  4. data/ISSUES.md +47 -0
  5. data/LICENSE +23 -0
  6. data/README.md +29 -0
  7. data/Rakefile +167 -0
  8. data/UPGRADING.md +103 -0
  9. data/bin/bundle +22 -0
  10. data/bundler.gemspec +30 -0
  11. data/lib/bundler.rb +283 -0
  12. data/lib/bundler/capistrano.rb +11 -0
  13. data/lib/bundler/cli.rb +490 -0
  14. data/lib/bundler/definition.rb +429 -0
  15. data/lib/bundler/dependency.rb +130 -0
  16. data/lib/bundler/deployment.rb +53 -0
  17. data/lib/bundler/dsl.rb +243 -0
  18. data/lib/bundler/environment.rb +47 -0
  19. data/lib/bundler/fetcher.rb +101 -0
  20. data/lib/bundler/gem_helper.rb +146 -0
  21. data/lib/bundler/graph.rb +130 -0
  22. data/lib/bundler/index.rb +131 -0
  23. data/lib/bundler/installer.rb +117 -0
  24. data/lib/bundler/lazy_specification.rb +71 -0
  25. data/lib/bundler/lockfile_parser.rb +108 -0
  26. data/lib/bundler/remote_specification.rb +57 -0
  27. data/lib/bundler/resolver.rb +470 -0
  28. data/lib/bundler/rubygems_ext.rb +226 -0
  29. data/lib/bundler/runtime.rb +201 -0
  30. data/lib/bundler/settings.rb +117 -0
  31. data/lib/bundler/setup.rb +16 -0
  32. data/lib/bundler/shared_helpers.rb +167 -0
  33. data/lib/bundler/source.rb +675 -0
  34. data/lib/bundler/spec_set.rb +134 -0
  35. data/lib/bundler/templates/Executable +16 -0
  36. data/lib/bundler/templates/Gemfile +4 -0
  37. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  38. data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
  39. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  40. data/lib/bundler/templates/newgem/gitignore.tt +4 -0
  41. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +7 -0
  42. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  43. data/lib/bundler/templates/newgem/newgem.gemspec.tt +21 -0
  44. data/lib/bundler/ui.rb +73 -0
  45. data/lib/bundler/vendor/net/http/faster.rb +27 -0
  46. data/lib/bundler/vendor/net/http/persistent.rb +464 -0
  47. data/lib/bundler/vendor/thor.rb +319 -0
  48. data/lib/bundler/vendor/thor/actions.rb +297 -0
  49. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  50. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  51. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  52. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +229 -0
  53. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +104 -0
  54. data/lib/bundler/vendor/thor/base.rb +556 -0
  55. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  56. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  57. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  58. data/lib/bundler/vendor/thor/error.rb +30 -0
  59. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  60. data/lib/bundler/vendor/thor/parser.rb +4 -0
  61. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  62. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  63. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  64. data/lib/bundler/vendor/thor/parser/options.rb +174 -0
  65. data/lib/bundler/vendor/thor/shell.rb +88 -0
  66. data/lib/bundler/vendor/thor/shell/basic.rb +275 -0
  67. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  68. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  69. data/lib/bundler/vendor/thor/task.rb +114 -0
  70. data/lib/bundler/vendor/thor/util.rb +229 -0
  71. data/lib/bundler/vendor/thor/version.rb +3 -0
  72. data/lib/bundler/version.rb +6 -0
  73. data/lib/bundler/vlad.rb +9 -0
  74. data/man/bundle-config.ronn +90 -0
  75. data/man/bundle-exec.ronn +111 -0
  76. data/man/bundle-install.ronn +314 -0
  77. data/man/bundle-package.ronn +59 -0
  78. data/man/bundle-update.ronn +176 -0
  79. data/man/bundle.ronn +80 -0
  80. data/man/gemfile.5.ronn +279 -0
  81. data/man/index.txt +6 -0
  82. data/spec/cache/gems_spec.rb +219 -0
  83. data/spec/cache/git_spec.rb +9 -0
  84. data/spec/cache/path_spec.rb +27 -0
  85. data/spec/cache/platform_spec.rb +57 -0
  86. data/spec/install/deploy_spec.rb +197 -0
  87. data/spec/install/deprecated_spec.rb +37 -0
  88. data/spec/install/gems/c_ext_spec.rb +48 -0
  89. data/spec/install/gems/dependency_api_spec.rb +85 -0
  90. data/spec/install/gems/env_spec.rb +107 -0
  91. data/spec/install/gems/flex_spec.rb +313 -0
  92. data/spec/install/gems/groups_spec.rb +245 -0
  93. data/spec/install/gems/packed_spec.rb +84 -0
  94. data/spec/install/gems/platform_spec.rb +208 -0
  95. data/spec/install/gems/resolving_spec.rb +72 -0
  96. data/spec/install/gems/simple_case_spec.rb +715 -0
  97. data/spec/install/gems/standalone_spec.rb +162 -0
  98. data/spec/install/gems/sudo_spec.rb +73 -0
  99. data/spec/install/gems/win32_spec.rb +26 -0
  100. data/spec/install/gemspec_spec.rb +108 -0
  101. data/spec/install/git_spec.rb +571 -0
  102. data/spec/install/invalid_spec.rb +17 -0
  103. data/spec/install/path_spec.rb +353 -0
  104. data/spec/install/upgrade_spec.rb +26 -0
  105. data/spec/lock/git_spec.rb +35 -0
  106. data/spec/lock/lockfile_spec.rb +683 -0
  107. data/spec/other/check_spec.rb +221 -0
  108. data/spec/other/clean_spec.rb +202 -0
  109. data/spec/other/config_spec.rb +40 -0
  110. data/spec/other/console_spec.rb +54 -0
  111. data/spec/other/exec_spec.rb +241 -0
  112. data/spec/other/ext_spec.rb +16 -0
  113. data/spec/other/gem_helper_spec.rb +128 -0
  114. data/spec/other/help_spec.rb +38 -0
  115. data/spec/other/init_spec.rb +40 -0
  116. data/spec/other/newgem_spec.rb +24 -0
  117. data/spec/other/open_spec.rb +35 -0
  118. data/spec/other/show_spec.rb +82 -0
  119. data/spec/pack/gems_spec.rb +54 -0
  120. data/spec/quality_spec.rb +58 -0
  121. data/spec/resolver/basic_spec.rb +20 -0
  122. data/spec/resolver/platform_spec.rb +82 -0
  123. data/spec/runtime/executable_spec.rb +110 -0
  124. data/spec/runtime/load_spec.rb +107 -0
  125. data/spec/runtime/platform_spec.rb +90 -0
  126. data/spec/runtime/require_spec.rb +231 -0
  127. data/spec/runtime/setup_spec.rb +688 -0
  128. data/spec/runtime/with_clean_env_spec.rb +15 -0
  129. data/spec/spec_helper.rb +85 -0
  130. data/spec/support/artifice/endpoint.rb +50 -0
  131. data/spec/support/artifice/endpoint_fallback.rb +22 -0
  132. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  133. data/spec/support/artifice/endpoint_redirect.rb +11 -0
  134. data/spec/support/builders.rb +574 -0
  135. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  136. data/spec/support/fakeweb/windows.rb +23 -0
  137. data/spec/support/helpers.rb +246 -0
  138. data/spec/support/indexes.rb +112 -0
  139. data/spec/support/matchers.rb +89 -0
  140. data/spec/support/path.rb +73 -0
  141. data/spec/support/platforms.rb +53 -0
  142. data/spec/support/ruby_ext.rb +20 -0
  143. data/spec/support/rubygems_ext.rb +35 -0
  144. data/spec/support/rubygems_hax/platform.rb +11 -0
  145. data/spec/support/sudo.rb +21 -0
  146. data/spec/update/gems_spec.rb +121 -0
  147. data/spec/update/git_spec.rb +196 -0
  148. data/spec/update/source_spec.rb +51 -0
  149. metadata +294 -0
@@ -0,0 +1,107 @@
1
+ require "spec_helper"
2
+
3
+ describe "Bundler.load" do
4
+ before :each do
5
+ system_gems "rack-1.0.0"
6
+ # clear memoized method results
7
+ # TODO: Don't reset internal ivars
8
+ Bundler.instance_eval do
9
+ @load = nil
10
+ @runtime = nil
11
+ @definition = nil
12
+ end
13
+ end
14
+
15
+ describe "with a gemfile" do
16
+ before(:each) do
17
+ gemfile <<-G
18
+ source "file://#{gem_repo1}"
19
+ gem "rack"
20
+ G
21
+ end
22
+
23
+ it "provides a list of the env dependencies" do
24
+ Bundler.load.dependencies.should have_dep("rack", ">= 0")
25
+ end
26
+
27
+ it "provides a list of the resolved gems" do
28
+ Bundler.load.gems.should have_gem("rack-1.0.0", "bundler-#{Bundler::VERSION}")
29
+ end
30
+
31
+ it "ignores blank BUNDLE_GEMFILEs" do
32
+ lambda {
33
+ ENV['BUNDLE_GEMFILE'] = ""
34
+ Bundler.load
35
+ }.should_not raise_error(Bundler::GemfileNotFound)
36
+ end
37
+
38
+ end
39
+
40
+ describe "without a gemfile" do
41
+ it "raises an exception if the default gemfile is not found" do
42
+ lambda {
43
+ Bundler.load
44
+ }.should raise_error(Bundler::GemfileNotFound, /could not locate gemfile/i)
45
+ end
46
+
47
+ it "raises an exception if a specified gemfile is not found" do
48
+ lambda {
49
+ ENV['BUNDLE_GEMFILE'] = "omg.rb"
50
+ Bundler.load
51
+ }.should raise_error(Bundler::GemfileNotFound, /omg\.rb/)
52
+ end
53
+
54
+ it "does not find a Gemfile above the testing directory" do
55
+ bundler_gemfile = tmp.join("../Gemfile")
56
+ unless File.exists?(bundler_gemfile)
57
+ FileUtils.touch(bundler_gemfile)
58
+ @remove_bundler_gemfile = true
59
+ end
60
+ begin
61
+ lambda { Bundler.load }.should raise_error(Bundler::GemfileNotFound)
62
+ ensure
63
+ bundler_gemfile.rmtree if @remove_bundler_gemfile
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ describe "when called twice" do
70
+ it "doesn't try to load the runtime twice" do
71
+ system_gems "rack-1.0.0", "activesupport-2.3.5"
72
+ gemfile <<-G
73
+ gem "rack"
74
+ gem "activesupport", :group => :test
75
+ G
76
+
77
+ ruby <<-RUBY
78
+ require "bundler"
79
+ Bundler.setup :default
80
+ Bundler.require :default
81
+ puts RACK
82
+ begin
83
+ require "activesupport"
84
+ rescue LoadError
85
+ puts "no activesupport"
86
+ end
87
+ RUBY
88
+
89
+ out.split("\n").should == ["1.0.0", "no activesupport"]
90
+ end
91
+ end
92
+
93
+ describe "not hurting brittle rubygems" do
94
+ it "does not inject #source into the generated YAML of the gem specs" do
95
+ system_gems "activerecord-2.3.2", "activesupport-2.3.2"
96
+ gemfile <<-G
97
+ gem "activerecord"
98
+ G
99
+
100
+ Bundler.load.specs.each do |spec|
101
+ spec.to_yaml.should_not =~ /^\s+source:/
102
+ spec.to_yaml.should_not =~ /^\s+groups:/
103
+ end
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,90 @@
1
+ require "spec_helper"
2
+
3
+ describe "Bundler.setup with multi platform stuff" do
4
+ it "raises a friendly error when gems are missing locally" do
5
+ gemfile <<-G
6
+ source "file://#{gem_repo1}"
7
+ gem "rack"
8
+ G
9
+
10
+ lockfile <<-G
11
+ GEM
12
+ remote: file:#{gem_repo1}/
13
+ specs:
14
+ rack (1.0)
15
+
16
+ PLATFORMS
17
+ #{local_tag}
18
+
19
+ DEPENDENCIES
20
+ rack
21
+ G
22
+
23
+ ruby <<-R
24
+ begin
25
+ require 'bundler'
26
+ Bundler.setup
27
+ rescue Bundler::GemNotFound => e
28
+ puts "WIN"
29
+ end
30
+ R
31
+
32
+ out.should == "WIN"
33
+ end
34
+
35
+ it "will resolve correctly on the current platform when the lockfile was targetted for a different one" do
36
+ lockfile <<-G
37
+ GEM
38
+ remote: file:#{gem_repo1}/
39
+ specs:
40
+ nokogiri (1.4.2-java)
41
+ weakling (= 0.0.3)
42
+ weakling (0.0.3)
43
+
44
+ PLATFORMS
45
+ java
46
+
47
+ DEPENDENCIES
48
+ nokogiri
49
+ G
50
+
51
+ system_gems "nokogiri-1.4.2"
52
+
53
+ simulate_platform "x86-darwin-10"
54
+ gemfile <<-G
55
+ source "file://#{gem_repo1}"
56
+ gem "nokogiri"
57
+ G
58
+
59
+ should_be_installed "nokogiri 1.4.2"
60
+ end
61
+
62
+ it "will add the resolve for the current platform" do
63
+ lockfile <<-G
64
+ GEM
65
+ remote: file:#{gem_repo1}/
66
+ specs:
67
+ nokogiri (1.4.2-java)
68
+ weakling (= 0.0.3)
69
+ weakling (0.0.3)
70
+
71
+ PLATFORMS
72
+ java
73
+
74
+ DEPENDENCIES
75
+ nokogiri
76
+ G
77
+
78
+ system_gems "nokogiri-1.4.2", "platform_specific-1.0-x86-darwin-100"
79
+
80
+ simulate_platform "x86-darwin-100"
81
+
82
+ gemfile <<-G
83
+ source "file://#{gem_repo1}"
84
+ gem "nokogiri"
85
+ gem "platform_specific"
86
+ G
87
+
88
+ should_be_installed "nokogiri 1.4.2", "platform_specific 1.0 x86-darwin-100"
89
+ end
90
+ end
@@ -0,0 +1,231 @@
1
+ require "spec_helper"
2
+
3
+ describe "Bundler.require" do
4
+ before :each do
5
+ build_lib "one", "1.0.0" do |s|
6
+ s.write "lib/baz.rb", "puts 'baz'"
7
+ s.write "lib/qux.rb", "puts 'qux'"
8
+ end
9
+
10
+ build_lib "two", "1.0.0" do |s|
11
+ s.write "lib/two.rb", "puts 'two'"
12
+ s.add_dependency "three", "= 1.0.0"
13
+ end
14
+
15
+ build_lib "three", "1.0.0" do |s|
16
+ s.write "lib/three.rb", "puts 'three'"
17
+ s.add_dependency "seven", "= 1.0.0"
18
+ end
19
+
20
+ build_lib "four", "1.0.0" do |s|
21
+ s.write "lib/four.rb", "puts 'four'"
22
+ end
23
+
24
+ build_lib "five", "1.0.0", :no_default => true do |s|
25
+ s.write "lib/mofive.rb", "puts 'five'"
26
+ end
27
+
28
+ build_lib "six", "1.0.0" do |s|
29
+ s.write "lib/six.rb", "puts 'six'"
30
+ end
31
+
32
+ build_lib "seven", "1.0.0" do |s|
33
+ s.write "lib/seven.rb", "puts 'seven'"
34
+ end
35
+
36
+ gemfile <<-G
37
+ path "#{lib_path}"
38
+ gem "one", :group => :bar, :require => %w(baz qux)
39
+ gem "two"
40
+ gem "three", :group => :not
41
+ gem "four", :require => false
42
+ gem "five"
43
+ gem "six", :group => "string"
44
+ gem "seven", :group => :not
45
+ G
46
+ end
47
+
48
+ it "requires the gems" do
49
+ # default group
50
+ run "Bundler.require"
51
+ check out.should == "two"
52
+
53
+ # specific group
54
+ run "Bundler.require(:bar)"
55
+ check out.should == "baz\nqux"
56
+
57
+ # default and specific group
58
+ run "Bundler.require(:default, :bar)"
59
+ check out.should == "baz\nqux\ntwo"
60
+
61
+ # specific group given as a string
62
+ run "Bundler.require('bar')"
63
+ check out.should == "baz\nqux"
64
+
65
+ # specific group declared as a string
66
+ run "Bundler.require(:string)"
67
+ check out.should == "six"
68
+
69
+ # required in resolver order instead of gemfile order
70
+ run("Bundler.require(:not)")
71
+ out.split("\n").sort.should == ['seven', 'three']
72
+ end
73
+
74
+ it "allows requiring gems with non standard names explicitly" do
75
+ run "Bundler.require ; require 'mofive'"
76
+ out.should == "two\nfive"
77
+ end
78
+
79
+ it "raises an exception if a require is specified but the file does not exist" do
80
+ gemfile <<-G
81
+ path "#{lib_path}"
82
+ gem "two", :require => 'fail'
83
+ G
84
+
85
+ run <<-R
86
+ begin
87
+ Bundler.require
88
+ rescue LoadError => e
89
+ puts e.message
90
+ end
91
+ R
92
+ out.should == 'no such file to load -- fail'
93
+ end
94
+
95
+ describe "using bundle exec" do
96
+ it "requires the locked gems" do
97
+ bundle "exec ruby -e 'Bundler.require'"
98
+ check out.should == "two"
99
+
100
+ bundle "exec ruby -e 'Bundler.require(:bar)'"
101
+ check out.should == "baz\nqux"
102
+
103
+ bundle "exec ruby -e 'Bundler.require(:default, :bar)'"
104
+ out.should == "baz\nqux\ntwo"
105
+ end
106
+ end
107
+
108
+ describe "order" do
109
+ before(:each) do
110
+ build_lib "one", "1.0.0" do |s|
111
+ s.write "lib/one.rb", <<-ONE
112
+ if defined?(Two)
113
+ Two.two
114
+ else
115
+ puts "two_not_loaded"
116
+ end
117
+ puts 'one'
118
+ ONE
119
+ end
120
+
121
+ build_lib "two", "1.0.0" do |s|
122
+ s.write "lib/two.rb", <<-TWO
123
+ module Two
124
+ def self.two
125
+ puts 'module_two'
126
+ end
127
+ end
128
+ puts 'two'
129
+ TWO
130
+ end
131
+ end
132
+
133
+ it "works when the gems are in the Gemfile in the correct order" do
134
+ gemfile <<-G
135
+ path "#{lib_path}"
136
+ gem "two"
137
+ gem "one"
138
+ G
139
+
140
+ run "Bundler.require"
141
+ check out.should == "two\nmodule_two\none"
142
+ end
143
+
144
+ describe "a gem with different requires for different envs" do
145
+ before(:each) do
146
+ build_gem "multi_gem", :to_system => true do |s|
147
+ s.write "lib/one.rb", "puts 'ONE'"
148
+ s.write "lib/two.rb", "puts 'TWO'"
149
+ end
150
+
151
+ install_gemfile <<-G
152
+ gem "multi_gem", :require => "one", :group => :one
153
+ gem "multi_gem", :require => "two", :group => :two
154
+ G
155
+ end
156
+
157
+ it "requires both with Bundler.require(both)" do
158
+ run "Bundler.require(:one, :two)"
159
+ out.should == "ONE\nTWO"
160
+ end
161
+
162
+ it "requires one with Bundler.require(:one)" do
163
+ run "Bundler.require(:one)"
164
+ out.should == "ONE"
165
+ end
166
+
167
+ it "requires :two with Bundler.require(:two)" do
168
+ run "Bundler.require(:two)"
169
+ out.should == "TWO"
170
+ end
171
+ end
172
+
173
+ it "fails when the gems are in the Gemfile in the wrong order" do
174
+ gemfile <<-G
175
+ path "#{lib_path}"
176
+ gem "one"
177
+ gem "two"
178
+ G
179
+
180
+ run "Bundler.require"
181
+ check out.should == "two_not_loaded\none\ntwo"
182
+ end
183
+
184
+ describe "with busted gems" do
185
+ it "should be busted" do
186
+ build_gem "busted_require", :to_system => true do |s|
187
+ s.write "lib/busted_require.rb", "require 'no_such_file_omg'"
188
+ end
189
+
190
+ install_gemfile <<-G
191
+ gem "busted_require"
192
+ G
193
+
194
+ run "Bundler.require", :expect_err => true
195
+ err.should include("no such file to load -- no_such_file_omg")
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ describe "Bundler.require with platform specific dependencies" do
202
+ it "does not require the gems that are pinned to other platforms" do
203
+ install_gemfile <<-G
204
+ source "file://#{gem_repo1}"
205
+
206
+ platforms :#{not_local_tag} do
207
+ gem "fail", :require => "omgomg"
208
+ end
209
+
210
+ gem "rack", "1.0.0"
211
+ G
212
+
213
+ run "Bundler.require", :expect_err => true
214
+ err.should be_empty
215
+ end
216
+
217
+ it "requires gems pinned to multiple platforms, including the current one" do
218
+ install_gemfile <<-G
219
+ source "file://#{gem_repo1}"
220
+
221
+ platforms :#{not_local_tag}, :#{local_tag} do
222
+ gem "rack", :require => "rack"
223
+ end
224
+ G
225
+
226
+ run "Bundler.require; puts RACK", :expect_err => true
227
+
228
+ check out.should == "1.0.0"
229
+ err.should be_empty
230
+ end
231
+ end
@@ -0,0 +1,688 @@
1
+ require "spec_helper"
2
+
3
+ describe "Bundler.setup" do
4
+ describe "with no arguments" do
5
+ it "makes all groups available" do
6
+ install_gemfile <<-G
7
+ source "file://#{gem_repo1}"
8
+ gem "rack", :group => :test
9
+ G
10
+
11
+ ruby <<-RUBY
12
+ require 'rubygems'
13
+ require 'bundler'
14
+ Bundler.setup
15
+
16
+ require 'rack'
17
+ puts RACK
18
+ RUBY
19
+ err.should == ""
20
+ out.should == "1.0.0"
21
+ end
22
+ end
23
+
24
+ describe "when called with groups" do
25
+ before(:each) do
26
+ install_gemfile <<-G
27
+ source "file://#{gem_repo1}"
28
+ gem "rack", :group => :test
29
+ G
30
+ end
31
+
32
+ it "doesn't make all groups available" do
33
+ ruby <<-RUBY
34
+ require 'rubygems'
35
+ require 'bundler'
36
+ Bundler.setup(:default)
37
+
38
+ begin
39
+ require 'rack'
40
+ rescue LoadError
41
+ puts "WIN"
42
+ end
43
+ RUBY
44
+ err.should == ""
45
+ out.should == "WIN"
46
+ end
47
+
48
+ it "leaves all groups available if they were already" do
49
+ ruby <<-RUBY
50
+ require 'rubygems'
51
+ require 'bundler'
52
+ Bundler.setup
53
+ Bundler.setup(:default)
54
+
55
+ require 'rack'
56
+ puts RACK
57
+ RUBY
58
+ err.should == ""
59
+ out.should == "1.0.0"
60
+ end
61
+ end
62
+
63
+ it "raises if the Gemfile was not yet installed" do
64
+ gemfile <<-G
65
+ source "file://#{gem_repo1}"
66
+ gem "rack"
67
+ G
68
+
69
+ ruby <<-R
70
+ require 'rubygems'
71
+ require 'bundler'
72
+
73
+ begin
74
+ Bundler.setup
75
+ puts "FAIL"
76
+ rescue Bundler::GemNotFound
77
+ puts "WIN"
78
+ end
79
+ R
80
+
81
+ out.should == "WIN"
82
+ end
83
+
84
+ it "doesn't create a Gemfile.lock if the setup fails" do
85
+ gemfile <<-G
86
+ source "file://#{gem_repo1}"
87
+ gem "rack"
88
+ G
89
+
90
+ ruby <<-R, :expect_err => true
91
+ require 'rubygems'
92
+ require 'bundler'
93
+
94
+ Bundler.setup
95
+ R
96
+
97
+ bundled_app("Gemfile.lock").should_not exist
98
+ end
99
+
100
+ it "doesn't change the Gemfile.lock if the setup fails" do
101
+ install_gemfile <<-G
102
+ source "file://#{gem_repo1}"
103
+ gem "rack"
104
+ G
105
+
106
+ lockfile = File.read(bundled_app("Gemfile.lock"))
107
+
108
+ gemfile <<-G
109
+ source "file://#{gem_repo1}"
110
+ gem "rack"
111
+ gem "nosuchgem", "10.0"
112
+ G
113
+
114
+ ruby <<-R, :expect_err => true
115
+ require 'rubygems'
116
+ require 'bundler'
117
+
118
+ Bundler.setup
119
+ R
120
+
121
+ File.read(bundled_app("Gemfile.lock")).should == lockfile
122
+ end
123
+
124
+ it "makes a Gemfile.lock if setup succeeds" do
125
+ install_gemfile <<-G
126
+ source "file://#{gem_repo1}"
127
+ gem "rack"
128
+ G
129
+
130
+ File.read(bundled_app("Gemfile.lock"))
131
+
132
+ FileUtils.rm(bundled_app("Gemfile.lock"))
133
+
134
+ run "1"
135
+ bundled_app("Gemfile.lock").should exist
136
+ end
137
+
138
+ it "uses BUNDLE_GEMFILE to locate the gemfile if present" do
139
+ gemfile <<-G
140
+ source "file://#{gem_repo1}"
141
+ gem "rack"
142
+ G
143
+
144
+ gemfile bundled_app('4realz'), <<-G
145
+ source "file://#{gem_repo1}"
146
+ gem "activesupport", "2.3.5"
147
+ G
148
+
149
+ ENV['BUNDLE_GEMFILE'] = bundled_app('4realz').to_s
150
+ bundle :install
151
+
152
+ should_be_installed "activesupport 2.3.5"
153
+ end
154
+
155
+ it "prioritizes gems in BUNDLE_PATH over gems in GEM_HOME" do
156
+ ENV['BUNDLE_PATH'] = bundled_app('.bundle').to_s
157
+ install_gemfile <<-G
158
+ source "file://#{gem_repo1}"
159
+ gem "rack", "1.0.0"
160
+ G
161
+
162
+ build_gem "rack", "1.0", :to_system => true do |s|
163
+ s.write "lib/rack.rb", "RACK = 'FAIL'"
164
+ end
165
+
166
+ should_be_installed "rack 1.0.0"
167
+ end
168
+
169
+ describe "crippling rubygems" do
170
+ describe "by replacing #gem" do
171
+ before :each do
172
+ install_gemfile <<-G
173
+ source "file://#{gem_repo1}"
174
+ gem "rack", "0.9.1"
175
+ G
176
+ end
177
+
178
+ it "replaces #gem but raises when the gem is missing" do
179
+ run <<-R
180
+ begin
181
+ gem "activesupport"
182
+ puts "FAIL"
183
+ rescue LoadError
184
+ puts "WIN"
185
+ end
186
+ R
187
+
188
+ out.should == "WIN"
189
+ end
190
+
191
+ it "version_requirement is now deprecated in rubygems 1.4.0+ when gem is missing" do
192
+ run <<-R, :expect_err => true
193
+ begin
194
+ gem "activesupport"
195
+ puts "FAIL"
196
+ rescue LoadError
197
+ puts "WIN"
198
+ end
199
+ R
200
+
201
+ err.should be_empty
202
+ end
203
+
204
+ it "replaces #gem but raises when the version is wrong" do
205
+ run <<-R
206
+ begin
207
+ gem "rack", "1.0.0"
208
+ puts "FAIL"
209
+ rescue LoadError
210
+ puts "WIN"
211
+ end
212
+ R
213
+
214
+ out.should == "WIN"
215
+ end
216
+
217
+ it "version_requirement is now deprecated in rubygesm 1.4.0+ when the version is wrong" do
218
+ run <<-R, :expect_err => true
219
+ begin
220
+ gem "rack", "1.0.0"
221
+ puts "FAIL"
222
+ rescue LoadError
223
+ puts "WIN"
224
+ end
225
+ R
226
+
227
+ err.should be_empty
228
+ end
229
+ end
230
+
231
+ describe "by hiding system gems" do
232
+ before :each do
233
+ system_gems "activesupport-2.3.5"
234
+ install_gemfile <<-G
235
+ source "file://#{gem_repo1}"
236
+ gem "yard"
237
+ G
238
+ end
239
+
240
+ it "removes system gems from Gem.source_index" do
241
+ run "require 'yard'"
242
+ out.should == "bundler-#{Bundler::VERSION}\nyard-1.0"
243
+ end
244
+
245
+ context "when the ruby stdlib is a substring of Gem.path" do
246
+ it "does not reject the stdlib from $LOAD_PATH" do
247
+ substring = "/" + $LOAD_PATH.find{|p| p =~ /vendor_ruby/ }.split("/")[2]
248
+ run "puts 'worked!'", :env => {"GEM_PATH" => substring}
249
+ out.should == "worked!"
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ describe "with paths" do
256
+ it "activates the gems in the path source" do
257
+ system_gems "rack-1.0.0"
258
+
259
+ build_lib "rack", "1.0.0" do |s|
260
+ s.write "lib/rack.rb", "puts 'WIN'"
261
+ end
262
+
263
+ gemfile <<-G
264
+ path "#{lib_path('rack-1.0.0')}"
265
+ source "file://#{gem_repo1}"
266
+ gem "rack"
267
+ G
268
+
269
+ run "require 'rack'"
270
+ out.should == "WIN"
271
+ end
272
+ end
273
+
274
+ describe "with git" do
275
+ before do
276
+ build_git "rack", "1.0.0"
277
+
278
+ gemfile <<-G
279
+ gem "rack", :git => "#{lib_path('rack-1.0.0')}"
280
+ G
281
+ end
282
+
283
+ it "provides a useful exception when the git repo is not checked out yet" do
284
+ run "1", :expect_err => true
285
+ err.should include("#{lib_path('rack-1.0.0')} (at master) is not checked out. Please run `bundle install`")
286
+ end
287
+
288
+ it "does not hit the git binary if the lockfile is available and up to date" do
289
+ bundle "install"
290
+
291
+ break_git!
292
+
293
+ ruby <<-R
294
+ require 'rubygems'
295
+ require 'bundler'
296
+
297
+ begin
298
+ Bundler.setup
299
+ puts "WIN"
300
+ rescue Exception => e
301
+ puts "FAIL"
302
+ end
303
+ R
304
+
305
+ out.should == "WIN"
306
+ end
307
+
308
+ it "provides a good exception if the lockfile is unavailable" do
309
+ bundle "install"
310
+
311
+ FileUtils.rm(bundled_app("Gemfile.lock"))
312
+
313
+ break_git!
314
+
315
+ ruby <<-R
316
+ require "rubygems"
317
+ require "bundler"
318
+
319
+ begin
320
+ Bundler.setup
321
+ puts "FAIL"
322
+ rescue Bundler::GitError => e
323
+ puts e.message
324
+ end
325
+ R
326
+
327
+ run "puts 'FAIL'", :expect_err => true
328
+
329
+ err.should_not include "This is not the git you are looking for"
330
+ end
331
+
332
+ it "works even when the cache directory has been deleted" do
333
+ bundle "install --path vendor/bundle"
334
+ FileUtils.rm_rf vendored_gems('cache')
335
+ should_be_installed "rack 1.0.0"
336
+ end
337
+
338
+ it "does not randomly change the path when specifying --path and the bundle directory becomes read only" do
339
+ begin
340
+ bundle "install --path vendor/bundle"
341
+
342
+ Dir["**/*"].each do |f|
343
+ File.directory?(f) ?
344
+ File.chmod(0555, f) :
345
+ File.chmod(0444, f)
346
+ end
347
+ should_be_installed "rack 1.0.0"
348
+ ensure
349
+ Dir["**/*"].each do |f|
350
+ File.directory?(f) ?
351
+ File.chmod(0755, f) :
352
+ File.chmod(0644, f)
353
+ end
354
+ end
355
+ end
356
+ end
357
+
358
+ describe "when excluding groups" do
359
+ it "doesn't change the resolve if --without is used" do
360
+ install_gemfile <<-G, :without => :rails
361
+ source "file://#{gem_repo1}"
362
+ gem "activesupport"
363
+
364
+ group :rails do
365
+ gem "rails", "2.3.2"
366
+ end
367
+ G
368
+
369
+ install_gems "activesupport-2.3.5"
370
+
371
+ should_be_installed "activesupport 2.3.2", :groups => :default
372
+ end
373
+
374
+ it "remembers --without and does not bail on bare Bundler.setup" do
375
+ install_gemfile <<-G, :without => :rails
376
+ source "file://#{gem_repo1}"
377
+ gem "activesupport"
378
+
379
+ group :rails do
380
+ gem "rails", "2.3.2"
381
+ end
382
+ G
383
+
384
+ install_gems "activesupport-2.3.5"
385
+
386
+ should_be_installed "activesupport 2.3.2"
387
+ end
388
+
389
+ it "remembers --without and does not include groups passed to Bundler.setup" do
390
+ install_gemfile <<-G, :without => :rails
391
+ source "file://#{gem_repo1}"
392
+ gem "activesupport"
393
+
394
+ group :rack do
395
+ gem "rack"
396
+ end
397
+
398
+ group :rails do
399
+ gem "rails", "2.3.2"
400
+ end
401
+ G
402
+
403
+ should_not_be_installed "activesupport 2.3.2", :groups => :rack
404
+ should_be_installed "rack 1.0.0", :groups => :rack
405
+ end
406
+ end
407
+
408
+ # Unfortunately, gem_prelude does not record the information about
409
+ # activated gems, so this test cannot work on 1.9 :(
410
+ if RUBY_VERSION < "1.9"
411
+ describe "preactivated gems" do
412
+ it "raises an exception if a pre activated gem conflicts with the bundle" do
413
+ system_gems "thin-1.0", "rack-1.0.0"
414
+ build_gem "thin", "1.1", :to_system => true do |s|
415
+ s.add_dependency "rack"
416
+ end
417
+
418
+ gemfile <<-G
419
+ gem "thin", "1.0"
420
+ G
421
+
422
+ ruby <<-R
423
+ require 'rubygems'
424
+ gem "thin"
425
+ require 'bundler'
426
+ begin
427
+ Bundler.setup
428
+ puts "FAIL"
429
+ rescue Gem::LoadError => e
430
+ puts e.message
431
+ end
432
+ R
433
+
434
+ out.should == "You have already activated thin 1.1, but your Gemfile requires thin 1.0. Consider using bundle exec."
435
+ end
436
+
437
+ it "version_requirement is now deprecated in rubygems 1.4.0+" do
438
+ system_gems "thin-1.0", "rack-1.0.0"
439
+ build_gem "thin", "1.1", :to_system => true do |s|
440
+ s.add_dependency "rack"
441
+ end
442
+
443
+ gemfile <<-G
444
+ gem "thin", "1.0"
445
+ G
446
+
447
+ ruby <<-R, :expect_err => true
448
+ require 'rubygems'
449
+ gem "thin"
450
+ require 'bundler'
451
+ begin
452
+ Bundler.setup
453
+ puts "FAIL"
454
+ rescue Gem::LoadError => e
455
+ puts e.message
456
+ end
457
+ R
458
+
459
+ err.should be_empty
460
+ end
461
+ end
462
+ end
463
+
464
+ # Rubygems returns loaded_from as a string
465
+ it "has loaded_from as a string on all specs" do
466
+ build_git "foo"
467
+ build_git "no-gemspec", :gemspec => false
468
+
469
+ install_gemfile <<-G
470
+ source "file://#{gem_repo1}"
471
+ gem "rack"
472
+ gem "foo", :git => "#{lib_path('foo-1.0')}"
473
+ gem "no-gemspec", "1.0", :git => "#{lib_path('no-gemspec-1.0')}"
474
+ G
475
+
476
+ run <<-R
477
+ Gem.loaded_specs.each do |n, s|
478
+ puts "FAIL" unless String === s.loaded_from
479
+ end
480
+ R
481
+
482
+ out.should be_empty
483
+ end
484
+
485
+ it "ignores empty gem paths" do
486
+ install_gemfile <<-G
487
+ source "file://#{gem_repo1}"
488
+ gem "rack"
489
+ G
490
+
491
+ ENV["GEM_HOME"] = ""
492
+ bundle %{exec ruby -e "require 'set'"}
493
+
494
+ err.should be_empty
495
+ end
496
+
497
+ it "should prepend gemspec require paths to $LOAD_PATH in order" do
498
+ update_repo2 do
499
+ build_gem("requirepaths") do |s|
500
+ s.write("lib/rq.rb", "puts 'yay'")
501
+ s.write("src/rq.rb", "puts 'nooo'")
502
+ s.require_paths = ["lib", "src"]
503
+ end
504
+ end
505
+
506
+ install_gemfile <<-G
507
+ source "file://#{gem_repo2}"
508
+ gem "requirepaths", :require => nil
509
+ G
510
+
511
+ run "require 'rq'"
512
+ out.should == "yay"
513
+ end
514
+
515
+ it "ignores Gem.refresh" do
516
+ system_gems "rack-1.0.0"
517
+
518
+ install_gemfile <<-G
519
+ source "file://#{gem_repo1}"
520
+ gem "activesupport"
521
+ G
522
+
523
+ run <<-R
524
+ Gem.refresh
525
+ puts Gem.source_index.find_name("rack").inspect
526
+ R
527
+
528
+ out.should == "[]"
529
+ end
530
+
531
+ describe "with git gems that don't have gemspecs" do
532
+ before :each do
533
+ build_git "no-gemspec", :gemspec => false
534
+
535
+ install_gemfile <<-G
536
+ gem "no-gemspec", "1.0", :git => "#{lib_path('no-gemspec-1.0')}"
537
+ G
538
+ end
539
+
540
+ it "loads the library via a virtual spec" do
541
+ run <<-R
542
+ require 'no-gemspec'
543
+ puts NOGEMSPEC
544
+ R
545
+
546
+ out.should == "1.0"
547
+ end
548
+ end
549
+
550
+ describe "with bundled and system gems" do
551
+ before :each do
552
+ system_gems "rack-1.0.0"
553
+
554
+ install_gemfile <<-G
555
+ source "file://#{gem_repo1}"
556
+
557
+ gem "activesupport", "2.3.5"
558
+ G
559
+ end
560
+
561
+ it "does not pull in system gems" do
562
+ run <<-R
563
+ require 'rubygems'
564
+
565
+ begin;
566
+ require 'rack'
567
+ rescue LoadError
568
+ puts 'WIN'
569
+ end
570
+ R
571
+
572
+ out.should == "WIN"
573
+ end
574
+
575
+ it "provides a gem method" do
576
+ run <<-R
577
+ gem 'activesupport'
578
+ require 'activesupport'
579
+ puts ACTIVESUPPORT
580
+ R
581
+
582
+ out.should == "2.3.5"
583
+ end
584
+
585
+ it "raises an exception if gem is used to invoke a system gem not in the bundle" do
586
+ run <<-R
587
+ begin
588
+ gem 'rack'
589
+ rescue LoadError => e
590
+ puts e.message
591
+ end
592
+ R
593
+
594
+ out.should == "rack is not part of the bundle. Add it to Gemfile."
595
+ end
596
+
597
+ it "sets GEM_HOME appropriately" do
598
+ run "puts ENV['GEM_HOME']"
599
+ out.should == default_bundle_path.to_s
600
+ end
601
+ end
602
+
603
+ describe "with system gems in the bundle" do
604
+ before :each do
605
+ system_gems "rack-1.0.0"
606
+
607
+ install_gemfile <<-G
608
+ source "file://#{gem_repo1}"
609
+ gem "rack", "1.0.0"
610
+ gem "activesupport", "2.3.5"
611
+ G
612
+ end
613
+
614
+ it "sets GEM_PATH appropriately" do
615
+ run "puts Gem.path"
616
+ paths = out.split("\n")
617
+ paths.should include(system_gem_path.to_s)
618
+ paths.should include(default_bundle_path.to_s)
619
+ end
620
+ end
621
+
622
+ describe "with a gemspec that requires other files" do
623
+ before :each do
624
+ build_git "bar", :gemspec => false do |s|
625
+ s.write "lib/bar/version.rb", %{BAR_VERSION = '1.0'}
626
+ s.write "bar.gemspec", <<-G
627
+ lib = File.expand_path('../lib/', __FILE__)
628
+ $:.unshift lib unless $:.include?(lib)
629
+ require 'bar/version'
630
+
631
+ Gem::Specification.new do |s|
632
+ s.name = 'bar'
633
+ s.version = BAR_VERSION
634
+ s.summary = 'Bar'
635
+ s.files = Dir["lib/**/*.rb"]
636
+ end
637
+ G
638
+ end
639
+
640
+ gemfile <<-G
641
+ gem "bar", :git => "#{lib_path('bar-1.0')}"
642
+ G
643
+ end
644
+
645
+ it "evals each gemspec in the context of its parent directory" do
646
+ bundle :install
647
+ run "require 'bar'; puts BAR"
648
+ out.should == "1.0"
649
+ end
650
+
651
+ it "error intelligently if the gemspec has a LoadError" do
652
+ update_git "bar", :gemspec => false do |s|
653
+ s.write "bar.gemspec", "require 'foobarbaz'"
654
+ end
655
+ bundle :install
656
+ out.should include("was a LoadError while evaluating bar.gemspec")
657
+ out.should include("foobarbaz")
658
+ out.should include("bar.gemspec:1")
659
+ out.should include("try to require a relative path") if RUBY_VERSION >= "1.9.0"
660
+ end
661
+
662
+ it "evals each gemspec with a binding from the top level" do
663
+ bundle "install"
664
+
665
+ ruby <<-RUBY
666
+ require 'bundler'
667
+ def Bundler.require(path)
668
+ raise "LOSE"
669
+ end
670
+ Bundler.load
671
+ RUBY
672
+
673
+ err.should == ""
674
+ out.should == ""
675
+ end
676
+ end
677
+
678
+ describe "when Bundler is bundled" do
679
+ it "doesn't blow up" do
680
+ install_gemfile <<-G
681
+ gem "bundler", :path => "#{File.expand_path("..", lib)}"
682
+ G
683
+
684
+ bundle %|exec ruby -e "require 'bundler'; Bundler.setup"|
685
+ err.should be_empty
686
+ end
687
+ end
688
+ end