lib/jspec.js in visionmedia-jspec-1.1.5 vs lib/jspec.js in visionmedia-jspec-1.1.6
- old
+ new
@@ -1,13 +1,13 @@
// JSpec - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
(function(){
- JSpec = {
+ var JSpec = {
- version : '1.1.5',
+ version : '1.1.6',
file : '',
suites : [],
matchers : {},
stats : { specs : 0, assertions : 0, failures : 0, passes : 0 },
options : { profile : false },
@@ -522,27 +522,44 @@
replace(/>/gmi, '>').
replace(/</gmi, '<')
},
/**
- * Invoke a matcher.
+ * Perform an assertion.
*
- * this.match('test', 'should', 'be_a', [String])
+ * expect(true).to('be', true)
+ * expect('foo').not_to('include', 'bar')
+ * expect([1, [2]]).to('include', 1, [2])
*
- * @param {object} actual
- * @param {bool, string} negate
- * @param {string} name
- * @param {array} expected
- * @return {bool}
- * @api private
+ * @param {mixed} actual
+ * @return {hash}
+ * @api public
*/
- match : function(actual, negate, name, expected) {
- if (typeof negate == 'string') negate = negate == 'should' ? false : true
- assertion = new JSpec.Assertion(this.matchers[name], actual, expected, negate)
- this.currentSpec.assertions.push(assertion.exec())
- return assertion.passed
+ expect : function(actual) {
+ assert = function(name, args, negate) {
+ expected = []
+ for (i = 1; i < args.length; i++) expected.push(args[i])
+ assertion = new JSpec.Assertion(JSpec.matchers[name], actual, expected, negate)
+ JSpec.currentSpec.assertions.push(assertion.exec())
+ return assertion.passed
+ }
+
+ to = function(name) {
+ return assert(name, arguments, false)
+ }
+
+ not_to = function(name) {
+ return assert(name, arguments, true)
+ }
+
+ return {
+ to : to,
+ should : to,
+ not_to: not_to,
+ should_not : not_to,
+ }
},
/**
* Iterate an object, invoking the given callback.
*
@@ -721,11 +738,13 @@
replace(/end(?= |\n|$)/gm, '});').
replace(/-\{/g, 'function(){').
replace(/(\d+)\.\.(\d+)/g, function(_, a, b){ return range(a, b) }).
replace(/([\s\(]+)\./gm, '$1this.').
replace(/\.should([_\.]not)?[_\.](\w+)(?: |$)(.*)$/gm, '.should$1_$2($3)').
- replace(/([\/ ]*)(.+?)\.(should(?:[_\.]not)?)[_\.](\w+)\((.*)\)$/gm, '$1 JSpec.match($2, "$3", "$4", [$5]);')
+ replace(/([\/ ]*)(.+?)\.(should(?:[_\.]not)?)[_\.](\w+)\((.*)\)$/gm, '$1 expect($2).$3("$4", $5)').
+ replace(/, \)/gm, ')').
+ replace(/should\.not/gm, 'should_not')
},
/**
* Create a range string which can be evaluated to a native array.
*
@@ -834,11 +853,11 @@
* @api public
*/
requires : function(dependency, message) {
try { eval(dependency) }
- catch (e) { error('JSpec depends on ' + dependency + ' ' + message, '') }
+ catch (e) { error('JSpec depends on ' + dependency + ' ' + message) }
},
/**
* Query against the current query strings keys
* or the queryString specified.
@@ -957,29 +976,30 @@
}
}
// --- Utility functions
- main = this
- puts = print
- map = JSpec.map
- any = JSpec.any
- last = JSpec.last
- fail = JSpec.fail
- range = JSpec.range
- each = JSpec.each
- option = JSpec.option
- inject = JSpec.inject
- error = JSpec.error
- escape = JSpec.escape
- extend = JSpec.extend
- print = JSpec.print
- hash = JSpec.hash
- query = JSpec.query
- strip = JSpec.strip
- color = JSpec.color
- addMatchers = JSpec.addMatchers
+ var main = this
+ var puts = print
+ var map = JSpec.map
+ var any = JSpec.any
+ var last = JSpec.last
+ var fail = JSpec.fail
+ var range = JSpec.range
+ var each = JSpec.each
+ var option = JSpec.option
+ var inject = JSpec.inject
+ var error = JSpec.error
+ var escape = JSpec.escape
+ var extend = JSpec.extend
+ var print = JSpec.print
+ var hash = JSpec.hash
+ var query = JSpec.query
+ var strip = JSpec.strip
+ var color = JSpec.color
+ var expect = JSpec.expect
+ var addMatchers = JSpec.addMatchers
// --- Matchers
addMatchers({
equal : "===",
@@ -1079,6 +1099,6 @@
// --- Expose
this.JSpec = JSpec
-})();
+})();
\ No newline at end of file