Skip to content

Commit

Permalink
tests: fix assert.throws() usage
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Aug 5, 2016
1 parent 143f120 commit 5c4191a
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 53 deletions.
2 changes: 1 addition & 1 deletion packages/compute/test/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('Zone', function() {
it('should throw if a target is not provided', function() {
assert.throws(function() {
zone.createAutoscaler(NAME, {}, assert.ifError);
}, 'Cannot create an autoscaler without a target.');
}, /Cannot create an autoscaler without a target\./);
});

it('should make the correct request', function(done) {
Expand Down
2 changes: 1 addition & 1 deletion packages/datastore/test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ describe('Request', function() {

assert.throws(function() {
request.request_({ method: 'runQuery' }, reqOpts, assert.ifError);
}, 'Read consistency cannot be specified in a transaction.');
}, /Read consistency cannot be specified in a transaction\./);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/logging/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ describe('Logging', function() {
it('should throw if a name is not provided', function() {
assert.throws(function() {
logging.createSink();
}, 'A sink name must be provided.');
}, /A sink name must be provided\./);
});

it('should throw if a config object is not provided', function() {
assert.throws(function() {
logging.createSink(SINK_NAME);
}, 'A sink configuration object must be provided.');
}, /A sink configuration object must be provided\./);
});

it('should set acls for a Bucket destination', function(done) {
Expand Down
4 changes: 2 additions & 2 deletions packages/prediction/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Prediction', function() {
it('should throw if a model ID is not provided', function() {
assert.throws(function() {
prediction.createModel();
}, /A model ID is required/);
}, /A model ID is required\./);
});

it('should make the correct API request', function(done) {
Expand Down Expand Up @@ -379,7 +379,7 @@ describe('Prediction', function() {
it('should throw if a name is not provided', function() {
assert.throws(function() {
prediction.model();
}, /A model ID is required/);
}, /A model ID is required\./);
});

it('should return a Model', function() {
Expand Down
4 changes: 2 additions & 2 deletions packages/pubsub/test/iam.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('IAM', function() {
it('should throw an error if a policy is not supplied', function() {
assert.throws(function() {
iam.setPolicy(util.noop);
}, /A policy object is required/);
}, /A policy object is required\./);
});

it('should make the correct API request', function(done) {
Expand All @@ -117,7 +117,7 @@ describe('IAM', function() {
it('should throw an error if permissions are missing', function() {
assert.throws(function() {
iam.testPermissions(util.noop);
}, /Permissions are required/);
}, /Permissions are required\./);
});

it('should make the correct API request', function(done) {
Expand Down
8 changes: 4 additions & 4 deletions packages/pubsub/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,13 @@ describe('PubSub', function() {
it('should throw if no Topic is provided', function() {
assert.throws(function() {
pubsub.subscribe();
}, /A Topic is required.*/);
}, /A Topic is required for a new subscription\./);
});

it('should throw if no sub name is provided', function() {
assert.throws(function() {
pubsub.subscribe('topic');
}, /A subscription name is required.*/);
}, /A subscription name is required for a new subscription\./);
});

it('should not require configuration options', function(done) {
Expand Down Expand Up @@ -680,7 +680,7 @@ describe('PubSub', function() {
it('should throw if no name is provided', function() {
assert.throws(function() {
pubsub.subscription();
}, /The name of a subscription is required/);
}, /The name of a subscription is required\./);
});

it('should return a Subscription object', function() {
Expand Down Expand Up @@ -716,7 +716,7 @@ describe('PubSub', function() {
it('should throw if a name is not provided', function() {
assert.throws(function() {
pubsub.topic();
}, /name must be specified/);
}, /A name must be specified for a new topic\./);
});

it('should return a Topic object', function() {
Expand Down
4 changes: 2 additions & 2 deletions packages/pubsub/test/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ describe('Subscription', function() {
it('should throw if no IDs are provided', function() {
assert.throws(function() {
subscription.ack();
}, /At least one ID/);
}, /At least one ID must be specified before it can be acknowledged\./);
assert.throws(function() {
subscription.ack([]);
}, /At least one ID/);
}, /At least one ID must be specified before it can be acknowledged\./);
});

it('should accept a single id', function() {
Expand Down
6 changes: 3 additions & 3 deletions packages/pubsub/test/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ describe('Topic', function() {
it('should throw if no message is provided', function() {
assert.throws(function() {
topic.publish();
}, /Cannot publish without a message/);
}, /Cannot publish without a message\./);

assert.throws(function() {
topic.publish([]);
}, /Cannot publish without a message/);
}, /Cannot publish without a message\./);
});

it('should throw if a message has no data', function() {
assert.throws(function() {
topic.publish({});
}, /Cannot publish message without a `data` property/);
}, /Cannot publish message without a `data` property\./);
});

it('should send correct api request', function(done) {
Expand Down
2 changes: 1 addition & 1 deletion packages/resource/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe('Resource', function() {

assert.throws(function() {
resourceWithoutProjectId.project();
}, /A project ID is required/);
}, /A project ID is required\./);
});
});
});
18 changes: 7 additions & 11 deletions packages/storage/test/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,19 @@ describe('Bucket', function() {

describe('combine', function() {
it('should throw if invalid sources are not provided', function() {
var error = 'You must provide at least two source files.';

assert.throws(function() {
bucket.combine();
}, new RegExp(error));
}, /You must provide at least two source files\./);

assert.throws(function() {
bucket.combine(['1']);
}, new RegExp(error));
}, /You must provide at least two source files\./);
});

it('should throw if a destination is not provided', function() {
var error = 'A destination file must be specified.';

assert.throws(function() {
bucket.combine(['1', '2']);
}, new RegExp(error));
}, /A destination file must be specified\./);
});

it('should accept string or file input for sources', function(done) {
Expand Down Expand Up @@ -292,7 +288,7 @@ describe('Bucket', function() {
it('should throw if content type cannot be determined', function() {
assert.throws(function() {
bucket.combine(['1', '2'], 'destination');
}, /A content type could not be detected/);
}, /A content type could not be detected for the destination file\./);
});

it('should make correct API request', function(done) {
Expand Down Expand Up @@ -395,13 +391,13 @@ describe('Bucket', function() {
it('should throw if an ID is not provided', function() {
assert.throws(function() {
bucket.createChannel();
}, 'An ID is required to create a channel.');
}, /An ID is required to create a channel\./);
});

it('should throw if an address is not provided', function() {
assert.throws(function() {
bucket.createChannel(ID, {});
}, 'An address is required to create a channel.');
}, /An address is required to create a channel\./);
});

it('should make the correct request', function(done) {
Expand Down Expand Up @@ -607,7 +603,7 @@ describe('Bucket', function() {
it('should throw if no name is provided', function() {
assert.throws(function() {
bucket.file();
}, /A file name must be specified/);
}, /A file name must be specified\./);
});

it('should return a File object', function() {
Expand Down
32 changes: 13 additions & 19 deletions packages/storage/test/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe('File', function() {
it('should throw if no destination is provided', function() {
assert.throws(function() {
file.copy();
}, /should have a name/);
}, /Destination file should have a name\./);
});

it('should URI encode file names', function(done) {
Expand Down Expand Up @@ -335,7 +335,7 @@ describe('File', function() {
it('should throw if a destination cannot be parsed', function() {
assert.throws(function() {
file.copy(function() {});
}, /should have a name/);
}, /Destination file should have a name\./);
});
});

Expand Down Expand Up @@ -479,21 +479,21 @@ describe('File', function() {
start: 3,
end: 8
});
}, /Cannot use validation with file ranges/);
}, /Cannot use validation with file ranges \(start\/end\)\./);

assert.throws(function() {
file.createReadStream({
validation: true,
start: 3
});
}, /Cannot use validation with file ranges/);
}, /Cannot use validation with file ranges \(start\/end\)\./);

assert.throws(function() {
file.createReadStream({
validation: true,
end: 8
});
}, /Cannot use validation with file ranges/);
}, /Cannot use validation with file ranges \(start\/end\)\./);

assert.doesNotThrow(function() {
file.createReadStream({
Expand Down Expand Up @@ -1600,7 +1600,7 @@ describe('File', function() {
file.getSignedPolicy({
expires: expires
}, function() {});
}, /cannot be in the past/);
}, /An expiration date cannot be in the past\./);
});
});

Expand Down Expand Up @@ -1635,7 +1635,7 @@ describe('File', function() {
expires: Date.now() + 5,
equals: [{}]
}, function() {});
}, /Equals condition must be an array/);
}, /Equals condition must be an array of 2 elements\./);
});

it('should throw if equal condition length is not 2', function() {
Expand All @@ -1644,7 +1644,7 @@ describe('File', function() {
expires: Date.now() + 5,
equals: [['1', '2', '3']]
}, function() {});
}, /Equals condition must be an array of 2 elements/);
}, /Equals condition must be an array of 2 elements\./);
});
});

Expand Down Expand Up @@ -1679,7 +1679,7 @@ describe('File', function() {
expires: Date.now() + 5,
startsWith: [{}]
}, function() {});
}, /StartsWith condition must be an array/);
}, /StartsWith condition must be an array of 2 elements\./);
});

it('should throw if prefix condition length is not 2', function() {
Expand All @@ -1688,7 +1688,7 @@ describe('File', function() {
expires: Date.now() + 5,
startsWith: [['1', '2', '3']]
}, function() {});
}, /StartsWith condition must be an array of 2 elements/);
}, /StartsWith condition must be an array of 2 elements\./);
});
});

Expand All @@ -1711,7 +1711,7 @@ describe('File', function() {
expires: Date.now() + 5,
contentLengthRange: [{max: 1}]
}, function() {});
}, /ContentLengthRange must have numeric min & max fields/);
}, /ContentLengthRange must have numeric min & max fields\./);
});

it('should throw if content length has no max', function() {
Expand All @@ -1720,7 +1720,7 @@ describe('File', function() {
expires: Date.now() + 5,
contentLengthRange: [{min: 0}]
}, function() {});
}, /ContentLengthRange must have numeric min & max fields/);
}, /ContentLengthRange must have numeric min & max fields\./);
});
});
});
Expand Down Expand Up @@ -1962,7 +1962,7 @@ describe('File', function() {
action: 'read',
expires: expires
}, function() {});
}, /cannot be in the past/);
}, /An expiration date cannot be in the past\./);
});
});

Expand Down Expand Up @@ -2077,12 +2077,6 @@ describe('File', function() {
});

describe('move', function() {
it('should throw if no destination is provided', function() {
assert.throws(function() {
file.move();
}, /should have a name/);
});

describe('copy to destination', function() {
function assertCopyFile(file, expectedDestination, callback) {
file.copy = function(destination) {
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('Storage', function() {
it('should throw if no name was provided', function() {
assert.throws(function() {
storage.bucket();
}, /A bucket name is needed/);
}, /A bucket name is needed to use Google Cloud Storage\./);
});

it('should accept a string for a name', function() {
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('Storage', function() {
it('should throw if no name is provided', function() {
assert.throws(function() {
storage.createBucket();
}, /A name is required/);
}, /A name is required to create a bucket\./);
});

it('should execute callback with bucket', function(done) {
Expand Down
4 changes: 2 additions & 2 deletions packages/translate/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Translate', function() {
it('should throw if an API key is not provided', function() {
assert.throws(function() {
new Translate({});
}, 'An API key is required to use the Translate API.');
}, /An API key is required to use the Translate API\./);
});

it('should localize the options', function() {
Expand Down Expand Up @@ -266,7 +266,7 @@ describe('Translate', function() {
it('should throw if `to` is not provided', function() {
assert.throws(function() {
translate.translate(INPUT, { from: SOURCE_LANG_CODE }, util.noop);
}, 'A target language is required to perform a translation.');
}, /A target language is required to perform a translation\./);
});

it('should make the correct API request', function(done) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vision/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('Vision', function() {

assert.throws(function() {
vision.detect(IMAGE, type, assert.ifError);
}, 'Requested detection feature not found: ' + type);
}, /Requested detection feature not found: not-real-type/);
});

it('should format the correct config', function(done) {
Expand Down

0 comments on commit 5c4191a

Please sign in to comment.