test-construct 1.2.0

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.
Files changed (40) hide show
  1. data/.devver/hooks/build +11 -0
  2. data/.devver/hooks/install_dependencies +3 -0
  3. data/.devver/hooks/notify +50 -0
  4. data/.devver/hooks/prepare_database +1 -0
  5. data/History.txt +4 -0
  6. data/README.markdown +144 -0
  7. data/Rakefile +36 -0
  8. data/bin/construct +8 -0
  9. data/bugs/issue-0127c8c6ba1d31b5488f4551f8d869e57d53956d.yaml +29 -0
  10. data/bugs/issue-404e5da7b128e5b34e7a33fbcd56603618010d92.yaml +22 -0
  11. data/bugs/issue-50798912193be32b1dc610d949a557b3860d96fd.yaml +23 -0
  12. data/bugs/issue-5a10ec7298127df3c62255ea59e01dcf831ff1d3.yaml +22 -0
  13. data/bugs/issue-67f704f8b7190ccc1157eec007c3d584779dc805.yaml +18 -0
  14. data/bugs/issue-881ae950569b6ca718fae0060f2751710b972fd2.yaml +22 -0
  15. data/bugs/issue-bc8dfdf3834bb84b1d942ab2a90ac8c82b4389fb.yaml +22 -0
  16. data/bugs/issue-d05e9a907202348d47c4bf92062c1f4673dcae68.yaml +18 -0
  17. data/bugs/issue-f30a3db19d917f8e72ca8689e099ef0cb2681fd3.yaml +20 -0
  18. data/bugs/project.yaml +16 -0
  19. data/construct.gemspec +40 -0
  20. data/geminstaller.yml +7 -0
  21. data/lib/construct.rb +68 -0
  22. data/lib/construct/helpers.rb +29 -0
  23. data/lib/construct/path_extensions.rb +52 -0
  24. data/tasks/ann.rake +80 -0
  25. data/tasks/bones.rake +20 -0
  26. data/tasks/gem.rake +201 -0
  27. data/tasks/git.rake +40 -0
  28. data/tasks/notes.rake +27 -0
  29. data/tasks/post_load.rake +34 -0
  30. data/tasks/rdoc.rake +51 -0
  31. data/tasks/rubyforge.rake +55 -0
  32. data/tasks/setup.rb +292 -0
  33. data/tasks/spec.rake +54 -0
  34. data/tasks/svn.rake +47 -0
  35. data/tasks/test.rake +40 -0
  36. data/tasks/zentest.rake +36 -0
  37. data/test-construct.gemspec +39 -0
  38. data/test/construct_test.rb +469 -0
  39. data/test/test_helper.rb +35 -0
  40. metadata +114 -0
@@ -0,0 +1,54 @@
1
+
2
+ if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
3
+ require 'spec/rake/verify_rcov'
4
+
5
+ namespace :spec do
6
+
7
+ desc 'Run all specs with basic output'
8
+ Spec::Rake::SpecTask.new(:run) do |t|
9
+ t.ruby_opts = PROJ.ruby_opts
10
+ t.spec_opts = PROJ.spec.opts
11
+ t.spec_files = PROJ.spec.files
12
+ t.libs += PROJ.libs
13
+ end
14
+
15
+ desc 'Run all specs with text output'
16
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
17
+ t.ruby_opts = PROJ.ruby_opts
18
+ t.spec_opts = PROJ.spec.opts + ['--format', 'specdoc']
19
+ t.spec_files = PROJ.spec.files
20
+ t.libs += PROJ.libs
21
+ end
22
+
23
+ if HAVE_RCOV
24
+ desc 'Run all specs with RCov'
25
+ Spec::Rake::SpecTask.new(:rcov) do |t|
26
+ t.ruby_opts = PROJ.ruby_opts
27
+ t.spec_opts = PROJ.spec.opts
28
+ t.spec_files = PROJ.spec.files
29
+ t.libs += PROJ.libs
30
+ t.rcov = true
31
+ t.rcov_dir = PROJ.rcov.dir
32
+ t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
33
+ end
34
+
35
+ RCov::VerifyTask.new(:verify) do |t|
36
+ t.threshold = PROJ.rcov.threshold
37
+ t.index_html = File.join(PROJ.rcov.dir, 'index.html')
38
+ t.require_exact_threshold = PROJ.rcov.threshold_exact
39
+ end
40
+
41
+ task :verify => :rcov
42
+ remove_desc_for_task %w(spec:clobber_rcov)
43
+ end
44
+
45
+ end # namespace :spec
46
+
47
+ desc 'Alias to spec:run'
48
+ task :spec => 'spec:run'
49
+
50
+ task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
51
+
52
+ end # if HAVE_SPEC_RAKE_SPECTASK
53
+
54
+ # EOF
@@ -0,0 +1,47 @@
1
+
2
+ if HAVE_SVN
3
+
4
+ unless PROJ.svn.root
5
+ info = %x/svn info ./
6
+ m = %r/^Repository Root:\s+(.*)$/.match(info)
7
+ PROJ.svn.root = (m.nil? ? '' : m[1])
8
+ end
9
+ PROJ.svn.root = File.join(PROJ.svn.root, PROJ.svn.path) unless PROJ.svn.path.empty?
10
+
11
+ namespace :svn do
12
+
13
+ # A prerequisites task that all other tasks depend upon
14
+ task :prereqs
15
+
16
+ desc 'Show tags from the SVN repository'
17
+ task :show_tags => 'svn:prereqs' do |t|
18
+ tags = %x/svn list #{File.join(PROJ.svn.root, PROJ.svn.tags)}/
19
+ tags.gsub!(%r/\/$/, '')
20
+ tags = tags.split("\n").sort {|a,b| b <=> a}
21
+ puts tags
22
+ end
23
+
24
+ desc 'Create a new tag in the SVN repository'
25
+ task :create_tag => 'svn:prereqs' do |t|
26
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
27
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
28
+
29
+ svn = PROJ.svn
30
+ trunk = File.join(svn.root, svn.trunk)
31
+ tag = "%s-%s" % [PROJ.name, PROJ.version]
32
+ tag = File.join(svn.root, svn.tags, tag)
33
+ msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
34
+
35
+ puts "Creating SVN tag '#{tag}'"
36
+ unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
37
+ abort "Tag creation failed"
38
+ end
39
+ end
40
+
41
+ end # namespace :svn
42
+
43
+ task 'gem:release' => 'svn:create_tag'
44
+
45
+ end # if PROJ.svn.path
46
+
47
+ # EOF
@@ -0,0 +1,40 @@
1
+
2
+ if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
3
+ require 'rake/testtask'
4
+
5
+ namespace :test do
6
+
7
+ Rake::TestTask.new(:run) do |t|
8
+ t.libs = PROJ.libs
9
+ t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
10
+ else PROJ.test.files end
11
+ t.ruby_opts += PROJ.ruby_opts
12
+ t.ruby_opts += PROJ.test.opts
13
+ end
14
+
15
+ if HAVE_RCOV
16
+ desc 'Run rcov on the unit tests'
17
+ task :rcov => :clobber_rcov do
18
+ opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
19
+ opts = opts.join(' ')
20
+ files = if test(?f, PROJ.test.file) then [PROJ.test.file]
21
+ else PROJ.test.files end
22
+ files = files.join(' ')
23
+ sh "#{RCOV} #{files} #{opts}"
24
+ end
25
+
26
+ task :clobber_rcov do
27
+ rm_r 'coverage' rescue nil
28
+ end
29
+ end
30
+
31
+ end # namespace :test
32
+
33
+ desc 'Alias to test:run'
34
+ task :test => 'test:run'
35
+
36
+ task :clobber => 'test:clobber_rcov' if HAVE_RCOV
37
+
38
+ end
39
+
40
+ # EOF
@@ -0,0 +1,36 @@
1
+ if HAVE_ZENTEST
2
+
3
+ # --------------------------------------------------------------------------
4
+ if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
5
+ require 'autotest'
6
+
7
+ namespace :test do
8
+ task :autotest do
9
+ Autotest.run
10
+ end
11
+ end
12
+
13
+ desc "Run the autotest loop"
14
+ task :autotest => 'test:autotest'
15
+
16
+ end # if test
17
+
18
+ # --------------------------------------------------------------------------
19
+ if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
20
+ require 'autotest/rspec'
21
+
22
+ namespace :spec do
23
+ task :autotest do
24
+ load '.autotest' if test(?f, '.autotest')
25
+ Autotest::Rspec.run
26
+ end
27
+ end
28
+
29
+ desc "Run the autotest loop"
30
+ task :autotest => 'spec:autotest'
31
+
32
+ end # if rspec
33
+
34
+ end # if HAVE_ZENTEST
35
+
36
+ # EOF
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{test-construct}
5
+ s.version = "1.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ben Brinckerhoff (ben@devver.net) and Avdi Grimm (avdi@devver.net)"]
9
+ s.date = %q{2010-01-22}
10
+ s.default_executable = %q{construct}
11
+ s.description = %q{}
12
+ s.email = %q{ben@devver.net, avdi@devver.net}
13
+ s.executables = ["construct"]
14
+ s.extra_rdoc_files = ["History.txt", "bin/construct"]
15
+ s.files = [".devver/hooks/build", ".devver/hooks/install_dependencies", ".devver/hooks/notify", ".devver/hooks/prepare_database", "History.txt", "README.markdown", "Rakefile", "bin/construct", "bugs/issue-0127c8c6ba1d31b5488f4551f8d869e57d53956d.yaml", "bugs/issue-404e5da7b128e5b34e7a33fbcd56603618010d92.yaml", "bugs/issue-50798912193be32b1dc610d949a557b3860d96fd.yaml", "bugs/issue-5a10ec7298127df3c62255ea59e01dcf831ff1d3.yaml", "bugs/issue-67f704f8b7190ccc1157eec007c3d584779dc805.yaml", "bugs/issue-881ae950569b6ca718fae0060f2751710b972fd2.yaml", "bugs/issue-bc8dfdf3834bb84b1d942ab2a90ac8c82b4389fb.yaml", "bugs/issue-d05e9a907202348d47c4bf92062c1f4673dcae68.yaml", "bugs/issue-f30a3db19d917f8e72ca8689e099ef0cb2681fd3.yaml", "bugs/project.yaml", "construct.gemspec", "geminstaller.yml", "lib/construct.rb", "lib/construct/helpers.rb", "lib/construct/path_extensions.rb", "tasks/ann.rake", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/notes.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/spec.rake", "tasks/svn.rake", "tasks/test.rake", "tasks/zentest.rake", "test/construct_test.rb", "test/test_helper.rb"]
16
+ s.homepage = %q{http://github.com/devver/construct}
17
+ s.rdoc_options = ["--main", "README.markdown"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{test-construct}
20
+ s.rubygems_version = %q{1.3.5}
21
+ s.summary = %q{Construct is a DSL for creating temporary files and directories during testing.}
22
+ s.test_files = ["test/construct_test.rb"]
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 3
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_development_dependency(%q<bones>, [">= 2.5.1"])
30
+ s.add_development_dependency(%q<jeremymcanally-pending>, ["~> 0.1"])
31
+ else
32
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
33
+ s.add_dependency(%q<jeremymcanally-pending>, ["~> 0.1"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
37
+ s.add_dependency(%q<jeremymcanally-pending>, ["~> 0.1"])
38
+ end
39
+ end
@@ -0,0 +1,469 @@
1
+ require File.join(File.dirname(__FILE__), %w[test_helper])
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'construct')
3
+
4
+ require 'tmpdir'
5
+ require 'English'
6
+ require 'ruby-debug'
7
+ require 'mocha'
8
+
9
+ class ConstructTest < Test::Unit::TestCase
10
+ include Construct::Helpers
11
+
12
+ def teardown
13
+ Construct.destroy_all!
14
+ end
15
+
16
+ testing 'using within_construct explicitly' do
17
+
18
+ test 'creates construct' do
19
+ num = rand(1_000_000_000)
20
+ Construct.stubs(:rand).returns(num)
21
+ Construct::within_construct do |construct|
22
+ assert File.directory?(File.join(Construct.tmpdir, "construct_container-#{$PROCESS_ID}-#{num}"))
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ testing 'creating a construct container' do
29
+
30
+ test 'should exist' do
31
+ num = rand(1_000_000_000)
32
+ self.stubs(:rand).returns(num)
33
+ within_construct do |construct|
34
+ assert File.directory?(File.join(Construct.tmpdir, "construct_container-#{$PROCESS_ID}-#{num}"))
35
+ end
36
+ end
37
+
38
+ test 'should yield to its block' do
39
+ sensor = 'no yield'
40
+ within_construct do
41
+ sensor = 'yielded'
42
+ end
43
+ assert_equal 'yielded', sensor
44
+ end
45
+
46
+ test 'block argument should be container directory Pathname' do
47
+ num = rand(1_000_000_000)
48
+ self.stubs(:rand).returns(num)
49
+ within_construct do |container_path|
50
+ expected_path = (Pathname(Construct.tmpdir) +
51
+ "construct_container-#{$PROCESS_ID}-#{num}")
52
+ assert_equal(expected_path, container_path)
53
+ end
54
+ end
55
+
56
+ test 'should not exist afterwards' do
57
+ path = nil
58
+ within_construct do |container_path|
59
+ path = container_path
60
+ end
61
+ assert !path.exist?
62
+ end
63
+
64
+ test 'should remove entire tree afterwards' do
65
+ path = nil
66
+ within_construct do |container_path|
67
+ path = container_path
68
+ (container_path + 'foo').mkdir
69
+ end
70
+ assert !path.exist?
71
+ end
72
+
73
+ test 'should remove dir if block raises exception' do
74
+ path = nil
75
+ begin
76
+ within_construct do |container_path|
77
+ path = container_path
78
+ raise 'something bad happens here'
79
+ end
80
+ rescue
81
+ end
82
+ assert !path.exist?
83
+ end
84
+
85
+ test 'should not capture exceptions raised in block' do
86
+ err = RuntimeError.new('an error')
87
+ begin
88
+ within_construct do
89
+ raise err
90
+ end
91
+ rescue RuntimeError => e
92
+ assert_same err, e
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ testing 'creating a file in a container' do
99
+
100
+ test 'should exist while in construct block' do
101
+ within_construct do |construct|
102
+ construct.file('foo.txt')
103
+ assert File.exists?(construct+'foo.txt')
104
+ end
105
+ end
106
+
107
+ test 'should not exist after construct block' do
108
+ filepath = 'unset'
109
+ within_construct do |construct|
110
+ filepath = construct.file('foo.txt')
111
+ end
112
+ assert !File.exists?(filepath)
113
+ end
114
+
115
+ test 'should have empty file contents by default' do
116
+ within_construct do |construct|
117
+ construct.file('foo.txt')
118
+ assert_equal '', File.read('foo.txt')
119
+ end
120
+ end
121
+
122
+ test 'writes contents to file' do
123
+ within_construct do |construct|
124
+ construct.file('foo.txt','abcxyz')
125
+ assert_equal 'abcxyz', File.read(construct+'foo.txt')
126
+ end
127
+ end
128
+
129
+ test 'contents can be given in a block' do
130
+ within_construct do |construct|
131
+ construct.file('foo.txt') do
132
+ <<-EOS
133
+ File
134
+ Contents
135
+ EOS
136
+ end
137
+ assert_equal "File\nContents\n", File.read(construct+'foo.txt')
138
+ end
139
+ end
140
+
141
+ test 'contents block overwrites contents argument' do
142
+ within_construct do |construct|
143
+ construct.file('foo.txt','abc') do
144
+ 'xyz'
145
+ end
146
+ assert_equal 'xyz', File.read(construct+'foo.txt')
147
+ end
148
+ end
149
+
150
+ test 'block is passed File object' do
151
+ within_construct do |construct|
152
+ construct.file('foo.txt') do |file|
153
+ assert_equal((construct+'foo.txt').to_s, file.path)
154
+ end
155
+ end
156
+ end
157
+
158
+ test 'can write to File object passed to block' do
159
+ within_construct do |construct|
160
+ construct.file('foo.txt') do |file|
161
+ file << 'abc'
162
+ end
163
+ assert_equal 'abc', File.read(construct+'foo.txt')
164
+ end
165
+ end
166
+
167
+ test 'file is closed after block ends' do
168
+ within_construct do |construct|
169
+ construct_file = nil
170
+ construct.file('foo.txt') do |file|
171
+ construct_file = file
172
+ end
173
+ assert construct_file.closed?
174
+ end
175
+ end
176
+
177
+ test 'block return value not used as content if passed File object' do
178
+ within_construct do |construct|
179
+ construct.file('foo.txt') do |file|
180
+ file << 'abc'
181
+ 'xyz'
182
+ end
183
+ assert_equal 'abc', File.read(construct+'foo.txt')
184
+ end
185
+ end
186
+
187
+ test 'contents argument is ignored if block takes File arg' do
188
+ within_construct do |construct|
189
+ construct.file('foo.txt','xyz') do |file|
190
+ file << 'abc'
191
+ end
192
+ assert_equal 'abc', File.read(construct+'foo.txt')
193
+ end
194
+ end
195
+
196
+ test 'returns file path' do
197
+ within_construct do |construct|
198
+ assert_equal(construct+'foo.txt', construct.file('foo.txt'))
199
+ end
200
+ end
201
+
202
+ test 'can create file including path in one call' do
203
+ within_construct do |construct|
204
+ construct.file('foo/bar/baz.txt')
205
+ assert (construct+'foo/bar/baz.txt').exist?
206
+ end
207
+ end
208
+
209
+ test 'can create file including path in one call when directories exists' do
210
+ within_construct do |construct|
211
+ construct.directory('foo/bar')
212
+ construct.file('foo/bar/baz.txt')
213
+ assert (construct+'foo/bar/baz.txt').exist?
214
+ end
215
+ end
216
+
217
+ test 'can create file including path with chained calls' do
218
+ within_construct do |construct|
219
+ construct.directory('foo').directory('bar').file('baz.txt')
220
+ assert (construct+'foo/bar/baz.txt').exist?
221
+ end
222
+ end
223
+
224
+ end
225
+
226
+ testing 'creating a subdirectory in container' do
227
+
228
+ test 'should exist while in construct block' do
229
+ within_construct do |construct|
230
+ construct.directory 'foo'
231
+ assert (construct+'foo').directory?
232
+ end
233
+ end
234
+
235
+ test 'should not exist after construct block' do
236
+ subdir = 'unset'
237
+ within_construct do |construct|
238
+ construct.directory 'foo'
239
+ subdir = construct + 'foo'
240
+ end
241
+ assert !subdir.directory?
242
+ end
243
+
244
+ test 'returns the new path name' do
245
+ within_construct do |construct|
246
+ assert_equal((construct+'foo'), construct.directory('foo'))
247
+ end
248
+ end
249
+
250
+ test 'yield to block' do
251
+ sensor = 'unset'
252
+ within_construct do |construct|
253
+ construct.directory('bar') do
254
+ sensor = 'yielded'
255
+ end
256
+ end
257
+ assert_equal 'yielded', sensor
258
+ end
259
+
260
+ test 'block argument is subdirectory path' do
261
+ within_construct do |construct|
262
+ construct.directory('baz') do |dir|
263
+ assert_equal((construct+'baz'),dir)
264
+ end
265
+ end
266
+ end
267
+
268
+ test 'can create nested directory in one call' do
269
+ within_construct do |construct|
270
+ construct.directory('foo/bar')
271
+ assert (construct+'foo/bar').directory?
272
+ end
273
+ end
274
+
275
+ test 'can create a nested directory in two calls' do
276
+ within_construct do |construct|
277
+ construct.directory('foo').directory('bar')
278
+ assert (construct+'foo/bar').directory?
279
+ end
280
+ end
281
+
282
+ end
283
+
284
+ testing "subdirectories changing the working directory" do
285
+
286
+ test 'can force directory stays the same' do
287
+ within_construct do |construct|
288
+ old_pwd = Dir.pwd
289
+ construct.directory('foo',false) do
290
+ assert_equal old_pwd, Dir.pwd
291
+ end
292
+ end
293
+ end
294
+
295
+ test 'defaults chdir setting from construct' do
296
+ within_construct(false) do |construct|
297
+ old_pwd = Dir.pwd
298
+ construct.directory('foo') do
299
+ assert_equal old_pwd, Dir.pwd
300
+ end
301
+ end
302
+ end
303
+
304
+ test 'can override construct default' do
305
+ within_construct(false) do |construct|
306
+ old_pwd = Dir.pwd
307
+ construct.directory('foo', true) do |dir|
308
+ assert_equal dir.to_s, Dir.pwd
309
+ end
310
+ end
311
+ end
312
+
313
+ test 'current working directory is within subdirectory' do
314
+ within_construct do |construct|
315
+ construct.directory('foo') do |dir|
316
+ assert_equal dir.to_s, Dir.pwd
317
+ end
318
+ end
319
+ end
320
+
321
+ test 'current working directory is unchanged outside of subdirectory' do
322
+ within_construct do |construct|
323
+ old_pwd = Dir.pwd
324
+ construct.directory('foo')
325
+ assert_equal old_pwd, Dir.pwd
326
+ end
327
+ end
328
+
329
+ test 'current working directory is unchanged after exception' do
330
+ within_construct do |construct|
331
+ old_pwd = Dir.pwd
332
+ begin
333
+ construct.directory('foo') do
334
+ raise 'something bad happens here'
335
+ end
336
+ rescue
337
+ end
338
+ assert_equal old_pwd, Dir.pwd
339
+ end
340
+ end
341
+
342
+ test 'should not capture exceptions raised in block' do
343
+ within_construct do |construct|
344
+ error = assert_raises RuntimeError do
345
+ construct.directory('foo') do
346
+ raise 'fail!'
347
+ end
348
+ end
349
+ assert_equal 'fail!', error.message
350
+ end
351
+ end
352
+
353
+ test 'checking for a file is relative to subdirectory' do
354
+ within_construct do |construct|
355
+ construct.directory('bar') do |dir|
356
+ dir.file('foo.txt')
357
+ assert File.exists?('foo.txt')
358
+ end
359
+ end
360
+ end
361
+
362
+ test 'checking for a directory is relative to subdirectory' do
363
+ within_construct do |construct|
364
+ construct.directory('foo') do |dir|
365
+ dir.directory('mydir')
366
+ assert File.directory?('mydir')
367
+ end
368
+ end
369
+ end
370
+
371
+ end
372
+
373
+ testing "changing the working directory" do
374
+
375
+ test 'can force directory stays the same' do
376
+ old_pwd = Dir.pwd
377
+ within_construct(false) do |construct|
378
+ assert_equal old_pwd, Dir.pwd
379
+ end
380
+ end
381
+
382
+ test 'current working directory is within construct' do
383
+ within_construct do |construct|
384
+ assert_equal construct.to_s, Dir.pwd
385
+ end
386
+ end
387
+
388
+ test 'current working directory is unchanged outside of construct' do
389
+ old_pwd = Dir.pwd
390
+ within_construct do |construct|
391
+ end
392
+ assert_equal old_pwd, Dir.pwd
393
+ end
394
+
395
+ test 'current working directory is unchanged after exception' do
396
+ old_pwd = Dir.pwd
397
+ begin
398
+ within_construct do |construct|
399
+ raise 'something bad happens here'
400
+ end
401
+ rescue
402
+ end
403
+ assert_equal old_pwd, Dir.pwd
404
+ end
405
+
406
+ test 'should not capture exceptions raised in block' do
407
+ error = assert_raises RuntimeError do
408
+ within_construct do
409
+ raise 'fail!'
410
+ end
411
+ end
412
+ assert_equal 'fail!', error.message
413
+ end
414
+
415
+ test 'checking for a file is relative to container' do
416
+ within_construct do |construct|
417
+ construct.file('foo.txt')
418
+ assert File.exists?('foo.txt')
419
+ end
420
+ end
421
+
422
+ test 'checking for a directory is relative to container' do
423
+ within_construct do |construct|
424
+ construct.directory('mydir')
425
+ assert File.directory?('mydir')
426
+ end
427
+ end
428
+
429
+ end
430
+
431
+ testing "#create_construct" do
432
+ test "returns a working Construct" do
433
+ it = create_construct
434
+ it.directory "foo"
435
+ it.file "bar", "CONTENTS"
436
+ assert (it + "foo").directory?
437
+ assert_equal "CONTENTS", (it + "bar").read
438
+ end
439
+ end
440
+
441
+ testing "#chdir" do
442
+ test "executes its block in the context of the construct" do
443
+ it = create_construct
444
+ assert_not_equal it.to_s, Dir.pwd
445
+ sensor = :unset
446
+ it.chdir do
447
+ sensor = Dir.pwd
448
+ end
449
+ assert_equal it.to_s, sensor
450
+ end
451
+
452
+ test "leaves construct directory on block exit" do
453
+ it = create_construct
454
+ it.chdir do
455
+ # NOOP
456
+ end
457
+ assert_not_equal it.to_s, Dir.pwd
458
+ end
459
+ end
460
+
461
+ testing "#destroy!" do
462
+ test "removes the construct container" do
463
+ it = create_construct
464
+ it.destroy!
465
+ assert !File.exist?(it.to_s)
466
+ end
467
+ end
468
+
469
+ end