jspec 2.11.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +522 -0
- data/Manifest +57 -0
- data/README.rdoc +825 -0
- data/Rakefile +75 -0
- data/bin/jspec +305 -0
- data/jspec.gemspec +44 -0
- data/lib/images/bg.png +0 -0
- data/lib/images/hr.png +0 -0
- data/lib/images/loading.gif +0 -0
- data/lib/images/sprites.bg.png +0 -0
- data/lib/images/sprites.png +0 -0
- data/lib/images/vr.png +0 -0
- data/lib/jspec.css +145 -0
- data/lib/jspec.jquery.js +71 -0
- data/lib/jspec.js +1771 -0
- data/lib/jspec.shell.js +36 -0
- data/lib/jspec.timers.js +90 -0
- data/lib/jspec.xhr.js +183 -0
- data/server/browsers.rb +228 -0
- data/server/helpers.rb +82 -0
- data/server/routes.rb +57 -0
- data/server/server.rb +88 -0
- data/spec/async +1 -0
- data/spec/env.js +695 -0
- data/spec/fixtures/test.html +1 -0
- data/spec/fixtures/test.json +1 -0
- data/spec/fixtures/test.xml +5 -0
- data/spec/helpers.js +66 -0
- data/spec/server.rb +2 -0
- data/spec/spec.dom.html +34 -0
- data/spec/spec.fixtures.js +18 -0
- data/spec/spec.grammar-less.js +34 -0
- data/spec/spec.grammar.js +226 -0
- data/spec/spec.jquery.js +176 -0
- data/spec/spec.jquery.xhr.js +65 -0
- data/spec/spec.js +166 -0
- data/spec/spec.matchers.js +493 -0
- data/spec/spec.modules.js +67 -0
- data/spec/spec.node.js +46 -0
- data/spec/spec.rhino.js +17 -0
- data/spec/spec.server.html +29 -0
- data/spec/spec.shared-behaviors.js +80 -0
- data/spec/spec.utils.js +279 -0
- data/spec/spec.xhr.js +156 -0
- data/templates/default/History.rdoc +4 -0
- data/templates/default/README.rdoc +29 -0
- data/templates/default/lib/yourlib.core.js +2 -0
- data/templates/default/spec/server.rb +4 -0
- data/templates/default/spec/spec.core.js +8 -0
- data/templates/default/spec/spec.dom.html +20 -0
- data/templates/default/spec/spec.rhino.js +8 -0
- data/templates/default/spec/spec.server.html +16 -0
- data/templates/rails/server.rb +4 -0
- data/templates/rails/spec.application.js +8 -0
- data/templates/rails/spec.dom.html +20 -0
- data/templates/rails/spec.rhino.js +8 -0
- data/templates/rails/spec.server.html +16 -0
- metadata +168 -0
data/spec/spec.js
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
|
2
|
+
describe 'Failing specs'
|
3
|
+
|
4
|
+
it 'should fail'
|
5
|
+
spec = mock_it(function(){
|
6
|
+
'test'.should.not.eql 'test'
|
7
|
+
})
|
8
|
+
spec.should.have_failure_message("expected 'test' to not eql 'test'")
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should fail with one faulty assertion'
|
12
|
+
spec = mock_it(function() {
|
13
|
+
'test'.should.equal 'test'
|
14
|
+
'test'.should.equal 'foo'
|
15
|
+
})
|
16
|
+
spec.should.have_failure_message("expected 'test' to be 'foo'")
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should fail and print array with square braces'
|
20
|
+
spec = mock_it(function() {
|
21
|
+
[1,2].should.equal [1,3]
|
22
|
+
})
|
23
|
+
spec.should.have_failure_message("expected [ 1, 2 ] to be [ 1, 3 ]")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should fail and print nested array'
|
27
|
+
spec = mock_it(function() {
|
28
|
+
[1, ['foo']].should.equal [1, ['bar', ['whatever', 1.0, { foo : 'bar', bar : { 1 : 2 } }]]]
|
29
|
+
})
|
30
|
+
spec.should.have_failure_message(/^expected \[\s*1,\s*\[\s*'foo'/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should fail with selector for jQuery objects'
|
34
|
+
spec = mock_it(function() {
|
35
|
+
elem = { jquery : '1.3.1', selector : '.foobar' }
|
36
|
+
elem.should.eql 'foo'
|
37
|
+
})
|
38
|
+
spec.should.have_failure_message("expected selector '.foobar' to eql 'foo'")
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should fail with negated message'
|
42
|
+
spec = mock_it(function(){
|
43
|
+
'1'.should.not.be_true
|
44
|
+
})
|
45
|
+
spec.should.have_failure_message(/expected '1' to not be true/)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should fail with positive message'
|
49
|
+
spec = mock_it(function() {
|
50
|
+
false.should.be_true
|
51
|
+
})
|
52
|
+
spec.should.have_failure_message(/expected false to be true/)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should fail saying which error has been thrown'
|
56
|
+
spec = mock_it(function() {
|
57
|
+
-{ throw 'foo' }.should.throw_error 'bar'
|
58
|
+
})
|
59
|
+
spec.should.have_failure_message("expected exception of 'bar' to be thrown, but got 'foo'")
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should fail saying no error was thrown'
|
63
|
+
spec = mock_it(function() {
|
64
|
+
-{ }.should.throw_error 'foo'
|
65
|
+
})
|
66
|
+
spec.should.have_failure_message("expected exception of 'foo' to be thrown, but nothing was")
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should fail saying no error matching was thrown'
|
70
|
+
spec = mock_it(function() {
|
71
|
+
-{ throw 'bar' }.should.throw_error(/foo/)
|
72
|
+
})
|
73
|
+
spec.should.have_failure_message("expected exception matching /foo/ to be thrown, but got 'bar'")
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should fail saying constructors'
|
77
|
+
spec = mock_it(function() {
|
78
|
+
-{ throw new TypeError('oh no') }.should.throw_error(Error)
|
79
|
+
})
|
80
|
+
spec.should.have_failure_message("expected Error to be thrown, but got TypeError: oh no")
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should fail saying multiple arg messages'
|
84
|
+
spec = mock_it(function() {
|
85
|
+
-{ throw new TypeError('oh no') }.should.throw_error(TypeError, /foo/)
|
86
|
+
})
|
87
|
+
spec.should.have_failure_message("expected TypeError and exception matching /foo/ to be thrown, but got TypeError: oh no")
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should fail with constructor name'
|
91
|
+
spec = mock_it(function() {
|
92
|
+
function Foo(){}
|
93
|
+
function Bar(){}
|
94
|
+
Bar.prototype.toString = function(){ return 'Bar: oh no' }
|
95
|
+
-{ throw new Bar }.should.throw_error Foo
|
96
|
+
})
|
97
|
+
spec.should.have_failure_message("expected Foo to be thrown, but got Bar: oh no")
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should fail with constructor name'
|
101
|
+
spec = mock_it(function() {
|
102
|
+
function Foo(){ this.toString = function(){ return '<Foo>' }}
|
103
|
+
foo = new Foo
|
104
|
+
foo.should.not.be_an_instance_of Foo
|
105
|
+
})
|
106
|
+
spec.should.have_failure_message("expected <Foo> to not be an instance of Foo")
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should fail with message of first failure'
|
110
|
+
spec = mock_it(function() {
|
111
|
+
true.should.be_true
|
112
|
+
'bar'.should.match(/foo/gm)
|
113
|
+
'bar'.should.include 'foo'
|
114
|
+
})
|
115
|
+
spec.should.have_failure_message("expected 'bar' to match /foo/gm")
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should fail with list'
|
119
|
+
spec = mock_it(function() {
|
120
|
+
['foo', 'bar'].should.include 'foo', 'car'
|
121
|
+
})
|
122
|
+
spec.should.have_failure_message("expected [ 'foo', 'bar' ] to include 'foo', 'car'")
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should catch exceptions throw within specs'
|
126
|
+
spec = mock_it(function() {
|
127
|
+
throw new Error('Oh noes!')
|
128
|
+
})
|
129
|
+
spec.should.have_failure_message(/Error: Oh noes!/)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should catch exceptions without constructors'
|
133
|
+
spec = mock_it(function() {
|
134
|
+
throw 'oh noes'
|
135
|
+
})
|
136
|
+
spec.should.have_failure_message(/oh noes/)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should catch indirect exceptions'
|
140
|
+
spec = mock_it(function() {
|
141
|
+
iDoNotExist.neitherDoI()
|
142
|
+
})
|
143
|
+
spec.should.have_failure_message(/iDoNotExist/)
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'Contexts'
|
149
|
+
before
|
150
|
+
JSpec.context = { iLike : 'cookies' }
|
151
|
+
end
|
152
|
+
|
153
|
+
after
|
154
|
+
JSpec.context = null
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should be replaceable'
|
158
|
+
iLike.should.equal 'cookies'
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe 'Misc'
|
163
|
+
it 'requires implementation'
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
@@ -0,0 +1,493 @@
|
|
1
|
+
|
2
|
+
describe 'Matchers'
|
3
|
+
|
4
|
+
describe 'eql'
|
5
|
+
it 'should work with strings'
|
6
|
+
'test'.should.eql 'test'
|
7
|
+
'test'.should.not.eql 'foo'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should work with numbers'
|
11
|
+
11.should.eql 11
|
12
|
+
10.should.not.eql 11
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should loosely compare numbers as strings'
|
16
|
+
'11'.should.eql 11
|
17
|
+
'10'.should.not.eql 11
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should hash compare arrays'
|
21
|
+
[1, 2].should.eql [1, 2]
|
22
|
+
[1, 2].should.not.eql [1, 3]
|
23
|
+
[1, 2, [3], { foo : 'bar' }].should.eql [1, 2, [3], { foo : 'bar' }]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should hash compare objects'
|
27
|
+
{ foo : 'bar' }.should.eql { foo : 'bar' }
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should hash compare objects with different orders'
|
31
|
+
a = { one : 'two', three : 'four' }
|
32
|
+
b = { three : 'four', one : 'two' }
|
33
|
+
a.should.eql b
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should hash compare arbitrary objects'
|
37
|
+
Foo = function(){}, Bar = function(){}
|
38
|
+
Bar.prototype = { doSomething : function(){ }}
|
39
|
+
foo = new Foo, foo2 = new Foo, bar = new Bar
|
40
|
+
foo.should.eql foo2
|
41
|
+
foo.should.not.eql bar
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should work with constructors'
|
45
|
+
Array.should.eql Array
|
46
|
+
Array.should.not.eql Object
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'equal'
|
51
|
+
it 'should perform strict comparisons'
|
52
|
+
'test'.should.equal 'test'
|
53
|
+
'1'.should.not.equal 1
|
54
|
+
true.should.be true
|
55
|
+
'1'.should.not.be true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'match'
|
60
|
+
it 'should match regular expressions'
|
61
|
+
'foobar'.should.match(/foo/)
|
62
|
+
'foobar'.should.not.match(/barfoo/)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'be_empty'
|
67
|
+
it 'should consider any object with zero length to be empty'
|
68
|
+
''.should.be_empty
|
69
|
+
' '.should.not.be_empty
|
70
|
+
[].should.be_empty
|
71
|
+
{ length : 0 }.should.be_empty
|
72
|
+
{}.should.be_empty
|
73
|
+
'cookies'.should.not.be_empty
|
74
|
+
[0].should.not.be_empty
|
75
|
+
{ length : 1 }.should.not.be_empty
|
76
|
+
{ foo : 'bar' }.should.not.be_empty
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'be_null'
|
81
|
+
it 'should check if a value is null'
|
82
|
+
a = 0
|
83
|
+
b = null
|
84
|
+
null.should.be_null
|
85
|
+
0.should.not.be_null
|
86
|
+
a.should.not.be_null
|
87
|
+
b.should.be_null
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'be_undefined'
|
92
|
+
it 'should check if a var is defined'
|
93
|
+
var foo
|
94
|
+
foo.should.be_undefined
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'have_length'
|
99
|
+
it 'should compare the length of an object'
|
100
|
+
'foo'.should.have_length 3
|
101
|
+
[1, 2].should.have_length 2
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'have_length_within'
|
106
|
+
it 'should check if an object has a length within the specified range'
|
107
|
+
'foo'.should.have_length_within 2..4
|
108
|
+
'f'.should.not.have_length_within 2..4
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'have_prop'
|
113
|
+
it 'should check if a property exists'
|
114
|
+
'foo'.should.have_prop 'length'
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should check that a property has a specific value'
|
118
|
+
'foo'.should.have_prop 'length', 3
|
119
|
+
{ length : '3' }.should.have_prop 'length', 3
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should check object hashes'
|
123
|
+
{ foo : 1..3 }.should.have_prop 'foo', 1..3
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should fail when the property does not exist'
|
127
|
+
'foo'.should.not.have_prop 'foo'
|
128
|
+
'foo'.should.not.have_prop 'foo', 'bar'
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should fail when it is a function'
|
132
|
+
'foo'.should.not.have_prop 'toString'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'have_property'
|
137
|
+
it 'should check if a property exists'
|
138
|
+
'foo'.should.have_property 'length'
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should check that a property has a specific value'
|
142
|
+
'foo'.should.have_property 'length', 3
|
143
|
+
{ length : '3' }.should.not.have_property 'length', 3
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should fail when the property does not exist'
|
147
|
+
'foo'.should.not.have_property 'foo'
|
148
|
+
'foo'.should.not.have_property 'foo', 'bar'
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should fail when it is a function'
|
152
|
+
'foo'.should.not.have_property 'toString'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe 'respond_to'
|
157
|
+
it 'should check if an object contains a method'
|
158
|
+
'test'.should.respond_to('toString')
|
159
|
+
'test'.should.not.respond_to('rawr')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'include'
|
164
|
+
it 'should check if an object includes a property'
|
165
|
+
{ hey : 'there' }.should.include 'hey'
|
166
|
+
{ hey : 'there' }.should.not.include 'foo'
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should check if a regular expression includes a string'
|
170
|
+
(/(foo)?bar/).should.include '(foo)'
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should check if a function body includes a string'
|
174
|
+
-{ return [foo, bar] }.should.include 'foo', 'bar'
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should check if an array contains element(s)'
|
178
|
+
[1,2,3].should.include 1
|
179
|
+
[1,2,3].should.include 1, 2, 3
|
180
|
+
[1].should.not.include 0
|
181
|
+
['foo', 'bar'].should.include 'foo', 'bar'
|
182
|
+
['foo', 'bar'].should.include 'bar', 'foo'
|
183
|
+
['foo', 'bar'].should.not.include 'foo', 'rawr'
|
184
|
+
['foo', 'bar'].should.not.include 'rawr', 'foo'
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should check hashes of array elements'
|
188
|
+
[1, [2]].should.include [2]
|
189
|
+
[1, [2]].should.include [2], 1
|
190
|
+
[1, { two : 'three' }].should.include { two : 'three' }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe 'be_a'
|
195
|
+
it 'should compare the constructor of an object'
|
196
|
+
'test'.should.be_a String
|
197
|
+
[].should.be_an Array
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe 'throw_error'
|
202
|
+
it 'should check if an error is thrown'
|
203
|
+
-{ throw 'error' }.should.throw_error
|
204
|
+
-{ return 'test' }.should.not.throw_error
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should check if an error with a specific message is thrown'
|
208
|
+
-{ throw 'some foo bar' }.should.throw_error('some foo bar')
|
209
|
+
-{ throw 'some foo bar' }.should.throw_error(/foo bar/)
|
210
|
+
-{ throw 'some foo bar' }.should.not.throw_error(/rawr/)
|
211
|
+
-{ throw 'some foo bar' }.should.not.throw_error('rawr')
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'should check if an error of a specific constructor is thrown'
|
215
|
+
-{ throw new Error('foo') }.should.throw_error(Error)
|
216
|
+
-{ throw new TypeError('foo') }.should.throw_error(TypeError)
|
217
|
+
-{ throw 'foo' }.should.throw_error Error
|
218
|
+
-{ throw 'foo' }.should.not.throw_error TypeError
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should check if an error with a specific constructor and message is thrown'
|
222
|
+
-{ throw new TypeError('oh no!') }.should.throw_error(TypeError, 'oh no!')
|
223
|
+
-{ throw new TypeError('oh no!') }.should.not.throw_error(TypeError, 'foo bar')
|
224
|
+
-{ throw new TypeError('oh no!') }.should.throw_error(TypeError, /oh no/)
|
225
|
+
-{ throw new TypeError('oh no!') }.should.not.throw_error(TypeError, /foo bar/)
|
226
|
+
-{ throw new TypeError('oh no!') }.should.not.throw_error(Error, 'oh no!')
|
227
|
+
-{ throw new TypeError('oh no!') }.should.not.throw_error(Error, 'foo bar')
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe 'be_an_instance_of'
|
232
|
+
it 'should check that an object is an instance of another'
|
233
|
+
MyObject = function(){}
|
234
|
+
myInstance = new MyObject()
|
235
|
+
{}.should.be_an_instance_of Object
|
236
|
+
[].should.be_an_instance_of Array
|
237
|
+
MyObject.should.be_an_instance_of Function
|
238
|
+
myInstance.should.be_an_instance_of MyObject
|
239
|
+
myInstance.should.be_an_instance_of Object
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe 'be_type'
|
244
|
+
it 'should compare the type of an object via typeof'
|
245
|
+
'hey'.should.be_type 'string'
|
246
|
+
{}.should.be_type 'object'
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe 'be_within'
|
251
|
+
it 'should check if a number is within a range'
|
252
|
+
5.should.be_within 1..10
|
253
|
+
15.should.not.be_within 10..5
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe 'have'
|
258
|
+
it 'should check the length of a property'
|
259
|
+
person = { pets : ['izzy', 'niko'] }
|
260
|
+
person.should.have 2, 'pets'
|
261
|
+
person.should.not.have 3, 'pets'
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe 'have_at_least'
|
266
|
+
it 'should check if a object has at least n of a property'
|
267
|
+
person = { pets : ['izzy', 'niko'] }
|
268
|
+
person.should.have_at_least 1, 'pets'
|
269
|
+
person.should.have_at_least 2, 'pets'
|
270
|
+
person.should.not.have_at_least 3, 'pets'
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe 'have_at_most'
|
275
|
+
it 'should check if an object has at most n of a property'
|
276
|
+
person = { pets : ['izzy', 'niko'] }
|
277
|
+
person.should.have_at_most 2, 'pets'
|
278
|
+
person.should.have_at_most 3, 'pets'
|
279
|
+
person.should.not.have_at_most 1, 'pets'
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe 'be_within'
|
284
|
+
it 'should check that an object has within n..n of a property'
|
285
|
+
person = { pets : ['izzy', 'niko'] }
|
286
|
+
person.should.have_within 1..2, 'pets'
|
287
|
+
person.should.have_within 2..5, 'pets'
|
288
|
+
person.should.not.have_within 5..10, 'pets'
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
describe 'receive'
|
293
|
+
before_each
|
294
|
+
person = { toString : function(){ return 'person' }}
|
295
|
+
personWithPets = {
|
296
|
+
toString : function(){ return 'personWithPets' },
|
297
|
+
getPets : function() { return ['izzy'] },
|
298
|
+
addPet : function(name) { return ['izzy', name] },
|
299
|
+
addPets : function(a, b) { return ['izzy', a, b] }
|
300
|
+
}
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'should pass when the method is invoked'
|
304
|
+
personWithPets.should.receive('getPets')
|
305
|
+
personWithPets.getPets()
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'should pass and original method should still return its result'
|
309
|
+
personWithPets.should.receive('getPets')
|
310
|
+
personWithPets.getPets().should.eql ['izzy']
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'should pass when the proper value is returned'
|
314
|
+
personWithPets.should.receive('getPets').and_return(['izzy'])
|
315
|
+
personWithPets.getPets()
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'should pass when invoked the expected number of times'
|
319
|
+
personWithPets.should.receive('getPets', 'twice').and_return(['izzy'])
|
320
|
+
personWithPets.getPets()
|
321
|
+
personWithPets.getPets()
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'should pass when a method is invoked with specific arguments'
|
325
|
+
personWithPets.should.receive('addPet', 'once').with_args('suki')
|
326
|
+
personWithPets.addPet('suki')
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'should pass with multiple arguments'
|
330
|
+
personWithPets.should.receive('addPets').with_args('suki', 'max')
|
331
|
+
personWithPets.addPets('suki', 'max')
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'should pass with arguments and return value'
|
335
|
+
personWithPets.should.receive('addPet').with_args('suki').and_return(['izzy', 'suki'])
|
336
|
+
personWithPets.addPet('suki')
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'should pass when argument is the correct type'
|
340
|
+
personWithPets.should.receive('addPet').with_args(an_instance_of(String))
|
341
|
+
personWithPets.addPet('suki')
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'should pass when return type is correct'
|
345
|
+
personWithPets.should.receive('addPet').and_return(an_instance_of(Array))
|
346
|
+
personWithPets.addPet('suki')
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'should pass when checking the type of multiple args and return types'
|
350
|
+
personWithPets.should.receive('addPets').with_args(an_instance_of(String), an_instance_of(String)).and_return(an_instance_of(Array))
|
351
|
+
personWithPets.addPets('suki', 'max')
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'should pass with negation when a method is not called'
|
355
|
+
personWithPets.should.not.receive('addPets')
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'should pass with negation with args'
|
359
|
+
personWithPets.should.not.receive('addPets').with_args('izzy')
|
360
|
+
personWithPets.addPets('max')
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'should pass with negation with return values'
|
364
|
+
personWithPets.should.not.receive('addPets').with_args('izzy').and_return('test')
|
365
|
+
personWithPets.addPets('izzy')
|
366
|
+
end
|
367
|
+
|
368
|
+
it 'should pass with negation with times'
|
369
|
+
personWithPets.should.not.receive('addPets', 'twice')
|
370
|
+
personWithPets.addPets('izzy')
|
371
|
+
end
|
372
|
+
|
373
|
+
it 'should pass with boolean args'
|
374
|
+
foo = { bar : function(arg){ return arg }}
|
375
|
+
foo.should.receive('bar', 'twice').with_args(true)
|
376
|
+
foo.bar(true)
|
377
|
+
foo.bar(true)
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'should pass with null args'
|
381
|
+
foo = { bar : function(arg){ return arg }}
|
382
|
+
foo.should.receive('bar').with_args(null)
|
383
|
+
foo.bar(null)
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'should pass with boolean return value true'
|
387
|
+
foo = { bar : function(){ return true }}
|
388
|
+
foo.should.receive('bar').and_return(true)
|
389
|
+
foo.bar()
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'should pass with boolean return value false'
|
393
|
+
foo = { bar : function(){ return false }}
|
394
|
+
foo.should.receive('bar').and_return(false)
|
395
|
+
foo.bar()
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'should pass with null return value'
|
399
|
+
foo = { bar : function(){ return null }}
|
400
|
+
foo.should.receive('bar').and_return(null)
|
401
|
+
foo.bar()
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'should fail when the method does not exist'
|
405
|
+
person.should.receive('getPets')
|
406
|
+
end
|
407
|
+
|
408
|
+
it 'should fail when the method is never invoked'
|
409
|
+
personWithPets.should.receive('getPets')
|
410
|
+
end
|
411
|
+
|
412
|
+
it 'should fail when improper value is returned'
|
413
|
+
personWithPets.should.receive('getPets').and_return(['niko'])
|
414
|
+
personWithPets.getPets()
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'should fail when checking the type of multiple args and return types'
|
418
|
+
personWithPets.should.receive('addPets').with_args(an_instance_of(String), an_instance_of(Array)).and_return(an_instance_of(Array))
|
419
|
+
personWithPets.addPets('suki', 'max')
|
420
|
+
end
|
421
|
+
|
422
|
+
it 'should fail when not invoked the expected number of times'
|
423
|
+
personWithPets.should.receive('getPets', 'twice').and_return(['izzy'])
|
424
|
+
personWithPets.getPets()
|
425
|
+
end
|
426
|
+
|
427
|
+
it 'should fail when not invoked many times'
|
428
|
+
personWithPets.should.receive('getPets', 3).and_return(['izzy'])
|
429
|
+
personWithPets.getPets()
|
430
|
+
personWithPets.getPets()
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'should fail when not invoked with specific arguments'
|
434
|
+
personWithPets.should.receive('addPet', 'once').with_args('suki')
|
435
|
+
personWithPets.addPet('niko')
|
436
|
+
end
|
437
|
+
|
438
|
+
it 'should fail when expecting multiple arguments'
|
439
|
+
personWithPets.should.receive('addPets').with_args('suki', 'max')
|
440
|
+
personWithPets.addPets('suki')
|
441
|
+
end
|
442
|
+
|
443
|
+
it 'should fail when argument is of the wrong type'
|
444
|
+
personWithPets.should.receive('addPet').with_args(an_instance_of(String))
|
445
|
+
personWithPets.addPet(['suki'])
|
446
|
+
end
|
447
|
+
|
448
|
+
it 'should fail when return type is incorrect'
|
449
|
+
personWithPets.should.receive('addPet').and_return(an_instance_of(String))
|
450
|
+
personWithPets.addPet('suki')
|
451
|
+
end
|
452
|
+
|
453
|
+
it 'should fail with negation when a method is called'
|
454
|
+
personWithPets.should.not.receive('addPets')
|
455
|
+
personWithPets.addPets('izzy')
|
456
|
+
end
|
457
|
+
|
458
|
+
it 'should fail with negation with args'
|
459
|
+
personWithPets.should.not.receive('addPets').with_args('izzy')
|
460
|
+
personWithPets.addPets('izzy')
|
461
|
+
end
|
462
|
+
|
463
|
+
it 'should fail with negation with return values'
|
464
|
+
personWithPets.should.not.receive('addPets').with_args('izzy').and_return(an_instance_of(Array))
|
465
|
+
personWithPets.addPets('izzy')
|
466
|
+
end
|
467
|
+
|
468
|
+
it 'should fail with negation with times'
|
469
|
+
personWithPets.should.not.receive('addPets', 'twice')
|
470
|
+
personWithPets.addPets('izzy')
|
471
|
+
personWithPets.addPets('max')
|
472
|
+
end
|
473
|
+
|
474
|
+
it 'should fail with boolean args'
|
475
|
+
foo = { bar : function(arg){ return arg }}
|
476
|
+
foo.should.receive('bar').with_args(true)
|
477
|
+
foo.bar(false)
|
478
|
+
end
|
479
|
+
|
480
|
+
it 'should fail with boolean return value true'
|
481
|
+
foo = { bar : function(){ return true }}
|
482
|
+
foo.should.receive('bar').and_return(false)
|
483
|
+
foo.bar()
|
484
|
+
end
|
485
|
+
|
486
|
+
it 'should fail with boolean return value false'
|
487
|
+
foo = { bar : function(){ return false }}
|
488
|
+
foo.should.receive('bar').and_return(true)
|
489
|
+
foo.bar()
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
end
|