Permalink
Browse files

Add File##overwrite:with:

  • Loading branch information...
1 parent c55bacd commit 992fd0b35f37e454f6fa309bc61b13b7c9a14a08 @bakkdoor committed Dec 21, 2012
Showing with 25 additions and 0 deletions.
  1. +13 −0 lib/file.fy
  2. +12 −0 tests/file.fy
View
@@ -15,6 +15,19 @@ class File {
File open: filename modes: ['write] with: block
}
+ def File overwrite: filename with: block {
+ """
+ @filename Filename of @File@ to overwrite.
+ @block @Block@ called with a @File@ object to write to (overwriting old contents.
+
+ Opens a @File@ for writing, overwriting old content.
+ """
+
+ File open: filename modes: ['truncate] with: block
+ }
+
+ metaclass alias_method: 'truncate:with: for: 'overwrite:with:
+
def File append: filename with: block {
"""
@filename Filename of @File@ to append to.
View
@@ -140,4 +140,16 @@ FancySpec describe: File with: {
]>
File delete: filename
}
+
+ it: "overwrites a file correctly" with: 'overwrite:with: when: {
+ filename = "/tmp/#{Time now to_i random}_overwrite_test.fy"
+ try {
+ File write: filename with: @{ println: "foo"; println: "bar" }
+ File read: filename . is: "foo\nbar\n"
+ File overwrite: filename with: @{ println: "bar"; println: "foo" }
+ File read: filename . is: "bar\nfoo\n"
+ } finally {
+ File delete!: filename
+ }
+ }
}

0 comments on commit 992fd0b

Please sign in to comment.