@@ -51,15 +51,14 @@ var vows = require('perjury'),
51
51
sinon = require ( 'sinon' ) ,
52
52
noopLog = require ( './lib/log' ) ,
53
53
persistenceutil = require ( './lib/persistence' ) ,
54
- db = require ( '../lib/persistence' ) ( '/tmp' ) ( noopLog ) ,
55
- wrapFsMocks = persistenceutil . wrapFsMocks ,
54
+ memoryPersistence = persistenceutil . memoryPersistence ,
55
+ db = memoryPersistence ( ) ( ) ,
56
56
data = {
57
57
singleLink : '<a href="http://nicenice.website/blag/new-puppy">So cute!</a>' ,
58
58
multipleLinks : '<a href="http://magic.geek/pics/another-doggo">Even cuter!</a> I love <a href="http://catscatscats.org/">cats</a> too!' ,
59
59
noHref : 'It\'s <a href="">yikes-worthy</a>!' ,
60
60
noLinks : 'I have absolutely no links at all.'
61
61
} ;
62
-
63
62
var clock ;
64
63
65
64
vows . describe ( 'Webmention module' ) . addBatch ( {
@@ -96,13 +95,33 @@ vows.describe('Webmention module').addBatch({
96
95
'we get a function back' : function ( err , webmention ) {
97
96
assert . isFunction ( webmention [ 1 ] ) ;
98
97
} ,
99
- 'and we set up persistence mocks' : wrapFsMocks ( {
100
- 'and we call the module with a post' : {
98
+ 'and we call the module with a post' : {
99
+ topic : function ( fns ) {
100
+ var webmention = fns [ 1 ] ,
101
+ cb = this . callback ;
102
+
103
+ webmention ( 'http://example.com/socute' ,
104
+ 100 ,
105
+ data . singleLink ,
106
+ function ( err ) {
107
+ cb ( err , fns ) ;
108
+ } ) ;
109
+ } ,
110
+ 'it works' : function ( err ) {
111
+ assert . ifError ( err ) ;
112
+ } ,
113
+ 'the spy was called' : function ( err , fns ) {
114
+ var spy = fns [ 0 ] ;
115
+ assert . isTrue ( spy . calledOnce ) ;
116
+ // XXX assert arguments
117
+ } ,
118
+ 'and we call it with the same data' : {
101
119
topic : function ( fns ) {
102
120
var webmention = fns [ 1 ] ,
103
121
cb = this . callback ;
104
122
105
123
webmention ( 'http://example.com/socute' ,
124
+ // Note: these are smaller because JS dates are in milliseconds but we're passing seconds
106
125
100 ,
107
126
data . singleLink ,
108
127
function ( err ) {
@@ -112,127 +131,105 @@ vows.describe('Webmention module').addBatch({
112
131
'it works' : function ( err ) {
113
132
assert . ifError ( err ) ;
114
133
} ,
115
- 'the spy was called' : function ( err , fns ) {
134
+ 'the spy wasn\'t called again ' : function ( err , fns ) {
116
135
var spy = fns [ 0 ] ;
117
136
assert . isTrue ( spy . calledOnce ) ;
118
- // XXX assert arguments
119
137
} ,
120
- 'and we call it with the same data ' : {
138
+ 'and we call it with a newer timestamp ' : {
121
139
topic : function ( fns ) {
122
140
var webmention = fns [ 1 ] ,
123
- cb = this . callback ;
141
+ cb = this . callback ;
142
+
143
+ // This shouldn't matter, but just in case, we set the clock to be past the edited timestamp
144
+ clock . tick ( 100 * 1000 ) ;
124
145
125
146
webmention ( 'http://example.com/socute' ,
126
- // Note: these are smaller because JS dates are in milliseconds but we're passing seconds
127
- 100 ,
128
- data . singleLink ,
129
- function ( err ) {
130
- cb ( err , fns ) ;
131
- } ) ;
147
+ 200 ,
148
+ data . singleLink ,
149
+ function ( err ) {
150
+ cb ( err , fns ) ;
151
+ } ) ;
152
+ } ,
153
+ teardown : function ( ) {
154
+ return clock . tick ( - 100 * 1000 ) ;
132
155
} ,
133
156
'it works' : function ( err ) {
134
157
assert . ifError ( err ) ;
135
158
} ,
136
- 'the spy wasn\'t called again ' : function ( err , fns ) {
159
+ 'the spy was called a second time ' : function ( err , fns ) {
137
160
var spy = fns [ 0 ] ;
138
- assert . isTrue ( spy . calledOnce ) ;
161
+ assert . isTrue ( spy . calledTwice ) ;
162
+ // XXX assert arguments
139
163
} ,
140
- 'and we call it with a newer timestamp' : {
164
+ // XXX find a way to not nest this so deeply - it
165
+ // has to be this way currently so the Sinon spy is
166
+ // called in the right order
167
+ 'and we call it with a post with multiple links' : {
141
168
topic : function ( fns ) {
142
169
var webmention = fns [ 1 ] ,
143
170
cb = this . callback ;
144
171
145
- // This shouldn't matter, but just in case, we set the clock to be past the edited timestamp
146
- clock . tick ( 100 * 1000 ) ;
147
-
148
- webmention ( 'http://example.com/socute' ,
172
+ webmention ( 'http://example.com/morecuteness' ,
149
173
200 ,
150
- data . singleLink ,
174
+ data . multipleLinks ,
151
175
function ( err ) {
152
176
cb ( err , fns ) ;
153
177
} ) ;
154
178
} ,
155
- teardown : function ( ) {
156
- return clock . tick ( - 100 * 1000 ) ;
157
- } ,
158
179
'it works' : function ( err ) {
159
180
assert . ifError ( err ) ;
160
181
} ,
161
- 'the spy was called a second time ' : function ( err , fns ) {
182
+ 'the spy was called two more times ' : function ( err , fns ) {
162
183
var spy = fns [ 0 ] ;
163
- assert . isTrue ( spy . calledTwice ) ;
164
- // XXX assert arguments
184
+ assert . equal ( spy . callCount , 4 ) ;
185
+ // XXX args
165
186
} ,
166
- // XXX find a way to not nest this so deeply - it
167
- // has to be this way currently so the Sinon spy is
168
- // called in the right order
169
- 'and we call it with a post with multiple links' : {
187
+ 'and we call the module with a post that has a blank <a href="">' : {
170
188
topic : function ( fns ) {
171
189
var webmention = fns [ 1 ] ,
172
190
cb = this . callback ;
173
191
174
- webmention ( 'http://example.com/morecuteness ' ,
192
+ webmention ( 'http://malformed.technology/everything_is_terrible ' ,
175
193
200 ,
176
- data . multipleLinks ,
194
+ data . noHref ,
177
195
function ( err ) {
178
196
cb ( err , fns ) ;
179
197
} ) ;
180
198
} ,
181
199
'it works' : function ( err ) {
182
200
assert . ifError ( err ) ;
183
201
} ,
184
- 'the spy was called two more times ' : function ( err , fns ) {
202
+ 'the spy wasn\'t called again ' : function ( err , fns ) {
185
203
var spy = fns [ 0 ] ;
186
204
assert . equal ( spy . callCount , 4 ) ;
187
205
// XXX args
206
+ }
207
+ } ,
208
+ 'and we call the module with a post that has no links at all' : {
209
+ topic : function ( fns ) {
210
+ var webmention = fns [ 1 ] ,
211
+ cb = this . callback ;
212
+
213
+ webmention ( 'http://ordinary.net/bland_post' ,
214
+ 200 ,
215
+ data . noLinks ,
216
+ function ( err ) {
217
+ cb ( err , fns ) ;
218
+ } ) ;
188
219
} ,
189
- 'and we call the module with a post that has a blank <a href="">' : {
190
- topic : function ( fns ) {
191
- var webmention = fns [ 1 ] ,
192
- cb = this . callback ;
193
-
194
- webmention ( 'http://malformed.technology/everything_is_terrible' ,
195
- 200 ,
196
- data . noHref ,
197
- function ( err ) {
198
- cb ( err , fns ) ;
199
- } ) ;
200
- } ,
201
- 'it works' : function ( err ) {
202
- assert . ifError ( err ) ;
203
- } ,
204
- 'the spy wasn\'t called again' : function ( err , fns ) {
205
- var spy = fns [ 0 ] ;
206
- assert . equal ( spy . callCount , 4 ) ;
207
- // XXX args
208
- }
220
+ 'it works' : function ( err ) {
221
+ assert . ifError ( err ) ;
209
222
} ,
210
- 'and we call the module with a post that has no links at all' : {
211
- topic : function ( fns ) {
212
- var webmention = fns [ 1 ] ,
213
- cb = this . callback ;
214
-
215
- webmention ( 'http://ordinary.net/bland_post' ,
216
- 200 ,
217
- data . noLinks ,
218
- function ( err ) {
219
- cb ( err , fns ) ;
220
- } ) ;
221
- } ,
222
- 'it works' : function ( err ) {
223
- assert . ifError ( err ) ;
224
- } ,
225
- 'the spy wasn\'t called again' : function ( err , fns ) {
226
- var spy = fns [ 0 ] ;
227
- assert . equal ( spy . callCount , 4 ) ;
228
- // XXX args
229
- }
223
+ 'the spy wasn\'t called again' : function ( err , fns ) {
224
+ var spy = fns [ 0 ] ;
225
+ assert . equal ( spy . callCount , 4 ) ;
226
+ // XXX args
230
227
}
231
228
}
232
229
}
233
230
}
234
231
}
235
- } )
232
+ }
236
233
}
237
234
}
238
235
} ) . export ( module ) ;
0 commit comments