visionmedia-jspec 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +6 -0
- data/README.rdoc +8 -0
- data/bin/jspec +1 -1
- data/jspec.gemspec +1 -1
- data/lib/jspec.js +15 -5
- data/spec/spec.utils.js +20 -1
- metadata +1 -1
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -209,6 +209,14 @@ JSpec currently provides very simple stubbing support shown below:
|
|
209
209
|
|
210
210
|
person = { toString : function(){ return '<Person>' } }
|
211
211
|
stub(person, 'toString').and_return('Ive been stubbed!')
|
212
|
+
|
213
|
+
After each spec all stubs are restored to their original methods so
|
214
|
+
there is no reason to explicitly call destub(). To persist stubs,
|
215
|
+
use a before_each hook:
|
216
|
+
|
217
|
+
before_each
|
218
|
+
stub(someObject, 'method').and_return({ some : thing })
|
219
|
+
end
|
212
220
|
|
213
221
|
To destub a method simply call destub() at any time:
|
214
222
|
|
data/bin/jspec
CHANGED
data/jspec.gemspec
CHANGED
data/lib/jspec.js
CHANGED
@@ -5,10 +5,11 @@
|
|
5
5
|
|
6
6
|
JSpec = {
|
7
7
|
|
8
|
-
version : '2.3.
|
8
|
+
version : '2.3.1',
|
9
9
|
suites : [],
|
10
10
|
allSuites : [],
|
11
11
|
matchers : {},
|
12
|
+
stubbed : [],
|
12
13
|
stats : { specs : 0, assertions : 0, failures : 0, passes : 0, specsFinished : 0, suitesFinished : 0 },
|
13
14
|
options : { profile : false },
|
14
15
|
|
@@ -899,7 +900,9 @@
|
|
899
900
|
|
900
901
|
/**
|
901
902
|
* Destub _object_'s _method_. When no _method_ is passed
|
902
|
-
* all stubbed methods are destubbed.
|
903
|
+
* all stubbed methods are destubbed. When no arguments
|
904
|
+
* are passed every object found in JSpec.stubbed will be
|
905
|
+
* destubbed.
|
903
906
|
*
|
904
907
|
* @param {mixed} object
|
905
908
|
* @param {string} method
|
@@ -915,14 +918,19 @@
|
|
915
918
|
delete object['__prototype__' + method]
|
916
919
|
delete object['__original____' + method]
|
917
920
|
}
|
918
|
-
else
|
921
|
+
else if (object) {
|
919
922
|
for (var key in object)
|
920
923
|
if (captures = key.match(/^(?:__prototype__|__original__)(.*)/))
|
921
924
|
destub(object, captures[1])
|
925
|
+
}
|
926
|
+
else
|
927
|
+
while (JSpec.stubbed.length)
|
928
|
+
destub(JSpec.stubbed.shift())
|
922
929
|
},
|
923
930
|
|
924
931
|
/**
|
925
|
-
* Stub _object_'s _method_.
|
932
|
+
* Stub _object_'s _method_.
|
933
|
+
*
|
926
934
|
* stub(foo, 'toString').and_return('bar')
|
927
935
|
*
|
928
936
|
* @param {mixed} object
|
@@ -934,13 +942,14 @@
|
|
934
942
|
stub : function(object, method) {
|
935
943
|
return {
|
936
944
|
and_return : function(result) {
|
945
|
+
JSpec.stubbed.push(object)
|
937
946
|
var type = object.hasOwnProperty(method) ? '__original__' : '__prototype__'
|
938
947
|
object[type + method] = object[method]
|
939
948
|
object[method] = function(){ return result }
|
940
949
|
}
|
941
950
|
}
|
942
951
|
},
|
943
|
-
|
952
|
+
|
944
953
|
/**
|
945
954
|
* Map callback return values.
|
946
955
|
*
|
@@ -1179,6 +1188,7 @@
|
|
1179
1188
|
catch (e) { fail(e) }
|
1180
1189
|
spec.runDeferredAssertions()
|
1181
1190
|
if (option('profile')) console.timeEnd(spec.description)
|
1191
|
+
destub()
|
1182
1192
|
this.stats.specsFinished++
|
1183
1193
|
this.stats.assertions += spec.assertions.length
|
1184
1194
|
},
|
data/spec/spec.utils.js
CHANGED
@@ -29,11 +29,30 @@ describe 'Utility'
|
|
29
29
|
object.stubby().should.eql 'Oh no im new'
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'should
|
32
|
+
it 'should destub all methods stubbed related to the object passed when no method is given'
|
33
33
|
destub(object)
|
34
34
|
object.toString().should.eql '<Im an object>'
|
35
35
|
object.stubby().should.eql 'Not stubbed'
|
36
36
|
end
|
37
|
+
|
38
|
+
describe 'should restore after each spec'
|
39
|
+
before
|
40
|
+
a = { toString : function(){ return 'Wahoo' }}
|
41
|
+
b = { toString : function(){ return 'Wahhhhhooo' }}
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should stub'
|
45
|
+
stub(a, 'toString').and_return('Oh no')
|
46
|
+
stub(b, 'toString').and_return('Oh noooo')
|
47
|
+
a.toString().should.eql 'Oh no'
|
48
|
+
b.toString().should.eql 'Oh noooo'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should restore'
|
52
|
+
a.toString().should.eql 'Wahoo'
|
53
|
+
b.toString().should.eql 'Wahhhhhooo'
|
54
|
+
end
|
55
|
+
end
|
37
56
|
end
|
38
57
|
end
|
39
58
|
|