Skip to content

Commit

Permalink
fix(init): to not give false warning about missing requirejs
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Apr 4, 2013
1 parent bf59278 commit 562607a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,21 @@ var StateMachine = function(rli) {
}
}

if (line && currentQuestion.validate) {
currentQuestion.validate(line);
if (line === '') {
line = null;
}

if (currentQuestion.boolean) {
line = (line === 'yes' || line === 'true' || line === 'on');
}

if (line !== null && currentQuestion.validate) {
currentQuestion.validate(line);
}

if (currentQuestion.multiple) {
answers[pendingQuestionId] = answers[pendingQuestionId] || [];
if (line) {
if (line !== null) {
answers[pendingQuestionId].push(line);
rli.prompt();

Expand Down
16 changes: 16 additions & 0 deletions test/unit/init.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ describe 'init', ->
expect(done).to.have.been.called


it 'should parse booleans before validation', ->
validator = sinon.spy (value) ->
expect(typeof value).to.equal 'boolean'

questions = [
{id: 'what', options: ['yes', 'no'], boolean: true, validate: validator}
{id: 'really', options: ['yes', 'no'], boolean: true, validate: validator}
]

machine.process questions, done
machine.onLine 'yes'
machine.onLine 'no'

expect(validator).to.have.been.calledTwice


describe 'getBasePath', ->

# just for windows.
Expand Down

0 comments on commit 562607a

Please sign in to comment.