UNPKG

2.71 kBtext/coffeescriptView Raw
1# Hey-coffee Tests
2# TJ Eastmond - tj.eastmond@gmail.com
3# Copyright 2013
4
5Hey = require '../'
6should = require 'should'
7mkdirp = require 'mkdirp'
8fs = require 'fs'
9exec = require('child_process').exec
10
11blogDir = process.cwd() + '/test/blog/'
12
13# misc functions
14create_blog_folder = -> mkdirp.sync blogDir
15delete_blog_folder = (callback) -> exec "rm -rf #{blogDir}", callback
16create_new_blog = (callback) ->
17 do create_blog_folder
18 @hey = new Hey blogDir
19 do @hey.init
20 callback?()
21
22describe '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
31describe '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
45describe '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
64describe '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