fig 2.0.0.pre.alpha.3 → 2.0.0.pre.alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fig/application_configuration.rb +2 -1
- data/lib/fig/command/options/parser.rb +4 -2
- data/lib/fig/command/options.rb +1 -1
- data/lib/fig/command.rb +17 -8
- data/lib/fig/figrc.rb +41 -14
- data/lib/fig/protocol/file.rb +3 -1
- data/lib/fig/protocol/ftp.rb +5 -5
- data/lib/fig/repository.rb +15 -11
- data/lib/fig/spec_utils.rb +312 -0
- data/lib/fig/url_access_disallowed_error.rb +5 -0
- data/lib/fig/version.rb +1 -1
- data/spec/application_configuration_spec.rb +73 -0
- data/spec/command/clean_spec.rb +62 -0
- data/spec/command/command_line_vs_package_spec.rb +32 -0
- data/spec/command/dump_package_definition_spec.rb +104 -0
- data/spec/command/environment_variables_spec.rb +62 -0
- data/spec/command/grammar_asset_spec.rb +391 -0
- data/spec/command/grammar_command_spec.rb +88 -0
- data/spec/command/grammar_environment_variable_spec.rb +384 -0
- data/spec/command/grammar_retrieve_spec.rb +74 -0
- data/spec/command/grammar_spec.rb +87 -0
- data/spec/command/grammar_spec_helper.rb +23 -0
- data/spec/command/include_file_spec.rb +73 -0
- data/spec/command/listing_spec.rb +1574 -0
- data/spec/command/miscellaneous_spec.rb +145 -0
- data/spec/command/publish_local_and_updates_spec.rb +32 -0
- data/spec/command/publishing_retrieval_spec.rb +423 -0
- data/spec/command/publishing_spec.rb +596 -0
- data/spec/command/running_commands_spec.rb +354 -0
- data/spec/command/suppress_includes_spec.rb +65 -0
- data/spec/command/suppress_warning_include_statement_missing_version_spec.rb +134 -0
- data/spec/command/update_lock_response_spec.rb +47 -0
- data/spec/command/usage_errors_spec.rb +481 -0
- data/spec/command_options_spec.rb +184 -0
- data/spec/command_spec.rb +49 -0
- data/spec/deparser/v1_spec.rb +64 -0
- data/spec/environment_variables_spec.rb +91 -0
- data/spec/figrc_spec.rb +144 -0
- data/spec/parser_spec.rb +398 -0
- data/spec/repository_spec.rb +117 -0
- data/spec/runtime_environment_spec.rb +357 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/split_repo_url_spec.rb +190 -0
- data/spec/statement/asset_spec.rb +203 -0
- data/spec/statement/configuration_spec.rb +41 -0
- data/spec/support/formatters/seed_spitter.rb +12 -0
- data/spec/working_directory_maintainer_spec.rb +102 -0
- metadata +58 -7
@@ -0,0 +1,481 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
4
|
+
|
5
|
+
require 'English'
|
6
|
+
|
7
|
+
require 'fig/command/package_loader'
|
8
|
+
|
9
|
+
describe 'Fig' do
|
10
|
+
describe 'usage errors: fig' do
|
11
|
+
before(:each) do
|
12
|
+
clean_up_test_environment
|
13
|
+
set_up_test_environment
|
14
|
+
end
|
15
|
+
|
16
|
+
it %q<prints usage message when passed an unknown option> do
|
17
|
+
out, err, exit_code =
|
18
|
+
fig %w<--no-such-option>, :fork => false, :no_raise_on_error => true
|
19
|
+
exit_code.should_not == 0
|
20
|
+
err.should =~ / --no-such-option /x
|
21
|
+
err.should =~ / usage /xi
|
22
|
+
out.should == ''
|
23
|
+
end
|
24
|
+
|
25
|
+
describe %q<prints message when no descriptor is specified and> do
|
26
|
+
describe %q<there's nothing to do and> do
|
27
|
+
it %q<there isn't a package.fig file> do
|
28
|
+
out, err, exit_code =
|
29
|
+
fig [], :fork => false, :no_raise_on_error => true
|
30
|
+
exit_code.should_not == 0
|
31
|
+
err.should =~ /nothing to do/i
|
32
|
+
out.should == ''
|
33
|
+
end
|
34
|
+
|
35
|
+
describe %q<there is a package.fig file> do
|
36
|
+
it %q<with no command statement> do
|
37
|
+
IO.write(
|
38
|
+
"#{FIG_SPEC_BASE_DIRECTORY}/#{Fig::Command::PackageLoader::DEFAULT_PACKAGE_FILE}",
|
39
|
+
<<-END_PACKAGE_DOT_FIG
|
40
|
+
config default
|
41
|
+
end
|
42
|
+
END_PACKAGE_DOT_FIG
|
43
|
+
)
|
44
|
+
|
45
|
+
out, err, exit_code =
|
46
|
+
fig [], :fork => false, :no_raise_on_error => true
|
47
|
+
exit_code.should_not == 0
|
48
|
+
err.should =~ /nothing to do/i
|
49
|
+
out.should == ''
|
50
|
+
end
|
51
|
+
|
52
|
+
it %q<with a command statement> do
|
53
|
+
IO.write(
|
54
|
+
"#{FIG_SPEC_BASE_DIRECTORY}/#{Fig::Command::PackageLoader::DEFAULT_PACKAGE_FILE}",
|
55
|
+
<<-END_PACKAGE_DOT_FIG
|
56
|
+
config default
|
57
|
+
command "echo foo"
|
58
|
+
end
|
59
|
+
END_PACKAGE_DOT_FIG
|
60
|
+
)
|
61
|
+
|
62
|
+
out, err, exit_code =
|
63
|
+
fig [], :fork => false, :no_raise_on_error => true
|
64
|
+
exit_code.should_not == 0
|
65
|
+
err.should =~ /nothing to do/i
|
66
|
+
out.should == ''
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it %q<prints error when extra parameters are given with a package descriptor> do
|
73
|
+
out, err, exit_code = fig(
|
74
|
+
%w<package/descriptor extra bits>,
|
75
|
+
:fork => false,
|
76
|
+
:no_raise_on_error => true
|
77
|
+
)
|
78
|
+
exit_code.should == 1
|
79
|
+
err.should =~ / extra /xi
|
80
|
+
err.should =~ / bits /xi
|
81
|
+
out.should == ''
|
82
|
+
end
|
83
|
+
|
84
|
+
it %q<prints error when a package descriptor consists solely of a version> do
|
85
|
+
out, err, exit_code =
|
86
|
+
fig %w</version>, :fork => false, :no_raise_on_error => true
|
87
|
+
exit_code.should == 1
|
88
|
+
err.should =~ /package name required/i
|
89
|
+
out.should == ''
|
90
|
+
end
|
91
|
+
|
92
|
+
it %q<prints error when a package descriptor consists solely of a config> do
|
93
|
+
out, err, exit_code =
|
94
|
+
fig %w<:config>, :fork => false, :no_raise_on_error => true
|
95
|
+
exit_code.should_not == 0
|
96
|
+
err.should =~ /package name required/i
|
97
|
+
out.should == ''
|
98
|
+
end
|
99
|
+
|
100
|
+
it %q<prints error when a package descriptor consists solely of a package> do
|
101
|
+
out, err, exit_code =
|
102
|
+
fig %w<package>, :fork => false, :no_raise_on_error => true
|
103
|
+
exit_code.should_not == 0
|
104
|
+
err.should =~ /version required/i
|
105
|
+
out.should == ''
|
106
|
+
end
|
107
|
+
|
108
|
+
it %q<prints error when a descriptor and --file is specified> do
|
109
|
+
out, err, exit_code = fig(
|
110
|
+
%w<package/version:default --file some.fig>,
|
111
|
+
:fork => false,
|
112
|
+
:no_raise_on_error => true
|
113
|
+
)
|
114
|
+
exit_code.should_not == 0
|
115
|
+
err.should =~ /cannot specify both a package descriptor.*and the --file option/i
|
116
|
+
out.should == ''
|
117
|
+
end
|
118
|
+
|
119
|
+
it %q<prints error when a descriptor contains a config and --config is specified> do
|
120
|
+
out, err, exit_code = fig(
|
121
|
+
%w<package/version:default --config nondefault>,
|
122
|
+
:fork => false,
|
123
|
+
:no_raise_on_error => true
|
124
|
+
)
|
125
|
+
exit_code.should_not == 0
|
126
|
+
err.should =~ /Cannot specify both --config and a config in the descriptor/
|
127
|
+
out.should == ''
|
128
|
+
end
|
129
|
+
|
130
|
+
it %q<prints error when extra parameters are given with a command> do
|
131
|
+
out, err, exit_code = fig(
|
132
|
+
%w<extra bits -- echo foo>,
|
133
|
+
:fork => false,
|
134
|
+
:no_raise_on_error => true
|
135
|
+
)
|
136
|
+
exit_code.should_not == 0
|
137
|
+
err.should =~ / extra /xi
|
138
|
+
err.should =~ / bits /xi
|
139
|
+
out.should == ''
|
140
|
+
end
|
141
|
+
|
142
|
+
it %q<prints error when multiple --list-* options are given> do
|
143
|
+
out, err, exit_code = fig(
|
144
|
+
%w<--list-remote --list-variables>,
|
145
|
+
:fork => false,
|
146
|
+
:no_raise_on_error => true
|
147
|
+
)
|
148
|
+
exit_code.should_not == 0
|
149
|
+
out.should == ''
|
150
|
+
|
151
|
+
err.should =~ /cannot specify/i
|
152
|
+
end
|
153
|
+
|
154
|
+
describe %q<prints error when unknown package is referenced> do
|
155
|
+
it %q<without --update> do
|
156
|
+
out, err, exit_code = fig(
|
157
|
+
%w<no-such-package/version --get PATH>,
|
158
|
+
:fork => false,
|
159
|
+
:no_raise_on_error => true
|
160
|
+
)
|
161
|
+
exit_code.should_not == 0
|
162
|
+
err.should =~ / no-such-package /x
|
163
|
+
out.should == ''
|
164
|
+
end
|
165
|
+
|
166
|
+
it %q<with --update> do
|
167
|
+
out, err, exit_code = fig(
|
168
|
+
%w<no-such-package/version --update --get PATH>,
|
169
|
+
:fork => false,
|
170
|
+
:no_raise_on_error => true
|
171
|
+
)
|
172
|
+
exit_code.should_not == 0
|
173
|
+
err.should =~ / no-such-package /x
|
174
|
+
out.should == ''
|
175
|
+
end
|
176
|
+
|
177
|
+
it %q<with --update-if-missing> do
|
178
|
+
out, err, exit_code = fig(
|
179
|
+
%w<no-such-package/version --update-if-missing --get PATH>,
|
180
|
+
:fork => false,
|
181
|
+
:no_raise_on_error => true
|
182
|
+
)
|
183
|
+
exit_code.should_not == 0
|
184
|
+
err.should =~ / no-such-package /x
|
185
|
+
out.should == ''
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe %q<prints error when referring to non-existent configuration> do
|
190
|
+
it %q<from the command-line as the base package> do
|
191
|
+
fig %w<--publish foo/1.2.3 --set FOO=BAR>, :fork => false
|
192
|
+
out, err, exit_code = fig(
|
193
|
+
%w<foo/1.2.3:non-existent-config --get FOO>,
|
194
|
+
:fork => false,
|
195
|
+
:no_raise_on_error => true
|
196
|
+
)
|
197
|
+
exit_code.should_not == 0
|
198
|
+
err.should =~ %r< non-existent-config >x
|
199
|
+
out.should == ''
|
200
|
+
end
|
201
|
+
|
202
|
+
it %q<from the command-line as an included package> do
|
203
|
+
fig %w<--publish foo/1.2.3 --set FOO=BAR>, :fork => false
|
204
|
+
out, err, exit_code = fig(
|
205
|
+
%w<--include foo/1.2.3:non-existent-config --get FOO>,
|
206
|
+
:fork => false,
|
207
|
+
:no_raise_on_error => true
|
208
|
+
)
|
209
|
+
exit_code.should_not == 0
|
210
|
+
err.should =~ %r< foo/1\.2\.3:non-existent-config >x
|
211
|
+
out.should == ''
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
it %q<prints error when --include is specified without a package version> do
|
216
|
+
out, err, exit_code = fig(
|
217
|
+
%w<--include package-without-version --get FOO>,
|
218
|
+
:fork => false,
|
219
|
+
:no_raise_on_error => true
|
220
|
+
)
|
221
|
+
exit_code.should_not == 0
|
222
|
+
err.should =~ %r< package-without-version >x
|
223
|
+
err.should =~ %r<no version specified>i
|
224
|
+
out.should == ''
|
225
|
+
end
|
226
|
+
|
227
|
+
it %q<prints error when --override is specified without a package version> do
|
228
|
+
out, err, exit_code = fig(
|
229
|
+
%w<--override package-without-version>,
|
230
|
+
:fork => false,
|
231
|
+
:no_raise_on_error => true
|
232
|
+
)
|
233
|
+
exit_code.should_not == 0
|
234
|
+
err.should =~ %r< package-without-version >x
|
235
|
+
err.should =~ %r<version required>i
|
236
|
+
out.should == ''
|
237
|
+
end
|
238
|
+
|
239
|
+
it %q<prints error when --override is specified with a package config> do
|
240
|
+
out, err, exit_code = fig(
|
241
|
+
%w<--override package/version:config-should-not-be-here>,
|
242
|
+
:fork => false,
|
243
|
+
:no_raise_on_error => true
|
244
|
+
)
|
245
|
+
exit_code.should_not == 0
|
246
|
+
err.should =~ %r< package/version:config-should-not-be-here >x
|
247
|
+
err.should =~ %r<config forbidden>i
|
248
|
+
out.should == ''
|
249
|
+
end
|
250
|
+
|
251
|
+
it %q<prints error when --publish-comment is specified when not publishing> do
|
252
|
+
out, err, exit_code = fig(
|
253
|
+
%w<--publish-comment whatever>,
|
254
|
+
:fork => false,
|
255
|
+
:no_raise_on_error => true
|
256
|
+
)
|
257
|
+
exit_code.should_not == 0
|
258
|
+
err.should =~ %r<cannot use --publish-comment when not publishing>i
|
259
|
+
out.should == ''
|
260
|
+
end
|
261
|
+
|
262
|
+
it %q<prints error when --publish-comment-file is specified when not publishing> do
|
263
|
+
out, err, exit_code = fig(
|
264
|
+
%w<--publish-comment-file whatever>,
|
265
|
+
:fork => false,
|
266
|
+
:no_raise_on_error => true
|
267
|
+
)
|
268
|
+
exit_code.should_not == 0
|
269
|
+
err.should =~ %r<cannot use --publish-comment-file when not publishing>i
|
270
|
+
out.should == ''
|
271
|
+
end
|
272
|
+
|
273
|
+
describe %q<refuses to publish> do
|
274
|
+
it %q<a package named "_meta"> do
|
275
|
+
out, err, exit_code =
|
276
|
+
fig(
|
277
|
+
%w<--publish _meta/version --set FOO=BAR>,
|
278
|
+
:fork => false,
|
279
|
+
:no_raise_on_error => true
|
280
|
+
)
|
281
|
+
err.should =~ %r< cannot .* _meta >x
|
282
|
+
exit_code.should_not == 0
|
283
|
+
out.should == ''
|
284
|
+
end
|
285
|
+
|
286
|
+
it %q<without a package name> do
|
287
|
+
out, err, exit_code = fig(
|
288
|
+
%w<--publish --set FOO=BAR>,
|
289
|
+
:fork => false,
|
290
|
+
:no_raise_on_error => true
|
291
|
+
)
|
292
|
+
exit_code.should_not == 0
|
293
|
+
err.should =~ %r<specify a descriptor>i
|
294
|
+
out.should == ''
|
295
|
+
end
|
296
|
+
|
297
|
+
it %q<without a version> do
|
298
|
+
out, err, exit_code = fig(
|
299
|
+
%w<--publish a-package --set FOO=BAR>,
|
300
|
+
:fork => false,
|
301
|
+
:no_raise_on_error => true
|
302
|
+
)
|
303
|
+
exit_code.should_not == 0
|
304
|
+
err.should =~ %r<version required>i
|
305
|
+
out.should == ''
|
306
|
+
end
|
307
|
+
|
308
|
+
it %q<when given the --include-file option> do
|
309
|
+
IO.write "#{CURRENT_DIRECTORY}/thingy.fig", 'config default end'
|
310
|
+
|
311
|
+
out, err, exit_code = fig(
|
312
|
+
[
|
313
|
+
'--publish',
|
314
|
+
'package/version',
|
315
|
+
'--include-file',
|
316
|
+
"'#{CURRENT_DIRECTORY}/thingy.fig'",
|
317
|
+
],
|
318
|
+
:fork => false,
|
319
|
+
:no_raise_on_error => true
|
320
|
+
)
|
321
|
+
err.should =~ %r< cannot .* include-file >ix
|
322
|
+
exit_code.should_not == 0
|
323
|
+
out.should == ''
|
324
|
+
end
|
325
|
+
|
326
|
+
it %q<a package with an include-file statement> do
|
327
|
+
IO.write "#{CURRENT_DIRECTORY}/thingy.fig", 'config default end'
|
328
|
+
|
329
|
+
input = <<-END
|
330
|
+
grammar v2
|
331
|
+
config default
|
332
|
+
include-file '#{CURRENT_DIRECTORY}/thingy.fig'
|
333
|
+
end
|
334
|
+
END
|
335
|
+
|
336
|
+
out, err, exit_code = fig(
|
337
|
+
%w<--publish package/version>,
|
338
|
+
input,
|
339
|
+
:fork => false,
|
340
|
+
:no_raise_on_error => true
|
341
|
+
)
|
342
|
+
err.should =~ %r< cannot .* include-file >ix
|
343
|
+
exit_code.should_not == 0
|
344
|
+
out.should == ''
|
345
|
+
end
|
346
|
+
|
347
|
+
it %q<a package with an archive of unknown type> do
|
348
|
+
archive_file = 'unknown.archive-type'
|
349
|
+
IO.write "#{CURRENT_DIRECTORY}/#{archive_file}", ''
|
350
|
+
|
351
|
+
input = <<-END
|
352
|
+
grammar v0
|
353
|
+
|
354
|
+
archive #{archive_file}
|
355
|
+
|
356
|
+
config default
|
357
|
+
end
|
358
|
+
END
|
359
|
+
|
360
|
+
out, err, exit_code = fig(
|
361
|
+
%w<--publish package/version>,
|
362
|
+
input,
|
363
|
+
:fork => false,
|
364
|
+
:no_raise_on_error => true
|
365
|
+
)
|
366
|
+
|
367
|
+
err.should =~ %r< \b #{ Regexp.escape(archive_file) } \b >ix
|
368
|
+
err.should =~ %r< \b unknown [ ] archive [ ] type \b >ix
|
369
|
+
|
370
|
+
exit_code.should_not == 0
|
371
|
+
out.should == ''
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
it %q<complains about command-line substitution of unreferenced packages> do
|
376
|
+
fig %w<--publish a-package/a-version --set FOO=BAR>, :fork => false
|
377
|
+
out, err, exit_code =
|
378
|
+
fig %w<-- echo @a-package>, :fork => false, :no_raise_on_error => true
|
379
|
+
exit_code.should_not == 0
|
380
|
+
err.should =~ %r<\ba-package\b.*has not been referenced>
|
381
|
+
out.should == ''
|
382
|
+
end
|
383
|
+
|
384
|
+
%w< --archive --resource >.each do
|
385
|
+
|option|
|
386
|
+
|
387
|
+
it %Q<warns about #{option} when not publishing> do
|
388
|
+
out, err =
|
389
|
+
fig ['--get', 'some_variable', option, 'some-asset'], :fork => false
|
390
|
+
err.should =~ /#{option}/
|
391
|
+
err.should =~ /\bsome-asset\b/
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
describe %q<prints error when attempting a remote operation and required URLs are missing or invalid> do
|
396
|
+
it %q<FIG_DOWNLOAD_URL not defined> do
|
397
|
+
begin
|
398
|
+
# Make sure all URL env vars are unset
|
399
|
+
ENV.delete('FIG_REMOTE_URL')
|
400
|
+
ENV.delete('FIG_DOWNLOAD_URL')
|
401
|
+
ENV.delete('FIG_UPLOAD_URL')
|
402
|
+
|
403
|
+
out, err, exit_code =
|
404
|
+
fig %w<--list-remote>, :fork => false, :no_raise_on_error => true
|
405
|
+
|
406
|
+
# Error should mention the missing FIG_DOWNLOAD_URL
|
407
|
+
err.should =~ %r<FIG_DOWNLOAD_URL>
|
408
|
+
out.should == ''
|
409
|
+
exit_code.should_not == 0
|
410
|
+
ensure
|
411
|
+
# Restore default test configuration
|
412
|
+
ENV['FIG_DOWNLOAD_URL'] = FIG_DOWNLOAD_URL
|
413
|
+
ENV['FIG_UPLOAD_URL'] = FIG_UPLOAD_URL
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
it %q<FIG_DOWNLOAD_URL empty> do
|
418
|
+
begin
|
419
|
+
# Clear all URLs, but set download to empty
|
420
|
+
ENV.delete('FIG_REMOTE_URL')
|
421
|
+
ENV['FIG_DOWNLOAD_URL'] = ''
|
422
|
+
ENV.delete('FIG_UPLOAD_URL')
|
423
|
+
|
424
|
+
out, err, exit_code =
|
425
|
+
fig %w<--list-remote>, :fork => false, :no_raise_on_error => true
|
426
|
+
|
427
|
+
err.should =~ %r<FIG_DOWNLOAD_URL>
|
428
|
+
out.should == ''
|
429
|
+
exit_code.should_not == 0
|
430
|
+
ensure
|
431
|
+
# Restore default test configuration
|
432
|
+
ENV['FIG_DOWNLOAD_URL'] = FIG_DOWNLOAD_URL
|
433
|
+
ENV['FIG_UPLOAD_URL'] = FIG_UPLOAD_URL
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
it %q<FIG_DOWNLOAD_URL all whitespace> do
|
438
|
+
begin
|
439
|
+
# Clear all URLs, but set download to whitespace
|
440
|
+
ENV.delete('FIG_REMOTE_URL')
|
441
|
+
ENV['FIG_DOWNLOAD_URL'] = " \n\t"
|
442
|
+
ENV.delete('FIG_UPLOAD_URL')
|
443
|
+
|
444
|
+
out, err, exit_code =
|
445
|
+
fig %w<--list-remote>, :fork => false, :no_raise_on_error => true
|
446
|
+
|
447
|
+
# With whitespace URLs, error is about bad URI format
|
448
|
+
err.should =~ %r<FIG_DOWNLOAD_URL>
|
449
|
+
out.should == ''
|
450
|
+
exit_code.should_not == 0
|
451
|
+
ensure
|
452
|
+
# Restore default test configuration
|
453
|
+
ENV['FIG_DOWNLOAD_URL'] = FIG_DOWNLOAD_URL
|
454
|
+
ENV['FIG_UPLOAD_URL'] = FIG_UPLOAD_URL
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
it %q<FIG_REMOTE_URL set but new URLs missing> do
|
459
|
+
begin
|
460
|
+
# Set remote URL but not the new ones
|
461
|
+
ENV['FIG_REMOTE_URL'] = "file:///some/path"
|
462
|
+
ENV.delete('FIG_DOWNLOAD_URL')
|
463
|
+
ENV.delete('FIG_UPLOAD_URL')
|
464
|
+
|
465
|
+
out, err, exit_code =
|
466
|
+
fig %w<--list-remote>, :fork => false, :no_raise_on_error => true
|
467
|
+
|
468
|
+
# Error should mention both old and new URLs
|
469
|
+
err.should =~ %r<FIG_REMOTE_URL is set but FIG_DOWNLOAD_URL and\/or FIG_UPLOAD_URL are missing>
|
470
|
+
out.should == ''
|
471
|
+
exit_code.should_not == 0
|
472
|
+
ensure
|
473
|
+
# Restore default test configuration
|
474
|
+
ENV.delete('FIG_REMOTE_URL')
|
475
|
+
ENV['FIG_DOWNLOAD_URL'] = FIG_DOWNLOAD_URL
|
476
|
+
ENV['FIG_UPLOAD_URL'] = FIG_UPLOAD_URL
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
+
|
5
|
+
require 'fig/command/option_error'
|
6
|
+
require 'fig/command/options'
|
7
|
+
|
8
|
+
def new_options(argv)
|
9
|
+
options = Fig::Command::Options.new()
|
10
|
+
options.process_command_line(argv)
|
11
|
+
|
12
|
+
return options
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_environment_variable_option(option_name)
|
16
|
+
it 'complains if there is no variable name' do
|
17
|
+
expect_invalid_value_error(option_name, '=whatever')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'accepts a simple variable value' do
|
21
|
+
new_options(["--#{option_name}", 'variable=value'])
|
22
|
+
# no exception
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'complains if there are unbalanced single quotes' do
|
26
|
+
expect_invalid_value_error(option_name, %q<'>)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'allows a variable value containing an escaped single quote' do
|
30
|
+
new_options( ["--#{option_name}", %q<variable=\'>] )
|
31
|
+
# no exception
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'complains if there are unbalanced double quotes' do
|
35
|
+
expect_invalid_value_error(option_name, %q<">)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'allows a variable value containing an escaped double quote' do
|
39
|
+
new_options( ["--#{option_name}", %q<variable=\">] )
|
40
|
+
# no exception
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'allows a variable value containing a space character' do
|
44
|
+
new_options( ["--#{option_name}", 'variable= stuff'] )
|
45
|
+
# no exception
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'allows a variable value containing an octothorpe' do
|
49
|
+
new_options( ["--#{option_name}", 'variable=red#green#blue'] )
|
50
|
+
# no exception
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'Command::Options' do
|
55
|
+
def expect_invalid_value_error(option_name, value)
|
56
|
+
expect { new_options(["--#{option_name}", value]) }.to raise_error(
|
57
|
+
Fig::Command::OptionError,
|
58
|
+
%r<\AInvalid value for --#{option_name}: "#{Regexp.quote(value)}">
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
describe %q<complains if a value isn't given to> do
|
63
|
+
[
|
64
|
+
%w< get >, # Queries
|
65
|
+
%w< set add append include override >, # Environment
|
66
|
+
%w< archive resource >, # Package contents
|
67
|
+
%w< file config log-level figrc > # Configuration
|
68
|
+
].flatten.each do
|
69
|
+
|option_name|
|
70
|
+
|
71
|
+
describe "--#{option_name}" do
|
72
|
+
it 'when it is the last option on the command-line' do
|
73
|
+
expect { new_options(["--#{option_name}"]) }.to raise_error(
|
74
|
+
Fig::Command::OptionError,
|
75
|
+
"Please provide a value for --#{option_name}."
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'when it is followed by' do
|
80
|
+
# One long option example and one short option example.
|
81
|
+
%w< --version -c >.each do
|
82
|
+
|following_option|
|
83
|
+
|
84
|
+
it following_option do
|
85
|
+
expect {
|
86
|
+
new_options( ["--#{option_name}", following_option])
|
87
|
+
}.to raise_error(
|
88
|
+
Fig::Command::OptionError,
|
89
|
+
"Please provide a value for --#{option_name}."
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '--file' do
|
99
|
+
{
|
100
|
+
'a' => 'a single character',
|
101
|
+
'x-' => 'a name without a hyphen at the front',
|
102
|
+
'-' => 'the stdin indicator'
|
103
|
+
}.each do
|
104
|
+
|option_value, description|
|
105
|
+
|
106
|
+
it %Q<allows #{description} ("#{option_value}") as a value> do
|
107
|
+
options = new_options(['--file', option_value])
|
108
|
+
options.package_definition_file.should == option_value
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '--set' do
|
114
|
+
check_environment_variable_option('set')
|
115
|
+
|
116
|
+
it 'allows the absence of an equals sign' do
|
117
|
+
new_options(%w< --set whatever >)
|
118
|
+
# no exception
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'allows an empty value' do
|
122
|
+
new_options(%w< --set whatever= >)
|
123
|
+
# no exception
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
%w< append add >.each do
|
128
|
+
|option_name|
|
129
|
+
|
130
|
+
describe "--#{option_name}" do
|
131
|
+
check_environment_variable_option(option_name)
|
132
|
+
|
133
|
+
it 'complains if there is no variable value' do
|
134
|
+
expect_invalid_value_error(option_name, 'whatever=')
|
135
|
+
end
|
136
|
+
|
137
|
+
%w[ ; : < > | ].each do
|
138
|
+
|character|
|
139
|
+
|
140
|
+
# Need to check this because they are not allowed in the v0 grammar.
|
141
|
+
it %Q<allows a variable value containing "#{character}"> do
|
142
|
+
new_options( ["--#{option_name}", "variable=#{character}"] )
|
143
|
+
# no exception
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
%w< archive resource >.each do
|
150
|
+
|asset_type|
|
151
|
+
|
152
|
+
describe "--#{asset_type}" do
|
153
|
+
it 'complains if there is no value' do
|
154
|
+
expect_invalid_value_error(asset_type, '')
|
155
|
+
end
|
156
|
+
|
157
|
+
%w[ " ' ].each do
|
158
|
+
|character|
|
159
|
+
|
160
|
+
it %Q<complains about a value containing unbalanced «#{character}»> do
|
161
|
+
expect_invalid_value_error(asset_type, character)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "accepts a value quoted by «#{character}»" do
|
165
|
+
new_options(["--#{asset_type}", "#{character}x#{character}"])
|
166
|
+
# no exception
|
167
|
+
end
|
168
|
+
|
169
|
+
it "accepts a value with an escaped «#{character}»" do
|
170
|
+
new_options(["--#{asset_type}", "x\\#{character}x"])
|
171
|
+
# no exception
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Just to check that people don't think that "@" is a special character
|
176
|
+
# here.
|
177
|
+
it %Q<complains about a value containing escaped «@»> do
|
178
|
+
expect_invalid_value_error(asset_type, '\\@')
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# vim: set fileencoding=utf8 :
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
+
|
5
|
+
require 'fig/command'
|
6
|
+
require 'fig/package_descriptor'
|
7
|
+
|
8
|
+
describe 'Command (in-process, instead of external program)' do
|
9
|
+
before(:each) do
|
10
|
+
clean_up_test_environment
|
11
|
+
set_up_test_environment
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'accepts post set-up action and ensures that it is invoked' do
|
15
|
+
command = Fig::Command.new
|
16
|
+
|
17
|
+
action = double('post set-up action')
|
18
|
+
action.should_receive(:set_up_finished)
|
19
|
+
|
20
|
+
command.add_post_set_up_action(action)
|
21
|
+
|
22
|
+
command.run_fig(
|
23
|
+
%w<--log-level off --set VARIABLE=VALUE --get UNDEFINED_VARIABLE>
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'accepts publish listener and ensures that it is invoked' do
|
28
|
+
command = Fig::Command.new
|
29
|
+
|
30
|
+
listener = double('publish listener')
|
31
|
+
listener.should_receive(:published).with(
|
32
|
+
hash_including(
|
33
|
+
:descriptor => instance_of(Fig::PackageDescriptor),
|
34
|
+
:time => anything(),
|
35
|
+
:login => anything(),
|
36
|
+
:host => anything(),
|
37
|
+
:local_destination => anything(),
|
38
|
+
:remote_destination => anything(),
|
39
|
+
:local_only => anything()
|
40
|
+
)
|
41
|
+
)
|
42
|
+
|
43
|
+
command.add_publish_listener(listener)
|
44
|
+
|
45
|
+
command.run_fig(
|
46
|
+
%w<--publish package/version --log-level off --set VARIABLE=VALUE>
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|