jspec 2.11.2
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 +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/helpers.js
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
JSpec.include({
|
3
|
+
name: 'Helpers',
|
4
|
+
utilities : {
|
5
|
+
mock_it : function(body) {
|
6
|
+
var spec = new JSpec.Spec('mock', body)
|
7
|
+
var prev = JSpec.currentSpec
|
8
|
+
JSpec.runSpec(spec)
|
9
|
+
JSpec.currentSpec = prev
|
10
|
+
return spec
|
11
|
+
}
|
12
|
+
},
|
13
|
+
|
14
|
+
matchers : {
|
15
|
+
have_failure_message : function(spec, expected) {
|
16
|
+
return JSpec.any(spec.assertions, function(assertion){
|
17
|
+
if (assertion.passed) return
|
18
|
+
switch (expected.constructor) {
|
19
|
+
case String: return assertion.message == expected
|
20
|
+
case RegExp: return expected.test(assertion.message)
|
21
|
+
default : return false
|
22
|
+
}
|
23
|
+
})
|
24
|
+
}
|
25
|
+
}
|
26
|
+
})
|
27
|
+
|
28
|
+
JSpec.include({
|
29
|
+
name: 'ExampleModule',
|
30
|
+
utilities : {
|
31
|
+
doFoo : function(){ return 'foo' },
|
32
|
+
doBar : function(){ return 'bar' }
|
33
|
+
},
|
34
|
+
randomHook : function(a, b) {
|
35
|
+
return [a, b]
|
36
|
+
},
|
37
|
+
beforeSpec : function() { addedBeforeSpec = true; doFoo() },
|
38
|
+
afterSpec : function() { addedAfterSpec = true },
|
39
|
+
beforeSuite : function() { addedBeforeSuite = true },
|
40
|
+
afterSuite : function() { addedAfterSuite = true },
|
41
|
+
checkJSpecContext : function(){ return each },
|
42
|
+
checkContext : function() { return fixture('test') },
|
43
|
+
checkModuleContext : function() { return this.name },
|
44
|
+
checkUtilityContext : function() { return doFoo() },
|
45
|
+
matchers : {
|
46
|
+
be_foo_bar : function() {
|
47
|
+
return true
|
48
|
+
}
|
49
|
+
},
|
50
|
+
DSLs : {
|
51
|
+
snake : {
|
52
|
+
some_snake_case_stuff : function(){
|
53
|
+
return true
|
54
|
+
}
|
55
|
+
},
|
56
|
+
camel : {
|
57
|
+
someCamelCaseStuff : function() {
|
58
|
+
return true
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
})
|
63
|
+
|
64
|
+
JSpec.include({
|
65
|
+
name : 'EmptyModule'
|
66
|
+
})
|
data/spec/server.rb
ADDED
data/spec/spec.dom.html
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<link type="text/css" rel="stylesheet" href="../lib/jspec.css" />
|
4
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
|
5
|
+
<script src="../lib/jspec.js"></script>
|
6
|
+
<script src="../lib/jspec.jquery.js"></script>
|
7
|
+
<script src="../lib/jspec.xhr.js"></script>
|
8
|
+
<script src="../lib/jspec.timers.js"></script>
|
9
|
+
<script src="helpers.js"></script>
|
10
|
+
<script src="spec.grammar-less.js"></script>
|
11
|
+
<script>
|
12
|
+
function runSuites() {
|
13
|
+
JSpec
|
14
|
+
.exec('spec.grammar.js')
|
15
|
+
.exec('spec.js')
|
16
|
+
.exec('spec.matchers.js')
|
17
|
+
.exec('spec.utils.js')
|
18
|
+
.exec('spec.fixtures.js')
|
19
|
+
.exec('spec.shared-behaviors.js')
|
20
|
+
.exec('spec.jquery.js')
|
21
|
+
.exec('spec.modules.js')
|
22
|
+
.exec('spec.xhr.js')
|
23
|
+
.exec('spec.jquery.xhr.js')
|
24
|
+
.run({ failuresOnly: true })
|
25
|
+
.report()
|
26
|
+
}
|
27
|
+
</script>
|
28
|
+
</head>
|
29
|
+
<body class="jspec" onLoad="runSuites();">
|
30
|
+
<div id="jspec-top"><h2 id="jspec-title">JSpec <em><script>document.write(JSpec.version)</script></em></h2></div>
|
31
|
+
<div id="jspec"><div class="loading"></div></div>
|
32
|
+
<div id="jspec-bottom"></div>
|
33
|
+
</body>
|
34
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
describe 'Utility'
|
3
|
+
describe 'fixture()'
|
4
|
+
it 'should return a files contents'
|
5
|
+
fixture('fixtures/test.html').should.eql '<p>test</p>'
|
6
|
+
fixture('test.html').should.eql '<p>test</p>'
|
7
|
+
fixture('test').should.eql '<p>test</p>'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should cache contents'
|
11
|
+
contents = fixture('test')
|
12
|
+
JSpec.cache['test'].should.eql contents
|
13
|
+
JSpec.cache['test'] = 'foo'
|
14
|
+
fixture('test').should.eql 'foo'
|
15
|
+
delete JSpec.cache['test']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -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
|
+
})
|
@@ -0,0 +1,226 @@
|
|
1
|
+
|
2
|
+
describe 'Grammar'
|
3
|
+
|
4
|
+
it 'should allow "it" spec literal'
|
5
|
+
true.should.be_true
|
6
|
+
end
|
7
|
+
|
8
|
+
n = 10
|
9
|
+
|
10
|
+
it 'should allow literal javascript outside of blocks'
|
11
|
+
n.should.eql 10
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should escape <html> in <p>descriptions</p> and body'
|
15
|
+
'<p></p>'.should.eql '<p></p>'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should parse correctly when "it" is within the body'
|
19
|
+
text = 'Get it at Github'
|
20
|
+
text.should.include 'it'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should parse correctly when "describe" is within the body'
|
24
|
+
text = 'It should work with describe'
|
25
|
+
text.should.include 'describe'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should parse correctly when "end" is within the body'
|
29
|
+
text = 'This should not end the parsing :)'
|
30
|
+
text.should.include 'not'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should parse correctly with "before" and "after" within the body'
|
34
|
+
text = 'This comes before that, which is after the rest'
|
35
|
+
text.should.include 'before'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should allow parens to be optional when no args are passed'
|
39
|
+
true.should.be_true
|
40
|
+
true.should.be_true()
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should not mess up with words like it or append in descriptions'
|
44
|
+
-{ element.append().end() }.should.throw_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should not mess up "end" in strings'
|
48
|
+
'foo end bar'.should.not.eql 'foo }); bar'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should allow semicolons'
|
52
|
+
true.should.be_true;
|
53
|
+
true.should.be_true();
|
54
|
+
true.should.be_true() ;
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should allow parens to be optional with args'
|
58
|
+
'foobar'.should.include 'foo'
|
59
|
+
'rawr'.should.not_include 'foo'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should allow literals without defining variables variables'
|
63
|
+
{}.should.be_an Object
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should allow alternative closure literal'
|
67
|
+
-{ throw 'test' }.should.throw_error
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should allow grammar-less assertions'
|
71
|
+
expect(true).to(be, true)
|
72
|
+
expect([1,2,3]).to(include, 1, 2, 3)
|
73
|
+
expect(true).not_to(be, false)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should allow multi-line expect() assertions'
|
77
|
+
expect(' \
|
78
|
+
foo \
|
79
|
+
bar \
|
80
|
+
').to(include, 'foo', 'bar')
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should allow commenting out of conversions'
|
84
|
+
// -{ throw 'foo' }.should.throw_error
|
85
|
+
// foo.should.not.eql 'bar'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should allow inclusive range literal n..n'
|
89
|
+
1..5.should.eql [1,2,3,4,5]
|
90
|
+
3..4.should.eql [3,4]
|
91
|
+
1..1.should.eql [1]
|
92
|
+
3..1.should.eql [3,2,1]
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should allow snakecase style assertions'
|
96
|
+
'foo'.should_equal('foo')
|
97
|
+
'foo'.should_equal 'foo'
|
98
|
+
'bar'.should_not_equal('foo')
|
99
|
+
'bar'.should_not_equal 'foo'
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should allow dot style assertions'
|
103
|
+
'foo'.should.equal('foo')
|
104
|
+
'foo'.should.equal 'foo'
|
105
|
+
'bar'.should.not.equal('foo')
|
106
|
+
'bar'.should.not.equal 'foo'
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'with nested describe'
|
110
|
+
it 'should work'
|
111
|
+
true.should.be_true
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'nested again'
|
115
|
+
it 'should still work'
|
116
|
+
true.should.be_true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'before / after blocks'
|
122
|
+
before
|
123
|
+
n = 1
|
124
|
+
hits = []
|
125
|
+
hits.push('before')
|
126
|
+
end
|
127
|
+
|
128
|
+
after
|
129
|
+
n = 0
|
130
|
+
hits.push('after')
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should work'
|
134
|
+
n.should.eql 1
|
135
|
+
hits.should.eql ['before']
|
136
|
+
n++
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should persist'
|
140
|
+
n.should.eql 2
|
141
|
+
hits.should.eql ['before']
|
142
|
+
end
|
143
|
+
|
144
|
+
describe 'with nested describe'
|
145
|
+
it 'should be accessable'
|
146
|
+
n.should.eql 1
|
147
|
+
hits.should.eql ['before']
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'before_each / after_each blocks'
|
153
|
+
hits = []
|
154
|
+
|
155
|
+
before_each
|
156
|
+
n = 1
|
157
|
+
hits.push('before_each')
|
158
|
+
end
|
159
|
+
|
160
|
+
after_each
|
161
|
+
o = 2
|
162
|
+
hits.push('after_each')
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should work'
|
166
|
+
n.should.eql 1
|
167
|
+
hits.should.eql ['before_each']
|
168
|
+
n = 2
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should not persist'
|
172
|
+
n.should.eql 1
|
173
|
+
o.should.eql 2
|
174
|
+
hits.should.eql ['before_each', 'after_each', 'before_each']
|
175
|
+
end
|
176
|
+
|
177
|
+
describe 'with nested describe'
|
178
|
+
it 'should be accessable'
|
179
|
+
n.should.eql 1
|
180
|
+
o.should.eql 2
|
181
|
+
hits.should.eql ['before_each', 'after_each', 'before_each', 'after_each', 'before_each']
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should continue hits'
|
185
|
+
hits.should.eql ['before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'after_each', 'before_each']
|
186
|
+
end
|
187
|
+
|
188
|
+
describe 'with more hooks'
|
189
|
+
before_each
|
190
|
+
hits.push('before_each')
|
191
|
+
end
|
192
|
+
|
193
|
+
after_each
|
194
|
+
hits.push('after_each')
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should continue hits, while cascading properly'
|
198
|
+
hits.should.eql ['before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'before_each']
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe 'with multiple hooks'
|
203
|
+
before_each
|
204
|
+
hits = []
|
205
|
+
end
|
206
|
+
|
207
|
+
before_each
|
208
|
+
hits.push('before_each')
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should work'
|
212
|
+
hits.should.eql ['before_each']
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
__END__
|
221
|
+
|
222
|
+
describe 'Grammar'
|
223
|
+
it 'should consider everything below __END__ a comment'
|
224
|
+
|
225
|
+
end
|
226
|
+
end
|
data/spec/spec.jquery.js
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
|
2
|
+
describe 'jQuery'
|
3
|
+
describe 'sandbox()'
|
4
|
+
before
|
5
|
+
dom = sandbox()
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should provide an empty DOM sandbox'
|
9
|
+
dom.prepend('<em>test</em>')
|
10
|
+
dom.should.have_text 'test'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'element() / elements()'
|
15
|
+
it 'should alias jQuery'
|
16
|
+
element.should.be jQuery
|
17
|
+
elements.should.be jQuery
|
18
|
+
end
|
19
|
+
end
|
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
|
+
describe 'matchers'
|
39
|
+
before_each
|
40
|
+
html = '<p><label><em>Save?</em></label> \
|
41
|
+
<select class="save form-select" style="display: none;"> \
|
42
|
+
<option value="0">No</option> \
|
43
|
+
<option value="1">Yes</option> \
|
44
|
+
</select> \
|
45
|
+
<strong>test</strong> \
|
46
|
+
<strong>test</strong> \
|
47
|
+
</p>'
|
48
|
+
elem = $(html)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should fail with pretty print of element'
|
52
|
+
spec = mock_it(function() {
|
53
|
+
elem.should.not.have_tag 'label'
|
54
|
+
})
|
55
|
+
spec.should.have_failure_message(/<label>\s*<em>Save?/i)
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'have_tag / have_one'
|
59
|
+
it 'should check if a single child is present'
|
60
|
+
elem.should.have_tag 'label'
|
61
|
+
elem.should.have_tag 'em'
|
62
|
+
elem.should.have_one 'label'
|
63
|
+
elem.should.not.have_tag 'input'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'have_tags / have_many'
|
68
|
+
it 'should check if more than one child is present'
|
69
|
+
elem.should.have_tags 'option'
|
70
|
+
elem.should.have_many 'option'
|
71
|
+
elem.should.not.have_many 'label'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'have_child'
|
76
|
+
it 'should check if a direct child is present'
|
77
|
+
elem.should.have_child 'label'
|
78
|
+
elem.should.not.have_child 'em'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'have_children'
|
83
|
+
it 'should check if more than one direct children are present'
|
84
|
+
elem.should.have_children 'strong'
|
85
|
+
elem.should.not.have_children 'select'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'have_text'
|
90
|
+
it 'should check for plain text'
|
91
|
+
elem.children('label').should.have_text 'Save?'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'have_value'
|
96
|
+
it 'should check if an element has the given value'
|
97
|
+
elem.find('option').get(1).should.have_value '1'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'have_class'
|
102
|
+
it 'should check if an element has the given class'
|
103
|
+
elem.children('select').should.have_class 'save'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'have_classes'
|
108
|
+
it 'should check if an element has the classes given'
|
109
|
+
elem.children('select').should.have_classes 'save', 'form-select'
|
110
|
+
elem.children('select').should.not.have_classes 'save', 'foo'
|
111
|
+
elem.children('select').should.not.have_classes 'foo', 'save'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'be_visible'
|
116
|
+
it 'should check that an element is not hidden or set to display of none'
|
117
|
+
element('#jspec-report').should.be_visible
|
118
|
+
'#jspec-report'.should.be_visible
|
119
|
+
'<input style="visibility: hidden;"/>'.should.not.be_visible
|
120
|
+
'<input style="display: none;"/>'.should.not.be_visible
|
121
|
+
'<input />'.should.be_visible
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'be_enabled'
|
126
|
+
it 'should check that an element is currently enabled'
|
127
|
+
'<input type="button"/>'.should.be_enabled
|
128
|
+
'<input type="button" disabled="disabled" />'.should.not.be_enabled
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe 'be_BOOLATTR'
|
133
|
+
it 'should check that an element is currently selected, disabled, checked etc'
|
134
|
+
'<input type="button"/>'.should.not.be_disabled
|
135
|
+
'<input type="button" disabled="disabled" />'.should.be_disabled
|
136
|
+
'<option value="foo" selected="selected">Foo</option>'.should.be_selected
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe 'have_ATTR'
|
141
|
+
it 'should check if an attribute exists'
|
142
|
+
'<input type="checkbox"/>'.should.have_type
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should check if an attribute has a specific value'
|
146
|
+
'<input type="checkbox"/>'.should.have_type 'checkbox'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'be_hidden'
|
151
|
+
it 'should check if an element is hidden'
|
152
|
+
'<input style="display: none;" />'.should.be_hidden
|
153
|
+
'<input style="visibility: hidden;" />'.should.be_hidden
|
154
|
+
'<input />'.should.not.be_hidden
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe 'have_attr'
|
159
|
+
before_each
|
160
|
+
elem = '<input type="button" title="some foo" value="Foo" />'
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should check that an element has the given attribute'
|
164
|
+
elem.should.have_attr 'title'
|
165
|
+
elem.should.not_have_attr 'rawr'
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should check that the given attribute has a specific value'
|
169
|
+
elem.should.have_attr 'title', 'some foo'
|
170
|
+
elem.should.not.have_attr 'some', 'rawr'
|
171
|
+
elem.should.not.have_attr 'title', 'bar'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
describe 'jQuery'
|
3
|
+
describe '.ajax()'
|
4
|
+
it "should call the success function when 200"
|
5
|
+
mock_request().and_return('{ foo: "bar" }', 'application/json')
|
6
|
+
var successCalled = false
|
7
|
+
$.ajax({
|
8
|
+
type: "POST",
|
9
|
+
url: 'foo',
|
10
|
+
dataType: 'json',
|
11
|
+
success: function() {
|
12
|
+
successCalled = true
|
13
|
+
}
|
14
|
+
})
|
15
|
+
successCalled.should.be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should call the error function when 404"
|
19
|
+
mock_request().and_return('{ foo: "bar" }', 'application/json', 404)
|
20
|
+
var errorCalled = false
|
21
|
+
$.ajax({
|
22
|
+
type: "POST",
|
23
|
+
url: 'foo',
|
24
|
+
dataType: 'json',
|
25
|
+
error: function() {
|
26
|
+
errorCalled = true
|
27
|
+
}
|
28
|
+
})
|
29
|
+
errorCalled.should.be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.getJSON()'
|
34
|
+
it 'should work with mockRequest'
|
35
|
+
mockRequest().and_return('{ foo : "bar" }')
|
36
|
+
$.getJSON('foo', function(response, statusText){
|
37
|
+
response.foo.should.eql 'bar'
|
38
|
+
statusText.should.eql 'success'
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should work with a json fixture'
|
43
|
+
mockRequest().and_return(fixture('test.json'))
|
44
|
+
$.getJSON('foo', function(response){
|
45
|
+
response.users.tj.email.should.eql 'tj@vision-media.ca'
|
46
|
+
})
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should not invoke callback when response status is 4xx'
|
50
|
+
mockRequest().and_return('foo', 'text/plain', 404)
|
51
|
+
$.getJSON('foo', function(){
|
52
|
+
fail('callback was invoked')
|
53
|
+
})
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.post()'
|
58
|
+
it 'should work with mockRequest'
|
59
|
+
mockRequest().and_return('<p></p>', 'text/html')
|
60
|
+
$.post('foo', function(response){
|
61
|
+
response.should.eql '<p></p>'
|
62
|
+
})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|