spec.plugins.view.js
This file
Path
spec/spec.plugins.view.js
105 lines · 3.1 KiB · JavaScript
Last changed by
Added view locals specvisionmediabefore adoption86cac58
History of this fileTake it
View is now a plugin [#87]visionmediabefore adoption8e408e3
lines 1–13why, one step back12describe 'Express'3 before_each4 reset()5 end6 7 describe 'View'8 describe 'set("views")'9 it 'should default to <root>/views'10 set('root', 'spec')11 set('views').should.eql 'spec/views'12 end13 endStarted view specsvisionmediabefore adoption00a8c64
lines 14–21why, one step back14 15 describe '#render()'16 before_each17 set('views', 'spec/fixtures')18 end19 20 describe 'given a valid view name'21 describe 'and layout of the same type exists'Spec for custom layoutvisionmediabefore adoptionda7ea96
line 22why, one step back22 it 'should render the layout and view'Started view specsvisionmediabefore adoption00a8c64
lines 23–36why, one step back23 get('/', function(){24 this.render('hello.haml.html')25 })26 get('/').body.should.include '<html><body>'27 get('/').body.should.include '<h2>Hello'28 end29 end30 31 describe 'and layout of the same type does not exist'32 it 'should throw an error'33 get('/', function(){34 this.render('hello.haml.html', { layout: 'front' })35 })36 -{ get('/') }.should.throw_error 'No such file or directory'Spec for custom layoutvisionmediabefore adoptionda7ea96
lines 37–46why, one step back37 end38 end39 40 describe 'given a custom layout name'41 it 'should render the layout and view'42 get('/', function(){43 this.render('hello.haml.html', { layout: 'page' })44 })45 get('/').body.should.include '<title>Express'46 get('/').body.should.include '<h2>Hello'Started view specsvisionmediabefore adoption00a8c64
lines 47–48why, one step back47 end48 endSpec for layout: falsevisionmediabefore adoptiona4cbbe5
lines 49–59why, one step back49 50 describe 'when layout: false'51 it 'should render the view only'52 get('/', function(){53 this.render('hello.haml.html', { layout: false })54 })55 get('/').body.should.not.include '<body>'56 get('/').body.should.include '<h2>Hello'57 end58 end59 Added view caching specsvisionmediabefore adoption9fd92e3
lines 60–76why, one step back60 describe 'when "cache view contents" is enabled'61 it 'should read the views into memory only once'62 enable('cache view contents')63 get('/', function(){64 this.render('hello.haml.html')65 })66 get('/cached', function(){67 return this.cache.get('spec/fixtures/hello.haml.html') ? 'yes' : 'no'68 })69 get('/cached').body.should.eql 'no'70 get('/')71 get('/cached').body.should.eql 'yes'72 get('/')73 get('/cached').body.should.eql 'yes'74 end75 end76 Added spec for invalid view enginevisionmediabefore adoption8fc0620
lines 77–85why, one step back77 describe 'when engine cannot be found'78 it 'should throw an error'79 get('/', function(){80 this.render('user.invalid.html')81 })82 -{ get('/') }.should.throw_error "Cannot find module 'invalid'"83 end84 end85 Added view locals specvisionmediabefore adoption86cac58
lines 86–100why, one step back86 describe 'when locals are passed'87 it 'should have direct access to locals'88 get('/user', function(){89 this.render('user.haml.html', {90 locals: {91 name: 'tj',92 email: 'tj@vision-media.ca'93 }94 })95 })96 get('/').should.include '<h1>tj</h1>'97 get('/').should.include '<p>tj@vision-media.ca</p>'98 end99 end100 Started view specsvisionmediabefore adoption00a8c64
lines 101–103why, one step back101 end102 103 endView is now a plugin [#87]visionmediabefore adoption8e408e3
lines 104–105why, one step back104 end105end