sphero-pwn
Version:
Driver for Sphero robots
77 lines (70 loc) • 2.59 kB
text/coffeescript
ChannelRecorder = SpheroPwn.ChannelRecorder
ReplayChannel = SpheroPwn.ReplayChannel
fs = require 'fs-promise'
temp = require('temp').track()
describe 'ChannelRecorder', ->
beforeEach (done) ->
temp.open 'recorder-', (error, info) =>
throw error if error
= info.path
fs.close(info.fd)
.then ->
done()
afterEach (done) ->
temp.cleanup (error, stats) ->
throw error if error
done()
it 'records a write correctly', ->
= new ReplayChannel testRecordingPath('synthetic-1write')
= new ChannelRecorder ,
.open()
.then =>
.write(new Buffer('Hello'))
.then =>
.close()
.then =>
fs.readFile , 'utf8'
.then (recording) =>
= recording
fs.readFile testRecordingPath('synthetic-1write'), 'utf8'
.then (goldenRecording) =>
expect().to.equal goldenRecording
it 'reports a read correctly', ->
(new Promise (resolve, reject) =>
= new ReplayChannel testRecordingPath('synthetic-1read')
= new ChannelRecorder ,
.onData = (data) => resolve data
.open()
).then (data) =>
expect(data).to.deep.equal new Buffer('world')
.close()
.then =>
fs.readFile , 'utf8'
.then (recording) =>
= recording
fs.readFile testRecordingPath('synthetic-1read'), 'utf8'
.then (goldenRecording) =>
expect().to.equal goldenRecording
it 'reports a write-read-write-read correctly', ->
= new ReplayChannel testRecordingPath('synthetic-wrwr')
= new ChannelRecorder ,
.open()
.then =>
new Promise (resolve, reject) =>
.onData = (data) => resolve data
.write(new Buffer('Hello')).catch (error) => reject error
.then (data) =>
expect(data).to.deep.equal new Buffer('world')
new Promise (resolve, reject) =>
.onData = (data) => resolve data
.write(new Buffer('hai')).catch (error) => reject error
.then (data) =>
expect(data).to.deep.equal new Buffer('bai')
.close()
.then =>
fs.readFile , 'utf8'
.then (recording) =>
= recording
fs.readFile testRecordingPath('synthetic-wrwr'), 'utf8'
.then (goldenRecording) =>
expect().to.equal goldenRecording