chai-1.6.0.js 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251
  1. ;(function(){
  2. /**
  3. * Require the given path.
  4. *
  5. * @param {String} path
  6. * @return {Object} exports
  7. * @api public
  8. */
  9. function require(path, parent, orig) {
  10. var resolved = require.resolve(path);
  11. // lookup failed
  12. if (null == resolved) {
  13. orig = orig || path;
  14. parent = parent || 'root';
  15. var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
  16. err.path = orig;
  17. err.parent = parent;
  18. err.require = true;
  19. throw err;
  20. }
  21. var module = require.modules[resolved];
  22. // perform real require()
  23. // by invoking the module's
  24. // registered function
  25. if (!module.exports) {
  26. module.exports = {};
  27. module.client = module.component = true;
  28. module.call(this, module.exports, require.relative(resolved), module);
  29. }
  30. return module.exports;
  31. }
  32. /**
  33. * Registered modules.
  34. */
  35. require.modules = {};
  36. /**
  37. * Registered aliases.
  38. */
  39. require.aliases = {};
  40. /**
  41. * Resolve `path`.
  42. *
  43. * Lookup:
  44. *
  45. * - PATH/index.js
  46. * - PATH.js
  47. * - PATH
  48. *
  49. * @param {String} path
  50. * @return {String} path or null
  51. * @api private
  52. */
  53. require.resolve = function(path) {
  54. if (path.charAt(0) === '/') path = path.slice(1);
  55. var index = path + '/index.js';
  56. var paths = [
  57. path,
  58. path + '.js',
  59. path + '.json',
  60. path + '/index.js',
  61. path + '/index.json'
  62. ];
  63. for (var i = 0; i < paths.length; i++) {
  64. var path = paths[i];
  65. if (require.modules.hasOwnProperty(path)) return path;
  66. }
  67. if (require.aliases.hasOwnProperty(index)) {
  68. return require.aliases[index];
  69. }
  70. };
  71. /**
  72. * Normalize `path` relative to the current path.
  73. *
  74. * @param {String} curr
  75. * @param {String} path
  76. * @return {String}
  77. * @api private
  78. */
  79. require.normalize = function(curr, path) {
  80. var segs = [];
  81. if ('.' != path.charAt(0)) return path;
  82. curr = curr.split('/');
  83. path = path.split('/');
  84. for (var i = 0; i < path.length; ++i) {
  85. if ('..' == path[i]) {
  86. curr.pop();
  87. } else if ('.' != path[i] && '' != path[i]) {
  88. segs.push(path[i]);
  89. }
  90. }
  91. return curr.concat(segs).join('/');
  92. };
  93. /**
  94. * Register module at `path` with callback `definition`.
  95. *
  96. * @param {String} path
  97. * @param {Function} definition
  98. * @api private
  99. */
  100. require.register = function(path, definition) {
  101. require.modules[path] = definition;
  102. };
  103. /**
  104. * Alias a module definition.
  105. *
  106. * @param {String} from
  107. * @param {String} to
  108. * @api private
  109. */
  110. require.alias = function(from, to) {
  111. if (!require.modules.hasOwnProperty(from)) {
  112. throw new Error('Failed to alias "' + from + '", it does not exist');
  113. }
  114. require.aliases[to] = from;
  115. };
  116. /**
  117. * Return a require function relative to the `parent` path.
  118. *
  119. * @param {String} parent
  120. * @return {Function}
  121. * @api private
  122. */
  123. require.relative = function(parent) {
  124. var p = require.normalize(parent, '..');
  125. /**
  126. * lastIndexOf helper.
  127. */
  128. function lastIndexOf(arr, obj) {
  129. var i = arr.length;
  130. while (i--) {
  131. if (arr[i] === obj) return i;
  132. }
  133. return -1;
  134. }
  135. /**
  136. * The relative require() itself.
  137. */
  138. function localRequire(path) {
  139. var resolved = localRequire.resolve(path);
  140. return require(resolved, parent, path);
  141. }
  142. /**
  143. * Resolve relative to the parent.
  144. */
  145. localRequire.resolve = function(path) {
  146. var c = path.charAt(0);
  147. if ('/' == c) return path.slice(1);
  148. if ('.' == c) return require.normalize(p, path);
  149. // resolve deps by returning
  150. // the dep in the nearest "deps"
  151. // directory
  152. var segs = parent.split('/');
  153. var i = lastIndexOf(segs, 'deps') + 1;
  154. if (!i) i = 0;
  155. path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
  156. return path;
  157. };
  158. /**
  159. * Check if module is defined at `path`.
  160. */
  161. localRequire.exists = function(path) {
  162. return require.modules.hasOwnProperty(localRequire.resolve(path));
  163. };
  164. return localRequire;
  165. };
  166. require.register("chai/index.js", function(exports, require, module){
  167. module.exports = require('./lib/chai');
  168. });
  169. require.register("chai/lib/chai.js", function(exports, require, module){
  170. /*!
  171. * chai
  172. * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
  173. * MIT Licensed
  174. */
  175. var used = []
  176. , exports = module.exports = {};
  177. /*!
  178. * Chai version
  179. */
  180. exports.version = '1.6.0';
  181. /*!
  182. * Primary `Assertion` prototype
  183. */
  184. exports.Assertion = require('./chai/assertion');
  185. /*!
  186. * Assertion Error
  187. */
  188. exports.AssertionError = require('./chai/error');
  189. /*!
  190. * Utils for plugins (not exported)
  191. */
  192. var util = require('./chai/utils');
  193. /**
  194. * # .use(function)
  195. *
  196. * Provides a way to extend the internals of Chai
  197. *
  198. * @param {Function}
  199. * @returns {this} for chaining
  200. * @api public
  201. */
  202. exports.use = function (fn) {
  203. if (!~used.indexOf(fn)) {
  204. fn(this, util);
  205. used.push(fn);
  206. }
  207. return this;
  208. };
  209. /*!
  210. * Core Assertions
  211. */
  212. var core = require('./chai/core/assertions');
  213. exports.use(core);
  214. /*!
  215. * Expect interface
  216. */
  217. var expect = require('./chai/interface/expect');
  218. exports.use(expect);
  219. /*!
  220. * Should interface
  221. */
  222. var should = require('./chai/interface/should');
  223. exports.use(should);
  224. /*!
  225. * Assert interface
  226. */
  227. var assert = require('./chai/interface/assert');
  228. exports.use(assert);
  229. });
  230. require.register("chai/lib/chai/assertion.js", function(exports, require, module){
  231. /*!
  232. * chai
  233. * http://chaijs.com
  234. * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
  235. * MIT Licensed
  236. */
  237. /*!
  238. * Module dependencies.
  239. */
  240. var AssertionError = require('./error')
  241. , util = require('./utils')
  242. , flag = util.flag;
  243. /*!
  244. * Module export.
  245. */
  246. module.exports = Assertion;
  247. /*!
  248. * Assertion Constructor
  249. *
  250. * Creates object for chaining.
  251. *
  252. * @api private
  253. */
  254. function Assertion (obj, msg, stack) {
  255. flag(this, 'ssfi', stack || arguments.callee);
  256. flag(this, 'object', obj);
  257. flag(this, 'message', msg);
  258. }
  259. /*!
  260. * ### Assertion.includeStack
  261. *
  262. * User configurable property, influences whether stack trace
  263. * is included in Assertion error message. Default of false
  264. * suppresses stack trace in the error message
  265. *
  266. * Assertion.includeStack = true; // enable stack on error
  267. *
  268. * @api public
  269. */
  270. Assertion.includeStack = false;
  271. /*!
  272. * ### Assertion.showDiff
  273. *
  274. * User configurable property, influences whether or not
  275. * the `showDiff` flag should be included in the thrown
  276. * AssertionErrors. `false` will always be `false`; `true`
  277. * will be true when the assertion has requested a diff
  278. * be shown.
  279. *
  280. * @api public
  281. */
  282. Assertion.showDiff = true;
  283. Assertion.addProperty = function (name, fn) {
  284. util.addProperty(this.prototype, name, fn);
  285. };
  286. Assertion.addMethod = function (name, fn) {
  287. util.addMethod(this.prototype, name, fn);
  288. };
  289. Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
  290. util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
  291. };
  292. Assertion.overwriteProperty = function (name, fn) {
  293. util.overwriteProperty(this.prototype, name, fn);
  294. };
  295. Assertion.overwriteMethod = function (name, fn) {
  296. util.overwriteMethod(this.prototype, name, fn);
  297. };
  298. /*!
  299. * ### .assert(expression, message, negateMessage, expected, actual)
  300. *
  301. * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
  302. *
  303. * @name assert
  304. * @param {Philosophical} expression to be tested
  305. * @param {String} message to display if fails
  306. * @param {String} negatedMessage to display if negated expression fails
  307. * @param {Mixed} expected value (remember to check for negation)
  308. * @param {Mixed} actual (optional) will default to `this.obj`
  309. * @api private
  310. */
  311. Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
  312. var ok = util.test(this, arguments);
  313. if (true !== showDiff) showDiff = false;
  314. if (true !== Assertion.showDiff) showDiff = false;
  315. if (!ok) {
  316. var msg = util.getMessage(this, arguments)
  317. , actual = util.getActual(this, arguments);
  318. throw new AssertionError({
  319. message: msg
  320. , actual: actual
  321. , expected: expected
  322. , stackStartFunction: (Assertion.includeStack) ? this.assert : flag(this, 'ssfi')
  323. , showDiff: showDiff
  324. });
  325. }
  326. };
  327. /*!
  328. * ### ._obj
  329. *
  330. * Quick reference to stored `actual` value for plugin developers.
  331. *
  332. * @api private
  333. */
  334. Object.defineProperty(Assertion.prototype, '_obj',
  335. { get: function () {
  336. return flag(this, 'object');
  337. }
  338. , set: function (val) {
  339. flag(this, 'object', val);
  340. }
  341. });
  342. });
  343. require.register("chai/lib/chai/error.js", function(exports, require, module){
  344. /*!
  345. * chai
  346. * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
  347. * MIT Licensed
  348. */
  349. /*!
  350. * Main export
  351. */
  352. module.exports = AssertionError;
  353. /**
  354. * # AssertionError (constructor)
  355. *
  356. * Create a new assertion error based on the Javascript
  357. * `Error` prototype.
  358. *
  359. * **Options**
  360. * - message
  361. * - actual
  362. * - expected
  363. * - operator
  364. * - startStackFunction
  365. *
  366. * @param {Object} options
  367. * @api public
  368. */
  369. function AssertionError (options) {
  370. options = options || {};
  371. this.message = options.message;
  372. this.actual = options.actual;
  373. this.expected = options.expected;
  374. this.operator = options.operator;
  375. this.showDiff = options.showDiff;
  376. if (options.stackStartFunction && Error.captureStackTrace) {
  377. var stackStartFunction = options.stackStartFunction;
  378. Error.captureStackTrace(this, stackStartFunction);
  379. }
  380. }
  381. /*!
  382. * Inherit from Error
  383. */
  384. AssertionError.prototype = Object.create(Error.prototype);
  385. AssertionError.prototype.name = 'AssertionError';
  386. AssertionError.prototype.constructor = AssertionError;
  387. /**
  388. * # toString()
  389. *
  390. * Override default to string method
  391. */
  392. AssertionError.prototype.toString = function() {
  393. return this.message;
  394. };
  395. });
  396. require.register("chai/lib/chai/core/assertions.js", function(exports, require, module){
  397. /*!
  398. * chai
  399. * http://chaijs.com
  400. * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
  401. * MIT Licensed
  402. */
  403. module.exports = function (chai, _) {
  404. var Assertion = chai.Assertion
  405. , toString = Object.prototype.toString
  406. , flag = _.flag;
  407. /**
  408. * ### Language Chains
  409. *
  410. * The following are provide as chainable getters to
  411. * improve the readability of your assertions. They
  412. * do not provide an testing capability unless they
  413. * have been overwritten by a plugin.
  414. *
  415. * **Chains**
  416. *
  417. * - to
  418. * - be
  419. * - been
  420. * - is
  421. * - that
  422. * - and
  423. * - have
  424. * - with
  425. * - at
  426. * - of
  427. * - same
  428. *
  429. * @name language chains
  430. * @api public
  431. */
  432. [ 'to', 'be', 'been'
  433. , 'is', 'and', 'have'
  434. , 'with', 'that', 'at'
  435. , 'of', 'same' ].forEach(function (chain) {
  436. Assertion.addProperty(chain, function () {
  437. return this;
  438. });
  439. });
  440. /**
  441. * ### .not
  442. *
  443. * Negates any of assertions following in the chain.
  444. *
  445. * expect(foo).to.not.equal('bar');
  446. * expect(goodFn).to.not.throw(Error);
  447. * expect({ foo: 'baz' }).to.have.property('foo')
  448. * .and.not.equal('bar');
  449. *
  450. * @name not
  451. * @api public
  452. */
  453. Assertion.addProperty('not', function () {
  454. flag(this, 'negate', true);
  455. });
  456. /**
  457. * ### .deep
  458. *
  459. * Sets the `deep` flag, later used by the `equal` and
  460. * `property` assertions.
  461. *
  462. * expect(foo).to.deep.equal({ bar: 'baz' });
  463. * expect({ foo: { bar: { baz: 'quux' } } })
  464. * .to.have.deep.property('foo.bar.baz', 'quux');
  465. *
  466. * @name deep
  467. * @api public
  468. */
  469. Assertion.addProperty('deep', function () {
  470. flag(this, 'deep', true);
  471. });
  472. /**
  473. * ### .a(type)
  474. *
  475. * The `a` and `an` assertions are aliases that can be
  476. * used either as language chains or to assert a value's
  477. * type.
  478. *
  479. * // typeof
  480. * expect('test').to.be.a('string');
  481. * expect({ foo: 'bar' }).to.be.an('object');
  482. * expect(null).to.be.a('null');
  483. * expect(undefined).to.be.an('undefined');
  484. *
  485. * // language chain
  486. * expect(foo).to.be.an.instanceof(Foo);
  487. *
  488. * @name a
  489. * @alias an
  490. * @param {String} type
  491. * @param {String} message _optional_
  492. * @api public
  493. */
  494. function an (type, msg) {
  495. if (msg) flag(this, 'message', msg);
  496. type = type.toLowerCase();
  497. var obj = flag(this, 'object')
  498. , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
  499. this.assert(
  500. type === _.type(obj)
  501. , 'expected #{this} to be ' + article + type
  502. , 'expected #{this} not to be ' + article + type
  503. );
  504. }
  505. Assertion.addChainableMethod('an', an);
  506. Assertion.addChainableMethod('a', an);
  507. /**
  508. * ### .include(value)
  509. *
  510. * The `include` and `contain` assertions can be used as either property
  511. * based language chains or as methods to assert the inclusion of an object
  512. * in an array or a substring in a string. When used as language chains,
  513. * they toggle the `contain` flag for the `keys` assertion.
  514. *
  515. * expect([1,2,3]).to.include(2);
  516. * expect('foobar').to.contain('foo');
  517. * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
  518. *
  519. * @name include
  520. * @alias contain
  521. * @param {Object|String|Number} obj
  522. * @param {String} message _optional_
  523. * @api public
  524. */
  525. function includeChainingBehavior () {
  526. flag(this, 'contains', true);
  527. }
  528. function include (val, msg) {
  529. if (msg) flag(this, 'message', msg);
  530. var obj = flag(this, 'object')
  531. this.assert(
  532. ~obj.indexOf(val)
  533. , 'expected #{this} to include ' + _.inspect(val)
  534. , 'expected #{this} to not include ' + _.inspect(val));
  535. }
  536. Assertion.addChainableMethod('include', include, includeChainingBehavior);
  537. Assertion.addChainableMethod('contain', include, includeChainingBehavior);
  538. /**
  539. * ### .ok
  540. *
  541. * Asserts that the target is truthy.
  542. *
  543. * expect('everthing').to.be.ok;
  544. * expect(1).to.be.ok;
  545. * expect(false).to.not.be.ok;
  546. * expect(undefined).to.not.be.ok;
  547. * expect(null).to.not.be.ok;
  548. *
  549. * @name ok
  550. * @api public
  551. */
  552. Assertion.addProperty('ok', function () {
  553. this.assert(
  554. flag(this, 'object')
  555. , 'expected #{this} to be truthy'
  556. , 'expected #{this} to be falsy');
  557. });
  558. /**
  559. * ### .true
  560. *
  561. * Asserts that the target is `true`.
  562. *
  563. * expect(true).to.be.true;
  564. * expect(1).to.not.be.true;
  565. *
  566. * @name true
  567. * @api public
  568. */
  569. Assertion.addProperty('true', function () {
  570. this.assert(
  571. true === flag(this, 'object')
  572. , 'expected #{this} to be true'
  573. , 'expected #{this} to be false'
  574. , this.negate ? false : true
  575. );
  576. });
  577. /**
  578. * ### .false
  579. *
  580. * Asserts that the target is `false`.
  581. *
  582. * expect(false).to.be.false;
  583. * expect(0).to.not.be.false;
  584. *
  585. * @name false
  586. * @api public
  587. */
  588. Assertion.addProperty('false', function () {
  589. this.assert(
  590. false === flag(this, 'object')
  591. , 'expected #{this} to be false'
  592. , 'expected #{this} to be true'
  593. , this.negate ? true : false
  594. );
  595. });
  596. /**
  597. * ### .null
  598. *
  599. * Asserts that the target is `null`.
  600. *
  601. * expect(null).to.be.null;
  602. * expect(undefined).not.to.be.null;
  603. *
  604. * @name null
  605. * @api public
  606. */
  607. Assertion.addProperty('null', function () {
  608. this.assert(
  609. null === flag(this, 'object')
  610. , 'expected #{this} to be null'
  611. , 'expected #{this} not to be null'
  612. );
  613. });
  614. /**
  615. * ### .undefined
  616. *
  617. * Asserts that the target is `undefined`.
  618. *
  619. * expect(undefined).to.be.undefined;
  620. * expect(null).to.not.be.undefined;
  621. *
  622. * @name undefined
  623. * @api public
  624. */
  625. Assertion.addProperty('undefined', function () {
  626. this.assert(
  627. undefined === flag(this, 'object')
  628. , 'expected #{this} to be undefined'
  629. , 'expected #{this} not to be undefined'
  630. );
  631. });
  632. /**
  633. * ### .exist
  634. *
  635. * Asserts that the target is neither `null` nor `undefined`.
  636. *
  637. * var foo = 'hi'
  638. * , bar = null
  639. * , baz;
  640. *
  641. * expect(foo).to.exist;
  642. * expect(bar).to.not.exist;
  643. * expect(baz).to.not.exist;
  644. *
  645. * @name exist
  646. * @api public
  647. */
  648. Assertion.addProperty('exist', function () {
  649. this.assert(
  650. null != flag(this, 'object')
  651. , 'expected #{this} to exist'
  652. , 'expected #{this} to not exist'
  653. );
  654. });
  655. /**
  656. * ### .empty
  657. *
  658. * Asserts that the target's length is `0`. For arrays, it checks
  659. * the `length` property. For objects, it gets the count of
  660. * enumerable keys.
  661. *
  662. * expect([]).to.be.empty;
  663. * expect('').to.be.empty;
  664. * expect({}).to.be.empty;
  665. *
  666. * @name empty
  667. * @api public
  668. */
  669. Assertion.addProperty('empty', function () {
  670. var obj = flag(this, 'object')
  671. , expected = obj;
  672. if (Array.isArray(obj) || 'string' === typeof object) {
  673. expected = obj.length;
  674. } else if (typeof obj === 'object') {
  675. expected = Object.keys(obj).length;
  676. }
  677. this.assert(
  678. !expected
  679. , 'expected #{this} to be empty'
  680. , 'expected #{this} not to be empty'
  681. );
  682. });
  683. /**
  684. * ### .arguments
  685. *
  686. * Asserts that the target is an arguments object.
  687. *
  688. * function test () {
  689. * expect(arguments).to.be.arguments;
  690. * }
  691. *
  692. * @name arguments
  693. * @alias Arguments
  694. * @api public
  695. */
  696. function checkArguments () {
  697. var obj = flag(this, 'object')
  698. , type = Object.prototype.toString.call(obj);
  699. this.assert(
  700. '[object Arguments]' === type
  701. , 'expected #{this} to be arguments but got ' + type
  702. , 'expected #{this} to not be arguments'
  703. );
  704. }
  705. Assertion.addProperty('arguments', checkArguments);
  706. Assertion.addProperty('Arguments', checkArguments);
  707. /**
  708. * ### .equal(value)
  709. *
  710. * Asserts that the target is strictly equal (`===`) to `value`.
  711. * Alternately, if the `deep` flag is set, asserts that
  712. * the target is deeply equal to `value`.
  713. *
  714. * expect('hello').to.equal('hello');
  715. * expect(42).to.equal(42);
  716. * expect(1).to.not.equal(true);
  717. * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
  718. * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
  719. *
  720. * @name equal
  721. * @alias equals
  722. * @alias eq
  723. * @alias deep.equal
  724. * @param {Mixed} value
  725. * @param {String} message _optional_
  726. * @api public
  727. */
  728. function assertEqual (val, msg) {
  729. if (msg) flag(this, 'message', msg);
  730. var obj = flag(this, 'object');
  731. if (flag(this, 'deep')) {
  732. return this.eql(val);
  733. } else {
  734. this.assert(
  735. val === obj
  736. , 'expected #{this} to equal #{exp}'
  737. , 'expected #{this} to not equal #{exp}'
  738. , val
  739. , this._obj
  740. , true
  741. );
  742. }
  743. }
  744. Assertion.addMethod('equal', assertEqual);
  745. Assertion.addMethod('equals', assertEqual);
  746. Assertion.addMethod('eq', assertEqual);
  747. /**
  748. * ### .eql(value)
  749. *
  750. * Asserts that the target is deeply equal to `value`.
  751. *
  752. * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
  753. * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
  754. *
  755. * @name eql
  756. * @alias eqls
  757. * @param {Mixed} value
  758. * @param {String} message _optional_
  759. * @api public
  760. */
  761. function assertEql(obj, msg) {
  762. if (msg) flag(this, 'message', msg);
  763. this.assert(
  764. _.eql(obj, flag(this, 'object'))
  765. , 'expected #{this} to deeply equal #{exp}'
  766. , 'expected #{this} to not deeply equal #{exp}'
  767. , obj
  768. , this._obj
  769. , true
  770. );
  771. }
  772. Assertion.addMethod('eql', assertEql);
  773. Assertion.addMethod('eqls', assertEql);
  774. /**
  775. * ### .above(value)
  776. *
  777. * Asserts that the target is greater than `value`.
  778. *
  779. * expect(10).to.be.above(5);
  780. *
  781. * Can also be used in conjunction with `length` to
  782. * assert a minimum length. The benefit being a
  783. * more informative error message than if the length
  784. * was supplied directly.
  785. *
  786. * expect('foo').to.have.length.above(2);
  787. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  788. *
  789. * @name above
  790. * @alias gt
  791. * @alias greaterThan
  792. * @param {Number} value
  793. * @param {String} message _optional_
  794. * @api public
  795. */
  796. function assertAbove (n, msg) {
  797. if (msg) flag(this, 'message', msg);
  798. var obj = flag(this, 'object');
  799. if (flag(this, 'doLength')) {
  800. new Assertion(obj, msg).to.have.property('length');
  801. var len = obj.length;
  802. this.assert(
  803. len > n
  804. , 'expected #{this} to have a length above #{exp} but got #{act}'
  805. , 'expected #{this} to not have a length above #{exp}'
  806. , n
  807. , len
  808. );
  809. } else {
  810. this.assert(
  811. obj > n
  812. , 'expected #{this} to be above ' + n
  813. , 'expected #{this} to be at most ' + n
  814. );
  815. }
  816. }
  817. Assertion.addMethod('above', assertAbove);
  818. Assertion.addMethod('gt', assertAbove);
  819. Assertion.addMethod('greaterThan', assertAbove);
  820. /**
  821. * ### .least(value)
  822. *
  823. * Asserts that the target is greater than or equal to `value`.
  824. *
  825. * expect(10).to.be.at.least(10);
  826. *
  827. * Can also be used in conjunction with `length` to
  828. * assert a minimum length. The benefit being a
  829. * more informative error message than if the length
  830. * was supplied directly.
  831. *
  832. * expect('foo').to.have.length.of.at.least(2);
  833. * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
  834. *
  835. * @name least
  836. * @alias gte
  837. * @param {Number} value
  838. * @param {String} message _optional_
  839. * @api public
  840. */
  841. function assertLeast (n, msg) {
  842. if (msg) flag(this, 'message', msg);
  843. var obj = flag(this, 'object');
  844. if (flag(this, 'doLength')) {
  845. new Assertion(obj, msg).to.have.property('length');
  846. var len = obj.length;
  847. this.assert(
  848. len >= n
  849. , 'expected #{this} to have a length at least #{exp} but got #{act}'
  850. , 'expected #{this} to have a length below #{exp}'
  851. , n
  852. , len
  853. );
  854. } else {
  855. this.assert(
  856. obj >= n
  857. , 'expected #{this} to be at least ' + n
  858. , 'expected #{this} to be below ' + n
  859. );
  860. }
  861. }
  862. Assertion.addMethod('least', assertLeast);
  863. Assertion.addMethod('gte', assertLeast);
  864. /**
  865. * ### .below(value)
  866. *
  867. * Asserts that the target is less than `value`.
  868. *
  869. * expect(5).to.be.below(10);
  870. *
  871. * Can also be used in conjunction with `length` to
  872. * assert a maximum length. The benefit being a
  873. * more informative error message than if the length
  874. * was supplied directly.
  875. *
  876. * expect('foo').to.have.length.below(4);
  877. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  878. *
  879. * @name below
  880. * @alias lt
  881. * @alias lessThan
  882. * @param {Number} value
  883. * @param {String} message _optional_
  884. * @api public
  885. */
  886. function assertBelow (n, msg) {
  887. if (msg) flag(this, 'message', msg);
  888. var obj = flag(this, 'object');
  889. if (flag(this, 'doLength')) {
  890. new Assertion(obj, msg).to.have.property('length');
  891. var len = obj.length;
  892. this.assert(
  893. len < n
  894. , 'expected #{this} to have a length below #{exp} but got #{act}'
  895. , 'expected #{this} to not have a length below #{exp}'
  896. , n
  897. , len
  898. );
  899. } else {
  900. this.assert(
  901. obj < n
  902. , 'expected #{this} to be below ' + n
  903. , 'expected #{this} to be at least ' + n
  904. );
  905. }
  906. }
  907. Assertion.addMethod('below', assertBelow);
  908. Assertion.addMethod('lt', assertBelow);
  909. Assertion.addMethod('lessThan', assertBelow);
  910. /**
  911. * ### .most(value)
  912. *
  913. * Asserts that the target is less than or equal to `value`.
  914. *
  915. * expect(5).to.be.at.most(5);
  916. *
  917. * Can also be used in conjunction with `length` to
  918. * assert a maximum length. The benefit being a
  919. * more informative error message than if the length
  920. * was supplied directly.
  921. *
  922. * expect('foo').to.have.length.of.at.most(4);
  923. * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
  924. *
  925. * @name most
  926. * @alias lte
  927. * @param {Number} value
  928. * @param {String} message _optional_
  929. * @api public
  930. */
  931. function assertMost (n, msg) {
  932. if (msg) flag(this, 'message', msg);
  933. var obj = flag(this, 'object');
  934. if (flag(this, 'doLength')) {
  935. new Assertion(obj, msg).to.have.property('length');
  936. var len = obj.length;
  937. this.assert(
  938. len <= n
  939. , 'expected #{this} to have a length at most #{exp} but got #{act}'
  940. , 'expected #{this} to have a length above #{exp}'
  941. , n
  942. , len
  943. );
  944. } else {
  945. this.assert(
  946. obj <= n
  947. , 'expected #{this} to be at most ' + n
  948. , 'expected #{this} to be above ' + n
  949. );
  950. }
  951. }
  952. Assertion.addMethod('most', assertMost);
  953. Assertion.addMethod('lte', assertMost);
  954. /**
  955. * ### .within(start, finish)
  956. *
  957. * Asserts that the target is within a range.
  958. *
  959. * expect(7).to.be.within(5,10);
  960. *
  961. * Can also be used in conjunction with `length` to
  962. * assert a length range. The benefit being a
  963. * more informative error message than if the length
  964. * was supplied directly.
  965. *
  966. * expect('foo').to.have.length.within(2,4);
  967. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  968. *
  969. * @name within
  970. * @param {Number} start lowerbound inclusive
  971. * @param {Number} finish upperbound inclusive
  972. * @param {String} message _optional_
  973. * @api public
  974. */
  975. Assertion.addMethod('within', function (start, finish, msg) {
  976. if (msg) flag(this, 'message', msg);
  977. var obj = flag(this, 'object')
  978. , range = start + '..' + finish;
  979. if (flag(this, 'doLength')) {
  980. new Assertion(obj, msg).to.have.property('length');
  981. var len = obj.length;
  982. this.assert(
  983. len >= start && len <= finish
  984. , 'expected #{this} to have a length within ' + range
  985. , 'expected #{this} to not have a length within ' + range
  986. );
  987. } else {
  988. this.assert(
  989. obj >= start && obj <= finish
  990. , 'expected #{this} to be within ' + range
  991. , 'expected #{this} to not be within ' + range
  992. );
  993. }
  994. });
  995. /**
  996. * ### .instanceof(constructor)
  997. *
  998. * Asserts that the target is an instance of `constructor`.
  999. *
  1000. * var Tea = function (name) { this.name = name; }
  1001. * , Chai = new Tea('chai');
  1002. *
  1003. * expect(Chai).to.be.an.instanceof(Tea);
  1004. * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
  1005. *
  1006. * @name instanceof
  1007. * @param {Constructor} constructor
  1008. * @param {String} message _optional_
  1009. * @alias instanceOf
  1010. * @api public
  1011. */
  1012. function assertInstanceOf (constructor, msg) {
  1013. if (msg) flag(this, 'message', msg);
  1014. var name = _.getName(constructor);
  1015. this.assert(
  1016. flag(this, 'object') instanceof constructor
  1017. , 'expected #{this} to be an instance of ' + name
  1018. , 'expected #{this} to not be an instance of ' + name
  1019. );
  1020. };
  1021. Assertion.addMethod('instanceof', assertInstanceOf);
  1022. Assertion.addMethod('instanceOf', assertInstanceOf);
  1023. /**
  1024. * ### .property(name, [value])
  1025. *
  1026. * Asserts that the target has a property `name`, optionally asserting that
  1027. * the value of that property is strictly equal to `value`.
  1028. * If the `deep` flag is set, you can use dot- and bracket-notation for deep
  1029. * references into objects and arrays.
  1030. *
  1031. * // simple referencing
  1032. * var obj = { foo: 'bar' };
  1033. * expect(obj).to.have.property('foo');
  1034. * expect(obj).to.have.property('foo', 'bar');
  1035. *
  1036. * // deep referencing
  1037. * var deepObj = {
  1038. * green: { tea: 'matcha' }
  1039. * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
  1040. * };
  1041. * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
  1042. * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
  1043. * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
  1044. *
  1045. * You can also use an array as the starting point of a `deep.property`
  1046. * assertion, or traverse nested arrays.
  1047. *
  1048. * var arr = [
  1049. * [ 'chai', 'matcha', 'konacha' ]
  1050. * , [ { tea: 'chai' }
  1051. * , { tea: 'matcha' }
  1052. * , { tea: 'konacha' } ]
  1053. * ];
  1054. *
  1055. * expect(arr).to.have.deep.property('[0][1]', 'matcha');
  1056. * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
  1057. *
  1058. * Furthermore, `property` changes the subject of the assertion
  1059. * to be the value of that property from the original object. This
  1060. * permits for further chainable assertions on that property.
  1061. *
  1062. * expect(obj).to.have.property('foo')
  1063. * .that.is.a('string');
  1064. * expect(deepObj).to.have.property('green')
  1065. * .that.is.an('object')
  1066. * .that.deep.equals({ tea: 'matcha' });
  1067. * expect(deepObj).to.have.property('teas')
  1068. * .that.is.an('array')
  1069. * .with.deep.property('[2]')
  1070. * .that.deep.equals({ tea: 'konacha' });
  1071. *
  1072. * @name property
  1073. * @alias deep.property
  1074. * @param {String} name
  1075. * @param {Mixed} value (optional)
  1076. * @param {String} message _optional_
  1077. * @returns value of property for chaining
  1078. * @api public
  1079. */
  1080. Assertion.addMethod('property', function (name, val, msg) {
  1081. if (msg) flag(this, 'message', msg);
  1082. var descriptor = flag(this, 'deep') ? 'deep property ' : 'property '
  1083. , negate = flag(this, 'negate')
  1084. , obj = flag(this, 'object')
  1085. , value = flag(this, 'deep')
  1086. ? _.getPathValue(name, obj)
  1087. : obj[name];
  1088. if (negate && undefined !== val) {
  1089. if (undefined === value) {
  1090. msg = (msg != null) ? msg + ': ' : '';
  1091. throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
  1092. }
  1093. } else {
  1094. this.assert(
  1095. undefined !== value
  1096. , 'expected #{this} to have a ' + descriptor + _.inspect(name)
  1097. , 'expected #{this} to not have ' + descriptor + _.inspect(name));
  1098. }
  1099. if (undefined !== val) {
  1100. this.assert(
  1101. val === value
  1102. , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
  1103. , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'
  1104. , val
  1105. , value
  1106. );
  1107. }
  1108. flag(this, 'object', value);
  1109. });
  1110. /**
  1111. * ### .ownProperty(name)
  1112. *
  1113. * Asserts that the target has an own property `name`.
  1114. *
  1115. * expect('test').to.have.ownProperty('length');
  1116. *
  1117. * @name ownProperty
  1118. * @alias haveOwnProperty
  1119. * @param {String} name
  1120. * @param {String} message _optional_
  1121. * @api public
  1122. */
  1123. function assertOwnProperty (name, msg) {
  1124. if (msg) flag(this, 'message', msg);
  1125. var obj = flag(this, 'object');
  1126. this.assert(
  1127. obj.hasOwnProperty(name)
  1128. , 'expected #{this} to have own property ' + _.inspect(name)
  1129. , 'expected #{this} to not have own property ' + _.inspect(name)
  1130. );
  1131. }
  1132. Assertion.addMethod('ownProperty', assertOwnProperty);
  1133. Assertion.addMethod('haveOwnProperty', assertOwnProperty);
  1134. /**
  1135. * ### .length(value)
  1136. *
  1137. * Asserts that the target's `length` property has
  1138. * the expected value.
  1139. *
  1140. * expect([ 1, 2, 3]).to.have.length(3);
  1141. * expect('foobar').to.have.length(6);
  1142. *
  1143. * Can also be used as a chain precursor to a value
  1144. * comparison for the length property.
  1145. *
  1146. * expect('foo').to.have.length.above(2);
  1147. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  1148. * expect('foo').to.have.length.below(4);
  1149. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  1150. * expect('foo').to.have.length.within(2,4);
  1151. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  1152. *
  1153. * @name length
  1154. * @alias lengthOf
  1155. * @param {Number} length
  1156. * @param {String} message _optional_
  1157. * @api public
  1158. */
  1159. function assertLengthChain () {
  1160. flag(this, 'doLength', true);
  1161. }
  1162. function assertLength (n, msg) {
  1163. if (msg) flag(this, 'message', msg);
  1164. var obj = flag(this, 'object');
  1165. new Assertion(obj, msg).to.have.property('length');
  1166. var len = obj.length;
  1167. this.assert(
  1168. len == n
  1169. , 'expected #{this} to have a length of #{exp} but got #{act}'
  1170. , 'expected #{this} to not have a length of #{act}'
  1171. , n
  1172. , len
  1173. );
  1174. }
  1175. Assertion.addChainableMethod('length', assertLength, assertLengthChain);
  1176. Assertion.addMethod('lengthOf', assertLength, assertLengthChain);
  1177. /**
  1178. * ### .match(regexp)
  1179. *
  1180. * Asserts that the target matches a regular expression.
  1181. *
  1182. * expect('foobar').to.match(/^foo/);
  1183. *
  1184. * @name match
  1185. * @param {RegExp} RegularExpression
  1186. * @param {String} message _optional_
  1187. * @api public
  1188. */
  1189. Assertion.addMethod('match', function (re, msg) {
  1190. if (msg) flag(this, 'message', msg);
  1191. var obj = flag(this, 'object');
  1192. this.assert(
  1193. re.exec(obj)
  1194. , 'expected #{this} to match ' + re
  1195. , 'expected #{this} not to match ' + re
  1196. );
  1197. });
  1198. /**
  1199. * ### .string(string)
  1200. *
  1201. * Asserts that the string target contains another string.
  1202. *
  1203. * expect('foobar').to.have.string('bar');
  1204. *
  1205. * @name string
  1206. * @param {String} string
  1207. * @param {String} message _optional_
  1208. * @api public
  1209. */
  1210. Assertion.addMethod('string', function (str, msg) {
  1211. if (msg) flag(this, 'message', msg);
  1212. var obj = flag(this, 'object');
  1213. new Assertion(obj, msg).is.a('string');
  1214. this.assert(
  1215. ~obj.indexOf(str)
  1216. , 'expected #{this} to contain ' + _.inspect(str)
  1217. , 'expected #{this} to not contain ' + _.inspect(str)
  1218. );
  1219. });
  1220. /**
  1221. * ### .keys(key1, [key2], [...])
  1222. *
  1223. * Asserts that the target has exactly the given keys, or
  1224. * asserts the inclusion of some keys when using the
  1225. * `include` or `contain` modifiers.
  1226. *
  1227. * expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
  1228. * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
  1229. *
  1230. * @name keys
  1231. * @alias key
  1232. * @param {String...|Array} keys
  1233. * @api public
  1234. */
  1235. function assertKeys (keys) {
  1236. var obj = flag(this, 'object')
  1237. , str
  1238. , ok = true;
  1239. keys = keys instanceof Array
  1240. ? keys
  1241. : Array.prototype.slice.call(arguments);
  1242. if (!keys.length) throw new Error('keys required');
  1243. var actual = Object.keys(obj)
  1244. , len = keys.length;
  1245. // Inclusion
  1246. ok = keys.every(function(key){
  1247. return ~actual.indexOf(key);
  1248. });
  1249. // Strict
  1250. if (!flag(this, 'negate') && !flag(this, 'contains')) {
  1251. ok = ok && keys.length == actual.length;
  1252. }
  1253. // Key string
  1254. if (len > 1) {
  1255. keys = keys.map(function(key){
  1256. return _.inspect(key);
  1257. });
  1258. var last = keys.pop();
  1259. str = keys.join(', ') + ', and ' + last;
  1260. } else {
  1261. str = _.inspect(keys[0]);
  1262. }
  1263. // Form
  1264. str = (len > 1 ? 'keys ' : 'key ') + str;
  1265. // Have / include
  1266. str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
  1267. // Assertion
  1268. this.assert(
  1269. ok
  1270. , 'expected #{this} to ' + str
  1271. , 'expected #{this} to not ' + str
  1272. );
  1273. }
  1274. Assertion.addMethod('keys', assertKeys);
  1275. Assertion.addMethod('key', assertKeys);
  1276. /**
  1277. * ### .throw(constructor)
  1278. *
  1279. * Asserts that the function target will throw a specific error, or specific type of error
  1280. * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
  1281. * for the error's message.
  1282. *
  1283. * var err = new ReferenceError('This is a bad function.');
  1284. * var fn = function () { throw err; }
  1285. * expect(fn).to.throw(ReferenceError);
  1286. * expect(fn).to.throw(Error);
  1287. * expect(fn).to.throw(/bad function/);
  1288. * expect(fn).to.not.throw('good function');
  1289. * expect(fn).to.throw(ReferenceError, /bad function/);
  1290. * expect(fn).to.throw(err);
  1291. * expect(fn).to.not.throw(new RangeError('Out of range.'));
  1292. *
  1293. * Please note that when a throw expectation is negated, it will check each
  1294. * parameter independently, starting with error constructor type. The appropriate way
  1295. * to check for the existence of a type of error but for a message that does not match
  1296. * is to use `and`.
  1297. *
  1298. * expect(fn).to.throw(ReferenceError)
  1299. * .and.not.throw(/good function/);
  1300. *
  1301. * @name throw
  1302. * @alias throws
  1303. * @alias Throw
  1304. * @param {ErrorConstructor} constructor
  1305. * @param {String|RegExp} expected error message
  1306. * @param {String} message _optional_
  1307. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  1308. * @api public
  1309. */
  1310. function assertThrows (constructor, errMsg, msg) {
  1311. if (msg) flag(this, 'message', msg);
  1312. var obj = flag(this, 'object');
  1313. new Assertion(obj, msg).is.a('function');
  1314. var thrown = false
  1315. , desiredError = null
  1316. , name = null
  1317. , thrownError = null;
  1318. if (arguments.length === 0) {
  1319. errMsg = null;
  1320. constructor = null;
  1321. } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
  1322. errMsg = constructor;
  1323. constructor = null;
  1324. } else if (constructor && constructor instanceof Error) {
  1325. desiredError = constructor;
  1326. constructor = null;
  1327. errMsg = null;
  1328. } else if (typeof constructor === 'function') {
  1329. name = (new constructor()).name;
  1330. } else {
  1331. constructor = null;
  1332. }
  1333. try {
  1334. obj();
  1335. } catch (err) {
  1336. // first, check desired error
  1337. if (desiredError) {
  1338. this.assert(
  1339. err === desiredError
  1340. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  1341. , 'expected #{this} to not throw #{exp}'
  1342. , desiredError
  1343. , err
  1344. );
  1345. return this;
  1346. }
  1347. // next, check constructor
  1348. if (constructor) {
  1349. this.assert(
  1350. err instanceof constructor
  1351. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  1352. , 'expected #{this} to not throw #{exp} but #{act} was thrown'
  1353. , name
  1354. , err
  1355. );
  1356. if (!errMsg) return this;
  1357. }
  1358. // next, check message
  1359. var message = 'object' === _.type(err) && "message" in err
  1360. ? err.message
  1361. : '' + err;
  1362. if ((message != null) && errMsg && errMsg instanceof RegExp) {
  1363. this.assert(
  1364. errMsg.exec(message)
  1365. , 'expected #{this} to throw error matching #{exp} but got #{act}'
  1366. , 'expected #{this} to throw error not matching #{exp}'
  1367. , errMsg
  1368. , message
  1369. );
  1370. return this;
  1371. } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
  1372. this.assert(
  1373. ~message.indexOf(errMsg)
  1374. , 'expected #{this} to throw error including #{exp} but got #{act}'
  1375. , 'expected #{this} to throw error not including #{act}'
  1376. , errMsg
  1377. , message
  1378. );
  1379. return this;
  1380. } else {
  1381. thrown = true;
  1382. thrownError = err;
  1383. }
  1384. }
  1385. var actuallyGot = ''
  1386. , expectedThrown = name !== null
  1387. ? name
  1388. : desiredError
  1389. ? '#{exp}' //_.inspect(desiredError)
  1390. : 'an error';
  1391. if (thrown) {
  1392. actuallyGot = ' but #{act} was thrown'
  1393. }
  1394. this.assert(
  1395. thrown === true
  1396. , 'expected #{this} to throw ' + expectedThrown + actuallyGot
  1397. , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
  1398. , desiredError
  1399. , thrownError
  1400. );
  1401. };
  1402. Assertion.addMethod('throw', assertThrows);
  1403. Assertion.addMethod('throws', assertThrows);
  1404. Assertion.addMethod('Throw', assertThrows);
  1405. /**
  1406. * ### .respondTo(method)
  1407. *
  1408. * Asserts that the object or class target will respond to a method.
  1409. *
  1410. * Klass.prototype.bar = function(){};
  1411. * expect(Klass).to.respondTo('bar');
  1412. * expect(obj).to.respondTo('bar');
  1413. *
  1414. * To check if a constructor will respond to a static function,
  1415. * set the `itself` flag.
  1416. *
  1417. * Klass.baz = function(){};
  1418. * expect(Klass).itself.to.respondTo('baz');
  1419. *
  1420. * @name respondTo
  1421. * @param {String} method
  1422. * @param {String} message _optional_
  1423. * @api public
  1424. */
  1425. Assertion.addMethod('respondTo', function (method, msg) {
  1426. if (msg) flag(this, 'message', msg);
  1427. var obj = flag(this, 'object')
  1428. , itself = flag(this, 'itself')
  1429. , context = ('function' === _.type(obj) && !itself)
  1430. ? obj.prototype[method]
  1431. : obj[method];
  1432. this.assert(
  1433. 'function' === typeof context
  1434. , 'expected #{this} to respond to ' + _.inspect(method)
  1435. , 'expected #{this} to not respond to ' + _.inspect(method)
  1436. );
  1437. });
  1438. /**
  1439. * ### .itself
  1440. *
  1441. * Sets the `itself` flag, later used by the `respondTo` assertion.
  1442. *
  1443. * function Foo() {}
  1444. * Foo.bar = function() {}
  1445. * Foo.prototype.baz = function() {}
  1446. *
  1447. * expect(Foo).itself.to.respondTo('bar');
  1448. * expect(Foo).itself.not.to.respondTo('baz');
  1449. *
  1450. * @name itself
  1451. * @api public
  1452. */
  1453. Assertion.addProperty('itself', function () {
  1454. flag(this, 'itself', true);
  1455. });
  1456. /**
  1457. * ### .satisfy(method)
  1458. *
  1459. * Asserts that the target passes a given truth test.
  1460. *
  1461. * expect(1).to.satisfy(function(num) { return num > 0; });
  1462. *
  1463. * @name satisfy
  1464. * @param {Function} matcher
  1465. * @param {String} message _optional_
  1466. * @api public
  1467. */
  1468. Assertion.addMethod('satisfy', function (matcher, msg) {
  1469. if (msg) flag(this, 'message', msg);
  1470. var obj = flag(this, 'object');
  1471. this.assert(
  1472. matcher(obj)
  1473. , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
  1474. , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
  1475. , this.negate ? false : true
  1476. , matcher(obj)
  1477. );
  1478. });
  1479. /**
  1480. * ### .closeTo(expected, delta)
  1481. *
  1482. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  1483. *
  1484. * expect(1.5).to.be.closeTo(1, 0.5);
  1485. *
  1486. * @name closeTo
  1487. * @param {Number} expected
  1488. * @param {Number} delta
  1489. * @param {String} message _optional_
  1490. * @api public
  1491. */
  1492. Assertion.addMethod('closeTo', function (expected, delta, msg) {
  1493. if (msg) flag(this, 'message', msg);
  1494. var obj = flag(this, 'object');
  1495. this.assert(
  1496. Math.abs(obj - expected) <= delta
  1497. , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
  1498. , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
  1499. );
  1500. });
  1501. function isSubsetOf(subset, superset) {
  1502. return subset.every(function(elem) {
  1503. return superset.indexOf(elem) !== -1;
  1504. })
  1505. }
  1506. /**
  1507. * ### .members
  1508. *
  1509. * Asserts that the target is a superset of `set`,
  1510. * or that the target and `set` have the same members.
  1511. *
  1512. * expect([1, 2, 3]).to.include.members([3, 2]);
  1513. * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
  1514. *
  1515. * expect([4, 2]).to.have.members([2, 4]);
  1516. * expect([5, 2]).to.not.have.members([5, 2, 1]);
  1517. *
  1518. * @name members
  1519. * @param {Array} set
  1520. * @param {String} message _optional_
  1521. * @api public
  1522. */
  1523. Assertion.addMethod('members', function (subset, msg) {
  1524. if (msg) flag(this, 'message', msg);
  1525. var obj = flag(this, 'object');
  1526. new Assertion(obj).to.be.an('array');
  1527. new Assertion(subset).to.be.an('array');
  1528. if (flag(this, 'contains')) {
  1529. return this.assert(
  1530. isSubsetOf(subset, obj)
  1531. , 'expected #{this} to be a superset of #{act}'
  1532. , 'expected #{this} to not be a superset of #{act}'
  1533. , obj
  1534. , subset
  1535. );
  1536. }
  1537. this.assert(
  1538. isSubsetOf(obj, subset) && isSubsetOf(subset, obj)
  1539. , 'expected #{this} to have the same members as #{act}'
  1540. , 'expected #{this} to not have the same members as #{act}'
  1541. , obj
  1542. , subset
  1543. );
  1544. });
  1545. };
  1546. });
  1547. require.register("chai/lib/chai/interface/assert.js", function(exports, require, module){
  1548. /*!
  1549. * chai
  1550. * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
  1551. * MIT Licensed
  1552. */
  1553. module.exports = function (chai, util) {
  1554. /*!
  1555. * Chai dependencies.
  1556. */
  1557. var Assertion = chai.Assertion
  1558. , flag = util.flag;
  1559. /*!
  1560. * Module export.
  1561. */
  1562. /**
  1563. * ### assert(expression, message)
  1564. *
  1565. * Write your own test expressions.
  1566. *
  1567. * assert('foo' !== 'bar', 'foo is not bar');
  1568. * assert(Array.isArray([]), 'empty arrays are arrays');
  1569. *
  1570. * @param {Mixed} expression to test for truthiness
  1571. * @param {String} message to display on error
  1572. * @name assert
  1573. * @api public
  1574. */
  1575. var assert = chai.assert = function (express, errmsg) {
  1576. var test = new Assertion(null);
  1577. test.assert(
  1578. express
  1579. , errmsg
  1580. , '[ negation message unavailable ]'
  1581. );
  1582. };
  1583. /**
  1584. * ### .fail(actual, expected, [message], [operator])
  1585. *
  1586. * Throw a failure. Node.js `assert` module-compatible.
  1587. *
  1588. * @name fail
  1589. * @param {Mixed} actual
  1590. * @param {Mixed} expected
  1591. * @param {String} message
  1592. * @param {String} operator
  1593. * @api public
  1594. */
  1595. assert.fail = function (actual, expected, message, operator) {
  1596. throw new chai.AssertionError({
  1597. actual: actual
  1598. , expected: expected
  1599. , message: message
  1600. , operator: operator
  1601. , stackStartFunction: assert.fail
  1602. });
  1603. };
  1604. /**
  1605. * ### .ok(object, [message])
  1606. *
  1607. * Asserts that `object` is truthy.
  1608. *
  1609. * assert.ok('everything', 'everything is ok');
  1610. * assert.ok(false, 'this will fail');
  1611. *
  1612. * @name ok
  1613. * @param {Mixed} object to test
  1614. * @param {String} message
  1615. * @api public
  1616. */
  1617. assert.ok = function (val, msg) {
  1618. new Assertion(val, msg).is.ok;
  1619. };
  1620. /**
  1621. * ### .equal(actual, expected, [message])
  1622. *
  1623. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  1624. *
  1625. * assert.equal(3, '3', '== coerces values to strings');
  1626. *
  1627. * @name equal
  1628. * @param {Mixed} actual
  1629. * @param {Mixed} expected
  1630. * @param {String} message
  1631. * @api public
  1632. */
  1633. assert.equal = function (act, exp, msg) {
  1634. var test = new Assertion(act, msg);
  1635. test.assert(
  1636. exp == flag(test, 'object')
  1637. , 'expected #{this} to equal #{exp}'
  1638. , 'expected #{this} to not equal #{act}'
  1639. , exp
  1640. , act
  1641. );
  1642. };
  1643. /**
  1644. * ### .notEqual(actual, expected, [message])
  1645. *
  1646. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  1647. *
  1648. * assert.notEqual(3, 4, 'these numbers are not equal');
  1649. *
  1650. * @name notEqual
  1651. * @param {Mixed} actual
  1652. * @param {Mixed} expected
  1653. * @param {String} message
  1654. * @api public
  1655. */
  1656. assert.notEqual = function (act, exp, msg) {
  1657. var test = new Assertion(act, msg);
  1658. test.assert(
  1659. exp != flag(test, 'object')
  1660. , 'expected #{this} to not equal #{exp}'
  1661. , 'expected #{this} to equal #{act}'
  1662. , exp
  1663. , act
  1664. );
  1665. };
  1666. /**
  1667. * ### .strictEqual(actual, expected, [message])
  1668. *
  1669. * Asserts strict equality (`===`) of `actual` and `expected`.
  1670. *
  1671. * assert.strictEqual(true, true, 'these booleans are strictly equal');
  1672. *
  1673. * @name strictEqual
  1674. * @param {Mixed} actual
  1675. * @param {Mixed} expected
  1676. * @param {String} message
  1677. * @api public
  1678. */
  1679. assert.strictEqual = function (act, exp, msg) {
  1680. new Assertion(act, msg).to.equal(exp);
  1681. };
  1682. /**
  1683. * ### .notStrictEqual(actual, expected, [message])
  1684. *
  1685. * Asserts strict inequality (`!==`) of `actual` and `expected`.
  1686. *
  1687. * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
  1688. *
  1689. * @name notStrictEqual
  1690. * @param {Mixed} actual
  1691. * @param {Mixed} expected
  1692. * @param {String} message
  1693. * @api public
  1694. */
  1695. assert.notStrictEqual = function (act, exp, msg) {
  1696. new Assertion(act, msg).to.not.equal(exp);
  1697. };
  1698. /**
  1699. * ### .deepEqual(actual, expected, [message])
  1700. *
  1701. * Asserts that `actual` is deeply equal to `expected`.
  1702. *
  1703. * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
  1704. *
  1705. * @name deepEqual
  1706. * @param {Mixed} actual
  1707. * @param {Mixed} expected
  1708. * @param {String} message
  1709. * @api public
  1710. */
  1711. assert.deepEqual = function (act, exp, msg) {
  1712. new Assertion(act, msg).to.eql(exp);
  1713. };
  1714. /**
  1715. * ### .notDeepEqual(actual, expected, [message])
  1716. *
  1717. * Assert that `actual` is not deeply equal to `expected`.
  1718. *
  1719. * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
  1720. *
  1721. * @name notDeepEqual
  1722. * @param {Mixed} actual
  1723. * @param {Mixed} expected
  1724. * @param {String} message
  1725. * @api public
  1726. */
  1727. assert.notDeepEqual = function (act, exp, msg) {
  1728. new Assertion(act, msg).to.not.eql(exp);
  1729. };
  1730. /**
  1731. * ### .isTrue(value, [message])
  1732. *
  1733. * Asserts that `value` is true.
  1734. *
  1735. * var teaServed = true;
  1736. * assert.isTrue(teaServed, 'the tea has been served');
  1737. *
  1738. * @name isTrue
  1739. * @param {Mixed} value
  1740. * @param {String} message
  1741. * @api public
  1742. */
  1743. assert.isTrue = function (val, msg) {
  1744. new Assertion(val, msg).is['true'];
  1745. };
  1746. /**
  1747. * ### .isFalse(value, [message])
  1748. *
  1749. * Asserts that `value` is false.
  1750. *
  1751. * var teaServed = false;
  1752. * assert.isFalse(teaServed, 'no tea yet? hmm...');
  1753. *
  1754. * @name isFalse
  1755. * @param {Mixed} value
  1756. * @param {String} message
  1757. * @api public
  1758. */
  1759. assert.isFalse = function (val, msg) {
  1760. new Assertion(val, msg).is['false'];
  1761. };
  1762. /**
  1763. * ### .isNull(value, [message])
  1764. *
  1765. * Asserts that `value` is null.
  1766. *
  1767. * assert.isNull(err, 'there was no error');
  1768. *
  1769. * @name isNull
  1770. * @param {Mixed} value
  1771. * @param {String} message
  1772. * @api public
  1773. */
  1774. assert.isNull = function (val, msg) {
  1775. new Assertion(val, msg).to.equal(null);
  1776. };
  1777. /**
  1778. * ### .isNotNull(value, [message])
  1779. *
  1780. * Asserts that `value` is not null.
  1781. *
  1782. * var tea = 'tasty chai';
  1783. * assert.isNotNull(tea, 'great, time for tea!');
  1784. *
  1785. * @name isNotNull
  1786. * @param {Mixed} value
  1787. * @param {String} message
  1788. * @api public
  1789. */
  1790. assert.isNotNull = function (val, msg) {
  1791. new Assertion(val, msg).to.not.equal(null);
  1792. };
  1793. /**
  1794. * ### .isUndefined(value, [message])
  1795. *
  1796. * Asserts that `value` is `undefined`.
  1797. *
  1798. * var tea;
  1799. * assert.isUndefined(tea, 'no tea defined');
  1800. *
  1801. * @name isUndefined
  1802. * @param {Mixed} value
  1803. * @param {String} message
  1804. * @api public
  1805. */
  1806. assert.isUndefined = function (val, msg) {
  1807. new Assertion(val, msg).to.equal(undefined);
  1808. };
  1809. /**
  1810. * ### .isDefined(value, [message])
  1811. *
  1812. * Asserts that `value` is not `undefined`.
  1813. *
  1814. * var tea = 'cup of chai';
  1815. * assert.isDefined(tea, 'tea has been defined');
  1816. *
  1817. * @name isUndefined
  1818. * @param {Mixed} value
  1819. * @param {String} message
  1820. * @api public
  1821. */
  1822. assert.isDefined = function (val, msg) {
  1823. new Assertion(val, msg).to.not.equal(undefined);
  1824. };
  1825. /**
  1826. * ### .isFunction(value, [message])
  1827. *
  1828. * Asserts that `value` is a function.
  1829. *
  1830. * function serveTea() { return 'cup of tea'; };
  1831. * assert.isFunction(serveTea, 'great, we can have tea now');
  1832. *
  1833. * @name isFunction
  1834. * @param {Mixed} value
  1835. * @param {String} message
  1836. * @api public
  1837. */
  1838. assert.isFunction = function (val, msg) {
  1839. new Assertion(val, msg).to.be.a('function');
  1840. };
  1841. /**
  1842. * ### .isNotFunction(value, [message])
  1843. *
  1844. * Asserts that `value` is _not_ a function.
  1845. *
  1846. * var serveTea = [ 'heat', 'pour', 'sip' ];
  1847. * assert.isNotFunction(serveTea, 'great, we have listed the steps');
  1848. *
  1849. * @name isNotFunction
  1850. * @param {Mixed} value
  1851. * @param {String} message
  1852. * @api public
  1853. */
  1854. assert.isNotFunction = function (val, msg) {
  1855. new Assertion(val, msg).to.not.be.a('function');
  1856. };
  1857. /**
  1858. * ### .isObject(value, [message])
  1859. *
  1860. * Asserts that `value` is an object (as revealed by
  1861. * `Object.prototype.toString`).
  1862. *
  1863. * var selection = { name: 'Chai', serve: 'with spices' };
  1864. * assert.isObject(selection, 'tea selection is an object');
  1865. *
  1866. * @name isObject
  1867. * @param {Mixed} value
  1868. * @param {String} message
  1869. * @api public
  1870. */
  1871. assert.isObject = function (val, msg) {
  1872. new Assertion(val, msg).to.be.a('object');
  1873. };
  1874. /**
  1875. * ### .isNotObject(value, [message])
  1876. *
  1877. * Asserts that `value` is _not_ an object.
  1878. *
  1879. * var selection = 'chai'
  1880. * assert.isObject(selection, 'tea selection is not an object');
  1881. * assert.isObject(null, 'null is not an object');
  1882. *
  1883. * @name isNotObject
  1884. * @param {Mixed} value
  1885. * @param {String} message
  1886. * @api public
  1887. */
  1888. assert.isNotObject = function (val, msg) {
  1889. new Assertion(val, msg).to.not.be.a('object');
  1890. };
  1891. /**
  1892. * ### .isArray(value, [message])
  1893. *
  1894. * Asserts that `value` is an array.
  1895. *
  1896. * var menu = [ 'green', 'chai', 'oolong' ];
  1897. * assert.isArray(menu, 'what kind of tea do we want?');
  1898. *
  1899. * @name isArray
  1900. * @param {Mixed} value
  1901. * @param {String} message
  1902. * @api public
  1903. */
  1904. assert.isArray = function (val, msg) {
  1905. new Assertion(val, msg).to.be.an('array');
  1906. };
  1907. /**
  1908. * ### .isNotArray(value, [message])
  1909. *
  1910. * Asserts that `value` is _not_ an array.
  1911. *
  1912. * var menu = 'green|chai|oolong';
  1913. * assert.isNotArray(menu, 'what kind of tea do we want?');
  1914. *
  1915. * @name isNotArray
  1916. * @param {Mixed} value
  1917. * @param {String} message
  1918. * @api public
  1919. */
  1920. assert.isNotArray = function (val, msg) {
  1921. new Assertion(val, msg).to.not.be.an('array');
  1922. };
  1923. /**
  1924. * ### .isString(value, [message])
  1925. *
  1926. * Asserts that `value` is a string.
  1927. *
  1928. * var teaOrder = 'chai';
  1929. * assert.isString(teaOrder, 'order placed');
  1930. *
  1931. * @name isString
  1932. * @param {Mixed} value
  1933. * @param {String} message
  1934. * @api public
  1935. */
  1936. assert.isString = function (val, msg) {
  1937. new Assertion(val, msg).to.be.a('string');
  1938. };
  1939. /**
  1940. * ### .isNotString(value, [message])
  1941. *
  1942. * Asserts that `value` is _not_ a string.
  1943. *
  1944. * var teaOrder = 4;
  1945. * assert.isNotString(teaOrder, 'order placed');
  1946. *
  1947. * @name isNotString
  1948. * @param {Mixed} value
  1949. * @param {String} message
  1950. * @api public
  1951. */
  1952. assert.isNotString = function (val, msg) {
  1953. new Assertion(val, msg).to.not.be.a('string');
  1954. };
  1955. /**
  1956. * ### .isNumber(value, [message])
  1957. *
  1958. * Asserts that `value` is a number.
  1959. *
  1960. * var cups = 2;
  1961. * assert.isNumber(cups, 'how many cups');
  1962. *
  1963. * @name isNumber
  1964. * @param {Number} value
  1965. * @param {String} message
  1966. * @api public
  1967. */
  1968. assert.isNumber = function (val, msg) {
  1969. new Assertion(val, msg).to.be.a('number');
  1970. };
  1971. /**
  1972. * ### .isNotNumber(value, [message])
  1973. *
  1974. * Asserts that `value` is _not_ a number.
  1975. *
  1976. * var cups = '2 cups please';
  1977. * assert.isNotNumber(cups, 'how many cups');
  1978. *
  1979. * @name isNotNumber
  1980. * @param {Mixed} value
  1981. * @param {String} message
  1982. * @api public
  1983. */
  1984. assert.isNotNumber = function (val, msg) {
  1985. new Assertion(val, msg).to.not.be.a('number');
  1986. };
  1987. /**
  1988. * ### .isBoolean(value, [message])
  1989. *
  1990. * Asserts that `value` is a boolean.
  1991. *
  1992. * var teaReady = true
  1993. * , teaServed = false;
  1994. *
  1995. * assert.isBoolean(teaReady, 'is the tea ready');
  1996. * assert.isBoolean(teaServed, 'has tea been served');
  1997. *
  1998. * @name isBoolean
  1999. * @param {Mixed} value
  2000. * @param {String} message
  2001. * @api public
  2002. */
  2003. assert.isBoolean = function (val, msg) {
  2004. new Assertion(val, msg).to.be.a('boolean');
  2005. };
  2006. /**
  2007. * ### .isNotBoolean(value, [message])
  2008. *
  2009. * Asserts that `value` is _not_ a boolean.
  2010. *
  2011. * var teaReady = 'yep'
  2012. * , teaServed = 'nope';
  2013. *
  2014. * assert.isNotBoolean(teaReady, 'is the tea ready');
  2015. * assert.isNotBoolean(teaServed, 'has tea been served');
  2016. *
  2017. * @name isNotBoolean
  2018. * @param {Mixed} value
  2019. * @param {String} message
  2020. * @api public
  2021. */
  2022. assert.isNotBoolean = function (val, msg) {
  2023. new Assertion(val, msg).to.not.be.a('boolean');
  2024. };
  2025. /**
  2026. * ### .typeOf(value, name, [message])
  2027. *
  2028. * Asserts that `value`'s type is `name`, as determined by
  2029. * `Object.prototype.toString`.
  2030. *
  2031. * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
  2032. * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
  2033. * assert.typeOf('tea', 'string', 'we have a string');
  2034. * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
  2035. * assert.typeOf(null, 'null', 'we have a null');
  2036. * assert.typeOf(undefined, 'undefined', 'we have an undefined');
  2037. *
  2038. * @name typeOf
  2039. * @param {Mixed} value
  2040. * @param {String} name
  2041. * @param {String} message
  2042. * @api public
  2043. */
  2044. assert.typeOf = function (val, type, msg) {
  2045. new Assertion(val, msg).to.be.a(type);
  2046. };
  2047. /**
  2048. * ### .notTypeOf(value, name, [message])
  2049. *
  2050. * Asserts that `value`'s type is _not_ `name`, as determined by
  2051. * `Object.prototype.toString`.
  2052. *
  2053. * assert.notTypeOf('tea', 'number', 'strings are not numbers');
  2054. *
  2055. * @name notTypeOf
  2056. * @param {Mixed} value
  2057. * @param {String} typeof name
  2058. * @param {String} message
  2059. * @api public
  2060. */
  2061. assert.notTypeOf = function (val, type, msg) {
  2062. new Assertion(val, msg).to.not.be.a(type);
  2063. };
  2064. /**
  2065. * ### .instanceOf(object, constructor, [message])
  2066. *
  2067. * Asserts that `value` is an instance of `constructor`.
  2068. *
  2069. * var Tea = function (name) { this.name = name; }
  2070. * , chai = new Tea('chai');
  2071. *
  2072. * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
  2073. *
  2074. * @name instanceOf
  2075. * @param {Object} object
  2076. * @param {Constructor} constructor
  2077. * @param {String} message
  2078. * @api public
  2079. */
  2080. assert.instanceOf = function (val, type, msg) {
  2081. new Assertion(val, msg).to.be.instanceOf(type);
  2082. };
  2083. /**
  2084. * ### .notInstanceOf(object, constructor, [message])
  2085. *
  2086. * Asserts `value` is not an instance of `constructor`.
  2087. *
  2088. * var Tea = function (name) { this.name = name; }
  2089. * , chai = new String('chai');
  2090. *
  2091. * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
  2092. *
  2093. * @name notInstanceOf
  2094. * @param {Object} object
  2095. * @param {Constructor} constructor
  2096. * @param {String} message
  2097. * @api public
  2098. */
  2099. assert.notInstanceOf = function (val, type, msg) {
  2100. new Assertion(val, msg).to.not.be.instanceOf(type);
  2101. };
  2102. /**
  2103. * ### .include(haystack, needle, [message])
  2104. *
  2105. * Asserts that `haystack` includes `needle`. Works
  2106. * for strings and arrays.
  2107. *
  2108. * assert.include('foobar', 'bar', 'foobar contains string "bar"');
  2109. * assert.include([ 1, 2, 3 ], 3, 'array contains value');
  2110. *
  2111. * @name include
  2112. * @param {Array|String} haystack
  2113. * @param {Mixed} needle
  2114. * @param {String} message
  2115. * @api public
  2116. */
  2117. assert.include = function (exp, inc, msg) {
  2118. var obj = new Assertion(exp, msg);
  2119. if (Array.isArray(exp)) {
  2120. obj.to.include(inc);
  2121. } else if ('string' === typeof exp) {
  2122. obj.to.contain.string(inc);
  2123. } else {
  2124. throw new chai.AssertionError({
  2125. message: 'expected an array or string'
  2126. , stackStartFunction: assert.include
  2127. });
  2128. }
  2129. };
  2130. /**
  2131. * ### .notInclude(haystack, needle, [message])
  2132. *
  2133. * Asserts that `haystack` does not include `needle`. Works
  2134. * for strings and arrays.
  2135. *i
  2136. * assert.notInclude('foobar', 'baz', 'string not include substring');
  2137. * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
  2138. *
  2139. * @name notInclude
  2140. * @param {Array|String} haystack
  2141. * @param {Mixed} needle
  2142. * @param {String} message
  2143. * @api public
  2144. */
  2145. assert.notInclude = function (exp, inc, msg) {
  2146. var obj = new Assertion(exp, msg);
  2147. if (Array.isArray(exp)) {
  2148. obj.to.not.include(inc);
  2149. } else if ('string' === typeof exp) {
  2150. obj.to.not.contain.string(inc);
  2151. } else {
  2152. throw new chai.AssertionError({
  2153. message: 'expected an array or string'
  2154. , stackStartFunction: assert.include
  2155. });
  2156. }
  2157. };
  2158. /**
  2159. * ### .match(value, regexp, [message])
  2160. *
  2161. * Asserts that `value` matches the regular expression `regexp`.
  2162. *
  2163. * assert.match('foobar', /^foo/, 'regexp matches');
  2164. *
  2165. * @name match
  2166. * @param {Mixed} value
  2167. * @param {RegExp} regexp
  2168. * @param {String} message
  2169. * @api public
  2170. */
  2171. assert.match = function (exp, re, msg) {
  2172. new Assertion(exp, msg).to.match(re);
  2173. };
  2174. /**
  2175. * ### .notMatch(value, regexp, [message])
  2176. *
  2177. * Asserts that `value` does not match the regular expression `regexp`.
  2178. *
  2179. * assert.notMatch('foobar', /^foo/, 'regexp does not match');
  2180. *
  2181. * @name notMatch
  2182. * @param {Mixed} value
  2183. * @param {RegExp} regexp
  2184. * @param {String} message
  2185. * @api public
  2186. */
  2187. assert.notMatch = function (exp, re, msg) {
  2188. new Assertion(exp, msg).to.not.match(re);
  2189. };
  2190. /**
  2191. * ### .property(object, property, [message])
  2192. *
  2193. * Asserts that `object` has a property named by `property`.
  2194. *
  2195. * assert.property({ tea: { green: 'matcha' }}, 'tea');
  2196. *
  2197. * @name property
  2198. * @param {Object} object
  2199. * @param {String} property
  2200. * @param {String} message
  2201. * @api public
  2202. */
  2203. assert.property = function (obj, prop, msg) {
  2204. new Assertion(obj, msg).to.have.property(prop);
  2205. };
  2206. /**
  2207. * ### .notProperty(object, property, [message])
  2208. *
  2209. * Asserts that `object` does _not_ have a property named by `property`.
  2210. *
  2211. * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
  2212. *
  2213. * @name notProperty
  2214. * @param {Object} object
  2215. * @param {String} property
  2216. * @param {String} message
  2217. * @api public
  2218. */
  2219. assert.notProperty = function (obj, prop, msg) {
  2220. new Assertion(obj, msg).to.not.have.property(prop);
  2221. };
  2222. /**
  2223. * ### .deepProperty(object, property, [message])
  2224. *
  2225. * Asserts that `object` has a property named by `property`, which can be a
  2226. * string using dot- and bracket-notation for deep reference.
  2227. *
  2228. * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
  2229. *
  2230. * @name deepProperty
  2231. * @param {Object} object
  2232. * @param {String} property
  2233. * @param {String} message
  2234. * @api public
  2235. */
  2236. assert.deepProperty = function (obj, prop, msg) {
  2237. new Assertion(obj, msg).to.have.deep.property(prop);
  2238. };
  2239. /**
  2240. * ### .notDeepProperty(object, property, [message])
  2241. *
  2242. * Asserts that `object` does _not_ have a property named by `property`, which
  2243. * can be a string using dot- and bracket-notation for deep reference.
  2244. *
  2245. * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
  2246. *
  2247. * @name notDeepProperty
  2248. * @param {Object} object
  2249. * @param {String} property
  2250. * @param {String} message
  2251. * @api public
  2252. */
  2253. assert.notDeepProperty = function (obj, prop, msg) {
  2254. new Assertion(obj, msg).to.not.have.deep.property(prop);
  2255. };
  2256. /**
  2257. * ### .propertyVal(object, property, value, [message])
  2258. *
  2259. * Asserts that `object` has a property named by `property` with value given
  2260. * by `value`.
  2261. *
  2262. * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
  2263. *
  2264. * @name propertyVal
  2265. * @param {Object} object
  2266. * @param {String} property
  2267. * @param {Mixed} value
  2268. * @param {String} message
  2269. * @api public
  2270. */
  2271. assert.propertyVal = function (obj, prop, val, msg) {
  2272. new Assertion(obj, msg).to.have.property(prop, val);
  2273. };
  2274. /**
  2275. * ### .propertyNotVal(object, property, value, [message])
  2276. *
  2277. * Asserts that `object` has a property named by `property`, but with a value
  2278. * different from that given by `value`.
  2279. *
  2280. * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
  2281. *
  2282. * @name propertyNotVal
  2283. * @param {Object} object
  2284. * @param {String} property
  2285. * @param {Mixed} value
  2286. * @param {String} message
  2287. * @api public
  2288. */
  2289. assert.propertyNotVal = function (obj, prop, val, msg) {
  2290. new Assertion(obj, msg).to.not.have.property(prop, val);
  2291. };
  2292. /**
  2293. * ### .deepPropertyVal(object, property, value, [message])
  2294. *
  2295. * Asserts that `object` has a property named by `property` with value given
  2296. * by `value`. `property` can use dot- and bracket-notation for deep
  2297. * reference.
  2298. *
  2299. * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
  2300. *
  2301. * @name deepPropertyVal
  2302. * @param {Object} object
  2303. * @param {String} property
  2304. * @param {Mixed} value
  2305. * @param {String} message
  2306. * @api public
  2307. */
  2308. assert.deepPropertyVal = function (obj, prop, val, msg) {
  2309. new Assertion(obj, msg).to.have.deep.property(prop, val);
  2310. };
  2311. /**
  2312. * ### .deepPropertyNotVal(object, property, value, [message])
  2313. *
  2314. * Asserts that `object` has a property named by `property`, but with a value
  2315. * different from that given by `value`. `property` can use dot- and
  2316. * bracket-notation for deep reference.
  2317. *
  2318. * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
  2319. *
  2320. * @name deepPropertyNotVal
  2321. * @param {Object} object
  2322. * @param {String} property
  2323. * @param {Mixed} value
  2324. * @param {String} message
  2325. * @api public
  2326. */
  2327. assert.deepPropertyNotVal = function (obj, prop, val, msg) {
  2328. new Assertion(obj, msg).to.not.have.deep.property(prop, val);
  2329. };
  2330. /**
  2331. * ### .lengthOf(object, length, [message])
  2332. *
  2333. * Asserts that `object` has a `length` property with the expected value.
  2334. *
  2335. * assert.lengthOf([1,2,3], 3, 'array has length of 3');
  2336. * assert.lengthOf('foobar', 5, 'string has length of 6');
  2337. *
  2338. * @name lengthOf
  2339. * @param {Mixed} object
  2340. * @param {Number} length
  2341. * @param {String} message
  2342. * @api public
  2343. */
  2344. assert.lengthOf = function (exp, len, msg) {
  2345. new Assertion(exp, msg).to.have.length(len);
  2346. };
  2347. /**
  2348. * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
  2349. *
  2350. * Asserts that `function` will throw an error that is an instance of
  2351. * `constructor`, or alternately that it will throw an error with message
  2352. * matching `regexp`.
  2353. *
  2354. * assert.throw(fn, 'function throws a reference error');
  2355. * assert.throw(fn, /function throws a reference error/);
  2356. * assert.throw(fn, ReferenceError);
  2357. * assert.throw(fn, ReferenceError, 'function throws a reference error');
  2358. * assert.throw(fn, ReferenceError, /function throws a reference error/);
  2359. *
  2360. * @name throws
  2361. * @alias throw
  2362. * @alias Throw
  2363. * @param {Function} function
  2364. * @param {ErrorConstructor} constructor
  2365. * @param {RegExp} regexp
  2366. * @param {String} message
  2367. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  2368. * @api public
  2369. */
  2370. assert.Throw = function (fn, errt, errs, msg) {
  2371. if ('string' === typeof errt || errt instanceof RegExp) {
  2372. errs = errt;
  2373. errt = null;
  2374. }
  2375. new Assertion(fn, msg).to.Throw(errt, errs);
  2376. };
  2377. /**
  2378. * ### .doesNotThrow(function, [constructor/regexp], [message])
  2379. *
  2380. * Asserts that `function` will _not_ throw an error that is an instance of
  2381. * `constructor`, or alternately that it will not throw an error with message
  2382. * matching `regexp`.
  2383. *
  2384. * assert.doesNotThrow(fn, Error, 'function does not throw');
  2385. *
  2386. * @name doesNotThrow
  2387. * @param {Function} function
  2388. * @param {ErrorConstructor} constructor
  2389. * @param {RegExp} regexp
  2390. * @param {String} message
  2391. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  2392. * @api public
  2393. */
  2394. assert.doesNotThrow = function (fn, type, msg) {
  2395. if ('string' === typeof type) {
  2396. msg = type;
  2397. type = null;
  2398. }
  2399. new Assertion(fn, msg).to.not.Throw(type);
  2400. };
  2401. /**
  2402. * ### .operator(val1, operator, val2, [message])
  2403. *
  2404. * Compares two values using `operator`.
  2405. *
  2406. * assert.operator(1, '<', 2, 'everything is ok');
  2407. * assert.operator(1, '>', 2, 'this will fail');
  2408. *
  2409. * @name operator
  2410. * @param {Mixed} val1
  2411. * @param {String} operator
  2412. * @param {Mixed} val2
  2413. * @param {String} message
  2414. * @api public
  2415. */
  2416. assert.operator = function (val, operator, val2, msg) {
  2417. if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
  2418. throw new Error('Invalid operator "' + operator + '"');
  2419. }
  2420. var test = new Assertion(eval(val + operator + val2), msg);
  2421. test.assert(
  2422. true === flag(test, 'object')
  2423. , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
  2424. , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
  2425. };
  2426. /**
  2427. * ### .closeTo(actual, expected, delta, [message])
  2428. *
  2429. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  2430. *
  2431. * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
  2432. *
  2433. * @name closeTo
  2434. * @param {Number} actual
  2435. * @param {Number} expected
  2436. * @param {Number} delta
  2437. * @param {String} message
  2438. * @api public
  2439. */
  2440. assert.closeTo = function (act, exp, delta, msg) {
  2441. new Assertion(act, msg).to.be.closeTo(exp, delta);
  2442. };
  2443. /**
  2444. * ### .sameMembers(set1, set2, [message])
  2445. *
  2446. * Asserts that `set1` and `set2` have the same members.
  2447. * Order is not taken into account.
  2448. *
  2449. * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
  2450. *
  2451. * @name sameMembers
  2452. * @param {Array} superset
  2453. * @param {Array} subset
  2454. * @param {String} message
  2455. * @api public
  2456. */
  2457. assert.sameMembers = function (set1, set2, msg) {
  2458. new Assertion(set1, msg).to.have.same.members(set2);
  2459. }
  2460. /**
  2461. * ### .includeMembers(superset, subset, [message])
  2462. *
  2463. * Asserts that `subset` is included in `superset`.
  2464. * Order is not taken into account.
  2465. *
  2466. * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
  2467. *
  2468. * @name includeMembers
  2469. * @param {Array} superset
  2470. * @param {Array} subset
  2471. * @param {String} message
  2472. * @api public
  2473. */
  2474. assert.includeMembers = function (superset, subset, msg) {
  2475. new Assertion(superset, msg).to.include.members(subset);
  2476. }
  2477. /*!
  2478. * Undocumented / untested
  2479. */
  2480. assert.ifError = function (val, msg) {
  2481. new Assertion(val, msg).to.not.be.ok;
  2482. };
  2483. /*!
  2484. * Aliases.
  2485. */
  2486. (function alias(name, as){
  2487. assert[as] = assert[name];
  2488. return alias;
  2489. })
  2490. ('Throw', 'throw')
  2491. ('Throw', 'throws');
  2492. };
  2493. });
  2494. require.register("chai/lib/chai/interface/expect.js", function(exports, require, module){
  2495. /*!
  2496. * chai
  2497. * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
  2498. * MIT Licensed
  2499. */
  2500. module.exports = function (chai, util) {
  2501. chai.expect = function (val, message) {
  2502. return new chai.Assertion(val, message);
  2503. };
  2504. };
  2505. });
  2506. require.register("chai/lib/chai/interface/should.js", function(exports, require, module){
  2507. /*!
  2508. * chai
  2509. * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
  2510. * MIT Licensed
  2511. */
  2512. module.exports = function (chai, util) {
  2513. var Assertion = chai.Assertion;
  2514. function loadShould () {
  2515. // modify Object.prototype to have `should`
  2516. Object.defineProperty(Object.prototype, 'should',
  2517. {
  2518. set: function (value) {
  2519. // See https://github.com/chaijs/chai/issues/86: this makes
  2520. // `whatever.should = someValue` actually set `someValue`, which is
  2521. // especially useful for `global.should = require('chai').should()`.
  2522. //
  2523. // Note that we have to use [[DefineProperty]] instead of [[Put]]
  2524. // since otherwise we would trigger this very setter!
  2525. Object.defineProperty(this, 'should', {
  2526. value: value,
  2527. enumerable: true,
  2528. configurable: true,
  2529. writable: true
  2530. });
  2531. }
  2532. , get: function(){
  2533. if (this instanceof String || this instanceof Number) {
  2534. return new Assertion(this.constructor(this));
  2535. } else if (this instanceof Boolean) {
  2536. return new Assertion(this == true);
  2537. }
  2538. return new Assertion(this);
  2539. }
  2540. , configurable: true
  2541. });
  2542. var should = {};
  2543. should.equal = function (val1, val2, msg) {
  2544. new Assertion(val1, msg).to.equal(val2);
  2545. };
  2546. should.Throw = function (fn, errt, errs, msg) {
  2547. new Assertion(fn, msg).to.Throw(errt, errs);
  2548. };
  2549. should.exist = function (val, msg) {
  2550. new Assertion(val, msg).to.exist;
  2551. }
  2552. // negation
  2553. should.not = {}
  2554. should.not.equal = function (val1, val2, msg) {
  2555. new Assertion(val1, msg).to.not.equal(val2);
  2556. };
  2557. should.not.Throw = function (fn, errt, errs, msg) {
  2558. new Assertion(fn, msg).to.not.Throw(errt, errs);
  2559. };
  2560. should.not.exist = function (val, msg) {
  2561. new Assertion(val, msg).to.not.exist;
  2562. }
  2563. should['throw'] = should['Throw'];
  2564. should.not['throw'] = should.not['Throw'];
  2565. return should;
  2566. };
  2567. chai.should = loadShould;
  2568. chai.Should = loadShould;
  2569. };
  2570. });
  2571. require.register("chai/lib/chai/utils/addChainableMethod.js", function(exports, require, module){
  2572. /*!
  2573. * Chai - addChainingMethod utility
  2574. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2575. * MIT Licensed
  2576. */
  2577. /*!
  2578. * Module dependencies
  2579. */
  2580. var transferFlags = require('./transferFlags');
  2581. /*!
  2582. * Module variables
  2583. */
  2584. // Check whether `__proto__` is supported
  2585. var hasProtoSupport = '__proto__' in Object;
  2586. // Without `__proto__` support, this module will need to add properties to a function.
  2587. // However, some Function.prototype methods cannot be overwritten,
  2588. // and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
  2589. var excludeNames = /^(?:length|name|arguments|caller)$/;
  2590. // Cache `Function` properties
  2591. var call = Function.prototype.call,
  2592. apply = Function.prototype.apply;
  2593. /**
  2594. * ### addChainableMethod (ctx, name, method, chainingBehavior)
  2595. *
  2596. * Adds a method to an object, such that the method can also be chained.
  2597. *
  2598. * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
  2599. * var obj = utils.flag(this, 'object');
  2600. * new chai.Assertion(obj).to.be.equal(str);
  2601. * });
  2602. *
  2603. * Can also be accessed directly from `chai.Assertion`.
  2604. *
  2605. * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
  2606. *
  2607. * The result can then be used as both a method assertion, executing both `method` and
  2608. * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
  2609. *
  2610. * expect(fooStr).to.be.foo('bar');
  2611. * expect(fooStr).to.be.foo.equal('foo');
  2612. *
  2613. * @param {Object} ctx object to which the method is added
  2614. * @param {String} name of method to add
  2615. * @param {Function} method function to be used for `name`, when called
  2616. * @param {Function} chainingBehavior function to be called every time the property is accessed
  2617. * @name addChainableMethod
  2618. * @api public
  2619. */
  2620. module.exports = function (ctx, name, method, chainingBehavior) {
  2621. if (typeof chainingBehavior !== 'function')
  2622. chainingBehavior = function () { };
  2623. Object.defineProperty(ctx, name,
  2624. { get: function () {
  2625. chainingBehavior.call(this);
  2626. var assert = function () {
  2627. var result = method.apply(this, arguments);
  2628. return result === undefined ? this : result;
  2629. };
  2630. // Use `__proto__` if available
  2631. if (hasProtoSupport) {
  2632. // Inherit all properties from the object by replacing the `Function` prototype
  2633. var prototype = assert.__proto__ = Object.create(this);
  2634. // Restore the `call` and `apply` methods from `Function`
  2635. prototype.call = call;
  2636. prototype.apply = apply;
  2637. }
  2638. // Otherwise, redefine all properties (slow!)
  2639. else {
  2640. var asserterNames = Object.getOwnPropertyNames(ctx);
  2641. asserterNames.forEach(function (asserterName) {
  2642. if (!excludeNames.test(asserterName)) {
  2643. var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
  2644. Object.defineProperty(assert, asserterName, pd);
  2645. }
  2646. });
  2647. }
  2648. transferFlags(this, assert);
  2649. return assert;
  2650. }
  2651. , configurable: true
  2652. });
  2653. };
  2654. });
  2655. require.register("chai/lib/chai/utils/addMethod.js", function(exports, require, module){
  2656. /*!
  2657. * Chai - addMethod utility
  2658. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2659. * MIT Licensed
  2660. */
  2661. /**
  2662. * ### .addMethod (ctx, name, method)
  2663. *
  2664. * Adds a method to the prototype of an object.
  2665. *
  2666. * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
  2667. * var obj = utils.flag(this, 'object');
  2668. * new chai.Assertion(obj).to.be.equal(str);
  2669. * });
  2670. *
  2671. * Can also be accessed directly from `chai.Assertion`.
  2672. *
  2673. * chai.Assertion.addMethod('foo', fn);
  2674. *
  2675. * Then can be used as any other assertion.
  2676. *
  2677. * expect(fooStr).to.be.foo('bar');
  2678. *
  2679. * @param {Object} ctx object to which the method is added
  2680. * @param {String} name of method to add
  2681. * @param {Function} method function to be used for name
  2682. * @name addMethod
  2683. * @api public
  2684. */
  2685. module.exports = function (ctx, name, method) {
  2686. ctx[name] = function () {
  2687. var result = method.apply(this, arguments);
  2688. return result === undefined ? this : result;
  2689. };
  2690. };
  2691. });
  2692. require.register("chai/lib/chai/utils/addProperty.js", function(exports, require, module){
  2693. /*!
  2694. * Chai - addProperty utility
  2695. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2696. * MIT Licensed
  2697. */
  2698. /**
  2699. * ### addProperty (ctx, name, getter)
  2700. *
  2701. * Adds a property to the prototype of an object.
  2702. *
  2703. * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
  2704. * var obj = utils.flag(this, 'object');
  2705. * new chai.Assertion(obj).to.be.instanceof(Foo);
  2706. * });
  2707. *
  2708. * Can also be accessed directly from `chai.Assertion`.
  2709. *
  2710. * chai.Assertion.addProperty('foo', fn);
  2711. *
  2712. * Then can be used as any other assertion.
  2713. *
  2714. * expect(myFoo).to.be.foo;
  2715. *
  2716. * @param {Object} ctx object to which the property is added
  2717. * @param {String} name of property to add
  2718. * @param {Function} getter function to be used for name
  2719. * @name addProperty
  2720. * @api public
  2721. */
  2722. module.exports = function (ctx, name, getter) {
  2723. Object.defineProperty(ctx, name,
  2724. { get: function () {
  2725. var result = getter.call(this);
  2726. return result === undefined ? this : result;
  2727. }
  2728. , configurable: true
  2729. });
  2730. };
  2731. });
  2732. require.register("chai/lib/chai/utils/eql.js", function(exports, require, module){
  2733. // This is (almost) directly from Node.js assert
  2734. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
  2735. module.exports = _deepEqual;
  2736. var getEnumerableProperties = require('./getEnumerableProperties');
  2737. // for the browser
  2738. var Buffer;
  2739. try {
  2740. Buffer = require('buffer').Buffer;
  2741. } catch (ex) {
  2742. Buffer = {
  2743. isBuffer: function () { return false; }
  2744. };
  2745. }
  2746. function _deepEqual(actual, expected, memos) {
  2747. // 7.1. All identical values are equivalent, as determined by ===.
  2748. if (actual === expected) {
  2749. return true;
  2750. } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
  2751. if (actual.length != expected.length) return false;
  2752. for (var i = 0; i < actual.length; i++) {
  2753. if (actual[i] !== expected[i]) return false;
  2754. }
  2755. return true;
  2756. // 7.2. If the expected value is a Date object, the actual value is
  2757. // equivalent if it is also a Date object that refers to the same time.
  2758. } else if (actual instanceof Date && expected instanceof Date) {
  2759. return actual.getTime() === expected.getTime();
  2760. // 7.3. Other pairs that do not both pass typeof value == 'object',
  2761. // equivalence is determined by ==.
  2762. } else if (typeof actual != 'object' && typeof expected != 'object') {
  2763. return actual === expected;
  2764. // 7.4. For all other Object pairs, including Array objects, equivalence is
  2765. // determined by having the same number of owned properties (as verified
  2766. // with Object.prototype.hasOwnProperty.call), the same set of keys
  2767. // (although not necessarily the same order), equivalent values for every
  2768. // corresponding key, and an identical 'prototype' property. Note: this
  2769. // accounts for both named and indexed properties on Arrays.
  2770. } else {
  2771. return objEquiv(actual, expected, memos);
  2772. }
  2773. }
  2774. function isUndefinedOrNull(value) {
  2775. return value === null || value === undefined;
  2776. }
  2777. function isArguments(object) {
  2778. return Object.prototype.toString.call(object) == '[object Arguments]';
  2779. }
  2780. function objEquiv(a, b, memos) {
  2781. if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
  2782. return false;
  2783. // an identical 'prototype' property.
  2784. if (a.prototype !== b.prototype) return false;
  2785. // check if we have already compared a and b
  2786. var i;
  2787. if (memos) {
  2788. for(i = 0; i < memos.length; i++) {
  2789. if ((memos[i][0] === a && memos[i][1] === b) ||
  2790. (memos[i][0] === b && memos[i][1] === a))
  2791. return true;
  2792. }
  2793. } else {
  2794. memos = [];
  2795. }
  2796. //~~~I've managed to break Object.keys through screwy arguments passing.
  2797. // Converting to array solves the problem.
  2798. if (isArguments(a)) {
  2799. if (!isArguments(b)) {
  2800. return false;
  2801. }
  2802. a = pSlice.call(a);
  2803. b = pSlice.call(b);
  2804. return _deepEqual(a, b, memos);
  2805. }
  2806. try {
  2807. var ka = getEnumerableProperties(a),
  2808. kb = getEnumerableProperties(b),
  2809. key;
  2810. } catch (e) {//happens when one is a string literal and the other isn't
  2811. return false;
  2812. }
  2813. // having the same number of owned properties (keys incorporates
  2814. // hasOwnProperty)
  2815. if (ka.length != kb.length)
  2816. return false;
  2817. //the same set of keys (although not necessarily the same order),
  2818. ka.sort();
  2819. kb.sort();
  2820. //~~~cheap key test
  2821. for (i = ka.length - 1; i >= 0; i--) {
  2822. if (ka[i] != kb[i])
  2823. return false;
  2824. }
  2825. // remember objects we have compared to guard against circular references
  2826. memos.push([ a, b ]);
  2827. //equivalent values for every corresponding key, and
  2828. //~~~possibly expensive deep test
  2829. for (i = ka.length - 1; i >= 0; i--) {
  2830. key = ka[i];
  2831. if (!_deepEqual(a[key], b[key], memos)) return false;
  2832. }
  2833. return true;
  2834. }
  2835. });
  2836. require.register("chai/lib/chai/utils/flag.js", function(exports, require, module){
  2837. /*!
  2838. * Chai - flag utility
  2839. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2840. * MIT Licensed
  2841. */
  2842. /**
  2843. * ### flag(object ,key, [value])
  2844. *
  2845. * Get or set a flag value on an object. If a
  2846. * value is provided it will be set, else it will
  2847. * return the currently set value or `undefined` if
  2848. * the value is not set.
  2849. *
  2850. * utils.flag(this, 'foo', 'bar'); // setter
  2851. * utils.flag(this, 'foo'); // getter, returns `bar`
  2852. *
  2853. * @param {Object} object (constructed Assertion
  2854. * @param {String} key
  2855. * @param {Mixed} value (optional)
  2856. * @name flag
  2857. * @api private
  2858. */
  2859. module.exports = function (obj, key, value) {
  2860. var flags = obj.__flags || (obj.__flags = Object.create(null));
  2861. if (arguments.length === 3) {
  2862. flags[key] = value;
  2863. } else {
  2864. return flags[key];
  2865. }
  2866. };
  2867. });
  2868. require.register("chai/lib/chai/utils/getActual.js", function(exports, require, module){
  2869. /*!
  2870. * Chai - getActual utility
  2871. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2872. * MIT Licensed
  2873. */
  2874. /**
  2875. * # getActual(object, [actual])
  2876. *
  2877. * Returns the `actual` value for an Assertion
  2878. *
  2879. * @param {Object} object (constructed Assertion)
  2880. * @param {Arguments} chai.Assertion.prototype.assert arguments
  2881. */
  2882. module.exports = function (obj, args) {
  2883. var actual = args[4];
  2884. return 'undefined' !== typeof actual ? actual : obj._obj;
  2885. };
  2886. });
  2887. require.register("chai/lib/chai/utils/getEnumerableProperties.js", function(exports, require, module){
  2888. /*!
  2889. * Chai - getEnumerableProperties utility
  2890. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2891. * MIT Licensed
  2892. */
  2893. /**
  2894. * ### .getEnumerableProperties(object)
  2895. *
  2896. * This allows the retrieval of enumerable property names of an object,
  2897. * inherited or not.
  2898. *
  2899. * @param {Object} object
  2900. * @returns {Array}
  2901. * @name getEnumerableProperties
  2902. * @api public
  2903. */
  2904. module.exports = function getEnumerableProperties(object) {
  2905. var result = [];
  2906. for (var name in object) {
  2907. result.push(name);
  2908. }
  2909. return result;
  2910. };
  2911. });
  2912. require.register("chai/lib/chai/utils/getMessage.js", function(exports, require, module){
  2913. /*!
  2914. * Chai - message composition utility
  2915. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2916. * MIT Licensed
  2917. */
  2918. /*!
  2919. * Module dependancies
  2920. */
  2921. var flag = require('./flag')
  2922. , getActual = require('./getActual')
  2923. , inspect = require('./inspect')
  2924. , objDisplay = require('./objDisplay');
  2925. /**
  2926. * ### .getMessage(object, message, negateMessage)
  2927. *
  2928. * Construct the error message based on flags
  2929. * and template tags. Template tags will return
  2930. * a stringified inspection of the object referenced.
  2931. *
  2932. * Messsage template tags:
  2933. * - `#{this}` current asserted object
  2934. * - `#{act}` actual value
  2935. * - `#{exp}` expected value
  2936. *
  2937. * @param {Object} object (constructed Assertion)
  2938. * @param {Arguments} chai.Assertion.prototype.assert arguments
  2939. * @name getMessage
  2940. * @api public
  2941. */
  2942. module.exports = function (obj, args) {
  2943. var negate = flag(obj, 'negate')
  2944. , val = flag(obj, 'object')
  2945. , expected = args[3]
  2946. , actual = getActual(obj, args)
  2947. , msg = negate ? args[2] : args[1]
  2948. , flagMsg = flag(obj, 'message');
  2949. msg = msg || '';
  2950. msg = msg
  2951. .replace(/#{this}/g, objDisplay(val))
  2952. .replace(/#{act}/g, objDisplay(actual))
  2953. .replace(/#{exp}/g, objDisplay(expected));
  2954. return flagMsg ? flagMsg + ': ' + msg : msg;
  2955. };
  2956. });
  2957. require.register("chai/lib/chai/utils/getName.js", function(exports, require, module){
  2958. /*!
  2959. * Chai - getName utility
  2960. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2961. * MIT Licensed
  2962. */
  2963. /**
  2964. * # getName(func)
  2965. *
  2966. * Gets the name of a function, in a cross-browser way.
  2967. *
  2968. * @param {Function} a function (usually a constructor)
  2969. */
  2970. module.exports = function (func) {
  2971. if (func.name) return func.name;
  2972. var match = /^\s?function ([^(]*)\(/.exec(func);
  2973. return match && match[1] ? match[1] : "";
  2974. };
  2975. });
  2976. require.register("chai/lib/chai/utils/getPathValue.js", function(exports, require, module){
  2977. /*!
  2978. * Chai - getPathValue utility
  2979. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  2980. * @see https://github.com/logicalparadox/filtr
  2981. * MIT Licensed
  2982. */
  2983. /**
  2984. * ### .getPathValue(path, object)
  2985. *
  2986. * This allows the retrieval of values in an
  2987. * object given a string path.
  2988. *
  2989. * var obj = {
  2990. * prop1: {
  2991. * arr: ['a', 'b', 'c']
  2992. * , str: 'Hello'
  2993. * }
  2994. * , prop2: {
  2995. * arr: [ { nested: 'Universe' } ]
  2996. * , str: 'Hello again!'
  2997. * }
  2998. * }
  2999. *
  3000. * The following would be the results.
  3001. *
  3002. * getPathValue('prop1.str', obj); // Hello
  3003. * getPathValue('prop1.att[2]', obj); // b
  3004. * getPathValue('prop2.arr[0].nested', obj); // Universe
  3005. *
  3006. * @param {String} path
  3007. * @param {Object} object
  3008. * @returns {Object} value or `undefined`
  3009. * @name getPathValue
  3010. * @api public
  3011. */
  3012. var getPathValue = module.exports = function (path, obj) {
  3013. var parsed = parsePath(path);
  3014. return _getPathValue(parsed, obj);
  3015. };
  3016. /*!
  3017. * ## parsePath(path)
  3018. *
  3019. * Helper function used to parse string object
  3020. * paths. Use in conjunction with `_getPathValue`.
  3021. *
  3022. * var parsed = parsePath('myobject.property.subprop');
  3023. *
  3024. * ### Paths:
  3025. *
  3026. * * Can be as near infinitely deep and nested
  3027. * * Arrays are also valid using the formal `myobject.document[3].property`.
  3028. *
  3029. * @param {String} path
  3030. * @returns {Object} parsed
  3031. * @api private
  3032. */
  3033. function parsePath (path) {
  3034. var str = path.replace(/\[/g, '.[')
  3035. , parts = str.match(/(\\\.|[^.]+?)+/g);
  3036. return parts.map(function (value) {
  3037. var re = /\[(\d+)\]$/
  3038. , mArr = re.exec(value)
  3039. if (mArr) return { i: parseFloat(mArr[1]) };
  3040. else return { p: value };
  3041. });
  3042. };
  3043. /*!
  3044. * ## _getPathValue(parsed, obj)
  3045. *
  3046. * Helper companion function for `.parsePath` that returns
  3047. * the value located at the parsed address.
  3048. *
  3049. * var value = getPathValue(parsed, obj);
  3050. *
  3051. * @param {Object} parsed definition from `parsePath`.
  3052. * @param {Object} object to search against
  3053. * @returns {Object|Undefined} value
  3054. * @api private
  3055. */
  3056. function _getPathValue (parsed, obj) {
  3057. var tmp = obj
  3058. , res;
  3059. for (var i = 0, l = parsed.length; i < l; i++) {
  3060. var part = parsed[i];
  3061. if (tmp) {
  3062. if ('undefined' !== typeof part.p)
  3063. tmp = tmp[part.p];
  3064. else if ('undefined' !== typeof part.i)
  3065. tmp = tmp[part.i];
  3066. if (i == (l - 1)) res = tmp;
  3067. } else {
  3068. res = undefined;
  3069. }
  3070. }
  3071. return res;
  3072. };
  3073. });
  3074. require.register("chai/lib/chai/utils/getProperties.js", function(exports, require, module){
  3075. /*!
  3076. * Chai - getProperties utility
  3077. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  3078. * MIT Licensed
  3079. */
  3080. /**
  3081. * ### .getProperties(object)
  3082. *
  3083. * This allows the retrieval of property names of an object, enumerable or not,
  3084. * inherited or not.
  3085. *
  3086. * @param {Object} object
  3087. * @returns {Array}
  3088. * @name getProperties
  3089. * @api public
  3090. */
  3091. module.exports = function getProperties(object) {
  3092. var result = Object.getOwnPropertyNames(subject);
  3093. function addProperty(property) {
  3094. if (result.indexOf(property) === -1) {
  3095. result.push(property);
  3096. }
  3097. }
  3098. var proto = Object.getPrototypeOf(subject);
  3099. while (proto !== null) {
  3100. Object.getOwnPropertyNames(proto).forEach(addProperty);
  3101. proto = Object.getPrototypeOf(proto);
  3102. }
  3103. return result;
  3104. };
  3105. });
  3106. require.register("chai/lib/chai/utils/index.js", function(exports, require, module){
  3107. /*!
  3108. * chai
  3109. * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
  3110. * MIT Licensed
  3111. */
  3112. /*!
  3113. * Main exports
  3114. */
  3115. var exports = module.exports = {};
  3116. /*!
  3117. * test utility
  3118. */
  3119. exports.test = require('./test');
  3120. /*!
  3121. * type utility
  3122. */
  3123. exports.type = require('./type');
  3124. /*!
  3125. * message utility
  3126. */
  3127. exports.getMessage = require('./getMessage');
  3128. /*!
  3129. * actual utility
  3130. */
  3131. exports.getActual = require('./getActual');
  3132. /*!
  3133. * Inspect util
  3134. */
  3135. exports.inspect = require('./inspect');
  3136. /*!
  3137. * Object Display util
  3138. */
  3139. exports.objDisplay = require('./objDisplay');
  3140. /*!
  3141. * Flag utility
  3142. */
  3143. exports.flag = require('./flag');
  3144. /*!
  3145. * Flag transferring utility
  3146. */
  3147. exports.transferFlags = require('./transferFlags');
  3148. /*!
  3149. * Deep equal utility
  3150. */
  3151. exports.eql = require('./eql');
  3152. /*!
  3153. * Deep path value
  3154. */
  3155. exports.getPathValue = require('./getPathValue');
  3156. /*!
  3157. * Function name
  3158. */
  3159. exports.getName = require('./getName');
  3160. /*!
  3161. * add Property
  3162. */
  3163. exports.addProperty = require('./addProperty');
  3164. /*!
  3165. * add Method
  3166. */
  3167. exports.addMethod = require('./addMethod');
  3168. /*!
  3169. * overwrite Property
  3170. */
  3171. exports.overwriteProperty = require('./overwriteProperty');
  3172. /*!
  3173. * overwrite Method
  3174. */
  3175. exports.overwriteMethod = require('./overwriteMethod');
  3176. /*!
  3177. * Add a chainable method
  3178. */
  3179. exports.addChainableMethod = require('./addChainableMethod');
  3180. });
  3181. require.register("chai/lib/chai/utils/inspect.js", function(exports, require, module){
  3182. // This is (almost) directly from Node.js utils
  3183. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
  3184. var getName = require('./getName');
  3185. var getProperties = require('./getProperties');
  3186. var getEnumerableProperties = require('./getEnumerableProperties');
  3187. module.exports = inspect;
  3188. /**
  3189. * Echos the value of a value. Trys to print the value out
  3190. * in the best way possible given the different types.
  3191. *
  3192. * @param {Object} obj The object to print out.
  3193. * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
  3194. * properties of objects.
  3195. * @param {Number} depth Depth in which to descend in object. Default is 2.
  3196. * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
  3197. * output. Default is false (no coloring).
  3198. */
  3199. function inspect(obj, showHidden, depth, colors) {
  3200. var ctx = {
  3201. showHidden: showHidden,
  3202. seen: [],
  3203. stylize: function (str) { return str; }
  3204. };
  3205. return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
  3206. }
  3207. // https://gist.github.com/1044128/
  3208. var getOuterHTML = function(element) {
  3209. if ('outerHTML' in element) return element.outerHTML;
  3210. var ns = "http://www.w3.org/1999/xhtml";
  3211. var container = document.createElementNS(ns, '_');
  3212. var elemProto = (window.HTMLElement || window.Element).prototype;
  3213. var xmlSerializer = new XMLSerializer();
  3214. var html;
  3215. if (document.xmlVersion) {
  3216. return xmlSerializer.serializeToString(element);
  3217. } else {
  3218. container.appendChild(element.cloneNode(false));
  3219. html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
  3220. container.innerHTML = '';
  3221. return html;
  3222. }
  3223. };
  3224. // Returns true if object is a DOM element.
  3225. var isDOMElement = function (object) {
  3226. if (typeof HTMLElement === 'object') {
  3227. return object instanceof HTMLElement;
  3228. } else {
  3229. return object &&
  3230. typeof object === 'object' &&
  3231. object.nodeType === 1 &&
  3232. typeof object.nodeName === 'string';
  3233. }
  3234. };
  3235. function formatValue(ctx, value, recurseTimes) {
  3236. // Provide a hook for user-specified inspect functions.
  3237. // Check that value is an object with an inspect function on it
  3238. if (value && typeof value.inspect === 'function' &&
  3239. // Filter out the util module, it's inspect function is special
  3240. value.inspect !== exports.inspect &&
  3241. // Also filter out any prototype objects using the circular check.
  3242. !(value.constructor && value.constructor.prototype === value)) {
  3243. return value.inspect(recurseTimes);
  3244. }
  3245. // Primitive types cannot have properties
  3246. var primitive = formatPrimitive(ctx, value);
  3247. if (primitive) {
  3248. return primitive;
  3249. }
  3250. // If it's DOM elem, get outer HTML.
  3251. if (isDOMElement(value)) {
  3252. return getOuterHTML(value);
  3253. }
  3254. // Look up the keys of the object.
  3255. var visibleKeys = getEnumerableProperties(value);
  3256. var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
  3257. // Some type of object without properties can be shortcutted.
  3258. // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
  3259. // a `stack` plus `description` property; ignore those for consistency.
  3260. if (keys.length === 0 || (isError(value) && (
  3261. (keys.length === 1 && keys[0] === 'stack') ||
  3262. (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
  3263. ))) {
  3264. if (typeof value === 'function') {
  3265. var name = getName(value);
  3266. var nameSuffix = name ? ': ' + name : '';
  3267. return ctx.stylize('[Function' + nameSuffix + ']', 'special');
  3268. }
  3269. if (isRegExp(value)) {
  3270. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  3271. }
  3272. if (isDate(value)) {
  3273. return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
  3274. }
  3275. if (isError(value)) {
  3276. return formatError(value);
  3277. }
  3278. }
  3279. var base = '', array = false, braces = ['{', '}'];
  3280. // Make Array say that they are Array
  3281. if (isArray(value)) {
  3282. array = true;
  3283. braces = ['[', ']'];
  3284. }
  3285. // Make functions say that they are functions
  3286. if (typeof value === 'function') {
  3287. var name = getName(value);
  3288. var nameSuffix = name ? ': ' + name : '';
  3289. base = ' [Function' + nameSuffix + ']';
  3290. }
  3291. // Make RegExps say that they are RegExps
  3292. if (isRegExp(value)) {
  3293. base = ' ' + RegExp.prototype.toString.call(value);
  3294. }
  3295. // Make dates with properties first say the date
  3296. if (isDate(value)) {
  3297. base = ' ' + Date.prototype.toUTCString.call(value);
  3298. }
  3299. // Make error with message first say the error
  3300. if (isError(value)) {
  3301. return formatError(value);
  3302. }
  3303. if (keys.length === 0 && (!array || value.length == 0)) {
  3304. return braces[0] + base + braces[1];
  3305. }
  3306. if (recurseTimes < 0) {
  3307. if (isRegExp(value)) {
  3308. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  3309. } else {
  3310. return ctx.stylize('[Object]', 'special');
  3311. }
  3312. }
  3313. ctx.seen.push(value);
  3314. var output;
  3315. if (array) {
  3316. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  3317. } else {
  3318. output = keys.map(function(key) {
  3319. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  3320. });
  3321. }
  3322. ctx.seen.pop();
  3323. return reduceToSingleString(output, base, braces);
  3324. }
  3325. function formatPrimitive(ctx, value) {
  3326. switch (typeof value) {
  3327. case 'undefined':
  3328. return ctx.stylize('undefined', 'undefined');
  3329. case 'string':
  3330. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  3331. .replace(/'/g, "\\'")
  3332. .replace(/\\"/g, '"') + '\'';
  3333. return ctx.stylize(simple, 'string');
  3334. case 'number':
  3335. return ctx.stylize('' + value, 'number');
  3336. case 'boolean':
  3337. return ctx.stylize('' + value, 'boolean');
  3338. }
  3339. // For some reason typeof null is "object", so special case here.
  3340. if (value === null) {
  3341. return ctx.stylize('null', 'null');
  3342. }
  3343. }
  3344. function formatError(value) {
  3345. return '[' + Error.prototype.toString.call(value) + ']';
  3346. }
  3347. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  3348. var output = [];
  3349. for (var i = 0, l = value.length; i < l; ++i) {
  3350. if (Object.prototype.hasOwnProperty.call(value, String(i))) {
  3351. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  3352. String(i), true));
  3353. } else {
  3354. output.push('');
  3355. }
  3356. }
  3357. keys.forEach(function(key) {
  3358. if (!key.match(/^\d+$/)) {
  3359. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  3360. key, true));
  3361. }
  3362. });
  3363. return output;
  3364. }
  3365. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  3366. var name, str;
  3367. if (value.__lookupGetter__) {
  3368. if (value.__lookupGetter__(key)) {
  3369. if (value.__lookupSetter__(key)) {
  3370. str = ctx.stylize('[Getter/Setter]', 'special');
  3371. } else {
  3372. str = ctx.stylize('[Getter]', 'special');
  3373. }
  3374. } else {
  3375. if (value.__lookupSetter__(key)) {
  3376. str = ctx.stylize('[Setter]', 'special');
  3377. }
  3378. }
  3379. }
  3380. if (visibleKeys.indexOf(key) < 0) {
  3381. name = '[' + key + ']';
  3382. }
  3383. if (!str) {
  3384. if (ctx.seen.indexOf(value[key]) < 0) {
  3385. if (recurseTimes === null) {
  3386. str = formatValue(ctx, value[key], null);
  3387. } else {
  3388. str = formatValue(ctx, value[key], recurseTimes - 1);
  3389. }
  3390. if (str.indexOf('\n') > -1) {
  3391. if (array) {
  3392. str = str.split('\n').map(function(line) {
  3393. return ' ' + line;
  3394. }).join('\n').substr(2);
  3395. } else {
  3396. str = '\n' + str.split('\n').map(function(line) {
  3397. return ' ' + line;
  3398. }).join('\n');
  3399. }
  3400. }
  3401. } else {
  3402. str = ctx.stylize('[Circular]', 'special');
  3403. }
  3404. }
  3405. if (typeof name === 'undefined') {
  3406. if (array && key.match(/^\d+$/)) {
  3407. return str;
  3408. }
  3409. name = JSON.stringify('' + key);
  3410. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  3411. name = name.substr(1, name.length - 2);
  3412. name = ctx.stylize(name, 'name');
  3413. } else {
  3414. name = name.replace(/'/g, "\\'")
  3415. .replace(/\\"/g, '"')
  3416. .replace(/(^"|"$)/g, "'");
  3417. name = ctx.stylize(name, 'string');
  3418. }
  3419. }
  3420. return name + ': ' + str;
  3421. }
  3422. function reduceToSingleString(output, base, braces) {
  3423. var numLinesEst = 0;
  3424. var length = output.reduce(function(prev, cur) {
  3425. numLinesEst++;
  3426. if (cur.indexOf('\n') >= 0) numLinesEst++;
  3427. return prev + cur.length + 1;
  3428. }, 0);
  3429. if (length > 60) {
  3430. return braces[0] +
  3431. (base === '' ? '' : base + '\n ') +
  3432. ' ' +
  3433. output.join(',\n ') +
  3434. ' ' +
  3435. braces[1];
  3436. }
  3437. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  3438. }
  3439. function isArray(ar) {
  3440. return Array.isArray(ar) ||
  3441. (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  3442. }
  3443. function isRegExp(re) {
  3444. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  3445. }
  3446. function isDate(d) {
  3447. return typeof d === 'object' && objectToString(d) === '[object Date]';
  3448. }
  3449. function isError(e) {
  3450. return typeof e === 'object' && objectToString(e) === '[object Error]';
  3451. }
  3452. function objectToString(o) {
  3453. return Object.prototype.toString.call(o);
  3454. }
  3455. });
  3456. require.register("chai/lib/chai/utils/objDisplay.js", function(exports, require, module){
  3457. /*!
  3458. * Chai - flag utility
  3459. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  3460. * MIT Licensed
  3461. */
  3462. /*!
  3463. * Module dependancies
  3464. */
  3465. var inspect = require('./inspect');
  3466. /**
  3467. * ### .objDisplay (object)
  3468. *
  3469. * Determines if an object or an array matches
  3470. * criteria to be inspected in-line for error
  3471. * messages or should be truncated.
  3472. *
  3473. * @param {Mixed} javascript object to inspect
  3474. * @name objDisplay
  3475. * @api public
  3476. */
  3477. module.exports = function (obj) {
  3478. var str = inspect(obj)
  3479. , type = Object.prototype.toString.call(obj);
  3480. if (str.length >= 40) {
  3481. if (type === '[object Function]') {
  3482. return !obj.name || obj.name === ''
  3483. ? '[Function]'
  3484. : '[Function: ' + obj.name + ']';
  3485. } else if (type === '[object Array]') {
  3486. return '[ Array(' + obj.length + ') ]';
  3487. } else if (type === '[object Object]') {
  3488. var keys = Object.keys(obj)
  3489. , kstr = keys.length > 2
  3490. ? keys.splice(0, 2).join(', ') + ', ...'
  3491. : keys.join(', ');
  3492. return '{ Object (' + kstr + ') }';
  3493. } else {
  3494. return str;
  3495. }
  3496. } else {
  3497. return str;
  3498. }
  3499. };
  3500. });
  3501. require.register("chai/lib/chai/utils/overwriteMethod.js", function(exports, require, module){
  3502. /*!
  3503. * Chai - overwriteMethod utility
  3504. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  3505. * MIT Licensed
  3506. */
  3507. /**
  3508. * ### overwriteMethod (ctx, name, fn)
  3509. *
  3510. * Overwites an already existing method and provides
  3511. * access to previous function. Must return function
  3512. * to be used for name.
  3513. *
  3514. * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
  3515. * return function (str) {
  3516. * var obj = utils.flag(this, 'object');
  3517. * if (obj instanceof Foo) {
  3518. * new chai.Assertion(obj.value).to.equal(str);
  3519. * } else {
  3520. * _super.apply(this, arguments);
  3521. * }
  3522. * }
  3523. * });
  3524. *
  3525. * Can also be accessed directly from `chai.Assertion`.
  3526. *
  3527. * chai.Assertion.overwriteMethod('foo', fn);
  3528. *
  3529. * Then can be used as any other assertion.
  3530. *
  3531. * expect(myFoo).to.equal('bar');
  3532. *
  3533. * @param {Object} ctx object whose method is to be overwritten
  3534. * @param {String} name of method to overwrite
  3535. * @param {Function} method function that returns a function to be used for name
  3536. * @name overwriteMethod
  3537. * @api public
  3538. */
  3539. module.exports = function (ctx, name, method) {
  3540. var _method = ctx[name]
  3541. , _super = function () { return this; };
  3542. if (_method && 'function' === typeof _method)
  3543. _super = _method;
  3544. ctx[name] = function () {
  3545. var result = method(_super).apply(this, arguments);
  3546. return result === undefined ? this : result;
  3547. }
  3548. };
  3549. });
  3550. require.register("chai/lib/chai/utils/overwriteProperty.js", function(exports, require, module){
  3551. /*!
  3552. * Chai - overwriteProperty utility
  3553. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  3554. * MIT Licensed
  3555. */
  3556. /**
  3557. * ### overwriteProperty (ctx, name, fn)
  3558. *
  3559. * Overwites an already existing property getter and provides
  3560. * access to previous value. Must return function to use as getter.
  3561. *
  3562. * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
  3563. * return function () {
  3564. * var obj = utils.flag(this, 'object');
  3565. * if (obj instanceof Foo) {
  3566. * new chai.Assertion(obj.name).to.equal('bar');
  3567. * } else {
  3568. * _super.call(this);
  3569. * }
  3570. * }
  3571. * });
  3572. *
  3573. *
  3574. * Can also be accessed directly from `chai.Assertion`.
  3575. *
  3576. * chai.Assertion.overwriteProperty('foo', fn);
  3577. *
  3578. * Then can be used as any other assertion.
  3579. *
  3580. * expect(myFoo).to.be.ok;
  3581. *
  3582. * @param {Object} ctx object whose property is to be overwritten
  3583. * @param {String} name of property to overwrite
  3584. * @param {Function} getter function that returns a getter function to be used for name
  3585. * @name overwriteProperty
  3586. * @api public
  3587. */
  3588. module.exports = function (ctx, name, getter) {
  3589. var _get = Object.getOwnPropertyDescriptor(ctx, name)
  3590. , _super = function () {};
  3591. if (_get && 'function' === typeof _get.get)
  3592. _super = _get.get
  3593. Object.defineProperty(ctx, name,
  3594. { get: function () {
  3595. var result = getter(_super).call(this);
  3596. return result === undefined ? this : result;
  3597. }
  3598. , configurable: true
  3599. });
  3600. };
  3601. });
  3602. require.register("chai/lib/chai/utils/test.js", function(exports, require, module){
  3603. /*!
  3604. * Chai - test utility
  3605. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  3606. * MIT Licensed
  3607. */
  3608. /*!
  3609. * Module dependancies
  3610. */
  3611. var flag = require('./flag');
  3612. /**
  3613. * # test(object, expression)
  3614. *
  3615. * Test and object for expression.
  3616. *
  3617. * @param {Object} object (constructed Assertion)
  3618. * @param {Arguments} chai.Assertion.prototype.assert arguments
  3619. */
  3620. module.exports = function (obj, args) {
  3621. var negate = flag(obj, 'negate')
  3622. , expr = args[0];
  3623. return negate ? !expr : expr;
  3624. };
  3625. });
  3626. require.register("chai/lib/chai/utils/transferFlags.js", function(exports, require, module){
  3627. /*!
  3628. * Chai - transferFlags utility
  3629. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  3630. * MIT Licensed
  3631. */
  3632. /**
  3633. * ### transferFlags(assertion, object, includeAll = true)
  3634. *
  3635. * Transfer all the flags for `assertion` to `object`. If
  3636. * `includeAll` is set to `false`, then the base Chai
  3637. * assertion flags (namely `object`, `ssfi`, and `message`)
  3638. * will not be transferred.
  3639. *
  3640. *
  3641. * var newAssertion = new Assertion();
  3642. * utils.transferFlags(assertion, newAssertion);
  3643. *
  3644. * var anotherAsseriton = new Assertion(myObj);
  3645. * utils.transferFlags(assertion, anotherAssertion, false);
  3646. *
  3647. * @param {Assertion} assertion the assertion to transfer the flags from
  3648. * @param {Object} object the object to transfer the flags too; usually a new assertion
  3649. * @param {Boolean} includeAll
  3650. * @name getAllFlags
  3651. * @api private
  3652. */
  3653. module.exports = function (assertion, object, includeAll) {
  3654. var flags = assertion.__flags || (assertion.__flags = Object.create(null));
  3655. if (!object.__flags) {
  3656. object.__flags = Object.create(null);
  3657. }
  3658. includeAll = arguments.length === 3 ? includeAll : true;
  3659. for (var flag in flags) {
  3660. if (includeAll ||
  3661. (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
  3662. object.__flags[flag] = flags[flag];
  3663. }
  3664. }
  3665. };
  3666. });
  3667. require.register("chai/lib/chai/utils/type.js", function(exports, require, module){
  3668. /*!
  3669. * Chai - type utility
  3670. * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
  3671. * MIT Licensed
  3672. */
  3673. /*!
  3674. * Detectable javascript natives
  3675. */
  3676. var natives = {
  3677. '[object Arguments]': 'arguments'
  3678. , '[object Array]': 'array'
  3679. , '[object Date]': 'date'
  3680. , '[object Function]': 'function'
  3681. , '[object Number]': 'number'
  3682. , '[object RegExp]': 'regexp'
  3683. , '[object String]': 'string'
  3684. };
  3685. /**
  3686. * ### type(object)
  3687. *
  3688. * Better implementation of `typeof` detection that can
  3689. * be used cross-browser. Handles the inconsistencies of
  3690. * Array, `null`, and `undefined` detection.
  3691. *
  3692. * utils.type({}) // 'object'
  3693. * utils.type(null) // `null'
  3694. * utils.type(undefined) // `undefined`
  3695. * utils.type([]) // `array`
  3696. *
  3697. * @param {Mixed} object to detect type of
  3698. * @name type
  3699. * @api private
  3700. */
  3701. module.exports = function (obj) {
  3702. var str = Object.prototype.toString.call(obj);
  3703. if (natives[str]) return natives[str];
  3704. if (obj === null) return 'null';
  3705. if (obj === undefined) return 'undefined';
  3706. if (obj === Object(obj)) return 'object';
  3707. return typeof obj;
  3708. };
  3709. });
  3710. require.alias("chai/index.js", "chai/index.js");
  3711. if (typeof exports == "object") {
  3712. module.exports = require("chai");
  3713. } else if (typeof define == "function" && define.amd) {
  3714. define(function(){ return require("chai"); });
  3715. } else {
  3716. this["chai"] = require("chai");
  3717. }})();