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
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "Bundler::Manifest" do
def dep(name, version, options = {})
Bundler::Dependency.new(name, {:version => version}.merge(options))
end
before(:all) do
@sources = %W(file://#{gem_repo1} file://#{gem_repo2})
@deps = []
@deps << dep("rails", "2.3.2")
@deps << dep("rack", "0.9.1")
end
describe "Manifest with dependencies" do
before(:each) do
FileUtils.rm_rf(tmp_dir)
FileUtils.mkdir_p(tmp_dir)
@manifest = Bundler::Manifest.new(@sources, @deps, tmp_bindir, tmp_gem_path)
@saved_load_path, @saved_loaded_features = $:.dup, $".dup
end
after(:each) do
Object.send(:remove_const, :VerySimpleForTests) if defined?(VerySimpleForTests)
$:.replace @saved_load_path
$".replace @saved_loaded_features
end
it "has a list of sources and dependencies" do
@manifest.sources.should == @sources
@manifest.dependencies.should == @deps
end
it "bundles itself (running all of the steps)" do
@manifest.install
gems = %w(rack-0.9.1 actionmailer-2.3.2
activerecord-2.3.2 activesupport-2.3.2
rake-0.8.7 actionpack-2.3.2
activeresource-2.3.2 rails-2.3.2)
tmp_gem_path.should have_cached_gems(*gems)
tmp_gem_path.should have_installed_gems(*gems)
end
it "skips fetching the source index if all gems are present" do
@manifest.install
Bundler::Finder.should_not_receive(:new)
@manifest.install
end
it "logs 'Done' when done" do
@manifest.install
@log_output.should have_log_message("Done.")
end
it "does the full fetching if a gem in the cache does not match the manifest" do
@manifest.install
deps = []
deps << dep("rails", "2.3.2")
deps << dep("rack", "1.0.0")
manifest = Bundler::Manifest.new(@sources, deps, tmp_bindir, tmp_gem_path)
manifest.install
gems = %w(rack-1.0.0 actionmailer-2.3.2
activerecord-2.3.2 activesupport-2.3.2
rake-0.8.7 actionpack-2.3.2
activeresource-2.3.2 rails-2.3.2)
tmp_gem_path.should have_cached_gems(*gems)
tmp_gem_path.should have_installed_gems(*gems)
end
it "removes gems that are not needed anymore" do
@manifest.install
tmp_gem_path.should have_cached_gem("rack-0.9.1")
tmp_gem_path.should have_installed_gem("rack-0.9.1")
tmp_bindir("rackup").should exist
deps = @deps.dup
deps.pop
manifest = Bundler::Manifest.new(@sources, deps, tmp_bindir, tmp_gem_path)
manifest.install
tmp_gem_path.should_not have_cached_gem("rack-0.9.1")
tmp_gem_path.should_not have_installed_gem("rack-0.9.1")
tmp_bindir("rackup").should_not exist
@log_output.should have_log_message("Deleting rack-0.9.1.gem")
end
it "removes stray specfiles" do
spec = tmp_gem_path("specifications", "omg.gemspec")
FileUtils.mkdir_p(tmp_gem_path("specifications"))
FileUtils.touch(spec)
@manifest.install
spec.should_not exist
end
it "removes any stray directories in gems that are not to be installed" do
dir = tmp_gem_path("gems", "omg")
FileUtils.mkdir_p(dir)
@manifest.install
dir.should_not exist
end
it "raises a friendly exception if the manifest doesn't resolve" do
@manifest.dependencies << dep("active_support", "2.0")
lambda { @manifest.install }.should raise_error(Bundler::VersionConflict,
/rails \(= 2\.3\.2.*rack \(= 0\.9\.1.*active_support \(= 2\.0/m)
end
end
describe "runtime" do
before(:each) do
FileUtils.rm_rf(tmp_dir)
FileUtils.mkdir_p(tmp_dir)
end
it "makes gems available via Manifest#activate" do
manifest = Bundler::Manifest.new(@sources, [dep("very-simple", "1.0.0")], tmp_bindir, tmp_gem_path)
manifest.install
manifest.activate
$:.any? do |p|
File.expand_path(p) == File.expand_path(tmp_gem_path("gems", "very-simple-1.0", "lib"))
end.should be_true
end
it "makes gems available" do
manifest = Bundler::Manifest.new(@sources, [dep("very-simple", "1.0.0")], tmp_bindir, tmp_gem_path)
manifest.install
manifest.activate
manifest.require_all
$".any? do |f|
File.expand_path(f) ==
File.expand_path(tmp_gem_path("gems", "very-simple-1.0", "lib", "very-simple.rb"))
end
end
end
describe "environments" do
before(:all) do
FileUtils.rm_rf(tmp_dir)
FileUtils.mkdir_p(tmp_dir)
@manifest = Bundler::Manifest.new(@sources,
[dep("very-simple", "1.0.0", :only => "testing"),
dep("rack", "1.0.0")], tmp_bindir, tmp_gem_path)
@manifest.install
end
it "can provide a list of environments" do
@manifest.environments.should == ["testing", "default"]
end
it "knows what gems are in an environment" do
@manifest.gems_for("testing").should match_gems(
"very-simple" => ["1.0"], "rack" => ["1.0.0"])
@manifest.gems_for("production").should match_gems(
"rack" => ["1.0.0"])
end
it "can create load path files for each environment" do
tmp_gem_path('environments', 'testing.rb').should have_load_paths(tmp_gem_path,
"very-simple-1.0" => %w(bin lib),
"rack-1.0.0" => %w(bin lib)
)
tmp_gem_path('environments', 'default.rb').should have_load_paths(tmp_gem_path,
"rack-1.0.0" => %w(bin lib)
)
File.exist?(tmp_gem_path('environments', "production.rb")).should be_false
end
it "adds the environments path to the load paths" do
tmp_gem_path('environments', 'testing.rb').should have_load_paths(tmp_gem_path, [
"environments"
])
end
it "creates a rubygems.rb file in the environments directory" do
File.exist?(tmp_gem_path('environments', 'rubygems.rb')).should be_true
end
it "requires the Rubygems library" do
env = tmp_gem_path('environments', 'default.rb')
out = `#{Gem.ruby} -r #{env} -r rubygems -e 'puts Gem'`.strip
out.should == 'Gem'
end
it "removes the environments path from the load paths after rubygems is required" do
env = tmp_gem_path('environments', 'default.rb')
out = `#{Gem.ruby} -r #{env} -r rubygems -e 'puts $:'`
out.should_not include(tmp_gem_path('environments'))
end
it "Gem.loaded_specs has the gems that are included" do
env = tmp_gem_path('environments', 'default.rb')
out = `#{Gem.ruby} -r #{env} -r rubygems -e 'puts Gem.loaded_specs.map{|k,v|"\#{k} - \#{v.version}"}'`
out = out.split("\n")
out.should include("rack - 1.0.0")
end
it "Gem.loaded_specs has the gems that are included in the testing environment" do
env = tmp_gem_path('environments', 'testing.rb')
out = `#{Gem.ruby} -r #{env} -r rubygems -e 'puts Gem.loaded_specs.map{|k,v|"\#{k} - \#{v.version}"}'`
out = out.split("\n")
out.should include("rack - 1.0.0")
out.should include("very-simple - 1.0")
end
end
end
|