Skip to content
Browse files

Add spec for component shorthand

  • Loading branch information...
1 parent 5575a35 commit 1c1bc5bb4cb955f999842d9c6176de2567f98de9 Kenneth Kan committed Mar 2, 2014
Showing with 27 additions and 10 deletions.
  1. +18 −0 spec/Component.coffee
  2. +9 −10 spec/InPort.coffee
View
18 spec/Component.coffee
@@ -56,3 +56,21 @@ describe 'Component', ->
f = ->
s2.send 'some-data'
chai.expect(f).to.not.throw()
+
+ describe 'with component creation shorthand', ->
+ it 'should make component creation easy', ->
+ c = new component
+ inPorts:
+ in:
+ datatype: 'string'
+ required: true
+ processor: (packet, component) ->
+ chai.expect(packet).toEqual 'some-data'
+ chai.expect(component).toBe c
+
+ justProcessor: (packet, component) ->
+ chai.expect(packet).toEqual 'some-data'
+ chai.expect(component).toBe c
+
+ c.inPorts.in.send 'some-data'
+ c.inPorts.justProcessor.send 'some-data'
View
19 spec/InPort.coffee
@@ -44,7 +44,7 @@ describe 'Inport Port', ->
it 'should set context to port itself', ->
s = new socket
p = new inport
- p.on 'data', (packet, outPorts) ->
+ p.on 'data', (packet, component) ->
chai.expect(this).toBe p
chai.expect(packet).toEqual 'some-data'
p.attach s
@@ -97,9 +97,10 @@ describe 'Inport Port', ->
f = (type) ->
new inport
type: type
- it 'should be a URL', ->
+ it 'should be a URL or MIME', ->
chai.expect(-> f 'http://schema.org/Person').to.not.throw()
- chai.expect(-> f 'not-a-url').to.throw()
+ chai.expect(-> f 'text/javascript').to.not.throw()
+ chai.expect(-> f 'neither-a-url-nor-mime').to.throw()
describe 'with buffering', ->
it 'should buffer incoming packets until `receive()`d', ->
@@ -119,7 +120,7 @@ describe 'Inport Port', ->
# to "peek" into the latest packet until all preceding packets have
# been consumed.
chai.expect(data).toEqual 'buffered-data-1'
- # Now we consume it. Note that the context should the port itself.
+ # Now we consume it. Note that the context should be the port itself.
_data = @receive()
chai.expect(data).toEqual _data
s.send 'buffered-data-2'
@@ -171,22 +172,20 @@ describe 'Inport Port', ->
ps = new ports
outPorts:
out: new outport
- ps.add 'in', (packet, outPorts) ->
+ ps.add 'in', (packet, component) ->
chai.expect(packet).toEqual 'some-data'
- chai.assert outPorts.out instanceof outport
+ chai.assert component.outPorts.out instanceof outport
chai.assert ps.inPorts.in instanceof inport
ps.inPorts.in.attach s
s.send 'some-data'
it 'should also accept metadata (i.e. options) when provided', (done) ->
s = new socket
ps = new ports
- outPorts:
- out: new outport
ps.add 'in',
- type: 'string'
+ datatype: 'string'
required: true
- , (packet, outPorts) ->
+ , (packet, component) ->
chai.expect(packet).toEqual 'some-data'
done()
ps.inPorts.in.attach s

0 comments on commit 1c1bc5b

Please sign in to comment.
Something went wrong with that request. Please try again.