Skip to content
Myr

Renaming some spec files

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent c19b6e2 · Browse files · 8 files+341 added−384 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+341 added−384 removed

  • tests:+327 added−327 removed
  • other:+14 added−57 removed

8 files+341 added−384 removed

deleted:spec/spec.core.helpers.js-183 removed
12describe 'Express'3 before_each4 reset()5 end6 7 describe 'parseParams()'8 it 'should parse simple query string key / value pairs'9 parseParams('foo=bar').should.eql { foo: 'bar' }10 parseParams('foo=bar&baz=1').should.eql { foo: 'bar', baz: '1' }11 end12 13 it 'should parse named nested params'14 var user = { user: { name: 'tj', email: 'tj@vision-media.ca' }}15 parseParams('user[name]=tj&user[email]=tj@vision-media.ca').should.eql user16 end17 18 it 'should parse several levels of nesting'19 var user = { user: { name: 'tj', email: { primary: 'tj@vision-media.ca' }}}20 parseParams('user[name]=tj&user[email][primary]=tj@vision-media.ca').should.eql user21 end22 end23 24 describe 'toArray()'25 describe 'when given an array'26 it 'should return the array'27 toArray([1,2,3]).should.eql [1,2,3]28 end29 end30 31 describe 'when given an object with indexed values and length'32 it 'should return an array'33 var args = -{ return arguments }('foo', 'bar')34 toArray(args).should.eql ['foo', 'bar']35 end36 end37 end38 39 describe 'escape()'40 it 'should escape html'41 escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'42 end43 end44 45 describe 'extname()'46 it 'should return the a files extension'47 extname('image.png').should.eql 'png'48 extname('image.large.png').should.eql 'png'49 extname('/path/to/image.large.png').should.eql 'png'50 end51 52 it 'should return null when not found'53 extname('path').should.be_null54 extname('/just/a/path').should.be_null55 end56 end57 58 describe 'dirname()'59 it 'should return the directory path'60 dirname('/path/to/images/foo.bar.png').should.eql '/path/to/images'61 end62 end63 64 describe 'status()'65 it 'should set the response status'66 get('/user', function(){ status(500) })67 get('/user').status.should.eql 50068 end69 end70 71 describe 'header()'72 describe 'when given a field name and value'73 it 'should set the header'74 get('/user', function(){75 header('x-foo', 'bar')76 })77 get('/user').headers.should.have_property 'x-foo', 'bar'78 end 79 end80 81 describe 'when given a field name'82 it 'should return a request header value'83 get('/user', function(){84 return header('host')85 })86 get('/user').body.should.eql 'localhost'87 end88 89 it 'should be case-insensitive'90 get('/user', function(){91 return header('Host')92 })93 get('/user').body.should.eql 'localhost'94 end95 end96 end97 98 describe 'halt()'99 describe 'when given no arguments'100 it 'should respond with 404 Not Found'101 get('/user', function(){ halt() })102 get('/user').status.should.eql 404103 get('/user').body.should.include('Not Found')104 end105 end106 107 describe 'when given a status code'108 it 'should respond with that status and its associated default body'109   get('/user', function(){ halt(400) })110   get('/user').status.should.eql 400111   get('/user').body.should.include('Bad Request')112 end113 end114 115 describe 'when given a status code and body'116 it 'should respond with the status and its body'117 get('/user', function(){ halt(400, 'Oh noes!') })118 get('/user').status.should.eql 400119 get('/user').body.should.include('Oh noes!')120 end121 end122 123 describe 'when given an invalid status code'124 it 'should throw an InvalidStatusCode exception'125 // TODO: throw_error(InvalidStatusCode, ...) when jspec is fixed126 get('/user', function(){ halt(123123) })127 -{ get('/user') }.should.throw_error(/InvalidStatusCode: 123123 is an invalid HTTP response code/)128 try { get('/user') }129 catch (e) {130 e.should.be_an_instance_of ExpressError131 e.should.be_an_instance_of InvalidStatusCode132 }133 end134 end135 end136 137 describe 'param()'138 it 'should return a route placeholder value'139 get('/user/:id', function(){140 return 'user ' + param('id')141 })142 get('/user/12').body.should.eql 'user 12'143 end144 145 it 'should return several route placeholder values'146 get('/user/:id/:operation', function(){147 return param('operation') + 'ing user ' + param('id') 148 })149 get('/user/12/edit').body.should.eql 'editing user 12'150 end151 152 it 'should allow optional placeholders'153 get('/user/:id?', function(){154 return param('id') ? 'user ' + param('id') : 'users'155 })156 get('/user/12').body.should.eql 'user 12'157 get('/user').body.should.eql 'users'158 end159 160 it 'should allow placeholders as part of a segment'161 get('/report.:format', function(){162 return 'report as ' + param('format')163 })164 get('/report.csv').body.should.eql 'report as csv'165 get('/report.pdf').body.should.eql 'report as pdf'166 end167 168 it 'should allow optional placeholders in middle segments'169 get('/user/:id?/edit', function(){170 return param('id') ? 'editing ' + param('id') : 'editing your account'171 })172 get('/user/12/edit').body.should.eql 'editing 12'173 get('/user/edit').body.should.eql 'editing your account'174 end175 176 it 'should work with several routes'177 get('/user/:id', function(){ return param('id') })178 get('/product/:name', function(){ return param('name') })179 get('/user/12').body.should.eql '12'180 get('/product/ipod').body.should.eql 'ipod'181 end182 end183end
deleted:spec/spec.core.mime.js-37 removed
deleted:spec/spec.core.routing.js-104 removed
12describe 'Express'3 before_each4 reset()5 end6 7 describe 'route'8 describe 'with callback function'9 it 'should respond with a body string'10 get('/user', function(){11 return 'test'12 })13 get('/user').body.should.eql 'test'14 end15 end16 17 describe 'with options and callback function'18 it 'should respond with a body string'19 get('/user', {}, function(){20 return 'test with options'21 })22 get('/user').body.should.eql 'test with options'23 end24 end25 26 describe 'with a trailing slash in request path'27 it 'should still match'28 get('/user', {}, function(){29 return 'test with options'30 })31 get('/user/').body.should.eql 'test with options'32 end33 end34 35 describe 'with a trailing slash in route path'36 it 'should still match'37 get('/user/', {}, function(){38 return 'test with options'39 })40 get('/user').body.should.eql 'test with options'41 end42 end43 44 describe 'with a trailing whitespace in request path'45 it 'should still match'46 get('/user', {}, function(){47 return 'test with options'48 })49 get('/user/ ').body.should.eql 'test with options'50 end51 end52 53 describe 'with a trailing whitespace in route path'54 it 'should still match'55 get('/user/ ', {}, function(){56 return 'test with options'57 })58 get('/user').body.should.eql 'test with options'59 end60 end61 62 describe 'with several similar routes'63 it 'should match them properly'64 get('/foo', function(){65 return 'bar'66 })67 get('/foos', function(){68 return 'baz'69 })70 get('/foo').body.should.eql 'bar'71 get('/foos').body.should.eql 'baz'72 end73 end74 75 describe 'with several identical routes'76 it 'should match the first route'77 get('/foo', function(){78 return 'bar'79 })80 get('/foo', function(){81 return 'baz'82 })83 get('/foo').body.should.eql 'bar'84 end85 end86 87 describe 'with no response body'88 it 'should throw a InvalidResponseBody'89 get('/user', function(){90 Express.server.respond()91 })92 -{ get('/user') }.should.throw_error(/InvalidResponseBody: get "\/user" did not respond with a body string/)93 end94 end95 96 describe 'with an unmatchable request path'97 it 'should respond with 404 Not Found'98 get('/something').status.should.eql 40499 get('/something').body.should.eql 'Not Found'100 end101 end102 103 end104end
added:spec/spec.helpers.js+183 added
12describe 'Express'3 before_each4 reset()5 end6 7 describe 'parseParams()'8 it 'should parse simple query string key / value pairs'9 parseParams('foo=bar').should.eql { foo: 'bar' }10 parseParams('foo=bar&baz=1').should.eql { foo: 'bar', baz: '1' }11 end12 13 it 'should parse named nested params'14 var user = { user: { name: 'tj', email: 'tj@vision-media.ca' }}15 parseParams('user[name]=tj&user[email]=tj@vision-media.ca').should.eql user16 end17 18 it 'should parse several levels of nesting'19 var user = { user: { name: 'tj', email: { primary: 'tj@vision-media.ca' }}}20 parseParams('user[name]=tj&user[email][primary]=tj@vision-media.ca').should.eql user21 end22 end23 24 describe 'toArray()'25 describe 'when given an array'26 it 'should return the array'27 toArray([1,2,3]).should.eql [1,2,3]28 end29 end30 31 describe 'when given an object with indexed values and length'32 it 'should return an array'33 var args = -{ return arguments }('foo', 'bar')34 toArray(args).should.eql ['foo', 'bar']35 end36 end37 end38 39 describe 'escape()'40 it 'should escape html'41 escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'42 end43 end44 45 describe 'extname()'46 it 'should return the a files extension'47 extname('image.png').should.eql 'png'48 extname('image.large.png').should.eql 'png'49 extname('/path/to/image.large.png').should.eql 'png'50 end51 52 it 'should return null when not found'53 extname('path').should.be_null54 extname('/just/a/path').should.be_null55 end56 end57 58 describe 'dirname()'59 it 'should return the directory path'60 dirname('/path/to/images/foo.bar.png').should.eql '/path/to/images'61 end62 end63 64 describe 'status()'65 it 'should set the response status'66 get('/user', function(){ status(500) })67 get('/user').status.should.eql 50068 end69 end70 71 describe 'header()'72 describe 'when given a field name and value'73 it 'should set the header'74 get('/user', function(){75 header('x-foo', 'bar')76 })77 get('/user').headers.should.have_property 'x-foo', 'bar'78 end 79 end80 81 describe 'when given a field name'82 it 'should return a request header value'83 get('/user', function(){84 return header('host')85 })86 get('/user').body.should.eql 'localhost'87 end88 89 it 'should be case-insensitive'90 get('/user', function(){91 return header('Host')92 })93 get('/user').body.should.eql 'localhost'94 end95 end96 end97 98 describe 'halt()'99 describe 'when given no arguments'100 it 'should respond with 404 Not Found'101 get('/user', function(){ halt() })102 get('/user').status.should.eql 404103 get('/user').body.should.include('Not Found')104 end105 end106 107 describe 'when given a status code'108 it 'should respond with that status and its associated default body'109   get('/user', function(){ halt(400) })110   get('/user').status.should.eql 400111   get('/user').body.should.include('Bad Request')112 end113 end114 115 describe 'when given a status code and body'116 it 'should respond with the status and its body'117 get('/user', function(){ halt(400, 'Oh noes!') })118 get('/user').status.should.eql 400119 get('/user').body.should.include('Oh noes!')120 end121 end122 123 describe 'when given an invalid status code'124 it 'should throw an InvalidStatusCode exception'125 // TODO: throw_error(InvalidStatusCode, ...) when jspec is fixed126 get('/user', function(){ halt(123123) })127 -{ get('/user') }.should.throw_error(/InvalidStatusCode: 123123 is an invalid HTTP response code/)128 try { get('/user') }129 catch (e) {130 e.should.be_an_instance_of ExpressError131 e.should.be_an_instance_of InvalidStatusCode132 }133 end134 end135 end136 137 describe 'param()'138 it 'should return a route placeholder value'139 get('/user/:id', function(){140 return 'user ' + param('id')141 })142 get('/user/12').body.should.eql 'user 12'143 end144 145 it 'should return several route placeholder values'146 get('/user/:id/:operation', function(){147 return param('operation') + 'ing user ' + param('id') 148 })149 get('/user/12/edit').body.should.eql 'editing user 12'150 end151 152 it 'should allow optional placeholders'153 get('/user/:id?', function(){154 return param('id') ? 'user ' + param('id') : 'users'155 })156 get('/user/12').body.should.eql 'user 12'157 get('/user').body.should.eql 'users'158 end159 160 it 'should allow placeholders as part of a segment'161 get('/report.:format', function(){162 return 'report as ' + param('format')163 })164 get('/report.csv').body.should.eql 'report as csv'165 get('/report.pdf').body.should.eql 'report as pdf'166 end167 168 it 'should allow optional placeholders in middle segments'169 get('/user/:id?/edit', function(){170 return param('id') ? 'editing ' + param('id') : 'editing your account'171 })172 get('/user/12/edit').body.should.eql 'editing 12'173 get('/user/edit').body.should.eql 'editing your account'174 end175 176 it 'should work with several routes'177 get('/user/:id', function(){ return param('id') })178 get('/product/:name', function(){ return param('name') })179 get('/user/12').body.should.eql '12'180 get('/product/ipod').body.should.eql 'ipod'181 end182 end183end
added:spec/spec.mime.js+37 added
modified:spec/spec.node.js+3 added-3 removed
added:spec/spec.routing.js+104 added
12describe 'Express'3 before_each4 reset()5 end6 7 describe 'route'8 describe 'with callback function'9 it 'should respond with a body string'10 get('/user', function(){11 return 'test'12 })13 get('/user').body.should.eql 'test'14 end15 end16 17 describe 'with options and callback function'18 it 'should respond with a body string'19 get('/user', {}, function(){20 return 'test with options'21 })22 get('/user').body.should.eql 'test with options'23 end24 end25 26 describe 'with a trailing slash in request path'27 it 'should still match'28 get('/user', {}, function(){29 return 'test with options'30 })31 get('/user/').body.should.eql 'test with options'32 end33 end34 35 describe 'with a trailing slash in route path'36 it 'should still match'37 get('/user/', {}, function(){38 return 'test with options'39 })40 get('/user').body.should.eql 'test with options'41 end42 end43 44 describe 'with a trailing whitespace in request path'45 it 'should still match'46 get('/user', {}, function(){47 return 'test with options'48 })49 get('/user/ ').body.should.eql 'test with options'50 end51 end52 53 describe 'with a trailing whitespace in route path'54 it 'should still match'55 get('/user/ ', {}, function(){56 return 'test with options'57 })58 get('/user').body.should.eql 'test with options'59 end60 end61 62 describe 'with several similar routes'63 it 'should match them properly'64 get('/foo', function(){65 return 'bar'66 })67 get('/foos', function(){68 return 'baz'69 })70 get('/foo').body.should.eql 'bar'71 get('/foos').body.should.eql 'baz'72 end73 end74 75 describe 'with several identical routes'76 it 'should match the first route'77 get('/foo', function(){78 return 'bar'79 })80 get('/foo', function(){81 return 'baz'82 })83 get('/foo').body.should.eql 'bar'84 end85 end86 87 describe 'with no response body'88 it 'should throw a InvalidResponseBody'89 get('/user', function(){90 Express.server.respond()91 })92 -{ get('/user') }.should.throw_error(/InvalidResponseBody: get "\/user" did not respond with a body string/)93 end94 end95 96 describe 'with an unmatchable request path'97 it 'should respond with 404 Not Found'98 get('/something').status.should.eql 40499 get('/something').body.should.eql 'Not Found'100 end101 end102 103 end104end
modified:Readme.md+14 added-57 removed
35 unmodified lines
36 Express scored **2762**.3738## Examples3940See examples/simple.js for a working server that uses a synchronous handler. 41Just type "node examples/simple.js" and then go to http://localhost:3000/i/like/cheese4243For an asynchronous example, run "node examples/async.js" and then go to http://localhost:3000/wait/20004445GET /user/tj/edit40 require.paths.unshift("./lib")41 require('express')42 47 get('user/:name/:operation', function(){48 param('operation') + 'ing ' + param('name')49 })5051GET /articles43 set('views', dirname(__filename) + '/views')44 53 get('articles', function(){54 'list of articles'55 })5657GET /articles/1245 get('/user/:id?', function() {46 if (param('id'))47 return 'Viewing user ' + param('id')48 return 'Your user account'49 })50 59 get(/articles\/(\d+)/, function(){60 'article id ' + captures[1]61 })62 63POST /user/:id64 65 post('user/:id', function(){66 User.destroy(params('id')) ? 67 'User deleted' :68 'Failed to delete user'69 })70 71GET /login72 73 get('login', function() {74 '<form method="post" action="/login"> \75 <input type="text" name="user[name]" /> \76 <input type="password" name="user[pass]" /> \77 <input type="submit" value="Login"/> \78 </form>'79 })80 81POST /login82 83 post('login', function() {84 'Welcome ' + param('user').name85 })86 51## Settings5289 * basepath : defaults to '/'90 * defaultRoute : responds with page not found91 * mime.defaultType : defaults to 'application/octet-stream'92 * cookie.maxAge : defaults to 3600 milliseconds93 94## Public API9596 * Coming Soon53 set('views', '/path/to/views')54 set('views') // => '/path/to/views'55 56 enable('foo')57 disable('bar')58 59## Collections6061Express ships with the Collection class, allowing101you to chain iterations on array-like objects.62you to chain iterations on array-like objects and objects.6364 $(['tj', 'matt', 'taylor'])65 .select(function(name){ return name.charAt(0) == 't' })66 .reject(function(name){ return name.length < 4 })
15 unmodified lines
82 $ node spec/spec.node.js mime83 $ node spec/spec.node.js routing84 ...85 125## More Information126127 * [Mojo](http://github.com/visionmedia/mojo) JavaScript Mustache Templates12886## License 8788(The MIT License)89
20 unmodified lines