Skip to content

Commit

Permalink
Add flour.get tests, make it accept a path array
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobeat committed Apr 6, 2013
1 parent 0db61c3 commit 367814a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flour.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ flour =

# Get file(s)' contents
get: (filepath, cb) ->
if isWild filepath
if isWild(filepath) or Array.isArray(filepath)
return flour.getFiles filepath, (files) ->
results = []
count = files.length
files.forEach (f, i) ->
new File(f).read (output) ->
results[i] = output
results[i] = results[f] = output
if --count is 0 then cb results, files

new File(filepath).read cb
Expand Down
43 changes: 43 additions & 0 deletions test/flour.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fs = require 'fs'
path = require 'path'

flour = require '../flour'
File = require '../lib/file'

readFile = (file) -> fs.readFileSync(file).toString()
copyFile = (file, out) -> fs.writeFileSync out, readFile file
Expand Down Expand Up @@ -241,6 +242,48 @@ describe 'Bundle', ->
contents.should.include 'bundle2=function('
done()

describe 'flour.get', (contents) ->

s1 = "#{dir.sources}/compile.coffee"
s2 = "#{dir.sources}/compile.styl"

lintall = "#{dir.sources}/lint/*"
lint1 = "#{dir.sources}/lint/lint-1.js"
lint2 = "#{dir.sources}/lint/lint-1.js"

it 'should return an instance of File', (done) ->
flour.get s1, (f) ->
this.should.be.an.instanceof File
done()

it 'should return a single file\'s contents', (done) ->
flour.get s1, (contents) ->
contents.should.equal readFile(s1)
done()

it 'should return multiple file\'s contents', (done) ->
flour.get [s1, s2], (res) ->
# contents should be available at both index and filename keys
should.exist res[0]
should.exist res[1]
res[0].should.equal readFile(s1)
res[1].should.equal readFile(s2)

should.exist res[s1]
should.exist res[s2]
res[s1].should.equal readFile(s1)
res[s2].should.equal readFile(s2)

done()

it 'should accept complex paths/patterns', (done) ->
flour.get lintall, (res) ->
should.exist res[lint1]
should.exist res[lint2]
res[lint1].should.equal readFile(lint1)
res[lint2].should.equal readFile(lint2)
done()

describe 'File path handling', ->

m1 = "#{dir.temp}/multi1.js"
Expand Down

0 comments on commit 367814a

Please sign in to comment.