raus22-jspec 2.0.4

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.
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,323 @@
1
+
2
+ === 2.0.3 / 2009-05-15
3
+
4
+ * Table should span full width
5
+ (Very week release I know, but improperly styled things bug me :) )
6
+
7
+ === 2.0.2 / 2009-05-11
8
+
9
+ * Added rails integration link http://github.com/bhauman/jspec-rails
10
+ * Changed; puts() now displays constructor name when available
11
+ * Fixed Terminal output which was not displaying due to a recent commit
12
+ * fixed IE bug : DOM elements don't have valueOf() method
13
+
14
+ === 2.0.1 / 2009-05-01
15
+
16
+ * Added better failure messages for throw_error matcher
17
+ * Renamed print() to puts() [#108]
18
+
19
+ === 2.0.0 / 2009-04-27
20
+
21
+ * Added DOM loading indicator [#105]
22
+ * Added wait() helper for additional async support
23
+ * Added shared behavior support using should_behave_like('Another Suite')
24
+ * Added CSS body toggling [#1]
25
+ * Added receive matcher for Proxy Assertins
26
+ * Added grammar-less support
27
+ * Added an_instance_of() helper
28
+ * Removed .this literal
29
+ * Removed deprecated be_a_TYPE_input matchers
30
+
31
+ * Added ProxyAssertion
32
+ * Added select() util
33
+ * Added does() util for report-less assertions
34
+ * Added find() util
35
+ * Added JSpec.contentsOf()
36
+ * Added matchers to body evaluation [#90]
37
+
38
+ === 1.1.7 / 2009-04-22
39
+
40
+ * Removed trailing commas causing issues with IE (what a suprise ;) )
41
+
42
+ === 1.1.6 / 2009-04-22
43
+
44
+ * Fixed typo in requires()
45
+ * Added expect()
46
+
47
+ === 1.1.5 / 2009-04-17
48
+
49
+ * Strengthened specs for cascading hooks
50
+ * Fixed cascading hooks
51
+
52
+ === 1.1.4 / 2009-04-17
53
+
54
+ * Added rhino and server template files
55
+ * Added JSpec.hasXhr()
56
+ * Added JSpec.xhr()
57
+ * Added Ruby javascript testing server
58
+ * Added support for options passed to run()
59
+ * Added failuresOnly for Terminal formatter
60
+ * Added terminal assertion graphs
61
+ * Addec color() utility
62
+ * Added main.puts() since we use print() as a utility
63
+ * Added rhino support
64
+ * Added fail() utility function
65
+ * Added JSpec.Assertion
66
+ * Added normalizeMatcherMessage()
67
+ * Added normalizeMatcherBody()
68
+ * Added have_classes [#19]
69
+ * Added extend() utility
70
+ * Added be_an_instance_of matcher
71
+ * Added constructor checking support for throw_error matcher [#72]
72
+ * Added file support for exception messages, making them much easier to debug
73
+ * Added catching of exceptions throw within specs [#46]
74
+ * Changed; executable aborts when template does not exist
75
+ * Changed; matchers now normalized upon creation, accepts function, hash, or string.
76
+ * Changed be() matcher to be strict [#57]
77
+ * Changed error() to conditionally show line number when available
78
+ * Renamed Jspec.addSuite to JSpec.describe and Suite#addSpec to Suite#it
79
+ * Refactored be_a_TYPE_input matchers so that the deprication warning is logged only when calling the method
80
+ * Fixed JSpec.requires() now works with latest version of JSpec.error()
81
+ * Fixed error() now displays exceptions throw that do not respond to .message
82
+ * Fixed commenting bug [#37]
83
+ * Removed JSpec.main, now just using local main
84
+
85
+ === 1.1.3 / 2009-04-14
86
+
87
+ * Removed /test used for the executable, causing gem to fail building
88
+
89
+ === 1.1.2 / 2009-04-14
90
+
91
+ * Added `jspec update` sub-command [#63]
92
+
93
+ === 1.1.1 / 2009-04-12
94
+
95
+ * Added gemspec
96
+
97
+ === 1.1.0 / 2009-04-12
98
+
99
+ * jspec executable fully functional
100
+
101
+ === 1.0.4 / 2009-04-09
102
+
103
+ * Added `jspec bind`
104
+ * Added `jspec run`
105
+ * Added `jspec init`
106
+ * Added `jspec` executable
107
+ * Added gemspec and manifest
108
+ * Added command-line usage docs
109
+ * Added custom matchers documentation
110
+ * Removed double negation
111
+
112
+ === 1.0.3 / 2009-04-08
113
+
114
+ * Added have_prop matcher, have_property is now strict [#56]
115
+
116
+ === 1.0.2 / 2009-04-08
117
+
118
+ * Added be_selected, be_checked matchers
119
+ * Added string support to each() each('some foo bar', ...)
120
+ * Added have_ATTR matchers [#51]
121
+ * Deprected be_a_TYPE_input matchers [#50]
122
+
123
+ === 1.0.1 / 2009-04-07
124
+
125
+ * Added have_property matcher [#53]
126
+
127
+ === 1.0.0 / 2009-04-06
128
+
129
+ * Added option() which gives the query string option precedence [#39]
130
+ * Changed; Using JSpec.options.formatter not JSpec.formatter [#44]
131
+ * Fixed Console formatter, now displays nested suites
132
+ * Check out http://visionmedia.github.com/jspec for additional documentation!
133
+
134
+ === 0.9.6 / 2009-04-03
135
+
136
+ * Added nesting support
137
+ * Added printing of nested specs
138
+ * Added assertion graphs to DOM formatter
139
+ * Refactored preprocess()
140
+ * Refactored most of the specs
141
+ * Renamed preProcess() to preprocess()
142
+ * Removed running of a single suite via ?suite= for now
143
+
144
+ === 0.9.5 / 2009-04-02
145
+
146
+ * Added support for printing of function bodies and regexps [#27]
147
+ * Added support for strings / regexp with should_throw_error [#26]
148
+ * Added have_within matcher
149
+ * Added have_at_most matcher
150
+ * Added have_at_least matcher
151
+ * Added have matcher [#24]
152
+
153
+ === 0.9.4 / 2009-04-02
154
+
155
+ * Added be_a_TYPE_input matchers (be_a_checkbox_input, be_a_text_input, etc)
156
+ * Added be_disabled matcher [#21]
157
+ * Added be_enabled matcher [#20]
158
+ * Refactored be_visible and be_hidden with $(elem).is()
159
+
160
+ === 0.9.2 / 2009-04-02
161
+
162
+ * Added support for multi-arg failure messages [#2]
163
+ * Better printing of jQuery objects [#15]
164
+
165
+ === 0.9.1 / 2009-04-02
166
+
167
+ * Added support for dotted negation of assertions (foo.should.not.equal bar)
168
+ * Added support for dot-style assertions [#17] (foo.should_not.equal bar)
169
+
170
+ === 0.9.0 / 2009-04-01
171
+
172
+ * Added spec for strip()
173
+ * Added strip()
174
+ * Added any() util
175
+ * Added new improved include matcher
176
+ * Added have_many and have_one matchers
177
+ * Added have_attr matcher [#14]
178
+ * Added map() util
179
+ * Added inject() util
180
+ * Added escape() util
181
+ * Added recursive array and object printing
182
+ * Added DOM formatter option failuresOnly
183
+ * Added support for running of a single squite via ?suite=...
184
+ * Added query() util
185
+ * Added last() util
186
+ * Added be_within matcher, accepts a range literal
187
+ * Added inclusive range literal n..n
188
+ * Added row hover
189
+ * Refactored range()
190
+ * Refactored setMessage()
191
+ * Refactored hash()
192
+ * Changed; preprocessor passing array of args (multi-arg matcher support)
193
+ * Changed jQuery to $ for internal usage
194
+
195
+ === 0.8.0 / 2009-02-27
196
+
197
+ * Added a new style for the DOM formatter (not finished yet)
198
+
199
+ === 0.7.0 / 2009-02-27
200
+
201
+ * Added Console formatter (anything implementing the console object. Firebug, Safari 4, etc)
202
+ * Added JSpec.options.profile for optional profiling of specs
203
+ * Added this. literal alternative (view readme)
204
+ * Moved formatters into JSpec.formatters
205
+ * Added error() util
206
+ * Added savings raketask
207
+ * Fixed parse error bug in Safari 4
208
+
209
+ === 0.6.3 / 2009-02-26
210
+
211
+ * Added minification for jspec.jquery.js when packaging before release
212
+ * Added compression of css when packaging before release
213
+
214
+ === 0.6.2 / 2009-02-26
215
+
216
+ * Changed; using $ in jspec.jquery.js for JSpec, take that jQuery ;)
217
+ * Added addMatchers, print, hash, and each as 'utility functions' this allows
218
+ JSpec to do each(...) internally instead of JSpec.each(...), while still preventing
219
+ pollution of the global scope.
220
+
221
+ === 0.6.1 / 2009-02-26
222
+
223
+ * Added closrue literal -{ (view README)
224
+ * Added option to DOM formatter, now allows you to specify which element id to output to
225
+
226
+ === 0.6.0 / 2009-02-24
227
+
228
+ * Added JSpec.hash
229
+ * Added be_null matcher
230
+ * Allow recursive composite matching using should_eql and should_not_eql
231
+ For example [1, 2, [3]].should_eql([1, 2, [3]]) is true, works with object
232
+ 'hashes' as well.
233
+
234
+ === 0.5.1 / 2009-02-24
235
+
236
+ * Damn auto-release messed up
237
+
238
+ === 0.5.0 / 2009-02-24
239
+
240
+ * Added async support for jQuery
241
+ * Added JSpec.requires for dependencies
242
+ * Added JSpec.throw
243
+ * Added JSpec.runSpec
244
+ * Refactored jspec.jquery.js
245
+ * Fixed evalBody exceptions, previously was not showing exception message
246
+ * Fixed bug of JSpec interpreting // in a string such as http:// to be a comment.
247
+
248
+ === 0.4.1 / 2009-02-22
249
+
250
+ * Added elements() alias of element()
251
+ * Added support for string passed to runSuite; runSuite('Matchers') is the same as
252
+ runSuite(JSpec.suites['Matchers']).
253
+ * Fixed some documentation
254
+
255
+ === 0.4.0 / 2009-02-20
256
+
257
+ * Added comment literal (//)
258
+ * Added pre-processor for convering matchers.
259
+ For example 'test'.should_be_true becomes JSpec.match('test', 'should_be', 'true'),
260
+ preventing pollution of core prototypes.
261
+
262
+ === 0.3.2 / 2009-02-19
263
+
264
+ * Added TM bundle (go checkout my jspec.tmbundle repo on github)
265
+ * Renamed have_length_of to have_length
266
+
267
+ === 0.3.1 / 2009-02-19
268
+
269
+ * Added jquery js to package
270
+
271
+ === 0.3.0 / 2009-02-19
272
+
273
+ * Added JSpec.match
274
+ * Added options to report() which are passed to formatter
275
+ * Added sandbox helpers (reg / jquery)
276
+ * Added have_child and have_children
277
+ * Added have_tag and have_tags
278
+ * Changed exec to only load / eval file
279
+ * Fixed parser token issue, was previously matching things like end() as literal end
280
+
281
+ === 0.2.3 / 2009-02-18
282
+
283
+ * Changed test dir to spec
284
+ * Changed test.js to core.spec.js
285
+
286
+ === 0.2.2 / 2009-02-18
287
+
288
+ * Added contexts
289
+
290
+ === 0.2.0 / 2009-02-18
291
+
292
+ * Added release rake task
293
+ * Added package with minified alternative
294
+
295
+ === 0.1.0 / 2009-02-18
296
+
297
+ * Added new sexy syntax (warning: you will have to re-write your specs)
298
+ * Added pre-processor for optional matcher parens
299
+ * Added several new matchers
300
+ * Added matcher aliasing
301
+ * Added simple matcher declarations
302
+ * Added __END__
303
+ * Added yet-to-be-implemented specs
304
+ * Added loading of suites via JSpec.load
305
+
306
+ === 0.0.4 / 2008-11-03
307
+
308
+ * Added ability to pass only a description to it(), meaning not yet implemented
309
+
310
+ === 0.0.3 / 2008-10-28
311
+
312
+ * Added should_fail
313
+ * Added should_match
314
+ * Added should_not_match
315
+ * Added should_be and should_not_be
316
+
317
+ === 0.0.2 / 2008-10-28
318
+
319
+ * Fixed typo in documentation for pointing to the master repo
320
+
321
+ === 0.0.1 / 2008-10-28
322
+
323
+ * Initial release
@@ -0,0 +1,44 @@
1
+ bin/jspec
2
+ History.rdoc
3
+ jspec.gemspec
4
+ lib/images/bg.png
5
+ lib/images/hr.png
6
+ lib/images/loading.gif
7
+ lib/images/sprites.bg.png
8
+ lib/images/sprites.png
9
+ lib/images/vr.png
10
+ lib/jspec.css
11
+ lib/jspec.jquery.js
12
+ lib/jspec.js
13
+ Manifest
14
+ Rakefile
15
+ README.rdoc
16
+ server/browsers.rb
17
+ server/server.rb
18
+ spec/async
19
+ spec/jquery-1.3.1.js
20
+ spec/server.html
21
+ spec/spec.grammar-less.js
22
+ spec/spec.grammar.js
23
+ spec/spec.html
24
+ spec/spec.jquery.js
25
+ spec/spec.js
26
+ spec/spec.matchers.js
27
+ spec/spec.rhino.js
28
+ spec/spec.shared-behaviors.js
29
+ spec/spec.utils.js
30
+ templates/default/History.rdoc
31
+ templates/default/lib/yourlib.core.js
32
+ templates/default/README.rdoc
33
+ templates/default/spec/spec.core.js
34
+ templates/default/spec/spec.html
35
+ templates/rhino/History.rdoc
36
+ templates/rhino/lib/yourlib.core.js
37
+ templates/rhino/README.rdoc
38
+ templates/rhino/spec/spec.core.js
39
+ templates/rhino/spec/spec.js
40
+ templates/server/History.rdoc
41
+ templates/server/lib/yourlib.core.js
42
+ templates/server/README.rdoc
43
+ templates/server/spec/spec.core.js
44
+ templates/server/spec/spec.html
@@ -0,0 +1,495 @@
1
+
2
+ = JSpec
3
+
4
+ JSpec is a minimalistic JavaScript behavior driven development framework,
5
+ providing simple installation, extremely low learning curve, absolutely no pollution
6
+ to core prototypes, async request support, and incredibly sexy syntax, tons of matchers
7
+ and much more.
8
+
9
+ == Features
10
+
11
+ * Highly readable
12
+ * Framework / DOM independent
13
+ * Rhino support
14
+ * Async support
15
+ * Ruby JavaScript testing server
16
+ * Nested describes
17
+ * Does not pollute core object prototypes
18
+ * Cascading before/after/before_each/after_each hooks
19
+ * Extremely simple and intuitive matcher declaration
20
+ * Over 45 core matchers
21
+ * Allows parens to be optional when using matchers to increase readability
22
+ * Several helpful formatters (DOM, Console, Terminal, ...)
23
+ * Assertion graphs displaying how many, and which assertions pass or failed
24
+ * Default / customizable evaluation contexts
25
+ * DOM sandbox support
26
+ * Great looking default DOM theme
27
+ * `jspec` command-line utility for auto-running specs, and initializing project templates
28
+ * Proxy or 'Spy' assertions
29
+ * Shared behaviors
30
+ * Profiling
31
+ * Rails Integration (http://github.com/bhauman/jspec-rails)
32
+ * Tiny (15 kb compressed, 1600-ish LOC)
33
+
34
+ == Installation
35
+
36
+ Simply download JSpec and include JSpec.css and JSpec.js in your markup.
37
+ Head over to the downloads section on Github, clone this public repo, or
38
+ add JSpec as a git submodule with in your project. Alternatively JSpec is
39
+ also available as a Ruby Gem (though this is not required), which also
40
+ provides the `jspec` executable. To install as a gem simply:
41
+ $ sudo gem install visionmedia-jspec
42
+
43
+ At which point you may:
44
+ $ jspec init myproject
45
+
46
+ JSpec scripts should NOT be referenced via the <script> tag, they should be
47
+ loaded using the exec method (unless you are using the grammar-less alternative).
48
+ Below is an example:
49
+
50
+ ...
51
+ <script>
52
+ function runSuites() {
53
+ JSpec
54
+ .exec('spec.core.js')
55
+ .exec('spec.jquery.js')
56
+ .run({ failuresOnly : true })
57
+ .report()
58
+ }
59
+ </script>
60
+ <body onLoad="runSuites()">
61
+ ...
62
+
63
+ You may optionally want to use sources in the /pkg directory
64
+ for your project, since it includes compressed alternatives generated
65
+ each release.
66
+
67
+ == Example
68
+
69
+ describe 'ShoppingCart'
70
+ before_each
71
+ cart = new ShoppingCart
72
+ end
73
+
74
+ describe 'addProducts'
75
+ it 'should add several products'
76
+ cart.addProduct('cookie')
77
+ cart.addProduct('icecream')
78
+ cart.should.have 2, 'products'
79
+ end
80
+ end
81
+
82
+ describe 'checkout'
83
+ it 'should throw an error when checking out with no products'
84
+ -{ cart.clear().checkout() }.should.throw_error EmptyCart
85
+ end
86
+ end
87
+ end
88
+
89
+ == Grammar-less Example
90
+
91
+ JSpec's grammar is optional, you may also use the equivalent grammar-less
92
+ alternative below using pure JavaScript (when using the JSpec grammar you
93
+ may also use grammar-less assertions):
94
+
95
+ JSpec.describe('ShoppingCart', function(){
96
+ before_each(function{
97
+ cart = new ShoppingCart
98
+ })
99
+
100
+ describe('addProducts', function(){
101
+ it ('should add several products', function(){
102
+ cart.addProducts('cookie')
103
+ cart.addProducts('icecream')
104
+ expect(cart).to(have, 2, 'products')
105
+ })
106
+ })
107
+
108
+ describe('checkout', function(){
109
+ it ('should throw an error when checking out with no products', function(){
110
+ expect(function(){ cart.clear().checkout() }).to(throw_error, EmptyCart)
111
+ })
112
+ })
113
+ })
114
+
115
+ == Options
116
+
117
+ You may alter the way JSpec operates by assigning options via the
118
+ JSpec.options hash, by passing string-based option values via the
119
+ query string, or passing a hash to run(). For example
120
+ JSpec.options.failuresOnly = true, and ?failuresOnly=1 will both work.
121
+
122
+ * profile {bool} when enabled, uses console.time() in order to display performance information in your console log as specs are completed. (DOM, Console)
123
+ * failuresOnly {bool} displays only failing specs, making them quick to discover and fix (DOM, Terminal)
124
+ * reportToId {string} an element id to report to when using the DOM formatter (DOM)
125
+
126
+ == Matchers
127
+
128
+ * Core
129
+
130
+ - equal, be ===
131
+ - be_a, be_an have constructor of x
132
+ - be_an_instance_of instanceof x
133
+ - be_at_least >=
134
+ - be_at_most <=
135
+ - be_null == null
136
+ - be_empty length of 0
137
+ - be_true == true
138
+ - be_false == false
139
+ - be_type be type of x
140
+ - be_greater_than >
141
+ - be_less_than <
142
+ - throw_error should throw an error, optionally supply the error string for comparison
143
+ - have object should have n of property (person.should.have(2, 'pets'))
144
+ - have_at_least object should have at least n of property
145
+ - have_at_most object should have a maximum n of property
146
+ - have_within object should have within n..n of property (person.should.have_within(1..3, 'pets')
147
+ - have_length length of n
148
+ - have_prop object should have property x, optionally supplying an expected value
149
+ - have_property strict version of have_prop
150
+ - be_within checks if n is within the range passed
151
+ - include include substring, array element, or hash key
152
+ - match string should match regexp x
153
+ - respond_to property x should be a function
154
+ - eql matches simple literals (strings, numbers) with ==
155
+ However composites like arrays or 'hashes' are recursively matched,
156
+ meaning that [1, 2, [3]].should_eql([1, 2, [3]]) will be true.
157
+
158
+ * jQuery
159
+
160
+ - have_tag, have_one have exactly one tag
161
+ - have_tags, have_many have more than one tag
162
+ - have_child have exactly one child
163
+ - have_children have more than one child
164
+ - have_text have plain text
165
+ - have_attr have an attribute, with optional value
166
+ - have_type
167
+ - have_id
168
+ - have_title
169
+ - have_alt
170
+ - have_href
171
+ - have_rel
172
+ - have_rev
173
+ - have_name
174
+ - have_target
175
+ - have_value
176
+ - have_class
177
+ - have_classes
178
+ - be_visible
179
+ - be_hidden
180
+ - be_enabled
181
+ - be_disabled
182
+ - be_selected
183
+ - be_checked
184
+
185
+ == Proxy Assertions
186
+
187
+ Proxy or 'Spy' assertions allow you to assert that a method is called n number
188
+ of times, with x arguments, returning x value. For example:
189
+
190
+ person = { getPets : function(species){ return ['izzy'] }}
191
+ person.should.receive('getPets', 'twice').with_args(an_instance_of(String))and_return(['izzy'])
192
+ person.getPets('dog') // This will pass
193
+ person.getPets() // This will fail because we asked an instance of String
194
+
195
+ This is a useful mechanism for testing the behavior of your object, as well as
196
+ how other methods may interact with it. Below is another example:
197
+
198
+ array = ['foo', 'bar']
199
+ array.should.receive('toString').and_return('foo,bar')
200
+ 'array: ' + array // This line causes the spec to pass due to calling toString()
201
+
202
+ For more examples view spec/spec.matchers.js
203
+
204
+ == Helpers
205
+
206
+ * Core
207
+
208
+ - wait delay execution of a spec for the duration set (async support)
209
+ - an_instance_of used in conjunction with the 'receive' matcher
210
+
211
+ * jQuery
212
+
213
+ - sandbox used to generate new DOM sandbox, using jQuery object
214
+ - element same as invoking jQuery, just reads better and no need to worry about $ collisions
215
+ - elements alias of element
216
+
217
+ == Shared Behaviors
218
+
219
+ JSpec's support for shared behaviors allows multiple suites or describe blocks to share
220
+ common functionality. For example an Admin, would inherit all specs of User:
221
+
222
+ describe 'User'
223
+ before
224
+ User = function(name) { this.name = name }
225
+ user = new User('joe')
226
+ end
227
+
228
+ it 'should have a name'
229
+ user.should.have_property 'name'
230
+ end
231
+
232
+ describe 'Administrator'
233
+ should_behave_like('User')
234
+
235
+ before
236
+ Admin = function(name) { this.name = name }
237
+ Admin.prototype.may = function(perm){ return true }
238
+ user = new Admin('tj')
239
+ end
240
+
241
+ it 'should have access to all permissions'
242
+ user.may('edit pages').should.be_true
243
+ end
244
+ end
245
+ end
246
+
247
+ NOTE: both User and Administrator's before hooks implement the 'user' variable
248
+
249
+ == Async Support Using wait()
250
+
251
+ When using jQuery with JSpec all requests are switched to sync, allowing specs
252
+ to run naturally, however when testing functionality using setTimeout, setInterval etc
253
+ JSpec supplies the wait() utility to delay a spec from running:
254
+
255
+ it 'should wait for n milliseconds'
256
+ wait(2, 'seconds')
257
+ setTimeout(function(){
258
+ true.should.be true
259
+ }, 1500)
260
+ end
261
+
262
+ == Hooks
263
+
264
+ Currently the following hooks are supported, and may be utilized any number of times as they
265
+ are simply pushed to a stack. So for instance you may have two before_each blocks within the same
266
+ scope, they will both run, but this can help keep your specs readable.
267
+
268
+ * before run once before the suite is executed
269
+ * after run once after the suite is executed
270
+ * before_each run before each specification
271
+ * after_each run after each specification
272
+
273
+ == Custom Contexts
274
+
275
+ Custom contexts can be applied to supply helper
276
+ methods or properties to all subsequent bodies (other hooks, or specs).
277
+
278
+ Keep in mind that when replacing the default context you will loose
279
+ functionality provided by it, unless you manually merge it with your
280
+ custom context.
281
+
282
+ To reset the context simply assign null to obtain the original context.
283
+
284
+ ...
285
+ before
286
+ JSpec.context = { foo : 'bar' }
287
+ end
288
+
289
+ after
290
+ JSpec.context = null
291
+ end
292
+
293
+ it 'will work ;)'
294
+ foo.should_equal 'bar'
295
+ end
296
+ ...
297
+
298
+ == Async Support
299
+
300
+ Currently only jspec.jquery.js supports async requests. JSpec uses jQuery.ajaxSetup and sets all
301
+ requests to sync, which preserves execution order, and reports correctly.
302
+
303
+ it 'should load mah cookies (textfile)'
304
+ $.post('async', function(text){
305
+ text.should_eql 'cookies!'
306
+ })
307
+ end
308
+
309
+ == Pre-processor
310
+
311
+ The pre-processing capability of JSpec is extremely powerful. Your JavaScript
312
+ code is not necessarily what it seems. For example when you seemingly invoke a
313
+ object's prototype like below:
314
+
315
+ 'foobar'.should.include 'bar'
316
+
317
+ First parens are added:
318
+
319
+ 'foobar'.should.include('bar')
320
+
321
+ Secondly the matcher invocation is converted to a non-polluting match() call:
322
+
323
+ JSpec.match('foobar', 'should', 'include', 'bar')
324
+
325
+ This also means instead of:
326
+
327
+ var object = { foo : 'bar' }
328
+ object.should.include 'foo'
329
+
330
+ We can do:
331
+
332
+ { foo : 'bar' }.should.include 'foo'
333
+
334
+ === Closure Literal
335
+
336
+ These are equivalent:
337
+
338
+ -{ throw 'test' }.should.throw_error
339
+ function() { throw 'test' }.should.throw_error
340
+
341
+ === Inclusive Range Literal
342
+
343
+ The following expands to the array of [1,2,3,4,5]
344
+
345
+ n.should.be_within 1..5
346
+
347
+ == Formatters
348
+
349
+ To change a formatter simply alter the options hash like below, assigning
350
+ a new constructor, or pass it within the hash to run():
351
+
352
+ JSpec.options.formatter = JSpec.formatters.Console
353
+
354
+ OR
355
+
356
+ JSpec
357
+ .exec('...')
358
+ .run({ formatter : JSpec.formatters.Terminal })
359
+ .report()
360
+
361
+ == Custom Matchers
362
+
363
+ First lets create a simple equality matcher. In the case below JSpec is smart enough to realize
364
+ this is simply a binary operator, and simply transforms this into 'actual === expected'
365
+
366
+ JSpec.addMatchers({
367
+ equal : '==='
368
+ })
369
+
370
+ To alias a method to keep your specs readable you may alias them like below:
371
+
372
+ JSpec.addMatchers({
373
+ be : 'alias equal'
374
+ })
375
+
376
+ 'foo'.should.equal 'foo'
377
+ true.should.be true
378
+
379
+ Matchers with string bodies implicitly return the expression value.
380
+ The expanded version of the equal matcher would then be:
381
+
382
+ JSpec.addMatchers({
383
+ equal : 'actual === expected'
384
+ })
385
+
386
+ Large matchers or those which require several parameters may wish
387
+ to utilize the hash method:
388
+
389
+ JSpec.addMatchers({
390
+ equal : { match : function(actual, expected){
391
+ return actual === expected
392
+ }}
393
+ })
394
+
395
+ To keep JSpec tiny, JSpec will default to generating failure messages
396
+ for you, how ever this can be explicitly defined:
397
+
398
+ JSpec.addMatchers({
399
+ equal : {
400
+ match : function(actual, expected){
401
+ return actual === expected
402
+ },
403
+ message : function(actual, expected, negate) {
404
+ return 'a message here'
405
+ }
406
+ }
407
+ })
408
+
409
+ == JSpec Command-line Utility
410
+
411
+ When installed as a Ruby Gem, the `jspec` executable will become available,
412
+ allowing you to initialize project templates quickly, as well as auto-testing
413
+ specifications when a file is altered.
414
+
415
+ Initialize JSpec-driven project template in directory 'myproject':
416
+ $ jspec init myproject
417
+
418
+ Once within 'myproject' start testing by executing:
419
+ $ jspec
420
+
421
+ For additional usage execute:
422
+ $ jspec help
423
+
424
+ Or for specific usage:
425
+ $ jspec help run
426
+
427
+ == Rhino
428
+
429
+ JSpec provides transparent support for Rhino, while using the Terminal formatter.
430
+ Simply create a JavaScript file with contents similar to below, and then execute
431
+ the command following it:
432
+
433
+ load('lib/jspec.js')
434
+
435
+ JSpec
436
+ .exec('spec/spec.grammar.js')
437
+ .exec('spec/spec.core.js')
438
+ .run({ formatter : JSpec.formatters.Terminal, failuresOnly : true })
439
+ .report()
440
+
441
+ Initialize project with:
442
+ $ jspec init myproject --template rhino
443
+
444
+ Run with:
445
+ $ jspec run --rhino
446
+
447
+ Or bind (automated testing):
448
+ $ jspec --rhino
449
+
450
+ == Server
451
+
452
+ The Ruby JavaScript testing server included with JSpec simply runs
453
+ the spec suites within each browser you specify, while reporting result
454
+ back to the terminal. It is essentially the same as using the DOM formatter
455
+ and auto-testing each browser, however results are centralized to the terminal,
456
+ removing the need to manually view each browser's output.
457
+
458
+ Initialize project with:
459
+ $ jspec init myproject --template server
460
+
461
+ Run with:
462
+ $ jspec run --server
463
+
464
+ == More Information
465
+
466
+ * Syntax comparison with other frameworks http://gist.github.com/92283
467
+ * Get the TextMate bundle at https://github.com/visionmedia/jspec.tmbundle/tree
468
+ * For more information consult the JSpec source code documentation or visit http://visionmedia.github.com/jspec
469
+
470
+ == License
471
+
472
+ (The MIT License)
473
+
474
+ Copyright (c) 2008 - 2009 TJ Holowaychuk <tj@vision-media.ca>
475
+
476
+ Permission is hereby granted, free of charge, to any person obtaining
477
+ a copy of this software and associated documentation files (the
478
+ 'Software'), to deal in the Software without restriction, including
479
+ without limitation the rights to use, copy, modify, merge, publish,
480
+ distribute, sublicense, and/or sell copies of the Software, and to
481
+ permit persons to whom the Software is furnished to do so, subject to
482
+ the following conditions:
483
+
484
+ The above copyright notice and this permission notice shall be
485
+ included in all copies or substantial portions of the Software.
486
+
487
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
488
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
489
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
490
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
491
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
492
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
493
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
494
+
495
+