unexpected-messy
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -207,4 +207,12 @@ var messy = require('messy'), | ||
expectedBody = upgradedOrDowngradedMessageBodyAndSpecBody.specBody; | ||
if (value && typeof value === 'object') { | ||
this.errorMode = 'nested'; | ||
var unsupportedKeys = Object.keys(value).filter(function (key) { | ||
return key !== 'body' && key !== 'fileName' && key !== 'decodedBody' && key !== 'text' && key !== 'headers' && key !== 'parts'; | ||
}); | ||
if (unsupportedKeys.length > 0) { | ||
throw new Error('messy.Message to satisfy: Unsupported keys: ' + unsupportedKeys.join(', ')); | ||
} | ||
this.errorMode = 'bubble'; | ||
if ('fileName' in value) { | ||
@@ -222,2 +230,30 @@ expect(subject, 'to have file name satisfying', value.fileName); | ||
if (typeof value.parts !== 'undefined') { | ||
expect(subject, 'to be a multipart message'); | ||
expect(subject.parts, 'to be an array'); | ||
if (typeof value.parts === 'function') { | ||
expect(subject.parts, 'to satisfy', value.parts); | ||
} else { | ||
this.errorMode = 'bubble'; | ||
expect(value.parts, 'to be an object whose keys satisfy', /^\d+/); | ||
var highestPartNumber; | ||
if (Array.isArray(value.parts)) { | ||
highestPartNumber = value.parts.length; | ||
} else if (value.parts && typeof value.parts === 'object') { | ||
Object.keys(value.parts).forEach(function (key) { | ||
var partNumber = parseInt(key, 10); | ||
if (typeof partNumber === 'number' && (typeof highestPartNumber === 'undefined' || partNumber > highestPartNumber)) { | ||
highestPartNumber = partNumber; | ||
} | ||
}); | ||
} | ||
if (typeof highestPartNumber !== 'undefined') { | ||
expect(subject, 'to have at least this number of parts', highestPartNumber); | ||
} | ||
this.errorMode = 'default'; | ||
} | ||
} | ||
this.errorMode = 'default'; | ||
try { | ||
@@ -237,2 +273,7 @@ if (typeof value === 'string') { | ||
} | ||
if (typeof value.parts !== 'undefined' && typeof value.parts !== 'function') { | ||
Object.keys(value.parts).forEach(function (key) { | ||
expect(subject.parts[key], 'to satisfy', value.parts[key]); | ||
}); | ||
} | ||
} catch (e) { | ||
@@ -262,3 +303,28 @@ if (e._isUnexpected) { | ||
output.nl(2); | ||
if (typeof subjectBody === 'string') { | ||
if (subject.isMultipart) { | ||
var parts = subject.parts; | ||
parts.forEach(function (part, i) { | ||
output.text('--' + subject.boundary, 'green').nl(); | ||
var partSatisfyError, | ||
partSatisfyDiff; | ||
if (typeof value.parts !== 'function' && i in value.parts) { | ||
try { | ||
expect(part, 'to satisfy', value.parts[i]); | ||
} catch (_partSatisfyError) { | ||
partSatisfyError = _partSatisfyError; | ||
partSatisfyDiff = partSatisfyError.createDiff && partSatisfyError.createDiff(output.clone(), diff, inspect, equal); | ||
} | ||
if (partSatisfyDiff) { | ||
output.append(partSatisfyDiff.diff); | ||
} else { | ||
output.append(inspect(part)); | ||
if (partSatisfyError) { | ||
output.sp().error('// ' + (partSatisfyError.label || 'should satisfy') + ' ').append(inspect(value.parts[i])); | ||
} | ||
} | ||
} | ||
output.nl(); | ||
}); | ||
output.text('--' + subject.boundary + '--', 'green'); | ||
} else if (typeof subjectBody === 'string') { | ||
output.text(subjectBody); | ||
@@ -622,2 +688,8 @@ } else { | ||
}) | ||
.addAssertion('messy.Message', '[not] to be a multipart message', function (expect, subject) { | ||
expect(subject.isMultipart, '[not] to be truthy'); | ||
}) | ||
.addAssertion('messy.Message', '[not] to have at least this number of parts', function (expect, subject, value) { | ||
expect(subject.parts.length, '[not] to be >=', value); | ||
}) | ||
.addType({ | ||
@@ -730,4 +802,10 @@ name: 'messy.RequestLine', | ||
}).addAssertion('messy.HttpRequest', 'to [exhaustively] satisfy', function (expect, subject, value) { | ||
var messageValue = _.extend({}, value); | ||
delete messageValue.requestLine; | ||
var requestLineSpec = _.pick(value, messy.RequestLine.propertyNames); | ||
Object.keys(requestLineSpec).forEach(function (requestLineKey) { | ||
delete messageValue[requestLineKey]; | ||
}); | ||
try { | ||
expectMessageToSatisfy.call(this, expect, subject, value); | ||
expectMessageToSatisfy.call(this, expect, subject, messageValue); | ||
if ('requestLine' in value) { | ||
@@ -737,3 +815,4 @@ expect(subject.requestLine, 'to [exhaustively] satisfy', value.requestLine); | ||
// Make the RequestLine properties available for matching: | ||
expect(subject.requestLine, 'to [exhaustively] satisfy', _.pick(value, messy.RequestLine.propertyNames)); | ||
expect(subject.requestLine, 'to [exhaustively] satisfy', requestLineSpec); | ||
delete value.requestLine; | ||
} catch (e) { | ||
@@ -748,3 +827,3 @@ if (e._isUnexpected) { | ||
// Make the RequestLine properties available for matching: | ||
expect(subject.requestLine, 'to [exhaustively] satisfy', _.pick(value, messy.RequestLine.propertyNames)); | ||
expect(subject.requestLine, 'to [exhaustively] satisfy', requestLineSpec); | ||
} | ||
@@ -761,3 +840,3 @@ output.append(expect.inspect(subject.requestLine)); | ||
try { | ||
expectMessageToSatisfy.call(that, expect, subject, value); | ||
expectMessageToSatisfy.call(that, expect, subject, messageValue); | ||
output.append(expect.findTypeOf(new messy.Message()).inspect(subject, 3, output.clone(), inspect, equal)); | ||
@@ -893,2 +972,8 @@ } catch (e) { | ||
}).addAssertion('messy.HttpResponse', 'to [exhaustively] satisfy', function (expect, subject, value) { | ||
var messageValue = _.extend({}, value); | ||
delete messageValue.statusLine; | ||
var statusLineSpec = _.pick(value, messy.StatusLine.propertyNames); | ||
Object.keys(statusLineSpec).forEach(function (requestLineKey) { | ||
delete messageValue[requestLineKey]; | ||
}); | ||
try { | ||
@@ -899,5 +984,5 @@ if ('statusLine' in value) { | ||
// Make the StatusLine properties available for matching: | ||
expect(subject.statusLine, 'to [exhaustively] satisfy', _.pick(value, messy.StatusLine.propertyNames)); | ||
expect(subject.statusLine, 'to [exhaustively] satisfy', statusLineSpec); | ||
} | ||
expectMessageToSatisfy.call(this, expect, subject, value); | ||
expectMessageToSatisfy.call(this, expect, subject, messageValue); | ||
} catch (e) { | ||
@@ -912,3 +997,3 @@ if (e._isUnexpected) { | ||
// Make the StatusLine properties available for matching: | ||
expect(subject.statusLine, 'to [exhaustively] satisfy', _.pick(value, messy.StatusLine.propertyNames)); | ||
expect(subject.statusLine, 'to [exhaustively] satisfy', statusLineSpec); | ||
} | ||
@@ -924,3 +1009,3 @@ output.append(expect.inspect(subject.statusLine)); | ||
try { | ||
expectMessageToSatisfy.call(that, expect, subject, value); | ||
expectMessageToSatisfy.call(that, expect, subject, messageValue); | ||
var inspectedMessage = expect.findTypeOf(new messy.Message()).inspect(subject, 3, output.clone(), inspect, equal); | ||
@@ -927,0 +1012,0 @@ if (!inspectedMessage.isEmpty()) { |
{ | ||
"name": "unexpected-messy", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "Unexpected plugin for the messy library", | ||
@@ -42,5 +42,5 @@ "main": "lib/unexpectedMessy.js", | ||
"jshint": "2.5.5", | ||
"messy": "4.0.0", | ||
"messy": "4.0.1", | ||
"mocha": "2.0.1", | ||
"unexpected": "5.1.0" | ||
"unexpected": "5.4.0" | ||
}, | ||
@@ -47,0 +47,0 @@ "dependencies": { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141981
2636