chai.js 112 KB

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