spec.plugins.static.js
This file
Path
spec/spec.plugins.static.js
75 lines · 2.5 KiB · JavaScript
Last changed by
Closes #88.visionmediabefore adoptionb8f54d6
History of this fileTake it
Closes #88.visionmediabefore adoptionb8f54d6
lines 1–75why, one step back12describe 'Express'3 describe 'StaticFile'4 before5 StaticFile = require('express/plugins/static').File6 use(require('express/plugins/static').Static, { path: 'spec/fixtures' })7 end8 9 describe '#constructor'10 it 'should accept and assign #path'11 (new StaticFile('/foo/bar')).path.should.eql '/foo/bar'12 end13 14 it 'should throw an InvalidPathError when .. is found'15 // TODO: use throw_error when fixed...16 try { new StaticFile('/../foobar') }17 catch (e) {18 e.name.should.eql 'InvalidPathError'19 e.message.should.eql "`/../foobar' is not a valid path"20 }21 end22 end23 24 describe 'GET /public/*'25 it 'should transfer static files'26 get('/public/user.json').body.should.include '"name":'27 end28 end29 30 describe '#sendfile()'31 describe 'when the file exists'32 it 'should transfer the file'33 get('/public/*', function(file){34 this.sendfile('spec/fixtures/' + file)35 })36 get('/public/user.json').body.should.include '"name":'37 end38 39 it 'should automatically set the content type based on extension'40 get('/public/*', function(file){41 this.sendfile('spec/fixtures/' + file)42 })43 get('/public/user.json').headers['content-type'].should.eql 'application/json'44 end45 end46 47 describe 'when "cache static files" is enabled'48 it 'should transfer the file'49 enable('cache static files')50 get('/public/*', function(file){51 this.sendfile('spec/fixtures/' + file)52 })53 get('/cached', function(){54 return this.cache.get('spec/fixtures/user.json') ? 'yes' : 'no'55 })56 get('/cached').body.should.eql 'no'57 get('/public/user.json').body.should.include '"name":'58 get('/cached').body.should.eql 'yes'59 get('/cached').body.should.eql 'yes'60 end61 62 it 'should automatically set the content type based on extension'63 enable('cache static files')64 get('/public/*', function(file){65 this.sendfile('spec/fixtures/' + file)66 })67 get('/public/user.json').headers['content-type'].should.eql 'application/json'68 get('/public/user.json').headers['content-type'].should.eql 'application/json'69 get('/public/user.json').headers['content-type'].should.eql 'application/json'70 end71 end72 end73 74 end75end