visionmedia-jspec 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +6 -0
- data/README.rdoc +20 -0
- data/bin/jspec +1 -1
- data/jspec.gemspec +2 -2
- data/lib/jspec.js +48 -3
- data/server/server.rb +4 -7
- data/spec/spec.utils.js +48 -11
- metadata +2 -2
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -26,6 +26,7 @@ and much more.
|
|
26
26
|
* Great looking default DOM theme
|
27
27
|
* `jspec` command-line utility for auto-running specs, and initializing project templates
|
28
28
|
* Proxy or 'Spy' assertions
|
29
|
+
* Method Stubbing
|
29
30
|
* Shared behaviors
|
30
31
|
* Profiling
|
31
32
|
* Rails Integration (http://github.com/bhauman/jspec-rails)
|
@@ -202,6 +203,22 @@ how other methods may interact with it. Below is another example:
|
|
202
203
|
|
203
204
|
For more examples view spec/spec.matchers.js
|
204
205
|
|
206
|
+
== Method Stubbing
|
207
|
+
|
208
|
+
JSpec currently provides very simple stubbing support shown below:
|
209
|
+
|
210
|
+
person = { toString : function(){ return '<Person>' } }
|
211
|
+
stub(person, 'toString').and_return('Ive been stubbed!')
|
212
|
+
|
213
|
+
To destub a method simply call destub() at any time:
|
214
|
+
|
215
|
+
destub(person, 'toString')
|
216
|
+
|
217
|
+
If you would like to whipe an object clear of stubs simply pass it
|
218
|
+
to destub() without an additional method argument:
|
219
|
+
|
220
|
+
destub(person)
|
221
|
+
|
205
222
|
== Helpers
|
206
223
|
|
207
224
|
* Core
|
@@ -452,6 +469,9 @@ Run with:
|
|
452
469
|
|
453
470
|
* Tabs may cause a parse error. To prevent this use 'soft tabs' (setting in your IDE/Editor)
|
454
471
|
or use JSpec's grammar-less alternative (mentioned above).
|
472
|
+
|
473
|
+
* The negation of the should_receive matcher is currently not available. (ex:
|
474
|
+
foo.should.not.receive('toString()') will not work)
|
455
475
|
|
456
476
|
== More Information
|
457
477
|
|
data/bin/jspec
CHANGED
data/jspec.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{jspec}
|
5
|
-
s.version = "2.
|
5
|
+
s.version = "2.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-25}
|
10
10
|
s.default_executable = %q{jspec}
|
11
11
|
s.description = %q{JavaScript BDD Testing Framework}
|
12
12
|
s.email = %q{tj@vision-media.ca}
|
data/lib/jspec.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
JSpec = {
|
7
7
|
|
8
|
-
version : '2.
|
8
|
+
version : '2.3.0',
|
9
9
|
suites : [],
|
10
10
|
allSuites : [],
|
11
11
|
matchers : {},
|
@@ -896,6 +896,50 @@
|
|
896
896
|
})
|
897
897
|
return memo
|
898
898
|
},
|
899
|
+
|
900
|
+
/**
|
901
|
+
* Destub _object_'s _method_. When no _method_ is passed
|
902
|
+
* all stubbed methods are destubbed.
|
903
|
+
*
|
904
|
+
* @param {mixed} object
|
905
|
+
* @param {string} method
|
906
|
+
* @api public
|
907
|
+
*/
|
908
|
+
|
909
|
+
destub : function(object, method) {
|
910
|
+
if (method) {
|
911
|
+
if (object['__prototype__' + method])
|
912
|
+
delete object[method]
|
913
|
+
else
|
914
|
+
object[method] = object['__original__' + method]
|
915
|
+
delete object['__prototype__' + method]
|
916
|
+
delete object['__original____' + method]
|
917
|
+
}
|
918
|
+
else
|
919
|
+
for (var key in object)
|
920
|
+
if (captures = key.match(/^(?:__prototype__|__original__)(.*)/))
|
921
|
+
destub(object, captures[1])
|
922
|
+
},
|
923
|
+
|
924
|
+
/**
|
925
|
+
* Stub _object_'s _method_. Example:
|
926
|
+
* stub(foo, 'toString').and_return('bar')
|
927
|
+
*
|
928
|
+
* @param {mixed} object
|
929
|
+
* @param {string} method
|
930
|
+
* @return {hash}
|
931
|
+
* @api public
|
932
|
+
*/
|
933
|
+
|
934
|
+
stub : function(object, method) {
|
935
|
+
return {
|
936
|
+
and_return : function(result) {
|
937
|
+
var type = object.hasOwnProperty(method) ? '__original__' : '__prototype__'
|
938
|
+
object[type + method] = object[method]
|
939
|
+
object[method] = function(){ return result }
|
940
|
+
}
|
941
|
+
}
|
942
|
+
},
|
899
943
|
|
900
944
|
/**
|
901
945
|
* Map callback return values.
|
@@ -1272,6 +1316,8 @@
|
|
1272
1316
|
// --- Utility functions
|
1273
1317
|
|
1274
1318
|
var main = this
|
1319
|
+
var stub = JSpec.stub
|
1320
|
+
var destub = JSpec.destub
|
1275
1321
|
var map = JSpec.map
|
1276
1322
|
var any = JSpec.any
|
1277
1323
|
var find = JSpec.any
|
@@ -1424,5 +1470,4 @@
|
|
1424
1470
|
}
|
1425
1471
|
})
|
1426
1472
|
|
1427
|
-
})()
|
1428
|
-
|
1473
|
+
})()
|
data/server/server.rb
CHANGED
@@ -25,13 +25,10 @@ module JSpec
|
|
25
25
|
'close'
|
26
26
|
when /jspec/
|
27
27
|
type = 'application/javascript'
|
28
|
-
File.read File.join(JSPEC_ROOT, 'lib', File.basename(
|
29
|
-
|
30
|
-
type =
|
31
|
-
File.read File.join(root,
|
32
|
-
else
|
33
|
-
type = 'text/html'
|
34
|
-
File.read File.join(root, request.path_info) rescue ''
|
28
|
+
File.read File.join(JSPEC_ROOT, 'lib', File.basename(path))
|
29
|
+
else
|
30
|
+
type = Rack::Mime.mime_type File.extname(path)
|
31
|
+
File.read File.join(root, path) rescue ''
|
35
32
|
end
|
36
33
|
[200, { 'Content-Type' => type, 'Content-Length' => body.length.to_s }, body]
|
37
34
|
end
|
data/spec/spec.utils.js
CHANGED
@@ -1,6 +1,43 @@
|
|
1
1
|
|
2
2
|
describe 'Utility'
|
3
|
-
describe '
|
3
|
+
describe 'stubbing'
|
4
|
+
before_each
|
5
|
+
Object.prototype.stubby = function() { return 'Not stubbed' }
|
6
|
+
object = { toString : function() { return '<Im an object>' }}
|
7
|
+
stub(object, 'stubby').and_return('Im stubbed')
|
8
|
+
stub(object, 'toString').and_return('<No im not>')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'stub()'
|
12
|
+
it 'should stub :)'
|
13
|
+
object.stubby().should.eql 'Im stubbed'
|
14
|
+
object.toString().should.eql '<No im not>'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'destub()'
|
19
|
+
it 'should restore old methods'
|
20
|
+
destub(object, 'toString')
|
21
|
+
destub(object, 'stubby')
|
22
|
+
object.toString().should.eql '<Im an object>'
|
23
|
+
object.stubby().should.eql 'Not stubbed'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should restore prototypal methods'
|
27
|
+
Object.prototype.stubby = function() { return 'Oh no im new' }
|
28
|
+
destub(object, 'stubby')
|
29
|
+
object.stubby().should.eql 'Oh no im new'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should with a single argument should destub all methods stubbed related to the object passed'
|
33
|
+
destub(object)
|
34
|
+
object.toString().should.eql '<Im an object>'
|
35
|
+
object.stubby().should.eql 'Not stubbed'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'query()'
|
4
41
|
it 'should return a pairs value'
|
5
42
|
query('suite', '?suite=Positive%20specs').should.equal 'Positive specs'
|
6
43
|
end
|
@@ -10,7 +47,7 @@ describe 'Utility'
|
|
10
47
|
end
|
11
48
|
end
|
12
49
|
|
13
|
-
describe 'strip'
|
50
|
+
describe 'strip()'
|
14
51
|
it 'should strip whitespace by default'
|
15
52
|
strip(" foo \n\n").should.equal 'foo'
|
16
53
|
end
|
@@ -20,7 +57,7 @@ describe 'Utility'
|
|
20
57
|
end
|
21
58
|
end
|
22
59
|
|
23
|
-
describe 'each'
|
60
|
+
describe 'each()'
|
24
61
|
it 'should iterate an array'
|
25
62
|
result = []
|
26
63
|
each([1,2,3], function(value){
|
@@ -38,7 +75,7 @@ describe 'Utility'
|
|
38
75
|
end
|
39
76
|
end
|
40
77
|
|
41
|
-
describe 'map'
|
78
|
+
describe 'map()'
|
42
79
|
it 'should return an array of mapped values'
|
43
80
|
result = map([1,2,3], function(value){
|
44
81
|
return value * 2
|
@@ -54,7 +91,7 @@ describe 'Utility'
|
|
54
91
|
end
|
55
92
|
end
|
56
93
|
|
57
|
-
describe 'inject'
|
94
|
+
describe 'inject()'
|
58
95
|
it 'should provide a memo object while iterating, not expecting returning of memo for composits'
|
59
96
|
result = inject([1,2,3], [], function(memo, value){
|
60
97
|
memo.push(value)
|
@@ -70,7 +107,7 @@ describe 'Utility'
|
|
70
107
|
end
|
71
108
|
end
|
72
109
|
|
73
|
-
describe 'any'
|
110
|
+
describe 'any()'
|
74
111
|
it 'should return null when no matches are found'
|
75
112
|
result = any('some foo bar', function(value){
|
76
113
|
return value.length > 5
|
@@ -86,7 +123,7 @@ describe 'Utility'
|
|
86
123
|
end
|
87
124
|
end
|
88
125
|
|
89
|
-
describe 'select'
|
126
|
+
describe 'select()'
|
90
127
|
it 'should return an array of values when the callback evaluates to true'
|
91
128
|
result = select('some foo bar baz stuff', function(value){
|
92
129
|
return value.length > 3
|
@@ -95,13 +132,13 @@ describe 'Utility'
|
|
95
132
|
end
|
96
133
|
end
|
97
134
|
|
98
|
-
describe 'last'
|
135
|
+
describe 'last()'
|
99
136
|
it 'should return the last element in an array'
|
100
137
|
last(['foo', 'bar']).should.eql 'bar'
|
101
138
|
end
|
102
139
|
end
|
103
140
|
|
104
|
-
describe 'argumentsToArray'
|
141
|
+
describe 'argumentsToArray()'
|
105
142
|
it 'should return an array of arguments'
|
106
143
|
func = function(){ return argumentsToArray(arguments) }
|
107
144
|
func('foo', 'bar').should.eql ['foo', 'bar']
|
@@ -113,14 +150,14 @@ describe 'Utility'
|
|
113
150
|
end
|
114
151
|
end
|
115
152
|
|
116
|
-
describe 'does'
|
153
|
+
describe 'does()'
|
117
154
|
it 'should assert without reporting'
|
118
155
|
does('foo', 'eql', 'foo')
|
119
156
|
JSpec.currentSpec.assertions.should.have_length 0
|
120
157
|
end
|
121
158
|
end
|
122
159
|
|
123
|
-
describe 'contentsOf'
|
160
|
+
describe 'contentsOf()'
|
124
161
|
it 'should return a function body'
|
125
162
|
JSpec.contentsOf(-{ return 'foo' }).should.include 'return', 'foo'
|
126
163
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visionmedia-jspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-25 00:00:00 -07:00
|
13
13
|
default_executable: jspec
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|