1 |
|
2 |
|
3 |
|
4 |
|
5 | Hey = require '../'
|
6 | should = require 'should'
|
7 | mkdirp = require 'mkdirp'
|
8 | fs = require 'fs'
|
9 | exec = require('child_process').exec
|
10 |
|
11 | blogDir = process.cwd() + '/test/blog/'
|
12 |
|
13 |
|
14 | create_blog_folder = -> mkdirp.sync blogDir
|
15 | delete_blog_folder = (callback) -> exec "rm -rf #{blogDir}", callback
|
16 | create_new_blog = (callback) ->
|
17 | do create_blog_folder
|
18 | @hey = new Hey blogDir
|
19 | do @hey.init
|
20 | callback?()
|
21 |
|
22 | describe 'Hey-coffee', ->
|
23 | before -> @hey = new Hey
|
24 | it 'exists', -> @hey.should.be.an.Object
|
25 | it 'should have the methods the CLI depends on', ->
|
26 | @hey.init.should.be.type 'function'
|
27 | @hey.server.should.be.type 'function'
|
28 | @hey.publish.should.be.type 'function'
|
29 | @hey.watch.should.be.type 'function'
|
30 |
|
31 | describe 'Creating a blog', ->
|
32 | before -> create_new_blog.call this
|
33 | after (done) -> delete_blog_folder done
|
34 |
|
35 | it 'should throw an error if a blog already exists', -> (=> @hey.init()).should.throw()
|
36 | it 'should create a config file', -> fs.existsSync(@hey.configFile).should.be.true
|
37 | it 'should create a posts directory', -> fs.existsSync(@hey.postPath()).should.be.true
|
38 | it 'should create a pages directory', -> fs.existsSync(@hey.pagesDir).should.be.true
|
39 | it 'should create a public directory', -> fs.existsSync(@hey.publicDir).should.be.true
|
40 | it 'should create a layouts directory', -> fs.existsSync(@hey.layoutsDir).should.be.true
|
41 | it 'should create a site directory', -> fs.existsSync(@hey.siteDir).should.be.true
|
42 | it 'should create a cache file', -> fs.existsSync(@hey.cacheFile).should.be.true
|
43 | it 'should create a template file', -> fs.existsSync(@hey.templatePath(@hey.defaultTemplateFile)).should.be.true
|
44 |
|
45 | describe 'Building a blog', ->
|
46 | before -> create_new_blog.call this
|
47 | after (done) -> delete_blog_folder done
|
48 |
|
49 | it 'should not throw errors', (done) ->
|
50 | @hey.build done
|
51 |
|
52 | it 'should update the cache', (done) ->
|
53 | cache = JSON.parse fs.readFileSync(@hey.cacheFile).toString()
|
54 | cache.should.have.length 1
|
55 | do done
|
56 |
|
57 | it 'should create HTML files', (done) ->
|
58 | fs.existsSync("#{blogDir}site/index.html").should.be.true
|
59 | fs.existsSync("#{blogDir}site/2013/04/index.html").should.be.true
|
60 | fs.existsSync("#{blogDir}site/2013/04/22/first-post/index.html").should.be.true
|
61 | fs.existsSync("#{blogDir}site/tags/tests/index.html").should.be.true
|
62 | do done
|
63 |
|
64 | describe 'Archiving a blog', ->
|
65 | before -> create_new_blog.call this
|
66 | after (done) -> delete_blog_folder done
|
67 |
|
68 | it 'should create the versions/ folder', (done) ->
|
69 | @hey.backup =>
|
70 | fs.existsSync(@hey.versionsDir).should.be.true
|
71 | do done
|
72 |
|
73 | it 'should create the gzip file', (done) ->
|
74 | fs.readdirSync(@hey.versionsDir).should.have.length 1
|
75 | do done
|