Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (73 sloc) 2.704 kb
should = require 'should'
shell = require '..'
describe 'Request question', ->
it 'Question # req # string', (next) ->
stdin = new shell.NullStream
stdout = new shell.NullStream
stdout.on 'data', (data) ->
return unless data.trim()
data.should.eql 'My question: '
stdin.emit 'data', 'My answer'
app = shell
workspace: "#{__dirname}/plugins_http"
command: 'test string'
stdin: stdin
stdout: stdout
app.configure ->
app.use shell.router shell: app
app.cmd 'test string', (req, res) ->
req.question 'My question:', (value) ->
value.should.eql 'My answer'
next()
it 'Question # req # array of objects', (next) ->
expects = ['Question 1 ', 'Question 2 [v 2] ']
stdin = new shell.NullStream
stdout = new shell.NullStream
stdout.on 'data', (data) ->
return unless data.trim()
data.should.eql expects.shift()
stdin.emit 'data', "Value #{2 - expects.length}"
app = shell
workspace: "#{__dirname}/plugins_http"
command: 'test array'
stdin: stdin
stdout: stdout
app.configure ->
app.use shell.router shell: app
app.cmd 'test array', (req, res) ->
req.question [
name: 'Question 1'
,
name: 'Question 2'
value: 'v 2'
], (values) ->
values.should.eql
'Question 1': 'Value 1'
'Question 2': 'Value 2'
next()
it 'Question # req # object', (next) ->
expects = ['Question 1 ', 'Question 2 [v 2] ', 'Question 3 [v 3] ']
stdin = new shell.NullStream
stdout = new shell.NullStream
stdout.on 'data', (data) ->
return unless data.trim()
data.should.eql expects.shift()
stdin.emit 'data', "Value #{3 - expects.length}"
app = shell
workspace: "#{__dirname}/plugins_http"
command: 'test object'
stdin: stdin
stdout: stdout
app.configure ->
app.use shell.router shell: app
app.cmd 'test object', (req, res) ->
req.question
'Question 1': null
'Question 2': 'v 2'
'Question 3': { value: 'v 3'}
, (values) ->
values.should.eql
'Question 1': 'Value 1'
'Question 2': 'Value 2'
'Question 3': 'Value 3'
next()
Jump to Line
Something went wrong with that request. Please try again.