raus22-jspec 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/History.rdoc +323 -0
  2. data/Manifest +44 -0
  3. data/README.rdoc +495 -0
  4. data/Rakefile +72 -0
  5. data/bin/jspec +137 -0
  6. data/jspec.gemspec +35 -0
  7. data/lib/images/bg.png +0 -0
  8. data/lib/images/hr.png +0 -0
  9. data/lib/images/loading.gif +0 -0
  10. data/lib/images/sprites.bg.png +0 -0
  11. data/lib/images/sprites.png +0 -0
  12. data/lib/images/vr.png +0 -0
  13. data/lib/jspec.css +145 -0
  14. data/lib/jspec.jquery.js +64 -0
  15. data/lib/jspec.js +1468 -0
  16. data/server/browsers.rb +16 -0
  17. data/server/server.rb +103 -0
  18. data/spec/async +1 -0
  19. data/spec/jquery-1.3.1.js +4241 -0
  20. data/spec/server.html +23 -0
  21. data/spec/spec.grammar-less.js +34 -0
  22. data/spec/spec.grammar.js +179 -0
  23. data/spec/spec.html +27 -0
  24. data/spec/spec.jquery.js +166 -0
  25. data/spec/spec.js +119 -0
  26. data/spec/spec.matchers.js +382 -0
  27. data/spec/spec.rhino.js +12 -0
  28. data/spec/spec.shared-behaviors.js +51 -0
  29. data/spec/spec.utils.js +138 -0
  30. data/templates/default/History.rdoc +4 -0
  31. data/templates/default/README.rdoc +29 -0
  32. data/templates/default/lib/yourlib.core.js +2 -0
  33. data/templates/default/spec/spec.core.js +8 -0
  34. data/templates/default/spec/spec.html +20 -0
  35. data/templates/rhino/History.rdoc +4 -0
  36. data/templates/rhino/README.rdoc +29 -0
  37. data/templates/rhino/lib/yourlib.core.js +2 -0
  38. data/templates/rhino/spec/spec.core.js +8 -0
  39. data/templates/rhino/spec/spec.js +7 -0
  40. data/templates/server/History.rdoc +4 -0
  41. data/templates/server/README.rdoc +29 -0
  42. data/templates/server/lib/yourlib.core.js +2 -0
  43. data/templates/server/spec/spec.core.js +8 -0
  44. data/templates/server/spec/spec.html +15 -0
  45. metadata +120 -0
@@ -0,0 +1,23 @@
1
+ <html>
2
+ <head>
3
+ <script src="jquery-1.3.1.js"></script>
4
+ <script src="jspec.js"></script>
5
+ <script src="jspec.jquery.js"></script>
6
+ <script src="spec.grammar-less.js"></script>
7
+ <script>
8
+ function runSuites() {
9
+ JSpec
10
+ .exec('spec.grammar.js')
11
+ .exec('spec.js')
12
+ .exec('spec.matchers.js')
13
+ .exec('spec.utils.js')
14
+ .exec('spec.shared-behaviors.js')
15
+ .exec('spec.jquery.js')
16
+ .run()
17
+ .reportToServer()
18
+ }
19
+ </script>
20
+ </head>
21
+ <body class="jspec" onLoad="runSuites();">
22
+ </body>
23
+ </html>
@@ -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,179 @@
1
+
2
+ describe 'Grammar'
3
+
4
+ it 'should allow "it" spec literal'
5
+ true.should.be_true
6
+ end
7
+
8
+ n = 10
9
+ it 'should allow literal javascript outside of blocks'
10
+ n.should.eql 10
11
+ end
12
+
13
+ it 'should allow parens to be optional when no args are passed'
14
+ true.should.be_true
15
+ true.should.be_true()
16
+ end
17
+
18
+ it 'should allow parens to be optional with args'
19
+ 'foobar'.should.include 'foo'
20
+ 'rawr'.should.not_include 'foo'
21
+ end
22
+
23
+ it 'should allow literals without defining variables variables'
24
+ {}.should.be_an Object
25
+ end
26
+
27
+ it 'should allow alternative closure literal'
28
+ -{ throw 'test' }.should.throw_error
29
+ end
30
+
31
+ it 'should allow grammar-less assertions'
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')
42
+ end
43
+
44
+ it 'should allow commenting out of conversions'
45
+ // -{ throw 'foo' }.should.throw_error
46
+ // foo.should.not.eql 'bar'
47
+ end
48
+
49
+ it 'should allow inclusive range literal n..n'
50
+ 1..5.should.eql [1,2,3,4,5]
51
+ 3..4.should.eql [3,4]
52
+ 1..1.should.eql [1]
53
+ 3..1.should.eql [3,2,1]
54
+ end
55
+
56
+ it 'should allow snakecase style assertions'
57
+ 'foo'.should_equal('foo')
58
+ 'foo'.should_equal 'foo'
59
+ 'bar'.should_not_equal('foo')
60
+ 'bar'.should_not_equal 'foo'
61
+ end
62
+
63
+ it 'should allow dot style assertions'
64
+ 'foo'.should.equal('foo')
65
+ 'foo'.should.equal 'foo'
66
+ 'bar'.should.not.equal('foo')
67
+ 'bar'.should.not.equal 'foo'
68
+ end
69
+
70
+ describe 'with nested describe'
71
+ it 'should work'
72
+ true.should.be_true
73
+ end
74
+
75
+ describe 'nested again'
76
+ it 'should still work'
77
+ true.should.be_true
78
+ end
79
+ end
80
+ end
81
+
82
+ describe 'before / after blocks'
83
+ before
84
+ n = 1
85
+ hits = []
86
+ hits.push('before')
87
+ end
88
+
89
+ after
90
+ n = 0
91
+ hits.push('after')
92
+ end
93
+
94
+ it 'should work'
95
+ n.should.eql 1
96
+ hits.should.eql ['before']
97
+ n++
98
+ end
99
+
100
+ it 'should persist'
101
+ n.should.eql 2
102
+ hits.should.eql ['before']
103
+ end
104
+
105
+ describe 'with nested describe'
106
+ it 'should be accessable'
107
+ n.should.eql 1
108
+ hits.should.eql ['before']
109
+ end
110
+ end
111
+ end
112
+
113
+ describe 'before_each / after_each blocks'
114
+ hits = []
115
+
116
+ before_each
117
+ n = 1
118
+ hits.push('before_each')
119
+ end
120
+
121
+ after_each
122
+ o = 2
123
+ hits.push('after_each')
124
+ end
125
+
126
+ it 'should work'
127
+ n.should.eql 1
128
+ hits.should.eql ['before_each']
129
+ n = 2
130
+ end
131
+
132
+ it 'should not persist'
133
+ n.should.eql 1
134
+ o.should.eql 2
135
+ hits.should.eql ['before_each', 'after_each', 'before_each']
136
+ end
137
+
138
+ describe 'with nested describe'
139
+ it 'should be accessable'
140
+ n.should.eql 1
141
+ o.should.eql 2
142
+ hits.should.eql ['before_each', 'after_each', 'before_each', 'after_each', 'before_each']
143
+ end
144
+
145
+ it 'should continue hits'
146
+ hits.should.eql ['before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'after_each', 'before_each']
147
+ end
148
+
149
+ describe 'with more hooks'
150
+ before_each
151
+ hits.push('before_each')
152
+ end
153
+
154
+ after_each
155
+ hits.push('after_each')
156
+ end
157
+
158
+ it 'should continue hits, while cascading properly'
159
+ hits.should.eql ['before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'after_each', 'before_each', 'before_each']
160
+ end
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
176
+ end
177
+ end
178
+
179
+ end
@@ -0,0 +1,27 @@
1
+ <html>
2
+ <head>
3
+ <link type="text/css" rel="stylesheet" href="../lib/jspec.css" />
4
+ <script src="jquery-1.3.1.js"></script>
5
+ <script src="../lib/jspec.js"></script>
6
+ <script src="../lib/jspec.jquery.js"></script>
7
+ <script src="spec.grammar-less.js"></script>
8
+ <script>
9
+ function runSuites() {
10
+ JSpec
11
+ .exec('spec.grammar.js')
12
+ .exec('spec.js')
13
+ .exec('spec.matchers.js')
14
+ .exec('spec.utils.js')
15
+ .exec('spec.shared-behaviors.js')
16
+ .exec('spec.jquery.js')
17
+ .run()
18
+ .report()
19
+ }
20
+ </script>
21
+ </head>
22
+ <body class="jspec" onLoad="runSuites();">
23
+ <div id="jspec-top"><h2 id="jspec-title">JSpec <em><script>document.write(JSpec.version)</script></em></h2></div>
24
+ <div id="jspec"><div class="loading"></div></div>
25
+ <div id="jspec-bottom"></div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,166 @@
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 'async'
15
+ it 'should load mah cookies (textfile)'
16
+ $.post('async', function(text){
17
+ text.should_eql 'cookies!'
18
+ })
19
+ end
20
+
21
+ it 'should load mah cookies twice (ensure multiple async requests work)'
22
+ $.post('async', function(text){
23
+ text.should.eql 'cookies!'
24
+ })
25
+ $.post('async', function(text){
26
+ text.should.not.eql 'rawr'
27
+ })
28
+ end
29
+ end
30
+
31
+ describe 'matchers'
32
+ before_each
33
+ html = '<p><label><em>Save?</em></label> \
34
+ <select class="save form-select" style="display: none;"> \
35
+ <option value="0">No</option> \
36
+ <option value="1">Yes</option> \
37
+ </select> \
38
+ <strong>test</strong> \
39
+ <strong>test</strong> \
40
+ </p>'
41
+ elem = $(html)
42
+ end
43
+
44
+ it 'should fail with pretty print of element'
45
+ elem.should.not.have_tag 'label'
46
+ end
47
+
48
+ describe 'have_tag / have_one'
49
+ it 'should check if a single child is present'
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'
54
+ end
55
+ end
56
+
57
+ describe 'have_tags / have_many'
58
+ it 'should check if more than one child is present'
59
+ elem.should.have_tags 'option'
60
+ elem.should.have_many 'option'
61
+ elem.should.not.have_many 'label'
62
+ end
63
+ end
64
+
65
+ describe 'have_child'
66
+ it 'should check if a direct child is present'
67
+ elem.should.have_child 'label'
68
+ elem.should.not.have_child 'em'
69
+ end
70
+ end
71
+
72
+ describe 'have_children'
73
+ it 'should check if more than one direct children are present'
74
+ elem.should.have_children 'strong'
75
+ elem.should.not.have_children 'select'
76
+ end
77
+ end
78
+
79
+ describe 'have_text'
80
+ it 'should check for plain text'
81
+ elem.children('label').should.have_text 'Save?'
82
+ end
83
+ end
84
+
85
+ describe 'have_value'
86
+ it 'should check if an element has the given value'
87
+ elem.find('option').get(1).should.have_value '1'
88
+ end
89
+ end
90
+
91
+ describe 'have_class'
92
+ it 'should check if an element has the given class'
93
+ elem.children('select').should.have_class 'save'
94
+ end
95
+ end
96
+
97
+ describe 'have_classes'
98
+ it 'should check if an element has the classes given'
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'
102
+ end
103
+ end
104
+
105
+ describe 'be_visible'
106
+ it 'should check that an element is not hidden or set to display of none'
107
+ element('#jspec-report').should.be_visible
108
+ '#jspec-report'.should.be_visible
109
+ '<input style="visibility: hidden;"/>'.should.not.be_visible
110
+ '<input style="display: none;"/>'.should.not.be_visible
111
+ '<input />'.should.be_visible
112
+ end
113
+ end
114
+
115
+ describe 'be_enabled'
116
+ it 'should check that an element is currently enabled'
117
+ '<input type="button"/>'.should.be_enabled
118
+ '<input type="button" disabled="disabled" />'.should.not.be_enabled
119
+ end
120
+ end
121
+
122
+ describe 'be_BOOLATTR'
123
+ it 'should check that an element is currently selected, disabled, checked etc'
124
+ '<input type="button"/>'.should.not.be_disabled
125
+ '<input type="button" disabled="disabled" />'.should.be_disabled
126
+ '<option value="foo" selected="selected">Foo</option>'.should.be_selected
127
+ end
128
+ end
129
+
130
+ describe 'have_ATTR'
131
+ it 'should check if an attribute exists'
132
+ '<input type="checkbox"/>'.should.have_type
133
+ end
134
+
135
+ it 'should check if an attribute has a specific value'
136
+ '<input type="checkbox"/>'.should.have_type 'checkbox'
137
+ end
138
+ end
139
+
140
+ describe 'be_hidden'
141
+ it 'should check if an element is hidden'
142
+ '<input style="display: none;" />'.should.be_hidden
143
+ '<input style="visibility: hidden;" />'.should.be_hidden
144
+ '<input />'.should.not.be_hidden
145
+ end
146
+ end
147
+
148
+ describe 'have_attr'
149
+ before_each
150
+ elem = '<input type="button" title="some foo" value="Foo" />'
151
+ end
152
+
153
+ it 'should check that an element has the given attribute'
154
+ elem.should.have_attr 'title'
155
+ elem.should.not_have_attr 'rawr'
156
+ end
157
+
158
+ it 'should check that the given attribute has a specific value'
159
+ elem.should.have_attr 'title', 'some foo'
160
+ elem.should.not.have_attr 'some', 'rawr'
161
+ elem.should.not.have_attr 'title', 'bar'
162
+ end
163
+ end
164
+ end
165
+
166
+ end
@@ -0,0 +1,119 @@
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 saying an error was throw'
41
+ -{ throw 'foo' }.should.not.throw_error
42
+ end
43
+
44
+ it 'should fail saying which error has been thrown'
45
+ -{ throw 'foo' }.should.throw_error 'bar'
46
+ end
47
+
48
+ it 'should fail saying no error was thrown'
49
+ -{ }.should.throw_error 'foo'
50
+ end
51
+
52
+ it 'should fail saying no error matching was thrown'
53
+ -{ throw 'bar' }.should.throw_error(/foo/)
54
+ end
55
+
56
+ it 'should fail saying no error matching foo should be thrown'
57
+ -{ throw 'foo' }.should.not.throw_error(/foo/)
58
+ end
59
+
60
+ it 'should fail with constructor name'
61
+ function Foo(){}
62
+ function Bar(){}
63
+ Bar.prototype.toString = function(){ return 'Bar error: oh no' }
64
+ -{ throw new Bar }.should.throw_error Foo
65
+ end
66
+
67
+ it 'should fail with function body string'
68
+ -{ 'foo' }.should.not.include 'foo'
69
+ end
70
+
71
+ it 'should fail with constructor name'
72
+ function Foo(){ this.toString = function(){ return '<Foo>' }}
73
+ foo = new Foo
74
+ foo.should.not.be_an_instance_of Foo
75
+ end
76
+
77
+ it 'should fail with message of first failure'
78
+ true.should.be_true
79
+ 'bar'.should.match(/foo/gm)
80
+ 'bar'.should.include 'foo'
81
+ end
82
+
83
+ it 'should fail with list'
84
+ ['foo', 'bar'].should.include 'foo', 'car'
85
+ end
86
+
87
+ it 'should catch exceptions throw within specs'
88
+ throw new Error('Oh noes!')
89
+ end
90
+
91
+ it 'should catch improper exceptions'
92
+ throw 'oh noes'
93
+ end
94
+
95
+ it 'should catch proper exceptions'
96
+ iDoNotExist.neitherDoI()
97
+ end
98
+
99
+ end
100
+
101
+ describe 'Contexts'
102
+ before
103
+ JSpec.context = { iLike : 'cookies' }
104
+ end
105
+
106
+ after
107
+ JSpec.context = null
108
+ end
109
+
110
+ it 'should be replaceable'
111
+ iLike.should.equal 'cookies'
112
+ end
113
+ end
114
+
115
+ describe 'Misc'
116
+ it 'requires implementation'
117
+ end
118
+ end
119
+