@@ -2,36 +2,38 @@ var header = require('utilise/header')
22 , expect = require ( 'chai' ) . expect
33 , is = require ( 'utilise/is' )
44 , core = require ( './' ) . default
5- , ripple
65
76describe ( 'Core' , function ( ) {
8- beforeEach ( function ( ) {
9- ripple = core ( )
10- } )
11-
7+
128 it ( 'should create empty resource from name' , function ( ) {
9+ var ripple = core ( )
1310 expect ( ripple ( 'foo' , 'bar' ) ) . to . eql ( 'bar' )
1411 } )
1512
1613 it ( 'should fail to create resource it does not understand' , function ( ) {
14+ var ripple = core ( )
1715 expect ( ripple ( 'foo' ) ) . to . eql ( false )
1816 } )
1917
2018 it ( 'should set content-type by default' , function ( ) {
19+ var ripple = core ( )
2120 ripple ( 'foo' , 'bar' )
2221 expect ( header ( 'content-type' ) ( ripple . resources [ 'foo' ] ) ) . to . be . equal ( 'text/plain' )
2322 } )
2423
2524 it ( 'should create resource using alias' , function ( ) {
25+ var ripple = core ( )
2626 expect ( ripple . register ( 'foo' , 'bar' ) ) . to . eql ( 'bar' )
2727 } )
2828
2929 it ( 'should create and get resource from name' , function ( ) {
30+ var ripple = core ( )
3031 ripple ( 'foo' , 'bar' )
3132 expect ( ripple ( 'foo' ) ) . to . eql ( 'bar' )
3233 } )
3334
3435 it ( 'should create and get resource from obj' , function ( ) {
36+ var ripple = core ( )
3537 expect ( ripple ( { name : 'foo' , body : 'bar' , headers : { } } ) ) . to . eql ( 'bar' )
3638 expect ( ripple . resources . foo ) . to . eql ( {
3739 name : 'foo'
@@ -41,6 +43,7 @@ describe('Core', function() {
4143 } )
4244
4345 it ( 'should create import resources from another node' , function ( ) {
46+ var ripple = core ( )
4447 ripple ( { name : 'foo' , body : 'bar' , headers : { } } )
4548 var ripple2 = core ( )
4649 ripple2 ( ripple )
@@ -52,6 +55,7 @@ describe('Core', function() {
5255 } )
5356
5457 it ( 'should use explicitly set headers' , function ( ) {
58+ var ripple = core ( )
5559 expect ( ripple ( {
5660 name : 'sth'
5761 , body : { a : 1 }
@@ -65,6 +69,7 @@ describe('Core', function() {
6569 } )
6670
6771 it ( 'should support method chaining api' , function ( ) {
72+ var ripple = core ( )
6873 ripple
6974 . resource ( 'foo' , 'bar' )
7075 . resource ( 'bar' , 'foo' )
@@ -81,13 +86,15 @@ describe('Core', function() {
8186 } )
8287
8388 it ( 'should register multiple resources' , function ( ) {
89+ var ripple = core ( )
8490 ripple ( [ { name :'foo' , body :'1' } , { name :'bar' , body :'1' } ] )
8591
8692 expect ( 'foo' in ripple . resources ) . to . be . ok
8793 expect ( 'bar' in ripple . resources ) . to . be . ok
8894 } )
8995
9096 it ( 'should destroy existing headers by default' , function ( ) {
97+ var ripple = core ( )
9198 ripple ( { name : 'name' , body : 'foo' , headers : { 'foo' : 'bar' } } )
9299 expect ( ripple . resources . name . headers . foo ) . to . be . eql ( 'bar' )
93100
@@ -96,6 +103,7 @@ describe('Core', function() {
96103 } )
97104
98105 it ( 'should fail if cannot interpret resource' , function ( ) {
106+ var ripple = core ( )
99107 expect ( ripple ( 'foo' , [ ] ) ) . to . not . be . ok
100108 expect ( ripple ( 'bar' ) ) . to . not . be . ok
101109
@@ -104,31 +112,40 @@ describe('Core', function() {
104112 } )
105113
106114 it ( 'should fail if uses api incorrectly' , function ( ) {
115+ var ripple = core ( )
107116 expect ( ripple ( ) ) . to . be . eql ( ripple )
108117 expect ( ripple ( String ) ) . to . not . be . ok
109118 expect ( ripple . resources ) . to . eql ( { } )
110119 } )
111120
112121 it ( 'should skip empty objects' , function ( ) {
122+ var ripple = core ( )
113123 expect ( ripple ( { } ) ) . to . be . eql ( ripple )
114124 expect ( ripple . resources ) . to . eql ( { } )
115125 } )
116126
117127 it ( 'should not register type it does not understand' , function ( ) {
128+ var ripple = core ( )
118129 expect ( ripple ( { name : 'foo' , body : 'foo' , headers : { 'content-type' : 'application/jsx' } } ) ) . to . not . be . ok
119130 expect ( ripple . resources ) . to . eql ( { } )
120131 } )
121132
122133 it ( 'should emit global change events' , function ( ) {
123- var called = 0
124- , fn = function ( ) { called ++ }
134+ var ripple = core ( )
135+ , params
136+ , fn = function ( name , change ) { params = [ name , change ] }
125137
126138 ripple . on ( 'change' , fn )
127139 ripple ( 'foo' , 'bar' )
128- expect ( called ) . to . equal ( 1 )
140+ expect ( params ) . to . eql ( [ 'foo' , { type : 'update' , value : 'bar' } ] )
141+
142+ ripple . types [ 'data' ] = { header : 'data' , check : String }
143+ ripple ( 'boo' , { log : [ 'baz' ] } )
144+ expect ( params ) . to . eql ( [ 'boo' , 'baz' ] )
129145 } )
130146
131147 it ( 'should indicate if new resource' , function ( done ) {
148+ var ripple = core ( )
132149 ripple . once ( 'change' , function ( d , change ) {
133150 expect ( d ) . to . eql ( 'foo' )
134151 expect ( change ) . to . eql ( { type : 'update' , value : 'foo' } )
@@ -143,6 +160,7 @@ describe('Core', function() {
143160 } )
144161
145162 it ( 'should register new types by order' , function ( ) {
163+ var ripple = core ( )
146164 ripple ( 'text' , 'text' )
147165 expect ( ripple . resources . text . headers [ 'content-type' ] ) . to . eql ( 'text/plain' )
148166
0 commit comments