Let's try out our new test code. Open up a Workspace and execute
We can see that 120 tests were run and 119 passed. The test count looks correct since we just added one. And we know we have not written the actual method to do any work on FileList yet, so it's expected that our test failed. The bottom pane of TestRunner indicates that the failure was in our new test:
Let's create the #copySelectedFileToDirectory: method on FileList but not have it do anything yet. SUnit should exercise our test code and show us that it didn't work as expected. I created the method in the "file list menu" category of the FileList class.
Bring the TestRunner window back by clicking on the "O" of it's collapsed titlebar. In the list pane at the top, in the list pane menu, select the "deselect all" menu item. Then scroll to ours and click once on the FileListTest entry to select it. Click the "Run One" button on the right side of the TestRunner window.
2 tests were run and 1 failed. The failed test is in the list pane. Click on it to bring up the debugger. I selected the line before the "halt" in the debugger.
I kept stepping the debugger until I got to the #assert: statement after our call to the new non-functioning method.
Open a browser on FileList and select our #copySelectedFileToDirectory: method. One of the enhancements we installed earlier added a variables pane to the class browser. We can see that there are instance variables named "fileName" and "directory". With the argument passed to us of "aDirectory", we should be able to write some very straightforward code to copy our file.
Open up a second class browser and examine the FileDirectory class again. There's a method #copyFile:toFile: and #copyFileNamed:toFileNamed: to review. It looked as though the #copyFile:toFile: does what we want but it assumes we already have file streams open on the files. The #copyFileNamed:toFileNamed: method doesn't do exactly what we want either since (from the comments) it assumes that both files exist in the same directory. Looks like we will have to write a method on FileDirectory that does what we need.
I created this method in the "file operations" category of FileDirectory.
copyFileNamed: fileName toDirectory: aDirectory
"Copy the contents of the existing file into a directory."
| file1 file2 |
self = aDirectory ifTrue: [^ nil].
file1 := (self readOnlyFileNamed: fileName) binary.
file2 := (aDirectory newFileNamed: fileName) binary.
self copyFile: file1 toFile: file2.
directory copyFileNamed: fileName toDirectory: aDirectory
Continue on to the next page of second FileList enhancement.
Back to the beginning of this example.kirsten price naughty office