shell_test 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,13 @@
1
- == 0.4.0 2011/11/01
1
+ == 0.5.0 2011/11/01
2
+
3
+ Revert change so that FileMethods uses prepare/prepare_dir again (bad idea).
4
+ Expand functionality of prepare method.
5
+
6
+ * add atime/ctime/mtime methods to FileMethods
7
+ * allow prepare to set mode
8
+ * allow prepare to set atime/mtime
9
+
10
+ == 0.4.1 2011/11/01
2
11
 
3
12
  * allow Session#on to map symbols to ENV values
4
13
 
@@ -21,7 +21,7 @@ may be used independently, but by including ShellTest you get them all:
21
21
  include ShellTest
22
22
 
23
23
  def test_a_script
24
- script = setup_file 'script.sh', %{
24
+ script = prepare 'script.sh', %{
25
25
  echo goodnight $1
26
26
  }
27
27
 
@@ -32,7 +32,7 @@ may be used independently, but by including ShellTest you get them all:
32
32
  end
33
33
 
34
34
  def test_a_script_that_takes_input
35
- script = setup_file 'script.sh', %{
35
+ script = prepare 'script.sh', %{
36
36
  stty -echo
37
37
  while true; do
38
38
  printf "Do you wish to continue? [y/n]: "
@@ -133,7 +133,7 @@ file, then the directory for the test case would be
133
133
  include ShellTest::FileMethods
134
134
 
135
135
  def test_setup_of_a_test_specific_file
136
- path = setup_file('dir/file.txt') {|io| io << 'content' }
136
+ path = prepare('dir/file.txt') {|io| io << 'content' }
137
137
  assert_equal "content", File.read(path)
138
138
  end
139
139
  end
@@ -244,7 +244,7 @@ module ShellTest
244
244
  end
245
245
 
246
246
  # Creates a directory under method_dir.
247
- def setup_dir(relative_path)
247
+ def prepare_dir(relative_path)
248
248
  target_dir = path(relative_path)
249
249
  unless File.directory?(target_dir)
250
250
  FileUtils.mkdir_p(target_dir)
@@ -252,10 +252,8 @@ module ShellTest
252
252
  target_dir
253
253
  end
254
254
 
255
- alias prepare_dir setup_dir
256
-
257
- # Same as setup_file but does not outdent content.
258
- def _setup_file(relative_path, content=nil, &block)
255
+ # Same as prepare but does not outdent content.
256
+ def _prepare(relative_path, content=nil, options={}, &block)
259
257
  target = path(relative_path)
260
258
 
261
259
  if File.exists?(target)
@@ -269,6 +267,19 @@ module ShellTest
269
267
  File.open(target, 'w') {|io| io << content } if content
270
268
  File.open(target, 'a', &block) if block
271
269
 
270
+ if mode = options[:mode]
271
+ FileUtils.chmod(mode, target)
272
+ end
273
+
274
+ atime = options[:atime]
275
+ mtime = options[:mtime]
276
+
277
+ if atime || mtime
278
+ atime ||= File.atime(target)
279
+ mtime ||= File.mtime(target)
280
+ File.utime(atime, mtime, target)
281
+ end
282
+
272
283
  target
273
284
  end
274
285
 
@@ -279,16 +290,16 @@ module ShellTest
279
290
  # Content provided as a string is outdented (see StringMethods#outdent),
280
291
  # so this syntax is possible:
281
292
  #
282
- # path = setup_file 'file', %{
293
+ # path = prepare 'file', %{
283
294
  # line one
284
295
  # line two
285
296
  # }
286
297
  # File.read(path) # => "line one\nline two\n"
287
298
  #
288
299
  # Returns the absolute path to the new file.
289
- def setup_file(relative_path, content=nil, &block)
300
+ def prepare(relative_path, content=nil, options={}, &block)
290
301
  content = outdent(content) if content
291
- _setup_file(relative_path, content, &block)
302
+ _prepare(relative_path, content, options, &block)
292
303
  end
293
304
 
294
305
  # Returns the content of the file under method_dir, if it exists.
@@ -304,6 +315,24 @@ module ShellTest
304
315
  File.exists?(full_path) ? sprintf("%o", File.stat(full_path).mode) : nil
305
316
  end
306
317
 
318
+ # Returns the atime for the file under method_dir, if it exists.
319
+ def atime(relative_path)
320
+ full_path = path(relative_path)
321
+ File.exists?(full_path) ? File.atime(full_path) : nil
322
+ end
323
+
324
+ # Returns the ctime for the file under method_dir, if it exists.
325
+ def ctime(relative_path)
326
+ full_path = path(relative_path)
327
+ File.exists?(full_path) ? File.ctime(full_path) : nil
328
+ end
329
+
330
+ # Returns the mtime for the file under method_dir, if it exists.
331
+ def mtime(relative_path)
332
+ full_path = path(relative_path)
333
+ File.exists?(full_path) ? File.mtime(full_path) : nil
334
+ end
335
+
307
336
  # Removes a file or directory under method_dir, if it exists.
308
337
  def remove(relative_path)
309
338
  full_path = path(relative_path)
@@ -1,3 +1,3 @@
1
1
  module ShellTest
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shell_test
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Chiang