Skip to content
Browse files

support binary files as well

  • Loading branch information...
1 parent 86731c0 commit d2f00aeb6535b21f875808783c4f2aa16205c6fd @ctide committed Feb 6, 2012
Showing with 16 additions and 4 deletions.
  1. +6 −2 fakeweb.js
  2. +2 −2 package.json
  3. +8 −0 test/fakeweb-test.js
  4. BIN test/fixtures/grimace.jpg
View
8 fakeweb.js
@@ -144,8 +144,12 @@ function Fakeweb() {
registerUri = function(options) {
options.uri = parseUrl(options.uri);
interceptedUris[options.uri] = {};
- if (options.file) {
- interceptedUris[options.uri].response = fs.readFileSync(options.file);
+ if (options.file || options.binaryFile) {
+ if (options.binaryFile) {
+ interceptedUris[options.uri].response = fs.readFileSync(options.binaryFile, 'binary');
+ } else {
+ interceptedUris[options.uri].response = fs.readFileSync(options.file);
+ }
} else if (options.body != undefined) {
interceptedUris[options.uri].response = options.body;
}
View
4 package.json
@@ -2,7 +2,7 @@
"author": "ctide <christide@christide.com> (http://www.github.com/ctide)",
"name": "node-fakeweb",
"description": "Fakeweb implementation in node for testing HTTP requests",
- "version": "0.0.5",
+ "version": "0.0.6",
"homepage": "http://www.github.com/ctide/fakeweb",
"repository": {
"type": "git",
@@ -18,4 +18,4 @@
"devDependencies": {
"vows": "latest"
}
-}
+}
View
8 test/fakeweb-test.js
@@ -127,5 +127,13 @@ vows.describe('Fakeweb').addBatch({
assert.equal(data, 'body');
}
}
+ },
+ "won't truncate " : {
+ topic: function() {
+ fakeweb.registerUri({uri: 'http://www.testingimages.com/grimace.jpg', binaryFile: path.join(__dirname, 'fixtures', 'grimace.jpg'), contentType: 'image/jpeg'});
+ request.get({uri: 'http://www.testingimages.com/grimace.jpg'}, this.callback); },
+ 'binary files' : function(err, resp, body) {
+ assert.equal(body, fs.readFileSync(path.join(__dirname, 'fixtures', 'grimace.jpg'), 'binary'));
+ }
}
}).export(module);
View
BIN test/fixtures/grimace.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d2f00ae

Please sign in to comment.
Something went wrong with that request. Please try again.