11{assert } = require ' chai'
22sinon = require ' sinon'
33express = require ' express'
4-
54proxyquire = require (' proxyquire' ).noCallThru ()
65
6+ options = require ' ../../src/options'
77packageJson = require ' ../../package.json'
8+
9+ childProcessStub = require ' child_process'
810loggerStub = require ' ../../src/logger'
911interactiveConfigStub = require ' ../../src/interactive-config'
1012configUtilsStub = require ' ../../src/config-utils'
11- options = require ' ../../src/options'
12-
13- childProcessStub = require ' child_process'
13+ fsStub = require ' fs'
1414
1515PORT = 9876
1616
@@ -22,19 +22,24 @@ stdout = ''
2222addHooksStub = proxyquire ' ../../src/add-hooks' , {
2323 ' ./logger' : loggerStub
2424}
25+
2526transactionRunner = proxyquire ' ../../src/transaction-runner' , {
2627 ' ./add-hooks' : addHooksStub
2728 ' ./logger' : loggerStub
2829}
30+
2931dreddStub = proxyquire ' ../../src/dredd' , {
3032 ' ./transaction-runner' : transactionRunner
3133 ' ./logger' : loggerStub
3234}
35+
3336DreddCommand = proxyquire ' ../../src/dredd-command' , {
3437 ' ./dredd' : dreddStub
3538 ' console' : loggerStub
3639 ' ./interactive-init' : interactiveConfigStub
3740 ' child_process' : childProcessStub
41+ ' ./config-utils' : configUtilsStub
42+ ' fs' : fsStub
3843}
3944
4045
@@ -173,25 +178,6 @@ describe "DreddCommand class", () ->
173178
174179 assert .isObject dc .dreddInstance
175180
176- describe " when custom option is present" , () ->
177- it ' should parse custom options'
178- it ' the custom option should become an object'
179-
180- describe " when .dredd.yml file is present" , () ->
181- it ' should load it'
182-
183- describe " when load option is present" , () ->
184- it ' should load given file instead of .dredd.yml'
185-
186- describe " when config file is not parseable" , () ->
187- it ' should gracefuly end'
188-
189- describe " when server option is given" , () ->
190- it ' should run the server'
191-
192- describe " when test run finishes" , () ->
193- it ' should kill the server'
194-
195181 describe ' run with argv set to load regular blueprint' , ->
196182 dc = null
197183 runDreddStub = null
@@ -294,7 +280,85 @@ describe "DreddCommand class", () ->
294280 it ' prints out an error message' , ->
295281 assert .include stderr, ' Error: Must specify'
296282
297- # describe.only 'when using --server', () ->
283+
284+ describe ' when configuration was saved' , () ->
285+ before (done ) ->
286+ sinon .spy dreddStub .prototype , ' init'
287+ sinon .stub dreddStub .prototype , ' run' , (cb ) ->
288+ stats =
289+ tests : 0
290+ failures : 0
291+ errors : 0
292+ passes : 0
293+ skipped : 0
294+ start : 0
295+ end : 0
296+ duration : 0
297+ cb (null , stats)
298+
299+ sinon .stub interactiveConfigStub, ' run' , (config , cb ) ->
300+ cb ()
301+
302+ sinon .stub fsStub, ' existsSync' , () -> true
303+
304+ sinon .stub configUtilsStub, ' load' , () ->
305+ {
306+ " _" : [ ' blueprint' , ' endpoint' ]
307+ ' dry-run' : true
308+ hookfiles : null
309+ sandbox : false
310+ save : null
311+ load : null
312+ server : null
313+ init : false
314+ custom : []
315+ names : false
316+ only : []
317+ reporter : []
318+ output : []
319+ header : []
320+ sorted : false
321+ user : null
322+ ' inline-errors' : false
323+ details : false
324+ method : []
325+ color : true
326+ level : ' info'
327+ timestamp : false
328+ silent : false
329+ path : []
330+ ' $0' : ' node ./bin/dredd'
331+ }
332+
333+ execCommand argv : [' --names' ], ->
334+ done ()
335+
336+ after () ->
337+ dreddStub .prototype .run .restore ()
338+ dreddStub .prototype .init .restore ()
339+ interactiveConfigStub .run .restore ()
340+ configUtilsStub .load .restore ()
341+ fsStub .existsSync .restore ()
342+
343+ describe ' and I pass another CLI argument' , () ->
344+ it ' should want to exit with status 0' , () ->
345+ console .log stderr
346+ assert .equal exitStatus, 0
347+
348+ it ' should call dredd run' , () ->
349+ assert .isTrue dreddStub .prototype .run .called
350+
351+ it ' should override existing configuration' , () ->
352+ assert .isTrue dreddStub .prototype .init .called
353+ call = dreddStub .prototype .init .getCall (0 )
354+ passedConf = call .args [0 ]
355+ assert .propertyVal passedConf .options , ' names' , true
356+
357+
358+
359+
360+
361+ # describe 'when using --server', () ->
298362
299363 # beforeEach (done) ->
300364
0 commit comments