1 |
|
2 | fs = require 'fs'
|
3 | should = require 'should'
|
4 | mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
|
5 | test = require './test'
|
6 |
|
7 | describe 'render', ->
|
8 |
|
9 | scratch = test.scratch @
|
10 |
|
11 | it 'should use `content`', (next) ->
|
12 | destination = "#{scratch}/render.eco"
|
13 | mecano.render
|
14 | content: 'Hello <%- @who %>'
|
15 | destination: destination
|
16 | context: who: 'you'
|
17 | , (err, rendered) ->
|
18 | should.not.exist err
|
19 | rendered.should.eql 1
|
20 | fs.readFile destination, 'ascii', (err, content) ->
|
21 | content.should.eql 'Hello you'
|
22 | next()
|
23 |
|
24 | it 'should use `source`', (next) ->
|
25 | destination = "#{scratch}/render.eco"
|
26 | mecano.render
|
27 | source: "#{__dirname}/../resources/render.eco"
|
28 | destination: destination
|
29 | context: who: 'you'
|
30 | , (err, rendered) ->
|
31 | should.not.exist err
|
32 | rendered.should.eql 1
|
33 | fs.readFile destination, 'ascii', (err, content) ->
|
34 | content.should.eql 'Hello you'
|
35 | next()
|
36 |
|
37 | it 'should be unhappy', (next) ->
|
38 | destination = "#{scratch}/render.eco"
|
39 | mecano.render
|
40 | source: "oups"
|
41 | destination: destination
|
42 | , (err, rendered) ->
|
43 | err.message.should.eql 'Invalid source, got "oups"'
|
44 | next()
|
45 |
|
46 |
|
47 |
|