diff --git a/lib/storage/bucket.js b/lib/storage/bucket.js index 7e5c498fb72..01c5adb62be 100644 --- a/lib/storage/bucket.js +++ b/lib/storage/bucket.js @@ -198,6 +198,10 @@ Bucket.prototype.delete = function(callback) { * var file = bucket.file('my-existing-file.png'); */ Bucket.prototype.file = function(name) { + if (!name) { + throw Error('A file name must be specified.'); + } + return new File(this, name); }; diff --git a/lib/storage/file.js b/lib/storage/file.js index 8e1a26ef7cf..dfed164dd20 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -64,10 +64,6 @@ var STORAGE_UPLOAD_BASE_URL = 'https://www.googleapis.com/upload/storage/v1/b'; * @constructor */ function File(bucket, name, metadata) { - if (!name) { - throw Error('A file name must be specified.'); - } - this.bucket = bucket; this.makeReq_ = bucket.makeReq_.bind(bucket); this.metadata = metadata || {}; diff --git a/test/storage/bucket.js b/test/storage/bucket.js index 5718e196826..172c45c8a33 100644 --- a/test/storage/bucket.js +++ b/test/storage/bucket.js @@ -118,15 +118,19 @@ describe('Bucket', function() { var file; var metadata = { a: 'b' }; - beforeEach(function() { - file = bucket.file(FILE_NAME, metadata); + it('should throw if no name was provided', function() { + assert.throws(function() { + file = bucket.file(); + }, /A file name must be specified./); }); it('should return a File object', function() { + file = bucket.file(FILE_NAME, metadata); assert(file instanceof FakeFile); }); it('should pass filename to File object', function() { + file = bucket.file(FILE_NAME, metadata); assert.equal(file.name, FILE_NAME); }); }); diff --git a/test/storage/file.js b/test/storage/file.js index fd9cfa4e0ea..955c092e89a 100644 --- a/test/storage/file.js +++ b/test/storage/file.js @@ -125,12 +125,6 @@ describe('File', function() { }); describe('initialization', function() { - it('should throw if no name is provided', function() { - assert.throws(function() { - new File(bucket); - }, /A file name must be specified/); - }); - it('should assign file name', function() { assert.equal(file.name, FILE_NAME); });