Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit c2a4c60

Browse files
author
Adam Kliment
committed
Merge pull request #184 from apiaryio/netmilk/dredd-yml-override
Dredd init fix
2 parents 550e849 + 471ce82 commit c2a4c60

File tree

7 files changed

+130
-45
lines changed

7 files changed

+130
-45
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ to Gavel's [behavior specification][].
2020

2121
## Get Started Testing API Documentation and backend
2222

23-
1. I you don't have [Node.js](https://nodejs.org/) installed, you may want to use [NVM](https://github.com/creationix/nvm)
24-
1. Create an API blueprint in `blueprint.md`
25-
1. Install Dredd
23+
- I you don't have [Node.js](https://nodejs.org/) installed, you may want to use [NVM](https://github.com/creationix/nvm)
24+
- Create an API blueprint in `blueprint.md`
25+
- Install Dredd
2626

27-
```
28-
$ npm install -g dredd
29-
```
27+
```
28+
$ npm install -g dredd
29+
```
3030

31-
1. Run interactive configuration:
31+
- Run interactive configuration:
3232

33-
```
34-
$ dredd init
35-
```
33+
```
34+
$ dredd init
35+
```
3636

37-
1. Run dredd
37+
- Run dredd
3838

39-
```
40-
$ dredd
41-
```
39+
```
40+
$ dredd
41+
```
4242

4343
## Documentation
4444

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dredd",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"description": "API Blueprint testing tool",
55
"main": "lib/dredd.js",
66
"bin": {

src/dredd-command.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class DreddCommand
3232

3333
setOptimistArgv: ->
3434
@optimist = optimist(@custom['argv'], @custom['cwd'])
35+
@cliArgv = @optimist.argv
3536

3637
@optimist.usage(
3738
"""
@@ -134,6 +135,12 @@ class DreddCommand
134135
console.log 'Configuration dredd.yml found, ignoring other arguments.'
135136
@argv = configUtils.load()
136137

138+
# overwrite saved config with cli arguments
139+
for key, value of @cliArgv
140+
if key != "_" and key != "$0"
141+
@argv[key] = value
142+
143+
137144
parseCustomConfig: () ->
138145
@argv.custom = configUtils.parseCustom @argv.custom
139146

src/dredd.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ removeDuplicates = (arr) ->
2828

2929
class Dredd
3030
constructor: (config) ->
31+
@init(config)
32+
33+
# this is here only because there there is no way how to spy a constructor in CoffeScript
34+
init: (config) ->
3135
@tests = []
3236
@stats =
3337
tests: 0

src/interactive-config.coffee

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,28 @@ interactiveConfig.prompt = (config = {}, callback) ->
4040
name: "apiaryApiKey"
4141
message: "Please enter Apiary API key or leave empty for anonymous reporter"
4242
default: config['custom']?['apiaryApiKey']
43-
when: (answers) -> (answers['apiary'] == true && ! config['custom']?['apiaryApiKey']?)
43+
when: (answers) ->
44+
# it's not GA on the Apiary side yet
45+
if process.env['APIARY_BETA']?
46+
(answers['apiary'] == true && ! config['custom']?['apiaryApiKey']?)
47+
else
48+
false
4449
}
4550

4651
questions.push {
4752
type: "input"
4853
name: "apiaryApiName"
4954
message: "Please enter Apiary API name"
5055
default: config['custom']?['apiaryApiName']
51-
when: (answers) -> (
52-
(answers['apiary'] == true && ! config['custom']?['apiaryApiName']?) &&
53-
(answers['apiary'] == true && answers['apiaryApiKey'] != '')
54-
)
56+
when: (answers) ->
57+
# it's not GA on the Apiary side yet
58+
if process.env['APIARY_BETA']?
59+
(
60+
(answers['apiary'] == true && ! config['custom']?['apiaryApiName']?) &&
61+
(answers['apiary'] == true && answers['apiaryApiKey'] != '')
62+
)
63+
else
64+
false
5565
}
5666

5767
questions.push {

test/integration/cli-test.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ describe "Command line interface", () ->
962962
it 'stdout shoud contain sandbox messagae', () ->
963963
assert.include stdout, 'Loading hookfiles in sandboxed context'
964964

965-
# WARNING: this text is excluded from code coverage
965+
# WARNING: this test is excluded from code coverage
966966
# it for some reason decreases coverage on local and in coveralls
967967
describe 'when using --server', () ->
968968
resourceRequested = false

test/unit/dredd-command-test.coffee

Lines changed: 88 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{assert} = require 'chai'
22
sinon = require 'sinon'
33
express = require 'express'
4-
54
proxyquire = require('proxyquire').noCallThru()
65

6+
options = require '../../src/options'
77
packageJson = require '../../package.json'
8+
9+
childProcessStub = require 'child_process'
810
loggerStub = require '../../src/logger'
911
interactiveConfigStub = require '../../src/interactive-config'
1012
configUtilsStub = require '../../src/config-utils'
11-
options = require '../../src/options'
12-
13-
childProcessStub = require 'child_process'
13+
fsStub = require 'fs'
1414

1515
PORT = 9876
1616

@@ -22,19 +22,24 @@ stdout = ''
2222
addHooksStub = proxyquire '../../src/add-hooks', {
2323
'./logger': loggerStub
2424
}
25+
2526
transactionRunner = proxyquire '../../src/transaction-runner', {
2627
'./add-hooks': addHooksStub
2728
'./logger': loggerStub
2829
}
30+
2931
dreddStub = proxyquire '../../src/dredd', {
3032
'./transaction-runner': transactionRunner
3133
'./logger': loggerStub
3234
}
35+
3336
DreddCommand = 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

Comments
 (0)