Skip to content

Commit

Permalink
test(preprocessor): fix the unit tests after DI refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Feb 28, 2013
1 parent ca22cd4 commit 03e9dfb
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions test/unit/preprocessor.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@
#==============================================================================
describe 'preprocessor', ->
mocks = require 'mocks'
di = require 'di'

m = pp = mockFs = doneSpy = fakePreprocessor = null
m = pp = mockFs = fakePreprocessor = null

beforeEach ->
mockFs = mocks.fs.create
some:
'a.js': mocks.fs.file 0, 'originalContent'
injector = new di.Injector [{'preprocessor:fake': ['factory', -> fakePreprocessor]}]

mocks_ =
fs: mockFs
minimatch: require 'minimatch'

m = mocks.loadFile __dirname + '/../../lib/preprocessor.js', mocks_
pp = m.createPreprocessor {'**/*.js': 'fake'}, null, injector


it 'should preprocess matching file', (done) ->
fakePreprocessor = sinon.spy (content, file, basePath, done) ->
fakePreprocessor = sinon.spy (content, file, done) ->
file.path = file.path + '-preprocessed'
file.contentPath = '/some/new.js'
done 'new-content'

mocks_ =
fs: mockFs
minimatch: require 'minimatch'
'./preprocessors/Coffee': fakePreprocessor

m = mocks.loadFile __dirname + '/../../lib/preprocessor.js', mocks_
pp = m.createPreprocessor {'**/*.js': 'coffee'}, null

file = {originalPath: '/some/a.js', path: 'path'}

pp file, ->
Expand All @@ -34,18 +35,11 @@ describe 'preprocessor', ->
expect(mockFs.readFileSync('/some/new.js').toString()).to.equal 'new-content'
done()


it 'should ignore not matching file', (done) ->
fakePreprocessor = sinon.spy (content, file, basePath, done) ->
fakePreprocessor = sinon.spy (content, file, done) ->
done ''

mocks_ =
fs: mockFs
minimatch: require 'minimatch'
'./preprocessors/Coffee': fakePreprocessor

m = mocks.loadFile __dirname + '/../../lib/preprocessor.js', mocks_
pp = m.createPreprocessor {'**/*.js': 'coffee'}, null

file = {originalPath: '/some/a.txt', path: 'path'}

pp file, ->
Expand Down

0 comments on commit 03e9dfb

Please sign in to comment.