jspec 2.11.13 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +714 -0
- data/Manifest +51 -36
- data/README.md +968 -0
- data/Rakefile +4 -53
- data/bin/jspec +93 -224
- data/jspec.gemspec +5 -5
- data/lib/images/sprites.png +0 -0
- data/lib/jspec.css +2 -2
- data/lib/jspec.growl.js +115 -0
- data/lib/jspec.jquery.js +1 -1
- data/lib/jspec.js +98 -101
- data/lib/jspec.shell.js +5 -2
- data/lib/jspec.timers.js +1 -1
- data/lib/jspec.xhr.js +12 -2
- data/spec/commands/example_command.rb +19 -0
- data/spec/dom.html +33 -0
- data/spec/node.js +32 -0
- data/spec/rhino.js +24 -0
- data/spec/ruby/bin/init_spec.rb +101 -0
- data/spec/ruby/bin/install_spec.rb +141 -0
- data/spec/ruby/bin/run_spec.rb +0 -0
- data/spec/ruby/bin/shell_spec.rb +13 -0
- data/spec/ruby/bin/spec_helper.rb +25 -0
- data/spec/ruby/bin/update_spec.rb +72 -0
- data/spec/server.html +29 -0
- data/spec/server.rb +1 -1
- data/spec/{env.js → support/env.js} +554 -664
- data/spec/support/jquery.js +4376 -0
- data/spec/{helpers.js → unit/helpers.js} +2 -0
- data/spec/{spec.fixtures.js → unit/spec.fixtures.js} +0 -1
- data/spec/{spec.grammar-less.js → unit/spec.grammar-less.js} +0 -0
- data/spec/{spec.grammar.js → unit/spec.grammar.js} +1 -11
- data/spec/{spec.jquery.js → unit/spec.jquery.js} +0 -17
- data/spec/{spec.jquery.xhr.js → unit/spec.jquery.xhr.js} +13 -2
- data/spec/unit/spec.js +187 -0
- data/spec/{spec.matchers.js → unit/spec.matchers.js} +141 -66
- data/spec/{spec.modules.js → unit/spec.modules.js} +0 -0
- data/spec/{spec.shared-behaviors.js → unit/spec.shared-behaviors.js} +0 -0
- data/spec/{spec.utils.js → unit/spec.utils.js} +123 -22
- data/spec/{spec.xhr.js → unit/spec.xhr.js} +11 -10
- data/{server → src}/browsers.rb +23 -0
- data/{server → src}/helpers.rb +2 -17
- data/src/installables.rb +229 -0
- data/src/project.rb +340 -0
- data/{server → src}/routes.rb +1 -1
- data/{server → src}/server.rb +0 -0
- data/support/js.jar +0 -0
- data/templates/default/History.md +5 -0
- data/templates/default/{README.rdoc → Readme.md} +3 -3
- data/templates/default/lib/{yourlib.core.js → yourlib.js} +0 -0
- data/templates/default/spec/commands/example_command.rb +19 -0
- data/templates/default/spec/{spec.dom.html → dom.html} +5 -3
- data/templates/default/spec/rhino.js +10 -0
- data/templates/default/spec/server.html +18 -0
- data/templates/default/spec/unit/spec.helper.js +0 -0
- data/templates/default/spec/{spec.core.js → unit/spec.js} +0 -0
- data/templates/rails/commands/example_commands.rb +19 -0
- data/templates/rails/{spec.dom.html → dom.html} +4 -2
- data/templates/rails/rhino.js +10 -0
- data/templates/rails/server.html +18 -0
- data/templates/rails/unit/spec.helper.js +0 -0
- data/templates/rails/{spec.application.js → unit/spec.js} +0 -0
- metadata +56 -41
- data/History.rdoc +0 -590
- data/README.rdoc +0 -842
- data/spec/async +0 -1
- data/spec/jquery.js +0 -19
- data/spec/spec.dom.html +0 -34
- data/spec/spec.js +0 -166
- data/spec/spec.node.js +0 -46
- data/spec/spec.rhino.js +0 -23
- data/spec/spec.server.html +0 -29
- data/templates/default/History.rdoc +0 -4
- data/templates/default/spec/spec.rhino.js +0 -8
- data/templates/default/spec/spec.server.html +0 -16
- data/templates/rails/spec.rhino.js +0 -8
- data/templates/rails/spec.server.html +0 -16
@@ -3,10 +3,12 @@ JSpec.include({
|
|
3
3
|
name: 'Helpers',
|
4
4
|
utilities : {
|
5
5
|
mock_it : function(body) {
|
6
|
+
JSpec.assert = false
|
6
7
|
var spec = new JSpec.Spec('mock', body)
|
7
8
|
var prev = JSpec.currentSpec
|
8
9
|
JSpec.runSpec(spec)
|
9
10
|
JSpec.currentSpec = prev
|
11
|
+
JSpec.assert = true
|
10
12
|
return spec
|
11
13
|
}
|
12
14
|
},
|
File without changes
|
@@ -121,16 +121,6 @@ describe 'Grammar'
|
|
121
121
|
true.should.be(true);
|
122
122
|
end
|
123
123
|
end
|
124
|
-
|
125
|
-
describe "with some tabs"
|
126
|
-
before_each
|
127
|
-
foo = 'baz'
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'should work'
|
131
|
-
foo.should.eql 'baz'
|
132
|
-
end
|
133
|
-
end
|
134
124
|
|
135
125
|
describe 'with nested describe'
|
136
126
|
it 'should work'
|
@@ -248,4 +238,4 @@ __END__
|
|
248
238
|
this should not matter because it is
|
249
239
|
considered a comment by the JSpec grammar :)
|
250
240
|
and is sometimes useful for temp reference info
|
251
|
-
when writting specs.
|
241
|
+
when writting specs.
|
@@ -18,23 +18,6 @@ describe 'jQuery'
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe 'async'
|
22
|
-
it 'should load mah cookies (textfile)'
|
23
|
-
$.get('async', function(text){
|
24
|
-
text.should_eql 'cookies!'
|
25
|
-
})
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should load mah cookies twice (ensure multiple async requests work)'
|
29
|
-
$.get('async', function(text){
|
30
|
-
text.should.eql 'cookies!'
|
31
|
-
})
|
32
|
-
$.get('async', function(text){
|
33
|
-
text.should.not.eql 'rawr'
|
34
|
-
})
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
21
|
describe 'matchers'
|
39
22
|
before_each
|
40
23
|
html = '<p><label><em>Save?</em></label> \
|
@@ -4,32 +4,43 @@ describe 'jQuery'
|
|
4
4
|
it "should call the success function when 200"
|
5
5
|
mock_request().and_return('{ foo: "bar" }', 'application/json')
|
6
6
|
var successCalled = false
|
7
|
+
var errorCalled = false
|
7
8
|
$.ajax({
|
8
9
|
type: "POST",
|
9
10
|
url: 'foo',
|
10
11
|
dataType: 'json',
|
11
12
|
success: function() {
|
12
13
|
successCalled = true
|
14
|
+
},
|
15
|
+
error: function(xhr, status, e) {
|
16
|
+
alert(status)
|
17
|
+
errorCalled = true
|
13
18
|
}
|
14
19
|
})
|
15
20
|
successCalled.should.be_true
|
21
|
+
errorCalled.should.be_false
|
16
22
|
end
|
17
|
-
|
23
|
+
|
18
24
|
it "should call the error function when 404"
|
19
25
|
mock_request().and_return('{ foo: "bar" }', 'application/json', 404)
|
26
|
+
var successCalled = false
|
20
27
|
var errorCalled = false
|
21
28
|
$.ajax({
|
22
29
|
type: "POST",
|
23
30
|
url: 'foo',
|
24
31
|
dataType: 'json',
|
32
|
+
success: function() {
|
33
|
+
successCalled = true
|
34
|
+
},
|
25
35
|
error: function() {
|
26
36
|
errorCalled = true
|
27
37
|
}
|
28
38
|
})
|
39
|
+
successCalled.should.be_false
|
29
40
|
errorCalled.should.be_true
|
30
41
|
end
|
31
42
|
end
|
32
|
-
|
43
|
+
|
33
44
|
describe '.getJSON()'
|
34
45
|
it 'should work with mockRequest'
|
35
46
|
mockRequest().and_return('{ foo : "bar" }')
|
data/spec/unit/spec.js
ADDED
@@ -0,0 +1,187 @@
|
|
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
|
+
describe 'throw_error'
|
56
|
+
before
|
57
|
+
// The Error.name property is not defined in IE
|
58
|
+
Error.name = "Error"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should fail saying which error has been thrown'
|
62
|
+
spec = mock_it(function() {
|
63
|
+
-{ throw 'foo' }.should.throw_error 'bar'
|
64
|
+
})
|
65
|
+
spec.should.have_failure_message('expected exception of "bar" to be thrown, but got "foo"')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should fail saying no error was thrown'
|
69
|
+
spec = mock_it(function() {
|
70
|
+
-{ }.should.throw_error 'foo'
|
71
|
+
})
|
72
|
+
spec.should.have_failure_message('expected exception of "foo" to be thrown, but nothing was')
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should fail saying no error matching was thrown'
|
76
|
+
spec = mock_it(function() {
|
77
|
+
-{ throw 'bar' }.should.throw_error(/foo/)
|
78
|
+
})
|
79
|
+
spec.should.have_failure_message('expected exception matching /foo/ to be thrown, but got "bar"')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should fail saying constructors'
|
83
|
+
spec = mock_it(function() {
|
84
|
+
// IE loses scope of virtually everything once global inside nested eval()s
|
85
|
+
// Create everything we need here.
|
86
|
+
function CustomError(message) { this.message = message }
|
87
|
+
CustomError.prototype.toString = -{ return 'CustomError: oh no' }
|
88
|
+
-{ throw new CustomError('oh no') }.should.throw_error(Error)
|
89
|
+
})
|
90
|
+
spec.should.have_failure_message("expected Error to be thrown, but got CustomError: oh no")
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should fail saying multiple arg messages'
|
94
|
+
spec = mock_it(function() {
|
95
|
+
// IE loses scope of virtually everything once global inside nested eval()s
|
96
|
+
// Create everything we need here.
|
97
|
+
function CustomError(message) { this.message = message }
|
98
|
+
CustomError.name = "CustomError"
|
99
|
+
CustomError.prototype.toString = function(){ return 'CustomError: oh no' }
|
100
|
+
-{ throw new CustomError('oh no') }.should.throw_error(CustomError, /foo/)
|
101
|
+
})
|
102
|
+
spec.should.have_failure_message("expected CustomError and exception matching /foo/ to be thrown, but got CustomError: oh no")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should fail with constructor name'
|
107
|
+
spec = mock_it(function() {
|
108
|
+
function Foo(){ this.toString = function(){ return '<Foo>' }}
|
109
|
+
Foo.name = "Foo"
|
110
|
+
foo = new Foo
|
111
|
+
foo.should.not.be_an_instance_of Foo
|
112
|
+
})
|
113
|
+
spec.should.have_failure_message("expected <Foo> to not be an instance of Foo")
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should fail with message of first failure'
|
117
|
+
spec = mock_it(function() {
|
118
|
+
true.should.be_true
|
119
|
+
'bar'.should.match(/foo/gm)
|
120
|
+
'bar'.should.include 'foo'
|
121
|
+
})
|
122
|
+
spec.should.have_failure_message('expected "bar" to match /foo/gm')
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should fail with list'
|
126
|
+
spec = mock_it(function() {
|
127
|
+
['foo', 'bar'].should.include 'foo', 'car'
|
128
|
+
})
|
129
|
+
spec.should.have_failure_message('expected [ "foo", "bar" ] to include "foo", "car"')
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should list all failure messages'
|
133
|
+
spec = mock_it(function() {
|
134
|
+
false.should.be_true
|
135
|
+
true.should.be_false
|
136
|
+
})
|
137
|
+
spec.should.have_failure_message('expected false to be true ')
|
138
|
+
spec.should.have_failure_message('expected true to be false ')
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should catch exceptions throw within specs'
|
142
|
+
spec = mock_it(function() {
|
143
|
+
// IE loses scope of virtually everything once global inside nested eval()s
|
144
|
+
// Create everything we need here.
|
145
|
+
Error.prototype.toString = -{ return "Error: " + this.message }
|
146
|
+
throw new Error('Oh noes!')
|
147
|
+
})
|
148
|
+
spec.should.have_failure_message(/Error: Oh noes!/)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should catch exceptions without constructors'
|
152
|
+
spec = mock_it(function() {
|
153
|
+
throw 'oh noes'
|
154
|
+
})
|
155
|
+
spec.should.have_failure_message(/oh noes/)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should catch indirect exceptions'
|
159
|
+
spec = mock_it(function() {
|
160
|
+
iDoNotExist.neitherDoI()
|
161
|
+
})
|
162
|
+
// NOTE: Most browsers will specifically mention iDoNotExist being undefined.
|
163
|
+
// IE only reports an Error.
|
164
|
+
spec.should.have_failure_message(/Error/)
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'Contexts'
|
170
|
+
before
|
171
|
+
JSpec.context = { iLike : 'cookies' }
|
172
|
+
end
|
173
|
+
|
174
|
+
after
|
175
|
+
JSpec.context = null
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should be replaceable'
|
179
|
+
iLike.should.equal 'cookies'
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'Misc'
|
184
|
+
it 'requires implementation'
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
@@ -12,18 +12,32 @@ describe 'Matchers'
|
|
12
12
|
10.should.not.eql 11
|
13
13
|
end
|
14
14
|
|
15
|
-
it 'should
|
16
|
-
|
17
|
-
|
15
|
+
it 'should work with regular expressions'
|
16
|
+
a = /foo/
|
17
|
+
b = /foo/
|
18
|
+
c = /foo/g
|
19
|
+
d = /bar/
|
20
|
+
a.should.eql a
|
21
|
+
a.should.eql b
|
22
|
+
a.should.not.eql c
|
23
|
+
a.should.not.eql d
|
18
24
|
end
|
19
25
|
|
20
|
-
it 'should
|
26
|
+
it 'should work with dates'
|
27
|
+
a = new Date('May 25 1987')
|
28
|
+
b = new Date('May 25 1987')
|
29
|
+
c = new Date('May 25 1988')
|
30
|
+
a.should.eql b
|
31
|
+
a.should.not.eql c
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should work with arrays'
|
21
35
|
[1, 2].should.eql [1, 2]
|
22
36
|
[1, 2].should.not.eql [1, 3]
|
23
37
|
[1, 2, [3], { foo : 'bar' }].should.eql [1, 2, [3], { foo : 'bar' }]
|
24
38
|
end
|
25
39
|
|
26
|
-
it 'should
|
40
|
+
it 'should work with objects'
|
27
41
|
{ foo : 'bar' }.should.eql { foo : 'bar' }
|
28
42
|
end
|
29
43
|
|
@@ -33,11 +47,10 @@ describe 'Matchers'
|
|
33
47
|
a.should.eql b
|
34
48
|
end
|
35
49
|
|
36
|
-
it 'should
|
37
|
-
|
38
|
-
|
39
|
-
foo
|
40
|
-
foo.should.eql foo2
|
50
|
+
it 'should work with functions'
|
51
|
+
function foo(){}
|
52
|
+
function bar(){}
|
53
|
+
foo.should.eql foo
|
41
54
|
foo.should.not.eql bar
|
42
55
|
end
|
43
56
|
|
@@ -90,8 +103,8 @@ describe 'Matchers'
|
|
90
103
|
|
91
104
|
describe 'be_undefined'
|
92
105
|
it 'should check if a var is defined'
|
93
|
-
var
|
94
|
-
|
106
|
+
var rawr
|
107
|
+
rawr.should.be_undefined
|
95
108
|
end
|
96
109
|
end
|
97
110
|
|
@@ -116,7 +129,7 @@ describe 'Matchers'
|
|
116
129
|
|
117
130
|
it 'should check that a property has a specific value'
|
118
131
|
'foo'.should.have_prop 'length', 3
|
119
|
-
{ length :
|
132
|
+
{ length : 3 }.should.have_prop 'length', 3
|
120
133
|
end
|
121
134
|
|
122
135
|
it 'should check object hashes'
|
@@ -212,19 +225,24 @@ describe 'Matchers'
|
|
212
225
|
end
|
213
226
|
|
214
227
|
it 'should check if an error of a specific constructor is thrown'
|
228
|
+
function CustomError(message) { this.message = message }
|
229
|
+
CustomError.name = "CustomError"
|
215
230
|
-{ throw new Error('foo') }.should.throw_error(Error)
|
216
|
-
-{ throw new
|
217
|
-
-{ throw 'foo' }.should.throw_error
|
218
|
-
-{ throw 'foo' }.should.not.throw_error TypeError
|
231
|
+
-{ throw new CustomError('foo') }.should.throw_error(CustomError)
|
232
|
+
-{ throw 'foo' }.should.not.throw_error CustomError
|
219
233
|
end
|
220
234
|
|
221
235
|
it 'should check if an error with a specific constructor and message is thrown'
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
-{ throw new
|
227
|
-
-{ throw new
|
236
|
+
Error.name = "Error"
|
237
|
+
function CustomError(message) { this.message = message }
|
238
|
+
CustomError.name = "CustomError"
|
239
|
+
CustomError.prototype.toString = function(){ return 'CustomError: oh no!' }
|
240
|
+
-{ throw new CustomError('oh no!') }.should.throw_error(CustomError, 'oh no!')
|
241
|
+
-{ throw new CustomError('oh no!') }.should.not.throw_error(CustomError, 'foo bar')
|
242
|
+
-{ throw new CustomError('oh no!') }.should.throw_error(CustomError, /oh no/)
|
243
|
+
-{ throw new CustomError('oh no!') }.should.not.throw_error(CustomError, /foo bar/)
|
244
|
+
-{ throw new CustomError('oh no!') }.should.not.throw_error(Error, 'oh no!')
|
245
|
+
-{ throw new CustomError('oh no!') }.should.not.throw_error(Error, 'foo bar')
|
228
246
|
end
|
229
247
|
end
|
230
248
|
|
@@ -393,104 +411,161 @@ describe 'Matchers'
|
|
393
411
|
end
|
394
412
|
|
395
413
|
it 'should fail when the method does not exist'
|
396
|
-
|
414
|
+
spec = mock_it(function(){
|
415
|
+
person.should.receive('getPets')
|
416
|
+
})
|
417
|
+
spec.should.have_failure_message('expected person.getPets() to be called once, but was not called')
|
397
418
|
end
|
398
419
|
|
399
420
|
it 'should fail when the method is never invoked'
|
400
|
-
|
421
|
+
spec = mock_it(function(){
|
422
|
+
personWithPets.should.receive('getPets')
|
423
|
+
})
|
424
|
+
spec.should.have_failure_message('expected personWithPets.getPets() to be called once, but was not called')
|
401
425
|
end
|
402
426
|
|
403
427
|
it 'should fail when improper value is returned'
|
404
|
-
|
405
|
-
|
428
|
+
spec = mock_it(function(){
|
429
|
+
personWithPets.should.receive('getPets').and_return(['niko'])
|
430
|
+
personWithPets.getPets()
|
431
|
+
})
|
432
|
+
spec.should.have_failure_message('expected personWithPets.getPets() to return [ "niko" ] but got [ "izzy" ]')
|
406
433
|
end
|
407
434
|
|
408
435
|
it 'should fail when checking the type of multiple args and return types'
|
409
|
-
|
410
|
-
|
436
|
+
spec = mock_it(function(){
|
437
|
+
personWithPets.should.receive('addPets').with_args(an_instance_of(String), an_instance_of(Array)).and_return(an_instance_of(Array))
|
438
|
+
personWithPets.addPets('suki', 'max')
|
439
|
+
})
|
440
|
+
spec.should.have_failure_message('expected personWithPets.addPets() to be called with an instance of String, an instance of Array but was called with "suki", "max"')
|
411
441
|
end
|
412
442
|
|
413
443
|
it 'should fail when not invoked the expected number of times'
|
414
|
-
|
415
|
-
|
444
|
+
spec = mock_it(function(){
|
445
|
+
personWithPets.should.receive('getPets', 'twice').and_return(['izzy'])
|
446
|
+
personWithPets.getPets()
|
447
|
+
})
|
448
|
+
spec.should.have_failure_message('expected personWithPets.getPets() to be called twice, but was called once')
|
416
449
|
end
|
417
450
|
|
418
451
|
it 'should fail when not invoked many times'
|
419
|
-
|
420
|
-
|
421
|
-
|
452
|
+
spec = mock_it(function(){
|
453
|
+
personWithPets.should.receive('getPets', 3).and_return(['izzy'])
|
454
|
+
personWithPets.getPets()
|
455
|
+
personWithPets.getPets()
|
456
|
+
})
|
457
|
+
spec.should.have_failure_message('expected personWithPets.getPets() to be called 3 times, but was called twice')
|
422
458
|
end
|
423
459
|
|
424
460
|
it 'should fail when not invoked with specific arguments'
|
425
|
-
|
426
|
-
|
461
|
+
spec = mock_it(function(){
|
462
|
+
personWithPets.should.receive('addPet', 'once').with_args('suki')
|
463
|
+
personWithPets.addPet('niko')
|
464
|
+
})
|
465
|
+
spec.should.have_failure_message('expected personWithPets.addPet() to be called with "suki" but was called with "niko"')
|
427
466
|
end
|
428
467
|
|
429
468
|
it 'should fail when expecting multiple arguments'
|
430
|
-
|
431
|
-
|
469
|
+
spec = mock_it(function(){
|
470
|
+
personWithPets.should.receive('addPets').with_args('suki', 'max')
|
471
|
+
personWithPets.addPets('suki')
|
472
|
+
})
|
473
|
+
spec.should.have_failure_message('expected personWithPets.addPets() to be called with "suki", "max" but was called with "suki"')
|
432
474
|
end
|
433
475
|
|
434
476
|
it 'should fail when argument is of the wrong type'
|
435
|
-
|
436
|
-
|
477
|
+
spec = mock_it(function(){
|
478
|
+
personWithPets.should.receive('addPet').with_args(an_instance_of(String))
|
479
|
+
personWithPets.addPet(['suki'])
|
480
|
+
})
|
481
|
+
spec.should.have_failure_message('expected personWithPets.addPet() to be called with an instance of String but was called with [ "suki" ]')
|
437
482
|
end
|
438
483
|
|
439
484
|
it 'should fail when return type is incorrect'
|
440
|
-
|
441
|
-
|
485
|
+
spec = mock_it(function(){
|
486
|
+
personWithPets.should.receive('addPet').and_return(an_instance_of(String))
|
487
|
+
personWithPets.addPet('suki')
|
488
|
+
})
|
489
|
+
spec.should.have_failure_message('expected personWithPets.addPet() to return an instance of String but got [ "izzy", "suki" ]')
|
442
490
|
end
|
443
491
|
|
444
492
|
it 'should fail with negation when a method is called'
|
445
|
-
|
446
|
-
|
493
|
+
spec = mock_it(function(){
|
494
|
+
personWithPets.should.not.receive('addPets')
|
495
|
+
personWithPets.addPets('izzy')
|
496
|
+
})
|
497
|
+
spec.should.have_failure_message('expected personWithPets.addPets() not to be called once, but was called once')
|
447
498
|
end
|
448
499
|
|
449
500
|
it 'should fail with negation with args'
|
450
|
-
|
451
|
-
|
501
|
+
spec = mock_it(function(){
|
502
|
+
personWithPets.should.not.receive('addPets').with_args('izzy')
|
503
|
+
personWithPets.addPets('izzy')
|
504
|
+
})
|
505
|
+
spec.should.have_failure_message('expected personWithPets.addPets() not to be called with "izzy" but was')
|
452
506
|
end
|
453
507
|
|
454
508
|
it 'should fail with negation with return values'
|
455
|
-
|
456
|
-
|
509
|
+
spec = mock_it(function(){
|
510
|
+
personWithPets.should.not.receive('addPets').with_args('izzy').and_return(an_instance_of(Array))
|
511
|
+
personWithPets.addPets('izzy')
|
512
|
+
})
|
513
|
+
spec.should.have_failure_message('expected personWithPets.addPets() not to return an instance of Array but it did')
|
457
514
|
end
|
458
515
|
|
459
516
|
it 'should fail with negation when called once with no times specified'
|
460
|
-
|
461
|
-
|
517
|
+
spec = mock_it(function(){
|
518
|
+
personWithPets.should.not.receive('addPets')
|
519
|
+
personWithPets.addPets('izzy')
|
520
|
+
})
|
521
|
+
spec.should.have_failure_message('expected personWithPets.addPets() not to be called once, but was called once')
|
462
522
|
end
|
463
523
|
|
464
524
|
it 'should fail with negation when called more than once with no times specified'
|
465
|
-
|
466
|
-
|
467
|
-
|
525
|
+
spec = mock_it(function(){
|
526
|
+
personWithPets.should.not.receive('addPets')
|
527
|
+
personWithPets.addPets('izzy')
|
528
|
+
personWithPets.addPets('izzy')
|
529
|
+
})
|
530
|
+
spec.should.have_failure_message('expected personWithPets.addPets() not to be called once, but was called twice')
|
468
531
|
end
|
469
532
|
|
470
533
|
it 'should fail with negation when called more than the times specified'
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
534
|
+
spec = mock_it(function(){
|
535
|
+
personWithPets.should.not.receive('addPets', 3)
|
536
|
+
personWithPets.addPets('izzy')
|
537
|
+
personWithPets.addPets('izzy')
|
538
|
+
personWithPets.addPets('izzy')
|
539
|
+
personWithPets.addPets('izzy')
|
540
|
+
})
|
541
|
+
spec.should.have_failure_message('expected personWithPets.addPets() not to be called 3 times, but was called 4 times')
|
476
542
|
end
|
477
543
|
|
478
544
|
it 'should fail with boolean args'
|
479
|
-
|
480
|
-
|
481
|
-
|
545
|
+
spec = mock_it(function(){
|
546
|
+
foo = { bar : function(arg){ return arg }}
|
547
|
+
foo.should.receive('bar').with_args(true)
|
548
|
+
foo.bar(false)
|
549
|
+
})
|
550
|
+
spec.should.have_failure_message('expected [object Object].bar() to be called with true but was called with false')
|
482
551
|
end
|
483
552
|
|
484
553
|
it 'should fail with boolean return value true'
|
485
|
-
|
486
|
-
|
487
|
-
|
554
|
+
spec = mock_it(function(){
|
555
|
+
foo = { bar : function(){ return true }}
|
556
|
+
foo.should.receive('bar').and_return(false)
|
557
|
+
foo.bar()
|
558
|
+
})
|
559
|
+
spec.should.have_failure_message('expected [object Object].bar() to return false but got true')
|
488
560
|
end
|
489
561
|
|
490
562
|
it 'should fail with boolean return value false'
|
491
|
-
|
492
|
-
|
493
|
-
|
563
|
+
spec = mock_it(function(){
|
564
|
+
foo = { bar : function(){ return false }}
|
565
|
+
foo.should.receive('bar').and_return(true)
|
566
|
+
foo.bar()
|
567
|
+
})
|
568
|
+
spec.should.have_failure_message('expected [object Object].bar() to return true but got false')
|
494
569
|
end
|
495
570
|
end
|
496
571
|
|