Created
May 24, 2012 13:41
-
-
Save caoilte/2781601 to your computer and use it in GitHub Desktop.
Stubble: Unit Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("Build Packager", function(){ | |
var Stubble, mockConfig, realpathSyncMock, writeFileMock, fsMock, writePackageCallback, mapAllFilesSpy, | |
folderMock, zipAddFilesMock, zipMock, stub, packager, DIRECTORY_TO_ZIP; | |
beforeEach(function() { | |
Stubble = require('stubble'), | |
mockConfig = { | |
commandArgs: { | |
product: "mobile" | |
} | |
} | |
realpathSyncMock = jasmine.createSpy('fs: Real Path Sync'), | |
writeFileMock = jasmine.createSpy("fs: Write File"), | |
fsMock = { | |
realpathSync: realpathSyncMock, | |
writeFile: writeFileMock | |
}, | |
writePackageCallback = jasmine.createSpy("Write Package Callback"), | |
mapAllFilesSpy = jasmine.createSpy("Folder: Map All Files To Name And Path"), | |
folderMock = { | |
mapAllFiles: mapAllFilesSpy | |
}, | |
zipAddFilesMock = jasmine.createSpy("Zip: Add Files"), | |
zipMock = function() { | |
this.addFiles = zipAddFilesMock; | |
this.toBuffer = function() {}; | |
}, | |
stub = new Stubble({fs: fsMock, "../node_modules/node-native-zip/folder.js": folderMock, "node-native-zip": zipMock, "../config": mockConfig }); | |
packager = stub.require(__dirname+'/../packageCreator.js'); | |
DIRECTORY_TO_ZIP = "mobile"; | |
}); | |
var doPackaging = function(directoryToZip, filesToZip) { | |
realpathSyncMock.andReturn(directoryToZip); | |
packager.package(writePackageCallback); | |
// invoke aggregated results callback that should be called with the array of all files | |
mapAllFilesSpy.mostRecentCall.args[2](null, filesToZip); | |
// invoke zip add files result callback that should be called with any error object | |
zipAddFilesMock.mostRecentCall.args[1](null); | |
// invoke write file callback | |
writeFileMock.mostRecentCall.args[3](); | |
} | |
it("Given a DIRECTORY_TO_ZIP when a file in it is mapped then a tuple representing name/path should be returned for the zip method", function(){ | |
doPackaging(DIRECTORY_TO_ZIP); | |
var callback = jasmine.createSpy("Write Package Callback") | |
var fileName = "test.txt"; | |
var PATH = DIRECTORY_TO_ZIP + "/" + fileName; | |
mapAllFilesSpy.mostRecentCall.args[1](PATH, null, callback); | |
expect(callback).toHaveBeenCalledWith( | |
{ | |
name: fileName, | |
path: PATH | |
}); | |
}); | |
describe("Given a DIRECTORY_TO_ZIP when it is packaged then", function(){ | |
it("a file called DIRECTORY_TO_ZIP.zip should be created", function(){ | |
doPackaging(DIRECTORY_TO_ZIP); | |
expect(writePackageCallback).toHaveBeenCalled(); | |
}); | |
it("every file in that directory should be added to the zip file", function(){ | |
var FILES_IN_DIRECTORY = ['file1', 'file2']; | |
doPackaging(DIRECTORY_TO_ZIP, FILES_IN_DIRECTORY); | |
expect(zipAddFilesMock.mostRecentCall.args[0]).toBe(FILES_IN_DIRECTORY); | |
}); | |
}); | |
describe("First tests for the view module", function(){ | |
it("Asserts true is true", function(){ | |
expect(true).toBeTruthy(); | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment