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 CHANGED
@@ -1,4 +1,23 @@
1
1
 
2
+ === 2.0.0 / 2009-04-27
3
+
4
+ * Added DOM loading indicator [#105]
5
+ * Added wait() helper for additional async support
6
+ * Added shared behavior support using should_behave_like('Another Suite')
7
+ * Added CSS body toggling [#1]
8
+ * Added receive matcher for Proxy Assertins
9
+ * Added grammar-less support
10
+ * Added an_instance_of() helper
11
+ * Removed .this literal
12
+ * Removed deprecated be_a_TYPE_input matchers
13
+
14
+ * Added ProxyAssertion
15
+ * Added select() util
16
+ * Added does() util for report-less assertions
17
+ * Added find() util
18
+ * Added JSpec.contentsOf()
19
+ * Added matchers to body evaluation [#90]
20
+
2
21
  === 1.1.7 / 2009-04-22
3
22
 
4
23
  * Removed trailing commas causing issues with IE (what a suprise ;) )
data/Manifest CHANGED
@@ -3,6 +3,7 @@ History.rdoc
3
3
  jspec.gemspec
4
4
  lib/images/bg.png
5
5
  lib/images/hr.png
6
+ lib/images/loading.gif
6
7
  lib/images/sprites.bg.png
7
8
  lib/images/sprites.png
8
9
  lib/images/vr.png
@@ -17,12 +18,15 @@ server/server.rb
17
18
  spec/async
18
19
  spec/jquery-1.3.1.js
19
20
  spec/server.html
20
- spec/spec.core.dom.js
21
- spec/spec.core.js
21
+ spec/spec.grammar-less.js
22
22
  spec/spec.grammar.js
23
23
  spec/spec.html
24
24
  spec/spec.jquery.js
25
+ spec/spec.js
26
+ spec/spec.matchers.js
25
27
  spec/spec.rhino.js
28
+ spec/spec.shared-behaviors.js
29
+ spec/spec.utils.js
26
30
  templates/default/History.rdoc
27
31
  templates/default/lib/yourlib.core.js
28
32
  templates/default/README.rdoc
data/README.rdoc CHANGED
@@ -25,39 +25,10 @@ and much more.
25
25
  * DOM sandbox support
26
26
  * Great looking default DOM theme
27
27
  * `jspec` command-line utility for auto-running specs, and initializing project templates
28
+ * Proxy or 'Spy' assertions
29
+ * Shared behaviors
28
30
  * Profiling
29
- * Tiny (15 kb compressed, 1000-ish LOC)
30
-
31
- == Features Coming Soon
32
-
33
- * 'Spy' or 'Proxy' assertions. person.should.receive('addPet').with('suki').and_return(['suki'])
34
- * Grammar-less option. Dislike JSpec's grammar? well we will soon have grammar-less support,
35
- which in turn will make your specs look much like traditional JavaScript BDD frameworks:
36
- expect(this).to('be_coming', 'soon')
37
-
38
- == Example
39
-
40
- describe 'ShoppingCart'
41
- var cart
42
-
43
- before_each
44
- cart = new ShoppingCart
45
- end
46
-
47
- describe 'addProducts'
48
- it 'should add several products'
49
- cart.addProduct('cookie')
50
- cart.addProduct('icecream')
51
- cart.should.have 2, 'products'
52
- end
53
- end
54
-
55
- describe 'checkout'
56
- it 'throw an error when checking out with no products'
57
- -{ cart.clear().checkout() }.should.throw_error
58
- end
59
- end
60
- end
31
+ * Tiny (15 kb compressed, 1600-ish LOC)
61
32
 
62
33
  == Installation
63
34
 
@@ -91,6 +62,54 @@ You may optionally want to use sources in the /pkg directory
91
62
  for your project, since it includes compressed alternatives generated
92
63
  each release.
93
64
 
65
+ == Example
66
+
67
+ describe 'ShoppingCart'
68
+ before_each
69
+ cart = new ShoppingCart
70
+ end
71
+
72
+ describe 'addProducts'
73
+ it 'should add several products'
74
+ cart.addProduct('cookie')
75
+ cart.addProduct('icecream')
76
+ cart.should.have 2, 'products'
77
+ end
78
+ end
79
+
80
+ describe 'checkout'
81
+ it 'should throw an error when checking out with no products'
82
+ -{ cart.clear().checkout() }.should.throw_error EmptyCart
83
+ end
84
+ end
85
+ end
86
+
87
+ == Grammar-less Example
88
+
89
+ JSpec's grammar is optional, you may also use the equivalent grammar-less
90
+ alternative below using pure JavaScript (when using the JSpec grammar you
91
+ may also use grammar-less assertions):
92
+
93
+ JSpec.describe('ShoppingCart', function(){
94
+ before_each(function{
95
+ cart = new ShoppingCart
96
+ })
97
+
98
+ describe('addProducts', function(){
99
+ it ('should add several products', function(){
100
+ cart.addProducts('cookie')
101
+ cart.addProducts('icecream')
102
+ expect(cart).to(have, 2, 'products')
103
+ })
104
+ })
105
+
106
+ describe('checkout', function(){
107
+ it ('should throw an error when checking out with no products', function(){
108
+ expect(function(){ cart.clear().checkout() }).to(throw_error, EmptyCart)
109
+ })
110
+ })
111
+ })
112
+
94
113
  == Options
95
114
 
96
115
  You may alter the way JSpec operates by assigning options via the
@@ -153,6 +172,7 @@ JSpec.options.failuresOnly = true, and ?failuresOnly=1 will both work.
153
172
  - have_target
154
173
  - have_value
155
174
  - have_class
175
+ - have_classes
156
176
  - be_visible
157
177
  - be_hidden
158
178
  - be_enabled
@@ -160,11 +180,31 @@ JSpec.options.failuresOnly = true, and ?failuresOnly=1 will both work.
160
180
  - be_selected
161
181
  - be_checked
162
182
 
183
+ == Proxy Assertions
184
+
185
+ Proxy or 'Spy' assertions allow you to assert that a method is called n number
186
+ of times, with x arguments, returning x value. For example:
187
+
188
+ person = { getPets : function(species){ return ['izzy'] }}
189
+ person.should.receive('getPets', 'twice').with_args(an_instance_of(String))and_return(['izzy'])
190
+ person.getPets('dog') // This will pass
191
+ person.getPets() // This will fail because we asked an instance of String
192
+
193
+ This is a useful mechanism for testing the behavior of your object, as well as
194
+ how other methods may interact with it. Below is another example:
195
+
196
+ array = ['foo', 'bar']
197
+ array.should.receive('toString').and_return('foo,bar')
198
+ 'array: ' + array // This line causes the spec to pass due to calling toString()
199
+
200
+ For more examples view spec/spec.matchers.js
201
+
163
202
  == Helpers
164
203
 
165
204
  * Core
166
205
 
167
- - sandbox used to generate new DOM sandbox
206
+ - wait delay execution of a spec for the duration set (async support)
207
+ - an_instance_of used in conjunction with the 'receive' matcher
168
208
 
169
209
  * jQuery
170
210
 
@@ -172,6 +212,51 @@ JSpec.options.failuresOnly = true, and ?failuresOnly=1 will both work.
172
212
  - element same as invoking jQuery, just reads better and no need to worry about $ collisions
173
213
  - elements alias of element
174
214
 
215
+ == Shared Behaviors
216
+
217
+ JSpec's support for shared behaviors allows multiple suites or describe blocks to share
218
+ common functionality. For example an Admin, would inherit all specs of User:
219
+
220
+ describe 'User'
221
+ before
222
+ User = function(name) { this.name = name }
223
+ user = new User('joe')
224
+ end
225
+
226
+ it 'should have a name'
227
+ user.should.have_property 'name'
228
+ end
229
+
230
+ describe 'Administrator'
231
+ should_behave_like('User')
232
+
233
+ before
234
+ Admin = function(name) { this.name = name }
235
+ Admin.prototype.may = function(perm){ return true }
236
+ user = new Admin('tj')
237
+ end
238
+
239
+ it 'should have access to all permissions'
240
+ user.may('edit pages').should.be_true
241
+ end
242
+ end
243
+ end
244
+
245
+ NOTE: both User and Administrator's before hooks implement the 'user' variable
246
+
247
+ == Async Support Using wait()
248
+
249
+ When using jQuery with JSpec all requests are switched to sync, allowing specs
250
+ to run naturally, however when testing functionality using setTimeout, setInterval etc
251
+ JSpec supplies the wait() utility to delay a spec from running:
252
+
253
+ it 'should wait for n milliseconds'
254
+ wait(2, 'seconds')
255
+ setTimeout(function(){
256
+ true.should.be true
257
+ }, 1500)
258
+ end
259
+
175
260
  == Hooks
176
261
 
177
262
  Currently the following hooks are supported, and may be utilized any number of times as they
@@ -188,10 +273,9 @@ scope, they will both run, but this can help keep your specs readable.
188
273
  Custom contexts can be applied to supply helper
189
274
  methods or properties to all subsequent bodies (other hooks, or specs).
190
275
 
191
- In most cases the default context will suffice, in combination with the
192
- 'this' keyword. Keep in mind that when replacing the default context
193
- you will loose functionality provided by it, unless you manually merge it
194
- into your custom context.
276
+ Keep in mind that when replacing the default context you will loose
277
+ functionality provided by it, unless you manually merge it with your
278
+ custom context.
195
279
 
196
280
  To reset the context simply assign null to obtain the original context.
197
281
 
@@ -205,7 +289,7 @@ To reset the context simply assign null to obtain the original context.
205
289
  end
206
290
 
207
291
  it 'will work ;)'
208
- this.foo.should_equal 'bar'
292
+ foo.should_equal 'bar'
209
293
  end
210
294
  ...
211
295
 
@@ -258,50 +342,6 @@ The following expands to the array of [1,2,3,4,5]
258
342
 
259
343
  n.should.be_within 1..5
260
344
 
261
- === This Literal
262
-
263
- Commonly throughout using JSpec you will often need to do things like the following,
264
- while referencing 'this.cart' throughout your specs:
265
-
266
- before
267
- this.cart = new ShoppingCart
268
- end
269
-
270
- Thanks to the pre-processor we can simply use the terse alternative below:
271
-
272
- ...
273
- before
274
- .cart = new ShoppingCart
275
- end
276
-
277
- it '...'
278
- .cart.should.have 4, 'products'
279
- end
280
- ...
281
-
282
- Alternatively you may utilize literal javascript outside of the closures:
283
-
284
- ...
285
- cart = new ShoppingCart
286
-
287
- it '...'
288
- cart.should.have 4, 'products'
289
- end
290
- ...
291
-
292
- Another option is to declare a variable outside of the spec closures:
293
-
294
- var cart
295
-
296
- before
297
- cart = new ShoppingCart
298
- end
299
-
300
- it '...'
301
- cart.should.have 4, 'products'
302
- end
303
- ...
304
-
305
345
  == Formatters
306
346
 
307
347
  To change a formatter simply alter the options hash like below, assigning
@@ -425,10 +465,6 @@ Run with:
425
465
  * Get the TextMate bundle at https://github.com/visionmedia/jspec.tmbundle/tree
426
466
  * For more information consult the JSpec source code documentation or visit http://visionmedia.github.com/jspec
427
467
 
428
- == Known Issues
429
-
430
- * Opera likes to break for various reasons ... we are working on fixing these compat issues
431
-
432
468
  == License
433
469
 
434
470
  (The MIT License)
data/bin/jspec CHANGED
@@ -10,7 +10,7 @@ require 'fileutils'
10
10
  RHINO = 'java org.mozilla.javascript.tools.shell.Main'
11
11
 
12
12
  program :name, 'JSpec'
13
- program :version, '1.1.7'
13
+ program :version, '2.0.0'
14
14
  program :description, 'JavaScript BDD Testing Framework'
15
15
  default_command :bind
16
16
 
data/jspec.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{jspec}
5
- s.version = "1.1.7"
5
+ s.version = "2.0.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["TJ Holowaychuk"]
9
- s.date = %q{2009-04-22}
9
+ s.date = %q{2009-04-27}
10
10
  s.default_executable = %q{jspec}
11
11
  s.description = %q{JavaScript BDD Testing Framework}
12
12
  s.email = %q{tj@vision-media.ca}
13
13
  s.executables = ["jspec"]
14
- s.extra_rdoc_files = ["bin/jspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "README.rdoc"]
15
- s.files = ["bin/jspec", "History.rdoc", "jspec.gemspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/server.rb", "spec/async", "spec/jquery-1.3.1.js", "spec/server.html", "spec/spec.core.dom.js", "spec/spec.core.js", "spec/spec.grammar.js", "spec/spec.html", "spec/spec.jquery.js", "spec/spec.rhino.js", "templates/default/History.rdoc", "templates/default/lib/yourlib.core.js", "templates/default/README.rdoc", "templates/default/spec/spec.core.js", "templates/default/spec/spec.html", "templates/rhino/History.rdoc", "templates/rhino/lib/yourlib.core.js", "templates/rhino/README.rdoc", "templates/rhino/spec/spec.core.js", "templates/rhino/spec/spec.js", "templates/server/History.rdoc", "templates/server/lib/yourlib.core.js", "templates/server/README.rdoc", "templates/server/spec/spec.core.js", "templates/server/spec/spec.html"]
14
+ s.extra_rdoc_files = ["bin/jspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/loading.gif", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "README.rdoc"]
15
+ s.files = ["bin/jspec", "History.rdoc", "jspec.gemspec", "lib/images/bg.png", "lib/images/hr.png", "lib/images/loading.gif", "lib/images/sprites.bg.png", "lib/images/sprites.png", "lib/images/vr.png", "lib/jspec.css", "lib/jspec.jquery.js", "lib/jspec.js", "Manifest", "Rakefile", "README.rdoc", "server/browsers.rb", "server/server.rb", "spec/async", "spec/jquery-1.3.1.js", "spec/server.html", "spec/spec.grammar-less.js", "spec/spec.grammar.js", "spec/spec.html", "spec/spec.jquery.js", "spec/spec.js", "spec/spec.matchers.js", "spec/spec.rhino.js", "spec/spec.shared-behaviors.js", "spec/spec.utils.js", "templates/default/History.rdoc", "templates/default/lib/yourlib.core.js", "templates/default/README.rdoc", "templates/default/spec/spec.core.js", "templates/default/spec/spec.html", "templates/rhino/History.rdoc", "templates/rhino/lib/yourlib.core.js", "templates/rhino/README.rdoc", "templates/rhino/spec/spec.core.js", "templates/rhino/spec/spec.js", "templates/server/History.rdoc", "templates/server/lib/yourlib.core.js", "templates/server/README.rdoc", "templates/server/spec/spec.core.js", "templates/server/spec/spec.html"]
16
16
  s.has_rdoc = true
17
17
  s.homepage = %q{http://visionmedia.github.com/jspec}
18
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jspec", "--main", "README.rdoc"]
Binary file
data/lib/jspec.css CHANGED
@@ -1,6 +1,5 @@
1
1
  body.jspec {
2
2
  margin: 45px 0;
3
- text-align: center;
4
3
  font: 12px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
5
4
  background: #efefef url(images/bg.png) top left repeat-x;
6
5
  }
@@ -24,6 +23,12 @@ body.jspec {
24
23
  height: 15px;
25
24
  background: url(images/sprites.bg.png) bottom left no-repeat;
26
25
  }
26
+ #jspec .loading {
27
+ margin-top: -45px;
28
+ width: 1008px;
29
+ height: 80px;
30
+ background: url(images/loading.gif) 50% 50% no-repeat;
31
+ }
27
32
  #jspec-title {
28
33
  position: relative;
29
34
  top: 35px;
@@ -32,6 +37,7 @@ body.jspec {
32
37
  font-size: 22px;
33
38
  font-weight: normal;
34
39
  background: url(images/sprites.png) 0 -126px no-repeat;
40
+ text-align: center;
35
41
  }
36
42
  #jspec-title em {
37
43
  font-size: 10px;
@@ -68,7 +74,6 @@ body.jspec {
68
74
  color: #FA1616;
69
75
  }
70
76
  #jspec-report table {
71
- width: 100%;
72
77
  font-size: 11px;
73
78
  border-collapse: collapse;
74
79
  }
@@ -77,6 +82,16 @@ body.jspec {
77
82
  text-indent: 30px;
78
83
  color: #7B8D9B;
79
84
  }
85
+ #jspec-report tr.body {
86
+ display: none;
87
+ }
88
+ #jspec-report tr.body pre {
89
+ margin: 0;
90
+ padding: 0 0 5px 25px;
91
+ }
92
+ #jspec-report tr:not(.body):hover + tr.body {
93
+ display: block;
94
+ }
80
95
  #jspec-report tr td:first-child em {
81
96
  font-style: normal;
82
97
  font-weight: normal;
data/lib/jspec.jquery.js CHANGED
@@ -15,8 +15,7 @@
15
15
 
16
16
  JSpec.defaultContext.element = jQuery
17
17
  JSpec.defaultContext.elements = jQuery
18
- JSpec.defaultContext.defaultSandbox = JSpec.defaultContext.sandbox
19
- JSpec.defaultContext.sandbox = function() { return jQuery(JSpec.defaultContext.defaultSandbox()) }
18
+ JSpec.defaultContext.sandbox = function() { return jQuery('<div class="sandbox"></div>') }
20
19
 
21
20
  // --- Matchers
22
21
 
@@ -35,9 +34,9 @@
35
34
  have_class : "jQuery(actual).hasClass(expected)",
36
35
 
37
36
  have_classes : function(actual) {
38
- for (i = 1; i < arguments.length; i++)
39
- if (!jQuery(actual).hasClass(arguments[i])) return false
40
- return true
37
+ return !JSpec.any(JSpec.argumentsToArray(arguments, 1), function(arg){
38
+ return !JSpec.does(actual, 'have_class', arg)
39
+ })
41
40
  },
42
41
 
43
42
  have_attr : function(actual, attr, value) {
@@ -60,15 +59,6 @@
60
59
  })
61
60
  })
62
61
 
63
- // --- be_a_TYPE_input (deprecated)
64
-
65
- JSpec.each('checkbox radio file password submit image text reset button', function(type){
66
- JSpec.addMatcher('be_a_' + type + '_input', function(actual, expected) {
67
- console.warn("be_a_" + type + "_input is deprected; use have_type('" + type + "')");
68
- return jQuery(actual).get(0).type == type
69
- })
70
- })
71
-
72
62
  })()
73
63
 
74
64