oojspec 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/assets/javascripts/oojspec.js.coffee +17 -14
- data/lib/oojspec/version.rb +1 -1
- data/vendor/assets/javascripts/buster/html.js +19 -11
- data/vendor/assets/stylesheets/buster/buster-test.css +2 -2
- metadata +4 -5
- data/lib/assets/javascripts/oojspec/reporter/html-multi-level.js.coffee +0 -44
data/README.md
CHANGED
@@ -23,6 +23,8 @@ I'd rather prefer to write:
|
|
23
23
|
assert(seats.length)
|
24
24
|
```
|
25
25
|
|
26
|
+
For a more in-depth introduction, please check-out [this article](http://rosenfeld.herokuapp.com/en/articles/programming/2012-07-20-client-side-code-testing-with-oojspec).
|
27
|
+
|
26
28
|
# Examples
|
27
29
|
|
28
30
|
[Here is how it looks like](http://oojspec.herokuapp.com/)
|
@@ -154,7 +156,7 @@ By default this gem will expose `oojspec.describe` to the `window` object so tha
|
|
154
156
|
directly from the top-level, but you can disable this exposition if you prefer:
|
155
157
|
|
156
158
|
```ruby
|
157
|
-
config.sandbox_assets.options[:
|
159
|
+
config.sandbox_assets.options[:skip_oojspec_expose] = true
|
158
160
|
```
|
159
161
|
|
160
162
|
# What about non-Rails applications?
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# =require buster/all
|
2
|
-
# =require_tree ./oojspec
|
3
2
|
|
4
3
|
window.oojspec = new class OojspecRunner
|
5
4
|
constructor: ->
|
5
|
+
@timeout = 1000 # 1s - default timeout
|
6
6
|
@runner = buster.create buster.eventEmitter
|
7
7
|
@descriptions = []
|
8
8
|
@assertions = buster.assertions
|
@@ -56,26 +56,22 @@ class Description
|
|
56
56
|
run: (@runner, @assertions, @binding, @bare, @onFinish, @beforeBlocks = [], @afterBlocks = [])->
|
57
57
|
@runner.emit 'context:start', name: @description
|
58
58
|
@dsl = new DescribeDsl
|
59
|
-
|
60
|
-
@runWithContext()
|
61
|
-
else
|
62
|
-
@doRun()
|
59
|
+
@doRun() unless (@block.runSpecs or @block.prototype?.runSpecs) and @throwOnInvalidBinding()
|
63
60
|
|
64
61
|
doRun: -> @runAround @beforeBlocks, @afterBlocks, @onDescriptionFinished, @processDescriptionBlock
|
65
62
|
|
66
|
-
|
63
|
+
throwOnInvalidBinding: ->
|
67
64
|
try
|
68
65
|
@binding = if @block.prototype then new @block else @block
|
69
66
|
if @binding and not (@bare = @block.bare)
|
70
|
-
for reserved in RESERVED
|
71
|
-
|
72
|
-
throw new Error("'#{reserved}' method is reserved for oojspec usage only")
|
73
|
-
@binding[reserved] = @dsl[reserved]
|
74
|
-
@doRun()
|
67
|
+
for reserved in RESERVED when @binding[reserved]
|
68
|
+
throw new Error("'#{reserved}' method is reserved for oojspec usage only")
|
75
69
|
catch e
|
76
70
|
e.name = "syntax error"
|
77
71
|
@runner.emit 'test:error', name: @description, error: e
|
78
72
|
@onDescriptionFinished(e)
|
73
|
+
return true
|
74
|
+
false
|
79
75
|
|
80
76
|
onDescriptionFinished: (error)=>
|
81
77
|
if error and not error.handled
|
@@ -88,14 +84,21 @@ class Description
|
|
88
84
|
new AroundBlock(befores, afters, block).run @runner, @assertions, @binding, @bare, onFinish
|
89
85
|
|
90
86
|
processDescriptionBlock: (onFinish)=>
|
87
|
+
@binding or= {}
|
88
|
+
@injectDsl() unless @bare
|
91
89
|
if @block.runSpecs or @block.prototype?.runSpecs
|
92
90
|
@binding.runSpecs @dsl
|
93
91
|
else
|
94
|
-
|
95
|
-
|
92
|
+
@block.call @binding, @dsl
|
93
|
+
@removeDsl() unless @bare
|
94
|
+
@bare or= @binding.bare
|
96
95
|
@runAround @dsl._beforeAllBlocks_, @dsl._afterAllBlocks_, onFinish, (@onExamplesFinished)=>
|
97
96
|
@runNextStep()
|
98
97
|
|
98
|
+
injectDsl: -> @binding[p] = v for p, v of @dsl; return
|
99
|
+
|
100
|
+
removeDsl: -> delete @binding[p] for p in RESERVED_FOR_DESCRIPTION_DSL; return
|
101
|
+
|
99
102
|
runNextStep: =>
|
100
103
|
(@onExamplesFinished(); return) unless @dsl._examples_.length
|
101
104
|
nextStep = @dsl._examples_.shift()
|
@@ -254,7 +257,7 @@ class Example
|
|
254
257
|
else
|
255
258
|
@waitsFor step...
|
256
259
|
|
257
|
-
waitsFor: (@condition, timeout=
|
260
|
+
waitsFor: (@condition, timeout = @binding?.timeout or oojspec.timeout, @description)->
|
258
261
|
@deadline = timeout + new Date().getTime()
|
259
262
|
@keepTryingCondition()
|
260
263
|
|
data/lib/oojspec/version.rb
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
create: function (opt) {
|
19
19
|
var reporter = buster.create(this);
|
20
20
|
opt = opt || {};
|
21
|
-
reporter.
|
21
|
+
reporter._listStack = [];
|
22
22
|
reporter.doc = getDoc(opt);
|
23
23
|
var cssPath = opt.cssPath;
|
24
24
|
if (!cssPath && opt.detectCssPath !== false) {
|
@@ -60,7 +60,8 @@
|
|
60
60
|
"context:start": "contextStart", "context:end": "contextEnd",
|
61
61
|
"test:success": "testSuccess", "test:failure": "testFailure",
|
62
62
|
"test:error": "testError", "test:timeout": "testTimeout",
|
63
|
-
"test:deferred": "testDeferred", "suite:
|
63
|
+
"test:deferred": "testDeferred", "suite:start": "startTimer",
|
64
|
+
"suite:end": "addStats"
|
64
65
|
});
|
65
66
|
|
66
67
|
if (runner.console) {
|
@@ -71,17 +72,20 @@
|
|
71
72
|
},
|
72
73
|
|
73
74
|
contextStart: function (context) {
|
74
|
-
|
75
|
-
|
75
|
+
var container = this.root;
|
76
|
+
if (this._list) {
|
77
|
+
container = el(this.doc, "li");
|
78
|
+
this._list.appendChild(container);
|
76
79
|
}
|
77
|
-
|
78
|
-
this.
|
79
|
-
|
80
|
+
container.appendChild(el(this.doc, "h2", { text: context.name }));
|
81
|
+
this._list = el(this.doc, "ul");
|
82
|
+
container.appendChild(this._list);
|
83
|
+
this._listStack.unshift(this._list);
|
80
84
|
},
|
81
85
|
|
82
86
|
contextEnd: function (context) {
|
83
|
-
this.
|
84
|
-
this._list =
|
87
|
+
this._listStack.shift()
|
88
|
+
this._list = this._listStack[0];
|
85
89
|
},
|
86
90
|
|
87
91
|
testSuccess: function (test) {
|
@@ -145,6 +149,10 @@
|
|
145
149
|
stats.tests > 0 && stats.assertions > 0;
|
146
150
|
},
|
147
151
|
|
152
|
+
startTimer: function () {
|
153
|
+
this.startedAt = new Date();
|
154
|
+
},
|
155
|
+
|
148
156
|
addStats: function (stats) {
|
149
157
|
var diff = (new Date() - this.startedAt) / 1000;
|
150
158
|
|
@@ -182,6 +190,7 @@
|
|
182
190
|
list: function () {
|
183
191
|
if (!this._list) {
|
184
192
|
this._list = el(this.doc, "ul", { className: "test-results" });
|
193
|
+
this._listStack.unshift(this._list);
|
185
194
|
this.root.appendChild(this._list);
|
186
195
|
}
|
187
196
|
|
@@ -270,11 +279,10 @@
|
|
270
279
|
function addListItem(tagName, test, className) {
|
271
280
|
var prefix = tagName ? "<" + tagName + ">" : "";
|
272
281
|
var suffix = tagName ? "</" + tagName + ">" : "";
|
273
|
-
var name = this.contexts.slice(1).join(" ") + " " + test.name;
|
274
282
|
|
275
283
|
var item = el(this.doc, "li", {
|
276
284
|
className: className,
|
277
|
-
text: prefix + name
|
285
|
+
text: prefix + test.name + suffix
|
278
286
|
});
|
279
287
|
|
280
288
|
this.list().appendChild(item);
|
@@ -105,11 +105,11 @@ body.buster-test {
|
|
105
105
|
.buster-test h6,
|
106
106
|
.buster-test p {
|
107
107
|
font-weight: normal;
|
108
|
-
margin: 0 0
|
108
|
+
margin: 0.2em 0;
|
109
109
|
}
|
110
110
|
|
111
111
|
.buster-test ul {
|
112
|
-
margin: 0 0
|
112
|
+
margin: 0.2em 0 0.2em 15px;
|
113
113
|
}
|
114
114
|
|
115
115
|
/* Masthead */
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oojspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coffee-rails
|
@@ -52,7 +52,6 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- app/views/oojspec/runner.html.erb
|
55
|
-
- lib/assets/javascripts/oojspec/reporter/html-multi-level.js.coffee
|
56
55
|
- lib/assets/javascripts/oojspec.js.coffee
|
57
56
|
- lib/assets/stylesheets/oojspec.css.erb
|
58
57
|
- lib/tasks/oojspec_tasks.rake
|
@@ -86,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
85
|
version: '0'
|
87
86
|
segments:
|
88
87
|
- 0
|
89
|
-
hash:
|
88
|
+
hash: 3773166015855678549
|
90
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
90
|
none: false
|
92
91
|
requirements:
|
@@ -95,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
94
|
version: '0'
|
96
95
|
segments:
|
97
96
|
- 0
|
98
|
-
hash:
|
97
|
+
hash: 3773166015855678549
|
99
98
|
requirements: []
|
100
99
|
rubyforge_project:
|
101
100
|
rubygems_version: 1.8.24
|
@@ -1,44 +0,0 @@
|
|
1
|
-
h = buster.reporters.html
|
2
|
-
h._lists = []
|
3
|
-
|
4
|
-
# original private function defined in Buster.js. Re-writing it here in CS
|
5
|
-
el = (doc, tagName, properties) ->
|
6
|
-
e = doc.createElement(tagName)
|
7
|
-
for prop, value of properties
|
8
|
-
e.setAttribute prop, value if prop is "http-equiv"
|
9
|
-
prop = "innerHTML" if prop == "text"
|
10
|
-
e[prop] = value
|
11
|
-
e
|
12
|
-
|
13
|
-
oldCreate = h.create # patch create
|
14
|
-
h.create = ->
|
15
|
-
reporter = oldCreate.apply this, arguments
|
16
|
-
reporter._lists = []
|
17
|
-
reporter
|
18
|
-
|
19
|
-
h.contextStart = (context)->
|
20
|
-
container = @root
|
21
|
-
@_list.appendChild container = el(@doc, "li") if @_list
|
22
|
-
container.appendChild el(@doc, "h2", text: context.name)
|
23
|
-
container.appendChild @_list = el(@doc, "ul")
|
24
|
-
@_lists.unshift @_list
|
25
|
-
|
26
|
-
# fix Buster.js time reporting
|
27
|
-
oldListen = h.listen
|
28
|
-
h.listen = (runner)->
|
29
|
-
result = oldListen.apply this, arguments
|
30
|
-
runner.bind this, 'suite:start': 'suiteStart'
|
31
|
-
result
|
32
|
-
|
33
|
-
# doesn't currently exist in original reporter
|
34
|
-
h.suiteStart = -> @startedAt = new Date()
|
35
|
-
|
36
|
-
h.list = ->
|
37
|
-
unless @_list = @_lists[0]
|
38
|
-
@_lists.unshift @_list = el(this.doc, "ul", className: "test-results")
|
39
|
-
@root.appendChild(@_list)
|
40
|
-
@_list
|
41
|
-
|
42
|
-
h.contextEnd = (context)->
|
43
|
-
@_lists.shift()
|
44
|
-
@_list = @_lists[0]
|