rubycut-babushka 0.10.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/Gemfile +8 -0
  2. data/Gemfile.lock +31 -0
  3. data/README.markdown +246 -0
  4. data/Rakefile +26 -0
  5. data/bin/babushka +11 -0
  6. data/deps/babushka.rb +101 -0
  7. data/deps/dev.rb +12 -0
  8. data/deps/fhs.rb +31 -0
  9. data/deps/git.rb +29 -0
  10. data/deps/homebrew.rb +30 -0
  11. data/deps/os_x.rb +33 -0
  12. data/deps/packages.rb +22 -0
  13. data/deps/pkg_managers.rb +110 -0
  14. data/deps/ruby.rb +23 -0
  15. data/deps/rubygems.rb +24 -0
  16. data/deps/system.rb +10 -0
  17. data/deps/templates/app.rb +68 -0
  18. data/deps/templates/external.rb +12 -0
  19. data/deps/templates/installer.rb +31 -0
  20. data/deps/templates/managed.rb +105 -0
  21. data/deps/templates/ppa.rb +24 -0
  22. data/deps/templates/src.rb +42 -0
  23. data/deps/templates/tmbundle.rb +15 -0
  24. data/lib/babushka.rb +28 -0
  25. data/lib/babushka/accepts_block_for.rb +72 -0
  26. data/lib/babushka/accepts_list_for.rb +49 -0
  27. data/lib/babushka/accepts_value_for.rb +24 -0
  28. data/lib/babushka/base.rb +78 -0
  29. data/lib/babushka/bug_reporter.rb +55 -0
  30. data/lib/babushka/cmdline.rb +133 -0
  31. data/lib/babushka/cmdline/handler.rb +41 -0
  32. data/lib/babushka/cmdline/helpers.rb +127 -0
  33. data/lib/babushka/cmdline/parser.rb +69 -0
  34. data/lib/babushka/colorizer.rb +59 -0
  35. data/lib/babushka/core_patches/array.rb +171 -0
  36. data/lib/babushka/core_patches/blank.rb +22 -0
  37. data/lib/babushka/core_patches/bytes.rb +52 -0
  38. data/lib/babushka/core_patches/hash.rb +107 -0
  39. data/lib/babushka/core_patches/hashish.rb +14 -0
  40. data/lib/babushka/core_patches/integer.rb +25 -0
  41. data/lib/babushka/core_patches/io.rb +8 -0
  42. data/lib/babushka/core_patches/numeric.rb +16 -0
  43. data/lib/babushka/core_patches/object.rb +27 -0
  44. data/lib/babushka/core_patches/string.rb +116 -0
  45. data/lib/babushka/core_patches/symbol.rb +12 -0
  46. data/lib/babushka/core_patches/try.rb +15 -0
  47. data/lib/babushka/core_patches/uri.rb +24 -0
  48. data/lib/babushka/dep.rb +470 -0
  49. data/lib/babushka/dep_context.rb +18 -0
  50. data/lib/babushka/dep_definer.rb +115 -0
  51. data/lib/babushka/dep_pool.rb +49 -0
  52. data/lib/babushka/dep_runner.rb +85 -0
  53. data/lib/babushka/dsl.rb +26 -0
  54. data/lib/babushka/git_repo.rb +185 -0
  55. data/lib/babushka/helpers/git_helpers.rb +32 -0
  56. data/lib/babushka/helpers/log_helpers.rb +176 -0
  57. data/lib/babushka/helpers/path_helpers.rb +34 -0
  58. data/lib/babushka/helpers/run_helpers.rb +145 -0
  59. data/lib/babushka/helpers/shell_helpers.rb +229 -0
  60. data/lib/babushka/helpers/suggest_helpers.rb +16 -0
  61. data/lib/babushka/helpers/uri_helpers.rb +36 -0
  62. data/lib/babushka/ip.rb +160 -0
  63. data/lib/babushka/lambda_chooser.rb +40 -0
  64. data/lib/babushka/levenshtein.rb +125 -0
  65. data/lib/babushka/meta_dep.rb +65 -0
  66. data/lib/babushka/meta_dep_context.rb +15 -0
  67. data/lib/babushka/parameter.rb +143 -0
  68. data/lib/babushka/pkg_helper.rb +81 -0
  69. data/lib/babushka/pkg_helpers/apt_helper.rb +61 -0
  70. data/lib/babushka/pkg_helpers/base_helper.rb +19 -0
  71. data/lib/babushka/pkg_helpers/binpkgsrc_helper.rb +48 -0
  72. data/lib/babushka/pkg_helpers/binports_helper.rb +34 -0
  73. data/lib/babushka/pkg_helpers/brew_helper.rb +110 -0
  74. data/lib/babushka/pkg_helpers/gem_helper.rb +120 -0
  75. data/lib/babushka/pkg_helpers/macports_helper.rb +22 -0
  76. data/lib/babushka/pkg_helpers/npm_helper.rb +45 -0
  77. data/lib/babushka/pkg_helpers/pacman_helper.rb +27 -0
  78. data/lib/babushka/pkg_helpers/pip_helper.rb +45 -0
  79. data/lib/babushka/pkg_helpers/src_helper.rb +16 -0
  80. data/lib/babushka/pkg_helpers/yum_helper.rb +25 -0
  81. data/lib/babushka/popen.rb +40 -0
  82. data/lib/babushka/prompt.rb +176 -0
  83. data/lib/babushka/renderable.rb +67 -0
  84. data/lib/babushka/resource.rb +215 -0
  85. data/lib/babushka/run_reporter.rb +60 -0
  86. data/lib/babushka/shell.rb +108 -0
  87. data/lib/babushka/source.rb +216 -0
  88. data/lib/babushka/source_pool.rb +146 -0
  89. data/lib/babushka/system_definitions.rb +97 -0
  90. data/lib/babushka/system_profile.rb +210 -0
  91. data/lib/babushka/task.rb +142 -0
  92. data/lib/babushka/vars.rb +108 -0
  93. data/lib/babushka/version_of.rb +65 -0
  94. data/lib/babushka/version_str.rb +57 -0
  95. data/lib/babushka/xml_string.rb +28 -0
  96. data/lib/components.rb +82 -0
  97. data/lib/fancypath/fancypath.rb +200 -0
  98. data/lib/inkan/inkan.rb +76 -0
  99. data/spec/acceptance/acceptance.rb +43 -0
  100. data/spec/acceptance_helper.rb +113 -0
  101. data/spec/archives/Blah.app.zip +0 -0
  102. data/spec/archives/archive.tar +0 -0
  103. data/spec/archives/archive.tar.bz2 +0 -0
  104. data/spec/archives/archive.tar.gz +0 -0
  105. data/spec/archives/archive.tbz2 +0 -0
  106. data/spec/archives/archive.tgz +0 -0
  107. data/spec/archives/archive.zip +0 -0
  108. data/spec/archives/content.txt +5 -0
  109. data/spec/archives/invalid_archive +5 -0
  110. data/spec/archives/nested archive/content.txt +5 -0
  111. data/spec/archives/nested_archive.tar +0 -0
  112. data/spec/archives/really_a_gzip.zip +0 -0
  113. data/spec/archives/test-0.3.1.tgz +0 -0
  114. data/spec/archives/tgz_archive +0 -0
  115. data/spec/archives/zip_without_extension +0 -0
  116. data/spec/babushka/accepts_for_spec.rb +174 -0
  117. data/spec/babushka/accepts_for_support.rb +72 -0
  118. data/spec/babushka/cmdline/console_spec.rb +11 -0
  119. data/spec/babushka/cmdline/help_spec.rb +61 -0
  120. data/spec/babushka/cmdline/version_spec.rb +10 -0
  121. data/spec/babushka/core_patches_spec.rb +171 -0
  122. data/spec/babushka/dep_context_spec.rb +58 -0
  123. data/spec/babushka/dep_definer_spec.rb +152 -0
  124. data/spec/babushka/dep_definer_support.rb +36 -0
  125. data/spec/babushka/dep_spec.rb +567 -0
  126. data/spec/babushka/dep_support.rb +29 -0
  127. data/spec/babushka/deps_spec.rb +113 -0
  128. data/spec/babushka/gem_helper_spec.rb +90 -0
  129. data/spec/babushka/git_repo_spec.rb +396 -0
  130. data/spec/babushka/ip_spec.rb +131 -0
  131. data/spec/babushka/lambda_chooser_spec.rb +115 -0
  132. data/spec/babushka/meta_dep_definer_spec.rb +127 -0
  133. data/spec/babushka/meta_dep_wrapper_spec.rb +32 -0
  134. data/spec/babushka/parameter_spec.rb +135 -0
  135. data/spec/babushka/path_helpers_spec.rb +102 -0
  136. data/spec/babushka/prompt_spec.rb +188 -0
  137. data/spec/babushka/renderable_spec.rb +100 -0
  138. data/spec/babushka/resource_spec.rb +141 -0
  139. data/spec/babushka/run_helpers_spec.rb +26 -0
  140. data/spec/babushka/shell_helpers_spec.rb +244 -0
  141. data/spec/babushka/shell_spec.rb +19 -0
  142. data/spec/babushka/source_pool_spec.rb +320 -0
  143. data/spec/babushka/source_pool_support.rb +31 -0
  144. data/spec/babushka/source_spec.rb +382 -0
  145. data/spec/babushka/source_support.rb +17 -0
  146. data/spec/babushka/system_profile_spec.rb +61 -0
  147. data/spec/babushka/task_spec.rb +141 -0
  148. data/spec/babushka/uri_spec.rb +13 -0
  149. data/spec/babushka/vars_spec.rb +59 -0
  150. data/spec/babushka/version_of_spec.rb +110 -0
  151. data/spec/babushka/version_str_spec.rb +130 -0
  152. data/spec/babushka/version_str_support.rb +37 -0
  153. data/spec/babushka/xml_string_spec.rb +98 -0
  154. data/spec/deps/bad/broken.rb +7 -0
  155. data/spec/deps/bad/working.rb +3 -0
  156. data/spec/deps/good/meta.rb +14 -0
  157. data/spec/deps/good/test.rb +11 -0
  158. data/spec/deps/outer/deps.rb +19 -0
  159. data/spec/deps/outer/more deps.rb +11 -0
  160. data/spec/deps/params/params.rb +10 -0
  161. data/spec/fancypath/fancypath_spec.rb +272 -0
  162. data/spec/fancypath_support.rb +10 -0
  163. data/spec/inkan/inkan_spec.rb +217 -0
  164. data/spec/renderable/different_example.conf.erb +4 -0
  165. data/spec/renderable/example.conf.erb +3 -0
  166. data/spec/renderable/example.sh +6 -0
  167. data/spec/renderable/with_binding.conf.erb +4 -0
  168. data/spec/renderable/xml_example.conf.erb +8 -0
  169. data/spec/repos/remote.git.tgz +0 -0
  170. data/spec/spec_helper.rb +87 -0
  171. metadata +238 -0
@@ -0,0 +1,31 @@
1
+ def mock_sources
2
+ @source1 = Source.new nil, :name => 'source_1'
3
+ @source2 = Source.new nil, :name => 'source_2'
4
+ [Base.sources.anonymous, Base.sources.core, @source1, @source2].each {|s| s.stub!(:load!) }
5
+ Source.stub!(:present).and_return [@source1, @source2]
6
+
7
+ Base.sources.load_context :source => Base.sources.anonymous do
8
+ @anonymous_meta = meta 'anonymous_meta'
9
+ end
10
+ Base.sources.load_context :source => Base.sources.core do
11
+ @core_meta = meta 'core_meta'
12
+ @core_from = meta 'core_from'
13
+ end
14
+ Base.sources.load_context :source => @source1 do
15
+ @meta1 = meta :meta_1
16
+ @meta2 = meta 'meta_2'
17
+ @from1 = meta 'from_test'
18
+ end
19
+ Base.sources.load_context :source => @source2 do
20
+ @meta3 = meta :meta_3
21
+ @meta4 = meta 'meta_4'
22
+ @from2 = meta 'from_test'
23
+ @from2_2 = meta 'from_test_2'
24
+ end
25
+ end
26
+
27
+ def mock_dep dep_name, opts
28
+ Base.sources.load_context :source => opts[:in] do
29
+ dep dep_name, :template => opts[:template]
30
+ end
31
+ end
@@ -0,0 +1,382 @@
1
+ require 'spec_helper'
2
+ require 'source_support'
3
+
4
+ describe Source do
5
+ before(:all) {
6
+ @remote_1 = make_source_remote 'remote_1'
7
+ @remote_2 = make_source_remote 'remote_2'
8
+ }
9
+
10
+ describe Source, "arguments" do
11
+ it "should reject non-hash options" do
12
+ L{
13
+ Source.new 'a', 'b'
14
+ }.should raise_error(ArgumentError, 'Source.new options must be passed as a hash, not as "b".')
15
+ end
16
+ end
17
+
18
+ describe Source, '.discover_uri_and_type' do
19
+ it "should label nil paths as implicit" do
20
+ Source.discover_uri_and_type(nil).should == [nil, :implicit]
21
+ end
22
+ it "should work for public uris" do
23
+ [
24
+ 'git://github.com/benhoskings/babushka-deps.git',
25
+ 'http://github.com/benhoskings/babushka-deps.git',
26
+ 'file:///Users/ben/babushka/deps'
27
+ ].each {|uri|
28
+ Source.discover_uri_and_type(uri).should == [uri, :public]
29
+ }
30
+ end
31
+ it "should work for private uris" do
32
+ [
33
+ 'git@github.com:benhoskings/babushka-deps.git',
34
+ 'benhoskin.gs:~ben/babushka-deps.git'
35
+ ].each {|uri|
36
+ Source.discover_uri_and_type(uri).should == [uri, :private]
37
+ }
38
+ end
39
+ it "should work for local paths" do
40
+ Source.discover_uri_and_type('~/.babushka/deps').should == ['~/.babushka/deps'.p, :local]
41
+ Source.discover_uri_and_type('/tmp/babushka-deps').should == ['/tmp/babushka-deps', :local]
42
+ end
43
+ end
44
+
45
+ describe Source, '#uri_matches?' do
46
+ it "should match on equivalent URIs" do
47
+ Source.new(nil).uri_matches?(nil).should be_true
48
+ Source.new('~/.babushka/deps').uri_matches?('~/.babushka/deps').should be_true
49
+ Source.new('git://github.com/benhoskings/babushka-deps.git').uri_matches?('git://github.com/benhoskings/babushka-deps.git').should be_true
50
+ Source.new('git@github.com:benhoskings/babushka-deps.git').uri_matches?('git@github.com:benhoskings/babushka-deps.git').should be_true
51
+ end
52
+ it "should not match on differing URIs" do
53
+ Source.new(nil).uri_matches?('').should be_false
54
+ Source.new('~/.babushka/deps').uri_matches?('~/.babushka/babushka-deps').should be_false
55
+ Source.new('git://github.com/benhoskings/babushka-deps.git').uri_matches?('http://github.com/benhoskings/babushka-deps.git').should be_false
56
+ Source.new('git://github.com/benhoskings/babushka-deps.git').uri_matches?('git://github.com/benhoskings/babushka-deps').should be_false
57
+ Source.new('git@github.com:benhoskings/babushka-deps.git').uri_matches?('github.com:benhoskings/babushka-deps.git').should be_false
58
+ Source.new('git@github.com:benhoskings/babushka-deps.git').uri_matches?('git@github.com:benhoskings/babushka-deps').should be_false
59
+ end
60
+ end
61
+
62
+ describe Source, '#path' do
63
+ it "should work for implicit sources" do
64
+ Source.new(nil).path.should == nil
65
+ end
66
+ it "should work for local sources" do
67
+ Source.new('~/.babushka/deps').path.should == '~/.babushka/deps'.p
68
+ end
69
+ context "cloneable repos" do
70
+ context "without names" do
71
+ it "should work for public sources" do
72
+ Source.new('git://github.com/benhoskings/babushka-deps.git').path.should == tmp_prefix / 'sources/babushka-deps'
73
+ end
74
+ it "should work for private sources" do
75
+ Source.new('git@github.com:benhoskings/babushka-deps.git').path.should == tmp_prefix / 'sources/babushka-deps'
76
+ end
77
+ end
78
+ context "with names" do
79
+ it "should work for public sources" do
80
+ Source.new('git://github.com/benhoskings/babushka-deps.git', :name => 'custom_public_deps').path.should == tmp_prefix / 'sources/custom_public_deps'
81
+ end
82
+ it "should work for private sources" do
83
+ Source.new('git@github.com:benhoskings/babushka-deps.git', :name => 'custom_private_deps').path.should == tmp_prefix / 'sources/custom_private_deps'
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "loading deps" do
90
+ context "with a good source" do
91
+ before {
92
+ @source = Source.new('spec/deps/good')
93
+ @source.load!
94
+ }
95
+ it "should load deps from a file" do
96
+ @source.deps.names.should include('test dep 1')
97
+ @source.deps.names.should include('test dep 2')
98
+ end
99
+ it "should not have defined the deps" do
100
+ dep = @source.deps.for('test dep 1')
101
+ dep.dep_defined?.should be_false
102
+ end
103
+ it "should store the source the dep was loaded from" do
104
+ @source.deps.for('test dep 1').dep_source.should == @source
105
+ end
106
+ end
107
+ context "with a source with errors" do
108
+ before {
109
+ @source = Source.new('spec/deps/bad')
110
+ @source.load!
111
+ }
112
+ it "should recover from load errors" do
113
+ @source.deps.names.should include('broken test dep 1')
114
+ @source.deps.names.should include('test dep 1')
115
+ end
116
+ end
117
+ end
118
+
119
+ describe "loading deps with parameters" do
120
+ let(:source) { Source.new('spec/deps/params').tap(&:load!) }
121
+ let(:requires) { source.deps.for('top-level dep with params').context.requires }
122
+ it "should store the right number of requirements" do
123
+ requires.length.should == 2
124
+ end
125
+ it "should store the right kinds of objects" do
126
+ requires.map(&:class).should == [String, Babushka::Dep::Requirement]
127
+ end
128
+ it "should store string requirements properly" do
129
+ requires.first.should == 'a dep without params'
130
+ end
131
+ context "requirements" do
132
+ let(:requirement) { requires.last }
133
+ it "should store the name properly" do
134
+ requirement.name.should == 'another dep with params'
135
+ end
136
+ context "arguments" do
137
+ let(:args) { requirement.args }
138
+ it "should store parameters" do
139
+ args.map(&:class).should == [Parameter]
140
+ end
141
+ it "should store the name properly" do
142
+ args.map(&:name).should == [:param]
143
+ end
144
+ end
145
+ end
146
+ end
147
+
148
+ describe "defining deps" do
149
+ before {
150
+ @source = Source.new('spec/deps/good')
151
+ @source.load!
152
+ }
153
+ context "after loading" do
154
+ before {
155
+ @dep = @source.deps.for('test dep 1')
156
+ }
157
+ it "should not have defined the deps" do
158
+ @dep.dep_defined?.should == nil
159
+ end
160
+ end
161
+ end
162
+
163
+ describe "equality" do
164
+ it "should be equal when uri, name and type are the same" do
165
+ (Source.new(*@remote_1) == Source.new(*@remote_1)).should be_true
166
+ end
167
+ it "shouldn't be equal when the name differs" do
168
+ (Source.new(*@remote_1) == Source.new(@remote_1.first, :name => 'remote_other')).should be_false
169
+ end
170
+ it "shouldn't be equal when the uri differs" do
171
+ (Source.new(*@remote_1) == Source.new(@remote_2.first, :name => 'remote_1')).should be_false
172
+ end
173
+ end
174
+
175
+ describe Source, ".for_path" do
176
+ context "on a file" do
177
+ before {
178
+ `mkdir -p "#{tmp_prefix / 'sources'}"`
179
+ `touch "#{tmp_prefix / 'sources/regular_file'}"`
180
+ }
181
+ it "should raise when called on a file" do
182
+ L{
183
+ Source.for_path(Source.source_prefix / 'regular_file')
184
+ }.should raise_error(Errno::ENOTDIR, "Not a directory - #{Source.source_prefix / 'regular_file'}")
185
+ end
186
+ end
187
+ context "on a dir" do
188
+ before {
189
+ `mkdir -p "#{tmp_prefix / 'ad_hoc_source'}"`
190
+ @source = Source.for_path(tmp_prefix / 'ad_hoc_source')
191
+ }
192
+ it "should work on a dir" do
193
+ @source.should be_present
194
+ @source.path.should == tmp_prefix / 'ad_hoc_source'
195
+ @source.name.should == 'ad_hoc_source'
196
+ end
197
+ end
198
+ context "on a git repo" do
199
+ before {
200
+ Source.new(@remote_1.first).add!
201
+ @source = Source.for_path(Source.source_prefix / 'remote_1')
202
+ }
203
+ it "should work on a git repo" do
204
+ @source.should be_present
205
+ @source.path.should == Source.source_prefix / 'remote_1'
206
+ @source.name.should == 'remote_1'
207
+ end
208
+ after { @source.remove! }
209
+ end
210
+ context "on a git repo with a custom name" do
211
+ before {
212
+ Source.new(@remote_1.first, :name => 'custom_name_test').add!
213
+ @source = Source.for_path(Source.source_prefix / 'custom_name_test')
214
+ }
215
+ it "should work on a git repo" do
216
+ @source.should be_present
217
+ @source.path.should == Source.source_prefix / 'custom_name_test'
218
+ @source.name.should == 'custom_name_test'
219
+ end
220
+ after { @source.remove! }
221
+ end
222
+ end
223
+
224
+ describe "finding" do
225
+ before {
226
+ @source = Source.new('spec/deps/good')
227
+ @source.load!
228
+ }
229
+ it "should find the specified dep" do
230
+ @source.find('test dep 1').should be_an_instance_of(Dep)
231
+ @source.deps.items.include?(@source.find('test dep 1')).should be_true
232
+ end
233
+ it "should find the specified template" do
234
+ @source.find_template('test_meta_1').should be_an_instance_of(MetaDep)
235
+ @source.templates.items.include?(@source.find_template('test_meta_1')).should be_true
236
+ end
237
+ end
238
+
239
+ describe Source, "#present?" do
240
+ context "for local repos" do
241
+ it "should be true for valid paths" do
242
+ Source.new('spec/deps/good').should be_present
243
+ end
244
+ it "should be false for invalid paths" do
245
+ Source.new('spec/deps/nonexistent').should_not be_present
246
+ end
247
+ end
248
+ context "for remote repos" do
249
+ before {
250
+ @source_1 = Source.new(*@remote_1)
251
+ @source_2 = Source.new(*@remote_2)
252
+ }
253
+ it "should be false" do
254
+ @source_1.should_not be_present
255
+ Source.present.should == []
256
+ end
257
+ context "after cloning" do
258
+ before {
259
+ @source_1.add!
260
+ }
261
+ it "should be true" do
262
+ @source_1.should be_present
263
+ Source.present.should == [@source_1]
264
+ end
265
+ after {
266
+ @source_1.remove!
267
+ }
268
+ end
269
+ end
270
+ end
271
+
272
+ describe "cloning" do
273
+ context "unreadable sources" do
274
+ before {
275
+ @source = Source.new(tmp_prefix / "nonexistent.git", :name => 'unreadable')
276
+ @source.add!
277
+ }
278
+ it "shouldn't work" do
279
+ @source.path.should_not be_exists
280
+ end
281
+ end
282
+
283
+ context "readable sources" do
284
+ before(:all) {
285
+ @source = Source.new(*@remote_1)
286
+ }
287
+ context "normally" do
288
+ it "shouldn't be present yet" do
289
+ @source.path.should_not be_exists
290
+ end
291
+ context "after adding" do
292
+ before(:all) { @source.add! }
293
+ it "should be present now" do
294
+ @source.path.should be_exists
295
+ end
296
+ it "should not be available in Base.sources" do
297
+ Base.sources.current.include?(@source).should be_false
298
+ end
299
+ it "should be cloned into the source prefix" do
300
+ @source.path.to_s.starts_with?((tmp_prefix / 'sources').p.to_s).should be_true
301
+ end
302
+ after(:all) { @source.remove! }
303
+ end
304
+ end
305
+
306
+ context "without a name" do
307
+ before(:all) {
308
+ @nameless = Source.new(@remote_1.first)
309
+ }
310
+ it "should use the basename as the name" do
311
+ File.directory?(tmp_prefix / 'sources/remote_1').should be_false
312
+ @nameless.add!
313
+ File.directory?(tmp_prefix / 'sources/remote_1').should be_true
314
+ end
315
+ it "should set the name in the source" do
316
+ @nameless.name.should == 'remote_1'
317
+ end
318
+ after(:all) { @nameless.remove! }
319
+ end
320
+ context "with a name" do
321
+ before(:all) {
322
+ @fancypath_name = 'aliased_source_test'.p.basename
323
+ @aliased = Source.new(@remote_1.first, :name => @fancypath_name)
324
+ @aliased.add!
325
+ }
326
+ it "should override the name" do
327
+ File.directory?(tmp_prefix / 'sources/aliased_source_test').should be_true
328
+ end
329
+ it "should set the name in the source" do
330
+ @aliased.name.should == 'aliased_source_test'
331
+ end
332
+ it "should stringify the name" do
333
+ @fancypath_name.should be_an_instance_of(Fancypath)
334
+ @aliased.name.should be_an_instance_of(String)
335
+ end
336
+ after(:all) { @aliased.remove! }
337
+ end
338
+ context "duplication" do
339
+ before(:all) {
340
+ @source = Source.new @remote_1.first
341
+ @source.add!
342
+ }
343
+ context "with the same name and URL" do
344
+ before {
345
+ @dup_source = Source.new(@remote_1.first, :name => 'remote_1')
346
+ }
347
+ it "should work" do
348
+ L{ @dup_source.add! }.should_not raise_error
349
+ @dup_source.should == @source
350
+ end
351
+ end
352
+ context "with the same name and different URLs" do
353
+ it "should raise an exception and not add anything" do
354
+ @dup_source = Source.new(@remote_2.first, :name => 'remote_1')
355
+ L{
356
+ @dup_source.add!
357
+ }.should raise_error(SourceError, "There is already a source called '#{@source.name}' (it contains #{@source.uri}).")
358
+ end
359
+ end
360
+ context "with the same URL and different names" do
361
+ it "should raise an exception and not add anything" do
362
+ @dup_source = Source.new(@remote_1.first, :name => 'duplicate_test_different_name')
363
+ L{
364
+ @dup_source.add!
365
+ }.should raise_error(SourceError, "The source #{@source.uri} is already present (as '#{@source.name}').")
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
371
+
372
+ describe "classification" do
373
+ it "should treat file:// as public" do
374
+ (source = Source.new(*@remote_1)).add!
375
+ [source.uri, source.name, source.type].should == [@remote_1.first, 'remote_1', :public]
376
+ end
377
+ it "should treat local paths as local" do
378
+ (source = Source.new(@remote_1.first.gsub(/^file:\/\//, ''), @remote_1.last)).add!
379
+ [source.uri, source.name, source.type].should == [@remote_1.first.gsub(/^file:\/\//, ''), 'remote_1', :local]
380
+ end
381
+ end
382
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ def make_source_remote name = 'test'
4
+ ["file://#{tmp_prefix / 'source_remotes' / name}", {:name => name}].tap {|source|
5
+ source_path = source.first.gsub(/^file:\/\//, '')
6
+ unless File.exists? source_path / '.git'
7
+ shell %Q{
8
+ mkdir -p "#{source_path}" &&
9
+ cd "#{source_path}" &&
10
+ git init &&
11
+ echo 'dep "#{name}" do end' > '#{name}.rb' &&
12
+ git add . &&
13
+ git commit -m "committed during test run"
14
+ }
15
+ end
16
+ }
17
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Babushka::SystemProfile, '.for_host' do
4
+ it "should return OSXSystemProfile on Darwin boxes" do
5
+ Babushka::SystemProfile.should_receive(:shell).with("uname -s").and_return("Darwin")
6
+ Babushka::SystemProfile.for_host.should be_an_instance_of(Babushka::OSXSystemProfile)
7
+ end
8
+ it "should return nil on unknown boxes" do
9
+ Babushka::SystemProfile.should_receive(:shell).with("uname -s").and_return("LolOS")
10
+ Babushka::SystemProfile.for_host.should be_nil
11
+ end
12
+ context "on BSD boxes" do
13
+ it "should return DragonFlySystemProfile on Dragonfly boxes" do
14
+ Babushka::SystemProfile.should_receive(:shell).with("uname -s").and_return("DragonFly")
15
+ Babushka::SystemProfile.for_host.should be_an_instance_of(Babushka::DragonFlySystemProfile)
16
+ end
17
+ it "should return FreeBSDSystemProfile on FreeBSD boxes" do
18
+ Babushka::SystemProfile.should_receive(:shell).with("uname -s").and_return("FreeBSD")
19
+ Babushka::SystemProfile.for_host.should be_an_instance_of(Babushka::FreeBSDSystemProfile)
20
+ end
21
+ end
22
+ context "on Linux boxes" do
23
+ before {
24
+ Babushka::SystemProfile.should_receive(:shell).with("uname -s").and_return("Linux")
25
+ File.stub!(:exists?).and_return(false)
26
+ }
27
+ it "should return DebianSystemProfile on Debian boxes" do
28
+ File.should_receive(:exists?).with("/etc/debian_version").and_return(true)
29
+ Babushka::AptHelper.stub!(:install!) # so an `lsb_release` install isn't attempted
30
+ Babushka::SystemProfile.for_host.should be_an_instance_of(Babushka::DebianSystemProfile)
31
+ end
32
+ it "should return RedhatSystemProfile on Red Hat boxes" do
33
+ File.should_receive(:exists?).with("/etc/redhat-release").and_return(true)
34
+ Babushka::SystemProfile.for_host.should be_an_instance_of(Babushka::RedhatSystemProfile)
35
+ end
36
+ it "should return LinuxSystemProfile on unknown Linux boxes" do
37
+ Babushka::SystemProfile.for_host.class.should == Babushka::LinuxSystemProfile
38
+ end
39
+ it "should return a proper description on unknown Linux boxes" do
40
+ Babushka::SystemProfile.for_host.description.should == "Linux unknown"
41
+ end
42
+ context "version matching" do
43
+ before {
44
+ File.should_receive(:exists?).with("/etc/debian_version").and_return(true)
45
+ @profile = Babushka::SystemProfile.for_host
46
+ @profile.should_receive(:ensure_lsb_release).and_return(true)
47
+ @profile.should_receive(:shell).with("lsb_release -a").and_return(%Q{
48
+ No LSB modules are available.
49
+ Distributor ID: Debian
50
+ Description: Debian GNU/Linux 6.0.1 (squeeze)
51
+ Release: 6.0.1
52
+ Codename: squeeze
53
+ }.strip)
54
+ }
55
+ it "should detect debian squeeze" do
56
+ @profile.match_list.should == [:squeeze, :debian, :apt, :linux, :all]
57
+ @profile.version.should == '6.0.1'
58
+ end
59
+ end
60
+ end
61
+ end