Skip to content

Commit

Permalink
Started view specs
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Mar 18, 2010
1 parent e1152f6 commit 00a8c64
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/express/plugins/view.js
Expand Up @@ -84,8 +84,8 @@ exports.View = Plugin.extend({
if (set('cache view contents') && self.cache.get(path))
render(self.cache.get(path))
else
fs.readFile(path, function(e, content){
if (e) throw e
fs.readFile(path, function(err, content){
if (err) throw err
set('cache view contents')
? render(self.cache.set(path, content))
: render(content)
Expand Down
15 changes: 14 additions & 1 deletion lib/express/spec/mocks.js
Expand Up @@ -5,7 +5,20 @@
* Module dependencies.
*/

var utils = require('express/utils')
var utils = require('express/utils'),
fs = require('fs')

/**
* Mock fs.readFile()
*/

fs.readFile = function(path, fn) {
try {
fn(null, fs.readFileSync(path))
} catch (e) {
fn(e)
}
}

// --- MockRequest

Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/hello.haml.html
@@ -0,0 +1 @@
%h2 Hello
2 changes: 2 additions & 0 deletions spec/fixtures/layout.haml.html
@@ -0,0 +1,2 @@
%html
%body= body
28 changes: 28 additions & 0 deletions spec/spec.plugins.view.js
Expand Up @@ -11,5 +11,33 @@ describe 'Express'
set('views').should.eql 'spec/views'
end
end

describe '#render()'
before_each
set('views', 'spec/fixtures')
end

describe 'given a valid view name'
describe 'and layout of the same type exists'
it 'should render the view'
get('/', function(){
this.render('hello.haml.html')
})
get('/').body.should.include '<html><body>'
get('/').body.should.include '<h2>Hello'
end
end

describe 'and layout of the same type does not exist'
it 'should throw an error'
get('/', function(){
this.render('hello.haml.html', { layout: 'front' })
})
-{ get('/') }.should.throw_error 'No such file or directory'
end
end
end

end
end
end

0 comments on commit 00a8c64

Please sign in to comment.