visionmedia-jspec 1.1.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +19 -0
- data/Manifest +6 -2
- data/README.rdoc +122 -86
- data/bin/jspec +1 -1
- data/jspec.gemspec +4 -4
- data/lib/images/loading.gif +0 -0
- data/lib/jspec.css +17 -2
- data/lib/jspec.jquery.js +4 -14
- data/lib/jspec.js +508 -154
- data/server/browsers.rb +3 -11
- data/server/server.rb +2 -13
- data/spec/server.html +5 -2
- data/spec/spec.grammar-less.js +34 -0
- data/spec/spec.grammar.js +27 -16
- data/spec/spec.html +6 -3
- data/spec/spec.jquery.js +32 -34
- data/spec/spec.js +86 -0
- data/spec/{spec.core.js → spec.matchers.js} +115 -107
- data/spec/spec.rhino.js +5 -1
- data/spec/spec.shared-behaviors.js +51 -0
- data/spec/spec.utils.js +138 -0
- metadata +9 -4
- data/spec/spec.core.dom.js +0 -12
data/server/browsers.rb
CHANGED
@@ -9,16 +9,8 @@ module JSpec
|
|
9
9
|
self.class.to_s.split('::').last
|
10
10
|
end
|
11
11
|
|
12
|
-
class Firefox < self
|
13
|
-
end
|
14
|
-
|
15
|
-
class Safari < self
|
16
|
-
end
|
17
|
-
|
18
|
-
class Opera < self
|
19
|
-
end
|
20
|
-
|
21
|
-
class MSIE < self
|
22
|
-
end
|
12
|
+
class Firefox < self; end
|
13
|
+
class Safari < self; end
|
14
|
+
class Opera < self; end
|
23
15
|
end
|
24
16
|
end
|
data/server/server.rb
CHANGED
@@ -37,16 +37,7 @@ module JSpec
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def display_results browser, failures, passes
|
40
|
-
puts '
|
41
|
-
require 'rubygems'
|
42
|
-
require 'growl'
|
43
|
-
if failures.to_i > 0
|
44
|
-
notify_error "failed #{failures} assertion(s)", :title => browser
|
45
|
-
else
|
46
|
-
notify_ok "passed #{passes} assertion(s)", :title => browser
|
47
|
-
end
|
48
|
-
rescue
|
49
|
-
# Do nothing
|
40
|
+
puts '%-14s - passes: %s failures: %s' % [bold(browser), green(passes), red(failures)]
|
50
41
|
end
|
51
42
|
|
52
43
|
def browser string
|
@@ -76,9 +67,7 @@ module JSpec
|
|
76
67
|
|
77
68
|
def when_finished &block
|
78
69
|
Thread.new {
|
79
|
-
while responses.length < browsers.length
|
80
|
-
sleep 0.1
|
81
|
-
end
|
70
|
+
sleep 0.1 while responses.length < browsers.length
|
82
71
|
yield
|
83
72
|
}
|
84
73
|
end
|
data/spec/server.html
CHANGED
@@ -3,12 +3,15 @@
|
|
3
3
|
<script src="jquery-1.3.1.js"></script>
|
4
4
|
<script src="jspec.js"></script>
|
5
5
|
<script src="jspec.jquery.js"></script>
|
6
|
+
<script src="spec.grammar-less.js"></script>
|
6
7
|
<script>
|
7
8
|
function runSuites() {
|
8
9
|
JSpec
|
9
10
|
.exec('spec.grammar.js')
|
10
|
-
.exec('spec.
|
11
|
-
.exec('spec.
|
11
|
+
.exec('spec.js')
|
12
|
+
.exec('spec.matchers.js')
|
13
|
+
.exec('spec.utils.js')
|
14
|
+
.exec('spec.shared-behaviors.js')
|
12
15
|
.exec('spec.jquery.js')
|
13
16
|
.run()
|
14
17
|
.reportToServer()
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
JSpec.describe('Grammar-less', function(){
|
3
|
+
before(function(){
|
4
|
+
n = 1
|
5
|
+
})
|
6
|
+
|
7
|
+
it('should work', function(){
|
8
|
+
expect(true).to(be, true)
|
9
|
+
expect(n).to(equal, 1)
|
10
|
+
})
|
11
|
+
|
12
|
+
describe('with nested describes', function(){
|
13
|
+
before(function(){
|
14
|
+
hits = []
|
15
|
+
})
|
16
|
+
|
17
|
+
before_each(function(){
|
18
|
+
n++
|
19
|
+
hits.push('before_each')
|
20
|
+
})
|
21
|
+
|
22
|
+
it('should work', function(){
|
23
|
+
expect(true).not_to(be, false)
|
24
|
+
expect(n).to(eql, 2)
|
25
|
+
expect(hits).to(eql, ['before_each'])
|
26
|
+
})
|
27
|
+
|
28
|
+
it('should work again', function(){
|
29
|
+
expect(n).to(eql, 3)
|
30
|
+
expect(hits).to(eql, ['before_each', 'before_each'])
|
31
|
+
})
|
32
|
+
})
|
33
|
+
|
34
|
+
})
|
data/spec/spec.grammar.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
describe 'Grammar'
|
3
|
-
|
3
|
+
|
4
4
|
it 'should allow "it" spec literal'
|
5
5
|
true.should.be_true
|
6
6
|
end
|
@@ -29,9 +29,16 @@ describe 'Grammar'
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should allow grammar-less assertions'
|
32
|
-
expect(true).to(
|
33
|
-
expect([1,2,3]).to(
|
34
|
-
expect(true).not_to(
|
32
|
+
expect(true).to(be, true)
|
33
|
+
expect([1,2,3]).to(include, 1, 2, 3)
|
34
|
+
expect(true).not_to(be, false)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should allow multi-line expect() assertions'
|
38
|
+
expect(' \
|
39
|
+
foo \
|
40
|
+
bar \
|
41
|
+
').to(include, 'foo', 'bar')
|
35
42
|
end
|
36
43
|
|
37
44
|
it 'should allow commenting out of conversions'
|
@@ -39,11 +46,6 @@ describe 'Grammar'
|
|
39
46
|
// foo.should.not.eql 'bar'
|
40
47
|
end
|
41
48
|
|
42
|
-
it 'should allow . this. literal'
|
43
|
-
this.foo = 'bar'
|
44
|
-
.foo.should.eql 'bar'
|
45
|
-
end
|
46
|
-
|
47
49
|
it 'should allow inclusive range literal n..n'
|
48
50
|
1..5.should.eql [1,2,3,4,5]
|
49
51
|
3..4.should.eql [3,4]
|
@@ -70,10 +72,6 @@ describe 'Grammar'
|
|
70
72
|
true.should.be_true
|
71
73
|
end
|
72
74
|
|
73
|
-
it 'should still allow literal javascript outside of blocks'
|
74
|
-
n.should.eql 10
|
75
|
-
end
|
76
|
-
|
77
75
|
describe 'nested again'
|
78
76
|
it 'should still work'
|
79
77
|
true.should.be_true
|
@@ -82,10 +80,9 @@ describe 'Grammar'
|
|
82
80
|
end
|
83
81
|
|
84
82
|
describe 'before / after blocks'
|
85
|
-
var n, o, hits = []
|
86
|
-
|
87
83
|
before
|
88
84
|
n = 1
|
85
|
+
hits = []
|
89
86
|
hits.push('before')
|
90
87
|
end
|
91
88
|
|
@@ -108,7 +105,7 @@ describe 'Grammar'
|
|
108
105
|
describe 'with nested describe'
|
109
106
|
it 'should be accessable'
|
110
107
|
n.should.eql 1
|
111
|
-
hits.should.eql ['before'
|
108
|
+
hits.should.eql ['before']
|
112
109
|
end
|
113
110
|
end
|
114
111
|
end
|
@@ -162,6 +159,20 @@ describe 'Grammar'
|
|
162
159
|
hits.should.eql ['before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'before_each']
|
163
160
|
end
|
164
161
|
end
|
162
|
+
|
163
|
+
describe 'with multiple hooks'
|
164
|
+
before_each
|
165
|
+
hits = []
|
166
|
+
end
|
167
|
+
|
168
|
+
before_each
|
169
|
+
hits.push('before_each')
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should work'
|
173
|
+
hits.should.eql ['before_each']
|
174
|
+
end
|
175
|
+
end
|
165
176
|
end
|
166
177
|
end
|
167
178
|
|
data/spec/spec.html
CHANGED
@@ -4,12 +4,15 @@
|
|
4
4
|
<script src="jquery-1.3.1.js"></script>
|
5
5
|
<script src="../lib/jspec.js"></script>
|
6
6
|
<script src="../lib/jspec.jquery.js"></script>
|
7
|
+
<script src="spec.grammar-less.js"></script>
|
7
8
|
<script>
|
8
9
|
function runSuites() {
|
9
10
|
JSpec
|
10
11
|
.exec('spec.grammar.js')
|
11
|
-
.exec('spec.
|
12
|
-
.exec('spec.
|
12
|
+
.exec('spec.js')
|
13
|
+
.exec('spec.matchers.js')
|
14
|
+
.exec('spec.utils.js')
|
15
|
+
.exec('spec.shared-behaviors.js')
|
13
16
|
.exec('spec.jquery.js')
|
14
17
|
.run()
|
15
18
|
.report()
|
@@ -18,7 +21,7 @@
|
|
18
21
|
</head>
|
19
22
|
<body class="jspec" onLoad="runSuites();">
|
20
23
|
<div id="jspec-top"><h2 id="jspec-title">JSpec <em><script>document.write(JSpec.version)</script></em></h2></div>
|
21
|
-
<div id="jspec"></div>
|
24
|
+
<div id="jspec"><div class="loading"></div></div>
|
22
25
|
<div id="jspec-bottom"></div>
|
23
26
|
</body>
|
24
27
|
</html>
|
data/spec/spec.jquery.js
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
|
2
2
|
describe 'jQuery'
|
3
|
-
describe '
|
3
|
+
describe 'sandbox'
|
4
4
|
before
|
5
|
-
|
5
|
+
dom = sandbox()
|
6
6
|
end
|
7
|
-
|
8
|
-
it 'should
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
it 'should retain visibility within a sandbox'
|
13
|
-
.dom.children('em').hide().should.be_hidden
|
14
|
-
.dom.children('em').show().should.be_visible
|
7
|
+
|
8
|
+
it 'should provide an empty DOM sandbox'
|
9
|
+
dom.prepend('<em>test</em>')
|
10
|
+
dom.should.have_text 'test'
|
15
11
|
end
|
16
12
|
end
|
17
13
|
|
@@ -42,71 +38,73 @@ describe 'jQuery'
|
|
42
38
|
<strong>test</strong> \
|
43
39
|
<strong>test</strong> \
|
44
40
|
</p>'
|
45
|
-
|
41
|
+
elem = $(html)
|
46
42
|
end
|
47
43
|
|
48
44
|
it 'should fail with pretty print of element'
|
49
|
-
|
45
|
+
elem.should.not.have_tag 'label'
|
50
46
|
end
|
51
47
|
|
52
48
|
describe 'have_tag / have_one'
|
53
49
|
it 'should check if a single child is present'
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
elem.should.have_tag 'label'
|
51
|
+
elem.should.have_tag 'em'
|
52
|
+
elem.should.have_one 'label'
|
53
|
+
elem.should.not.have_tag 'input'
|
58
54
|
end
|
59
55
|
end
|
60
56
|
|
61
57
|
describe 'have_tags / have_many'
|
62
58
|
it 'should check if more than one child is present'
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
elem.should.have_tags 'option'
|
60
|
+
elem.should.have_many 'option'
|
61
|
+
elem.should.not.have_many 'label'
|
66
62
|
end
|
67
63
|
end
|
68
64
|
|
69
65
|
describe 'have_child'
|
70
66
|
it 'should check if a direct child is present'
|
71
|
-
|
72
|
-
|
67
|
+
elem.should.have_child 'label'
|
68
|
+
elem.should.not.have_child 'em'
|
73
69
|
end
|
74
70
|
end
|
75
71
|
|
76
72
|
describe 'have_children'
|
77
73
|
it 'should check if more than one direct children are present'
|
78
|
-
|
79
|
-
|
74
|
+
elem.should.have_children 'strong'
|
75
|
+
elem.should.not.have_children 'select'
|
80
76
|
end
|
81
77
|
end
|
82
78
|
|
83
79
|
describe 'have_text'
|
84
80
|
it 'should check for plain text'
|
85
|
-
|
81
|
+
elem.children('label').should.have_text 'Save?'
|
86
82
|
end
|
87
83
|
end
|
88
84
|
|
89
85
|
describe 'have_value'
|
90
86
|
it 'should check if an element has the given value'
|
91
|
-
|
87
|
+
elem.find('option').get(1).should.have_value '1'
|
92
88
|
end
|
93
89
|
end
|
94
90
|
|
95
91
|
describe 'have_class'
|
96
92
|
it 'should check if an element has the given class'
|
97
|
-
|
93
|
+
elem.children('select').should.have_class 'save'
|
98
94
|
end
|
99
95
|
end
|
100
96
|
|
101
97
|
describe 'have_classes'
|
102
98
|
it 'should check if an element has the classes given'
|
103
|
-
|
99
|
+
elem.children('select').should.have_classes 'save', 'form-select'
|
100
|
+
elem.children('select').should.not.have_classes 'save', 'foo'
|
101
|
+
elem.children('select').should.not.have_classes 'foo', 'save'
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
107
105
|
describe 'be_visible'
|
108
106
|
it 'should check that an element is not hidden or set to display of none'
|
109
|
-
|
107
|
+
element('#jspec-report').should.be_visible
|
110
108
|
'#jspec-report'.should.be_visible
|
111
109
|
'<input style="visibility: hidden;"/>'.should.not.be_visible
|
112
110
|
'<input style="display: none;"/>'.should.not.be_visible
|
@@ -149,18 +147,18 @@ describe 'jQuery'
|
|
149
147
|
|
150
148
|
describe 'have_attr'
|
151
149
|
before_each
|
152
|
-
|
150
|
+
elem = '<input type="button" title="some foo" value="Foo" />'
|
153
151
|
end
|
154
152
|
|
155
153
|
it 'should check that an element has the given attribute'
|
156
|
-
|
157
|
-
|
154
|
+
elem.should.have_attr 'title'
|
155
|
+
elem.should.not_have_attr 'rawr'
|
158
156
|
end
|
159
157
|
|
160
158
|
it 'should check that the given attribute has a specific value'
|
161
|
-
|
162
|
-
|
163
|
-
|
159
|
+
elem.should.have_attr 'title', 'some foo'
|
160
|
+
elem.should.not.have_attr 'some', 'rawr'
|
161
|
+
elem.should.not.have_attr 'title', 'bar'
|
164
162
|
end
|
165
163
|
end
|
166
164
|
end
|
data/spec/spec.js
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
|
2
|
+
describe 'Negative specs'
|
3
|
+
|
4
|
+
it 'should fail'
|
5
|
+
'test'.should.not_eql 'test'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should fail with one faulty assertion'
|
9
|
+
'test'.should.equal 'test'
|
10
|
+
'test'.should.equal 'foo'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should fail and print array with square braces'
|
14
|
+
[1,2].should.equal [1,3]
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should fail and print nested array'
|
18
|
+
[1, ['foo']].should.equal [1, ['bar', ['whatever', 1.0, { foo : 'bar', bar : { 1 : 2 } }]]]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should fail and print html elements'
|
22
|
+
elem = document.createElement('a')
|
23
|
+
elem.setAttribute('href', 'http://vision-media.ca')
|
24
|
+
elem.should.not.eql elem
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should fail with selector for jQuery objects'
|
28
|
+
elem = { jquery : '1.3.1', selector : '.foobar' }
|
29
|
+
elem.should.eql 'foo'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should fail with negative message'
|
33
|
+
'1'.should.not.be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should fail with positive message'
|
37
|
+
false.should.be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should fail with function body'
|
41
|
+
-{ throw 'foo' }.should.not.throw_error
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should fail with message of first failure'
|
45
|
+
true.should.be_true
|
46
|
+
'bar'.should.match(/foo/gm)
|
47
|
+
'bar'.should.include 'foo'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should fail with list'
|
51
|
+
['foo', 'bar'].should.include 'foo', 'car'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should catch exceptions throw within specs'
|
55
|
+
throw new Error('Oh noes!')
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should catch improper exceptions'
|
59
|
+
throw 'oh noes'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should catch proper exceptions'
|
63
|
+
iDoNotExist.neitherDoI()
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'Contexts'
|
69
|
+
before
|
70
|
+
JSpec.context = { iLike : 'cookies' }
|
71
|
+
end
|
72
|
+
|
73
|
+
after
|
74
|
+
JSpec.context = null
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should be replaceable'
|
78
|
+
iLike.should.equal 'cookies'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'Misc'
|
83
|
+
it 'requires implementation'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -34,6 +34,11 @@ describe 'Matchers'
|
|
34
34
|
foo.should.eql foo2
|
35
35
|
foo.should.not.eql bar
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'should work with constructors'
|
39
|
+
Array.should.eql Array
|
40
|
+
Array.should.not.eql Object
|
41
|
+
end
|
37
42
|
end
|
38
43
|
|
39
44
|
describe 'equal'
|
@@ -252,119 +257,122 @@ describe 'Matchers'
|
|
252
257
|
end
|
253
258
|
end
|
254
259
|
|
255
|
-
describe '
|
256
|
-
|
257
|
-
person = {}
|
260
|
+
describe 'receive'
|
261
|
+
before_each
|
262
|
+
person = { toString : function(){ return 'person' }}
|
263
|
+
personWithPets = {
|
264
|
+
toString : function(){ return 'personWithPets' },
|
265
|
+
getPets : function() { return ['izzy'] },
|
266
|
+
addPet : function(name) { return ['izzy', name] },
|
267
|
+
addPets : function(a, b) { return ['izzy', a, b] }
|
268
|
+
}
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'should fail when the method does not exist'
|
258
272
|
person.should.receive('getPets')
|
259
273
|
end
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
describe 'Negative specs'
|
265
|
-
|
266
|
-
it 'should fail'
|
267
|
-
'test'.should.not_eql 'test'
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'should fail with one faulty assertion'
|
271
|
-
'test'.should.equal 'test'
|
272
|
-
'test'.should.equal 'foo'
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'should fail and print array with square braces'
|
276
|
-
[1,2].should.equal [1,3]
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'should fail and print nested array'
|
280
|
-
[1, ['foo']].should.equal [1, ['bar', ['whatever', 1.0, { foo : 'bar', bar : { 1 : 2 } }]]]
|
281
|
-
end
|
282
|
-
|
283
|
-
it 'should fail and print html elements'
|
284
|
-
elem = document.createElement('a')
|
285
|
-
elem.setAttribute('href', 'http://vision-media.ca')
|
286
|
-
elem.should.not.eql elem
|
287
|
-
end
|
288
|
-
|
289
|
-
it 'should fail with selector for jQuery objects'
|
290
|
-
elem = { jquery : '1.3.1', selector : '.foobar' }
|
291
|
-
elem.should.eql 'foo'
|
292
|
-
end
|
293
|
-
|
294
|
-
it 'should fail with negative message'
|
295
|
-
'1'.should.not.be_true
|
296
|
-
end
|
297
|
-
|
298
|
-
it 'should fail with positive message'
|
299
|
-
false.should.be_true
|
300
|
-
end
|
301
|
-
|
302
|
-
it 'should fail with function body'
|
303
|
-
-{ rawr }.should.not.throw_error
|
304
|
-
end
|
305
|
-
|
306
|
-
it 'should fail with message of first failure'
|
307
|
-
true.should.be_true
|
308
|
-
'bar'.should.match(/foo/gm)
|
309
|
-
'bar'.should.include 'foo'
|
310
|
-
end
|
311
|
-
|
312
|
-
it 'should fail with list'
|
313
|
-
['foo', 'bar'].should.include 'foo', 'car'
|
314
|
-
end
|
315
|
-
|
316
|
-
it 'should catch exceptions throw within specs'
|
317
|
-
throw new Error('Oh noes!')
|
318
|
-
end
|
319
|
-
|
320
|
-
it 'should catch improper exceptions'
|
321
|
-
throw 'oh noes'
|
322
|
-
end
|
323
|
-
|
324
|
-
it 'should catch proper exceptions'
|
325
|
-
iDoNotExist
|
326
|
-
end
|
327
|
-
|
328
|
-
end
|
329
|
-
|
330
|
-
describe 'Utility'
|
331
|
-
describe 'query'
|
332
|
-
it 'should return a pairs value'
|
333
|
-
JSpec.query('suite', '?suite=Positive%20specs').should.equal 'Positive specs'
|
274
|
+
|
275
|
+
it 'should fail when the method is never invoked'
|
276
|
+
personWithPets.should.receive('getPets')
|
334
277
|
end
|
335
278
|
|
336
|
-
it 'should
|
337
|
-
|
279
|
+
it 'should pass when the method is invoked'
|
280
|
+
personWithPets.should.receive('getPets')
|
281
|
+
personWithPets.getPets()
|
338
282
|
end
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
JSpec.strip(" foo \n\n").should.equal 'foo'
|
283
|
+
|
284
|
+
it 'should pass and original method should still return its result'
|
285
|
+
personWithPets.should.receive('getPets')
|
286
|
+
personWithPets.getPets().should.eql ['izzy']
|
344
287
|
end
|
345
288
|
|
346
|
-
it 'should
|
347
|
-
|
289
|
+
it 'should pass when the proper value is returned'
|
290
|
+
personWithPets.should.receive('getPets').and_return(['izzy'])
|
291
|
+
personWithPets.getPets()
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'should fail when improper value is returned'
|
295
|
+
personWithPets.should.receive('getPets').and_return(['niko'])
|
296
|
+
personWithPets.getPets()
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'should fail when not invoked the expected number of times'
|
300
|
+
personWithPets.should.receive('getPets', 'twice').and_return(['izzy'])
|
301
|
+
personWithPets.getPets()
|
302
|
+
end
|
303
|
+
|
304
|
+
it 'should fail when not invoked many times'
|
305
|
+
personWithPets.should.receive('getPets', 3).and_return(['izzy'])
|
306
|
+
personWithPets.getPets()
|
307
|
+
personWithPets.getPets()
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'should pass when invoked the expected number of times'
|
311
|
+
personWithPets.should.receive('getPets', 'twice').and_return(['izzy'])
|
312
|
+
personWithPets.getPets()
|
313
|
+
personWithPets.getPets()
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should fail when not invoked with specific arguments'
|
317
|
+
personWithPets.should.receive('addPet', 'once').with_args('suki')
|
318
|
+
personWithPets.addPet('niko')
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'should pass when a method is invoked with specific arguments'
|
322
|
+
personWithPets.should.receive('addPet', 'once').with_args('suki')
|
323
|
+
personWithPets.addPet('suki')
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'should fail when expecting multiple arguments'
|
327
|
+
personWithPets.should.receive('addPets').with_args('suki', 'max')
|
328
|
+
personWithPets.addPets('suki')
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'should pass with multiple arguments'
|
332
|
+
personWithPets.should.receive('addPets').with_args('suki', 'max')
|
333
|
+
personWithPets.addPets('suki', 'max')
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'should pass with arguments and return value'
|
337
|
+
personWithPets.should.receive('addPet').with_args('suki').and_return(['izzy', 'suki'])
|
338
|
+
personWithPets.addPet('suki')
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'should fail when argument is of the wrong type'
|
342
|
+
personWithPets.should.receive('addPet').with_args(an_instance_of(String))
|
343
|
+
personWithPets.addPet(['suki'])
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'should pass when argument is the correct type'
|
347
|
+
personWithPets.should.receive('addPet').with_args(an_instance_of(String))
|
348
|
+
personWithPets.addPet('suki')
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'should fail when return type is incorrect'
|
352
|
+
personWithPets.should.receive('addPet').and_return(an_instance_of(String))
|
353
|
+
personWithPets.addPet('suki')
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'should pass when return type is correct'
|
357
|
+
personWithPets.should.receive('addPet').and_return(an_instance_of(Array))
|
358
|
+
personWithPets.addPet('suki')
|
359
|
+
end
|
360
|
+
|
361
|
+
it 'should fail when checking the type of multiple args and return types'
|
362
|
+
personWithPets.should.receive('addPets').with_args(an_instance_of(String), an_instance_of(Array)).and_return(an_instance_of(Array))
|
363
|
+
personWithPets.addPets('suki', 'max')
|
364
|
+
end
|
365
|
+
|
366
|
+
it 'should pass when checking the type of multiple args and return types'
|
367
|
+
personWithPets.should.receive('addPets').with_args(an_instance_of(String), an_instance_of(String)).and_return(an_instance_of(Array))
|
368
|
+
personWithPets.addPets('suki', 'max')
|
369
|
+
end
|
370
|
+
|
371
|
+
it 'should pass when checking for method calls to core prototypes'
|
372
|
+
array = ['foo', 'bar']
|
373
|
+
array.should.receive('toString').and_return('foo,bar')
|
374
|
+
'array: ' + array
|
348
375
|
end
|
349
376
|
end
|
350
|
-
|
351
|
-
|
352
|
-
describe 'Contexts'
|
353
|
-
before
|
354
|
-
JSpec.context = { iLike : 'cookies' }
|
355
|
-
end
|
356
|
-
|
357
|
-
after
|
358
|
-
JSpec.context = null
|
359
|
-
end
|
360
|
-
|
361
|
-
it 'should be replacable'
|
362
|
-
.iLike.should.equal 'cookies'
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
describe 'Misc'
|
367
|
-
it 'requires implementation'
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
377
|
+
|
378
|
+
end
|