Skip to content

Commit

Permalink
File overwrite tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
macalinao committed May 29, 2012
1 parent 6f3f324 commit d36c52f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,8 @@ archetype.generateFromDir('path/to/archetype/dir', 'path/to/destination/dir', {
});
```

Destination dir does not have to be created beforehand. It should be empty, however, or files present in the directory will be overwritten.

License
-------

Expand Down
30 changes: 30 additions & 0 deletions test/archetype.coffee
@@ -1,5 +1,6 @@
archetype = require '../lib/archetype'
fs = require 'fs'
mkdirp = require 'mkdirp'

describe 'archetype', ->
describe '#generate()' , ->
Expand All @@ -15,3 +16,32 @@ describe 'archetype', ->
archetype.generate 'test/archetypes/one_var', 'test/sandbox/one_var', asdf: 'cool site'
fs.readFileSync('test/sandbox/one_var/super.html', 'utf8').should.equal \
"<html><head><title>cool site</title></head><body>ASDF</body></html>\n"

it 'should filter multiple variables', ->
archetype.generate 'test/archetypes/multiple_vars/', 'test/sandbox/multiple_vars/', projectName: 'unknown', version: '9.0.1'
fs.readFileSync('test/sandbox/multiple_vars/package.json', 'utf8').should.equal \
"""
{
"name": "unknown",
"version": "9.0.1"
}
"""

it 'should work with existing directories', ->
mkdirp.sync 'test/sandbox/no_replace/'
archetype.generate 'test/archetypes/no_replace', 'test/sandbox/no_replace'
fs.readFileSync('test/sandbox/no_replace/myfile.arbitrary', 'utf8').should.equal "arbitrary file is arbitrary\n"

it 'should overwrite existing files', ->
mkdirp.sync 'test/sandbox/no_replace/'
fs.writeFileSync 'test/sandbox/no_replace/myfile.arbitrary', 'TROLOLOLO', 'utf8'
archetype.generate 'test/archetypes/no_replace', 'test/sandbox/no_replace'
fs.readFileSync('test/sandbox/no_replace/myfile.arbitrary', 'utf8').should.equal "arbitrary file is arbitrary\n"

it 'should not overwrite files it does not normally create', ->
mkdirp.sync 'test/sandbox/no_replace/'
fs.writeFileSync 'test/sandbox/no_replace/trololo.arbitrary', 'TROLOLOLO\n', 'utf8'
archetype.generate 'test/archetypes/no_replace', 'test/sandbox/no_replace'
fs.readFileSync('test/sandbox/no_replace/myfile.arbitrary', 'utf8').should.equal "arbitrary file is arbitrary\n"
fs.readFileSync('test/sandbox/no_replace/trololo.arbitrary', 'utf8').should.equal "TROLOLOLO\n"
4 changes: 4 additions & 0 deletions test/archetypes/multiple_vars/package.json
@@ -0,0 +1,4 @@
{
"name": "${projectName}",
"version": "${version}"
}

0 comments on commit d36c52f

Please sign in to comment.