Removed Collection specs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent ee91e3a · Browse files · 2 files·+0 added−463 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+0 added−463 removed
- tests:+0 added−463 removed
Provenance
- Commit
4b1c39f- Tree
3e80c4c- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
ee91e3a
2 files changed+0 added−463 removed
modified:spec/node.js-1 removed
20 unmodified lines21222324252526272821 unmodified lines20 unmodified lines 'utils', 'request', 'mime', 'static', 'collection', 'plugins', 'plugins.cache', 'plugins.view', 'plugins.common-logger',21 unmodified linesdeleted:spec/spec.collection.js-462 removed
1-2-process.mixin(require('express/collection'))3-4-describe 'Express'5- describe 'Collection'6- describe '$(array)'7- it 'should return a Collection'8- $(['foo', 'bar']).should.be_an_instance_of Collection9- end10- end11- 12- describe '$(object)'13- it 'should return a Collection'14- $({ foo: 'bar' }).should.be_an_instance_of Collection15- end16- end17- 18- describe '$(Collection)'19- it 'should return the collection passed'20- var collection = $(['foo'])21- $(collection).should.equal collection22- end23- end24- 25- describe 'shorthand expressions'26- describe 'with 3 or less chars'27- it 'should be considered binary operator between a / b'28- $(5..1).sort('-').toArray().should.eql 1..529- $(5..1).reduce(0, '+').should.eql 1530- end31- end32- 33- describe 'with over 3 chars'34- it 'should be considered a return expression'35- $(5..1).sort('a - b').toArray().should.eql 1..536- $(5..1).reduce(0, 'a + b').should.eql 1537- end38- 39- it 'should consider a single word a property on a'40- $(['foo', 'foobar']).map('length').toArray().should.eql [3, 6]41- end42- 43- it 'should consider a single function a method on a'44- $(['foo', 'foobar']).map('charAt(0)').toArray().should.eql ['f', 'f']45- end46- end47- end48- 49- describe '#at()'50- it 'should return the value at the given index'51- $(['foo', 'bar']).at(0).should.eql 'foo'52- $(['foo', 'bar']).at(1).should.eql 'bar'53- $(['foo', 'bar']).at(2).should.be_null54- end55- 56- it 'should work with objects'57- $({ foo: 'bar', baz: 'raz' }).at(0).should.eql 'bar'58- $({ foo: 'bar', baz: 'raz' }).at(1).should.eql 'raz'59- $({ foo: 'bar', baz: 'raz' }).at(2).should.be_null60- end61- end62- 63- describe '#each()'64- it 'should iterate passing index and value'65- var result = []66- $(['foo', 'bar']).each(function(val, i){67- result.push(i, val)68- })69- result.should.eql [0, 'foo', 1, 'bar']70- end71- 72- it 'should work with objects'73- var result = []74- $({ foo: 'bar', baz: 'raz' }).each(function(val, key){75- result.push(key, val)76- })77- result.should.eql ['foo', 'bar', 'baz', 'raz']78- end79- 80- it 'should return the collection'81- $([]).each(function(){}).should.be_an_instance_of Collection82- end83- end84- 85- describe '#reduce()'86- it 'should iterate with memo object'87- var sum = $([1,2,3]).reduce(0, function(sum, n){ return sum + n })88- sum.should.eql 689- end90- 91- it 'should allow shorthand expressions'92- $([1,2,3]).reduce(0, '+').should.eql 693- $([1,2,3]).reduce(0, 'a + b').should.eql 694- end95- end96- 97- describe '#map()'98- it 'should iterate collecting results into a new collection'99- var collection = $(['foo', 'bar']).map(function(val){ return val.toUpperCase() })100- collection.at(0).should.eql 'FOO'101- collection.at(1).should.eql 'BAR'102- end103- 104- it 'should work with objects'105- var collection = $({ foo: 'bar', baz: 'raz' }).map(function(val){ return val.toUpperCase() })106- collection.at(0).should.eql 'BAR'107- collection.at(1).should.eql 'RAZ'108- end109- 110- it 'should allow shorthand expressions'111- $(['foo', 'bar']).map('a.toUpperCase()').toArray().should.eql ['FOO', 'BAR']112- end113- end114- 115- describe '#first()'116- it 'should return the first value'117- $(['foo']).first().should.eql 'foo'118- end119- 120- it 'should return the first n values'121- $([5,4,3,2,1]).first(2).at(0).should.eql 5122- $([5,4,3,2,1]).first(2).at(1).should.eql 4123- end124- 125- it 'should work with objects'126- $({ foo: 'bar' }).first().should.eql 'bar'127- end 128- end129- 130- describe '#last()'131- it 'should return the last value'132- $(['foo', 'bar']).last().should.eql 'bar'133- end134- 135- it 'should return the last n values'136- $([5,4,3,2,1]).last(2).at(0).should.eql 2137- $([5,4,3,2,1]).last(2).at(1).should.eql 1138- end139- 140- it 'should work with objects'141- $({ a: 'foo', b: 'bar' }).last(2).at(0).should.eql 'foo'142- $({ a: 'foo', b: 'bar' }).last(2).at(1).should.eql 'bar'143- $({ a: 'foo', b: 'bar' }).last().should.eql 'bar'144- end 145- end146- 147- describe '#drop()'148- it 'should drop the first n values'149- $(1..5).drop(2).arr.should.eql 3..5150- end151- end152- 153- describe '#find()'154- it 'should return the value of the first match'155- var result = $(['foo', 'bar']).find(function(val){ return val.charAt(0) == 'b' })156- result.should.eql 'bar'157- end158- 159- it 'should return null when nothing matches'160- var result = $(['foo', 'bar']).find(function(val){ return val.charAt(0) == 'a' })161- result.should.be_null162- end163- 164- it 'should work with objects'165- var result = $({ foo: 'bar', baz: 'raz' }).find(function(val, key){166- return val.charAt(0) == 'r'167- })168- result.should.eql 'raz'169- end170- 171- it 'should allow shorthand expressions'172- $(['foo', 'bar']).find("a.charAt(0) == 'b'").should.eql 'bar'173- end174- end175- 176- describe '#all()'177- it 'should return true when all evaluate to true'178- $(['foo', 'foobar']).all(function(val){ return val.charAt(0) == 'f' }).should.be_true179- end180- 181- it 'should return false when any evaluate to false'182- $(['foo', 'bar', 'foobar']).all(function(val){ return val.charAt(0) == 'f' }).should.be_false183- end184- 185- it 'should work with objects'186- $({ a: 'foo', b: 'foobar' }).all(function(val){ return val.charAt(0) == 'f' }).should.be_true187- end188- 189- it 'should allow shorthand expressions'190- $(['foo', 'bar']).all('a.length > 2').should.be_true191- end192- end193- 194- describe '#any()'195- it 'should return true when found'196- $(['foo', 'bar']).any(function(val){ return val.charAt(0) == 'b' }).should.be_true197- end198- 199- it 'should return false when not found'200- $(['foo', 'bar']).any(function(val){ return val.charAt(0) == 'r' }).should.be_false201- end202- 203- it 'should work with objects'204- $({ foo: 'bar' }).any(function(val){ return val.charAt(0) == 'b' }).should.be_true205- $({ foo: 'bar' }).any(function(val){ return val.charAt(0) == 'c' }).should.be_false206- end207- 208- it 'should allow shorthand expressions'209- $(['foo', 'bar']).any('a.length > 2').should.be_true210- end211- end212- 213- describe '#select()'214- it 'should return values which evaluate to true'215- var result = $([1,2,3,4,5]).select(function(n){ return n % 2 })216- result.at(0).should.eql 1217- result.at(1).should.eql 3218- result.at(2).should.eql 5219- end220- 221- it 'should return a Collection'222- var result = $([1,2,3,4,5]).select(function(n){ return n % 2 })223- result.should.be_an_instance_of Collection224- end225- 226- it 'should allow shorthand expressions'227- $([1,2,3,4,5]).select('a % 2').toArray().should.eql [1,3,5]228- end229- end230- 231- describe '#reject()'232- it 'should return values which evaluate to false'233- var result = $([1,2,3,4,5,6]).reject(function(n){ return n % 2 })234- result.at(0).should.eql 2235- result.at(1).should.eql 4236- result.at(2).should.eql 6237- end238- 239- it 'should return a Collection'240- var result = $([1,2,3,4,5]).reject(function(n){ return n % 2 })241- result.should.be_an_instance_of Collection242- end243- 244- it 'should allow shorthand expressions'245- $(['foo', 'bar']).reject('a.charAt(0) == "b"').toArray().should.eql ['foo']246- end247- end248- 249- describe '#slice()'250- it 'should return a slice of values'251- var collection = $(['foo', 'bar', 'baz']).slice(1, 3)252- collection.at(0).should.eql 'bar'253- collection.at(1).should.eql 'baz'254- end255- 256- it 'should work with objects'257- var collection = $({ foo: 1, bar: 2, baz: 3, raz: 4 }).slice(1, 3)258- collection.at(0).should.eql 2259- collection.at(1).should.eql 3 260- end261- end262- 263- describe '#grep()'264- it 'should select values matching the regular expression passed'265- var result = $(['foo', 'bar', 'foobar', 'baz']).grep(/foo(bar)?/)266- result.at(0).should.eql 'foo'267- result.at(1).should.eql 'foobar'268- result.at(2).should.be_null269- end270- end271-272- describe '#toArray()'273- it 'should return an array'274- $(['foo', 'bar']).keys.toArray().should.eql ['0', '1']275- end276- 277- it 'should work on nested collections'278- $([$(['foo']), $(['bar'])]).toArray().should.eql [['foo'], ['bar']]279- end280- 281- it 'should work with objects'282- $({ foo: 'bar', baz: { name: 'wahoo' }}).toArray().should.eql ['bar', { name: 'wahoo' }]283- end284- end285- 286- describe '#min()'287- it 'should return the min value'288- $([4,5,2,3,62]).min().should.eql 2289- end290- end291- 292- describe '#max()'293- it 'should return the max value'294- $([3,5,2,3,43,2]).max().should.eql 43295- end296- end297- 298- describe '#length()'299- it 'should work with arrays'300- $([1,2,3]).length().should.eql 3301- end302- 303- it 'should work with objects'304- $({ a: 'b', c: 'd', e: 'f' }).length().should.eql 3305- end306- end307- 308- describe '#chunk()'309- it 'should group into chunks of the given size'310- $([1,1,2,2,3,3]).chunk(2).toArray().should.eql [[1,1],[2,2],[3,3]]311- $([1,1,2,2,3,3]).chunk(4).toArray().should.eql [[1,1,2,2],[3,3]]312- end313- end314- 315- describe '#sum()'316- it 'should return the sum of the numeric values'317- $([1,2,3]).sum().should.eql 6318- end319- end320- 321- describe '#avg()'322- it 'should return the average of numeric values'323- $([3,1]).avg().should.eql 2324- end325- end326- 327- describe '#merge()'328- it 'should merge two array collections'329- var a = $([1,2,3])330- var b = $([4,5,6])331- a.merge(b).toArray().should.eql [1,2,3,4,5,6]332- 333- var a = $([1,2,3])334- var b = [4,5,6]335- a.merge(b).toArray().should.eql [1,2,3,4,5,6]336- end337- 338- it 'should merge two object collections'339- var a = $({ a: 'b' })340- var b = $({ c: 'd' })341- a.merge(b).arr.should.eql { a: 'b', c: 'd' }342- 343- var a = $({ a: 'b' })344- var b = { c: 'd' }345- a.merge(b).arr.should.eql { a: 'b', c: 'd' }346- end347- 348- it 'should merge an array and object collection'349- var a = $([1,2])350- var b = $({ a: 'b', c: 'd' })351- a.merge(b).arr.should.eql [1, 2, 'b', 'd']352- 353- var a = $([1,2])354- var b = { a: 'b', c: 'd' }355- a.merge(b).arr.should.eql [1, 2, 'b', 'd']356- end357- 358- it 'should merge an object and array collection'359- var a = $({ a: 'b', c: 'd' })360- var b = $([1,2])361- a.merge(b).arr.should.eql { a: 'b', c: 'd', 0: 1, 1: 2 }362- 363- var a = $({ a: 'b', c: 'd' })364- var b = [1,2]365- a.merge(b).arr.should.eql { a: 'b', c: 'd', 0: 1, 1: 2 }366- end367- end368- 369- describe '#clone()'370- it 'should clone an array collection'371- var a = $([1,2,3])372- var b = a.clone()373- a.should.not.equal b374- b.arr.should.eql [1,2,3]375- b.arr.should.not.equal a.arr376- end377- 378- it 'should clone an object collection'379- var a = $({ foo: 'bar' })380- var b = a.clone()381- a.should.not.equal b382- b.arr.should.eql { foo: 'bar' }383- b.arr.should.not.equal a.arr384- end385- end386- 387- describe '#sample()'388- it 'should return a random value'389- Math.stub('random').and_return(0.1)390- $([1,2,3,4]).sample().should.eql 1391- end392- end393- 394- describe '#reverse()'395- it 'should reverse a collection'396- $([1,2,3]).reverse().toArray().should.eql [3,2,1]397- end398- end399- 400- describe '#sort()'401- it 'should sort a collection'402- $([3,1,2]).sort().toArray().should.eql [1,2,3]403- end404- 405- it 'should sort with a function'406- $([3,1,2]).sort(function(a, b){ return b - a }).toArray().should.eql [3,2,1]407- end408- 409- it 'should allow shorthand expressions'410- $([3,1,2]).sort('-').toArray().should.eql [1,2,3]411- end412- end413- 414- describe '#join()'415- it 'should join a collection with "" by default'416- $([1,2,3]).join().should.eql '123'417- end418- 419- it 'should join with an arbitrary string'420- $([1,2,3]).join(' ').should.eql '1 2 3'421- end422- 423- it 'should work with objects'424- $({ foo: 'bar', baz: 'raz' }).join(' ').should.eql 'bar raz'425- end426- end427- 428- describe '#includes()'429- it 'should return true when the value is present'430- $([1,2,3]).includes(2).should.be_true431- end432- 433- it 'should return true when all values are present'434- $([1,2,3]).includes(2, 3).should.be_true435- end436- 437- it 'should return false when the value is not present'438- $([1,2,3]).includes(4).should.be_false439- end440- 441- it 'should return false when the any value is not present'442- $([1,2,3]).includes(1,2,4).should.be_false443- $([1,2,3]).includes(1,4,2).should.be_false444- end445- end446- 447- describe '#toString()'448- it 'should output [Collection ...] for array'449- $([1,2,3]).toString().should.eql '[Collection 1,2,3]'450- end451- 452- it 'should output [Collection [object Object]] for object'453- $({ foo: "bar" }).toString().should.eql '[Collection [object Object]]'454- end455- 456- it 'should output [Collection [[Collection ...]]] for nested collections'457- $([$([1,2,3])]).toString().should.eql '[Collection [Collection 1,2,3]]'458- end459- end460- 461- end462-end