1 |
|
2 | fs = require 'fs'
|
3 | path = require 'path'
|
4 | fs.exists ?= path.exists
|
5 | should = require 'should'
|
6 | mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
|
7 | test = require './test'
|
8 |
|
9 | describe 'copy', ->
|
10 |
|
11 | scratch = test.scratch @
|
12 |
|
13 | it 'should only copy if destination does not exists', (next) ->
|
14 | source = "#{__dirname}/../resources/a_dir/a_file"
|
15 | destination = "#{scratch}/a_new_file"
|
16 | mecano.copy
|
17 | source: source
|
18 | destination: destination
|
19 | , (err, copied) ->
|
20 | should.not.exist err
|
21 | copied.should.eql 1
|
22 | mecano.copy
|
23 | source: source
|
24 | destination: destination
|
25 | , (err, copied) ->
|
26 | should.not.exist err
|
27 | copied.should.eql 0
|
28 | next()
|
29 |
|
30 | it 'should always copy with `force` option', (next) ->
|
31 | source = "#{__dirname}/../resources/a_dir/a_file"
|
32 | destination = "#{scratch}/a_new_file"
|
33 | mecano.copy
|
34 | source: source
|
35 | destination: destination
|
36 | , (err, copied) ->
|
37 | should.not.exist err
|
38 | copied.should.eql 1
|
39 | mecano.copy
|
40 | source: source
|
41 | destination: destination
|
42 | force: true
|
43 | , (err, copied) ->
|
44 | should.not.exist err
|
45 | copied.should.eql 1
|
46 | next()
|
47 |
|
48 | it 'should copy a file into an existing directory', (next) ->
|
49 | source = "#{__dirname}/../resources/a_dir/a_file"
|
50 | destination = "#{scratch}/"
|
51 |
|
52 | mecano.copy
|
53 | source: source
|
54 | destination: destination
|
55 | , (err, copied) ->
|
56 | should.not.exist err
|
57 | copied.should.eql 1
|
58 | fs.exists "#{destination}/a_file", (exists) ->
|
59 | should.ok exists
|
60 |
|
61 | mecano.copy
|
62 | source: source
|
63 | destination: destination
|
64 | , (err, copied) ->
|
65 | should.not.exist err
|
66 | copied.should.eql 0
|
67 | next()
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|