From b72355cbeadc8e907e48bbd7d9a11e6de17343f7 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 30 Jul 2013 12:09:52 -0700 Subject: [PATCH] fix(init): trim the inputs Closes #663 --- lib/init.js | 2 ++ test/unit/init.spec.coffee | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/init.js b/lib/init.js index ef9de918a..1458dd7fc 100755 --- a/lib/init.js +++ b/lib/init.js @@ -170,6 +170,8 @@ var StateMachine = function(rli) { this.onLine = function(line) { if (pendingQuestionId) { + line = line.trim(); + if (currentOptions) { currentOptionsPointer = currentOptions.indexOf(line); if (currentOptionsPointer === -1) { diff --git a/test/unit/init.spec.coffee b/test/unit/init.spec.coffee index 1f083c82e..cbd4bc3ed 100644 --- a/test/unit/init.spec.coffee +++ b/test/unit/init.spec.coffee @@ -54,6 +54,20 @@ describe 'init', -> expect(done).to.have.been.called + it 'should treat spaces as confirmation of multiple answers', -> + questions = [ + {id: 'browsers', multiple: true} + ] + + done = sinon.spy (answers) -> + expect(answers.browsers).to.deep.equal ['Chrome'] + + machine.process questions, done + machine.onLine 'Chrome' + machine.onLine ' ' + expect(done).to.have.been.called + + it 'should always return array for multiple', -> questions = [ {id: 'empty', multiple: true}