/
spec.core.js
174 lines (131 loc) · 2.98 KB
/
spec.core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
describe 'Positive specs'
it 'should pass'
'test'.should_equal('test')
end
it 'should pass with several assertions'
'foo'.should_equal('foo')
'bar'.should_equal('bar')
'bar'.should_not_equal('foo')
end
end
describe 'Negative specs'
it 'should fail'
'test'.should_not_eql('test')
end
it 'should fail with one faulty assertion'
'test'.should_equal('test')
'test'.should_equal('foo')
end
end
describe 'Misc'
it 'requires implementation'
end
end
describe 'Matchers'
it 'eql'
'test'.should_eql('test')
'1'.should_eql(1)
'1'.should_be(1)
end
it 'equal'
'test'.should_equal('test')
'1'.should_not_equal(1)
end
it 'match'
'foobar'.should_match(/foo/)
'foobar'.should_not_match(/barfoo/)
end
it 'be_empty'
var string = '', array = []
string.should_be_empty()
array.should_be_empty()
end
it 'have_length'
'test'.should_have_length(4)
end
it 'respond_to'
var string = 'test'
string.should_not_respond_to('whatever')
string.should_respond_to('toString')
end
it 'include'
'hey there'.should_include('hey')
var numbers = [1, 2, 3], object = { hey : 'there' }
numbers.should_include(2)
numbers.should_not_include(5)
object.should_include('hey')
end
it 'be_a'
var array = []
'test'.should_be_a(String)
array.should_be_an(Array)
end
it 'throw_error'
var lambda = function() { throw 'error' }
lambda.should_throw_error()
var lambda = function() { return 'test' }
lambda.should_not_throw_error()
end
it 'be_type'
var object = {}, func = function(){}
'hey'.should_be_type('string')
object.should_be_type('object')
func.should_be_type('function')
end
end
describe 'Position hooks'
before
this.beforeSpecNum = 0
this.afterSpecNum = 0
this.passBefore = true
end
before_each
this.beforeSpecNum++
end
after_each
this.afterSpecNum++
end
it 'before should work'
this.passBefore.should_be_true()
end
it 'before should work again'
this.passBefore.should_be_true()
end
it 'before / after each should work'
this.beforeSpecNum.should_equal(3)
this.afterSpecNum.should_equal(2)
end
end
describe 'Matcher messages'
it 'Fail with negative message'
'1'.should_not_be(true)
end
it 'Fail with positive message'
false.should_be(true)
end
it 'Fail second assertion message'
true.should_be(true)
'bar'.should_include('foo')
'bar'.should_match(/foo/)
end
end
describe 'Pre-processor'
it 'should allow parens to be optional when no args are passed'
true.should_be_true
true.should_be_true()
end
it 'should allow parens to be optional with args'
'foobar'.should_include 'foo'
end
end
describe 'Custom Contexts'
before
JSpec.context = { iLike : 'cookies' }
end
after
JSpec.context = null
end
it 'should allow helpers'
this.iLike.should_equal('cookies')
end
end