oojspec 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,6 @@
1
1
  # =require buster/all
2
+ # =require_self
3
+ # =require ./progress
2
4
 
3
5
  window.oojspec = new class OojspecRunner
4
6
  constructor: ->
@@ -8,12 +10,13 @@ window.oojspec = new class OojspecRunner
8
10
  @assertions = buster.assertions
9
11
  (logFormatter = buster.create buster.format).quoteStrings = false
10
12
  @assertions.format = buster.bind logFormatter, "ascii"
11
- @assertions.on 'pass', => @stats.tests++; @stats.assertions++
12
- @assertions.on 'failure', => @stats.tests++; @stats.failures++
13
+ @assertions.on 'pass', => @stats.assertions++
14
+ @assertions.on 'failure', => @stats.failures++
13
15
  #@runner.on 'context:start', => @stats.contexts++
14
- @runner.on 'test:timeout', => @stats.timeouts++; @assertions.emit 'failure'
15
- @runner.on 'test:error', => @stats.errors++
16
+ @runner.on 'test:timeout', => @stats.timeouts++; @assertions.emit 'failure'
17
+ @runner.on 'test:error', => @stats.errors++
16
18
  @runner.on 'test:deferred', => @stats.deferred++
19
+ @runner.on 'oojspec:examples:add', (count)=> @stats.tests += count
17
20
 
18
21
  @stats =
19
22
  contexts: 0
@@ -30,13 +33,13 @@ window.oojspec = new class OojspecRunner
30
33
  runSpecs: ->
31
34
  @reporter = buster.reporters.html.create detectCssPath: false
32
35
  @reporter.listen @runner
36
+ d.processDsl @runner for d in @descriptions
33
37
  @runner.emit 'suite:start', name: "Specs"
34
38
  @runNextDescription()
35
39
 
36
40
  runNextDescription: =>
37
41
  (@runner.emit 'suite:end', @stats; return) unless @descriptions.length
38
- # TODO: think about non null contexts usage
39
- @descriptions.shift().run @runner, @assertions, null, false, @runNextDescription
42
+ @descriptions.shift().run @assertions, @runNextDescription
40
43
 
41
44
  describe: (description, block)=>
42
45
  @stats.contexts++ # only root descriptions will be count
@@ -53,14 +56,23 @@ class Description
53
56
  @block = @description
54
57
  @description = @block.description or @block.name
55
58
 
56
- run: (@runner, @assertions, @binding, @bare, @onFinish, @beforeBlocks = [], @afterBlocks = [])->
57
- @runner.emit 'context:start', name: @description
59
+ processDsl: (@runner, @binding, @bare)->
58
60
  @dsl = new DescribeDsl
59
- @doRun() unless (@block.runSpecs or @block.prototype?.runSpecs) and @throwOnInvalidBinding()
61
+ (@block.runSpecs or @block.prototype?.runSpecs) and @detectBindingError()
60
62
 
61
- doRun: -> @runAround @beforeBlocks, @afterBlocks, @onDescriptionFinished, @processDescriptionBlock
63
+ @binding or= {}
64
+ @injectDsl() unless @bare
65
+ if @block.runSpecs or @block.prototype?.runSpecs
66
+ @binding.runSpecs @dsl
67
+ else
68
+ @block.call @binding, @dsl
69
+ @runner.emit 'oojspec:examples:add', @dsl._examplesCount_
70
+ @removeDsl() unless @bare
71
+ @bare or= @binding.bare
62
72
 
63
- throwOnInvalidBinding: ->
73
+ d.processDsl @runner, @binding, @bare for d in @dsl._examples_ when d instanceof Description
74
+
75
+ detectBindingError: ->
64
76
  try
65
77
  @binding = if @block.prototype then new @block else @block
66
78
  if @binding and not (@bare = @block.bare)
@@ -68,10 +80,21 @@ class Description
68
80
  throw new Error("'#{reserved}' method is reserved for oojspec usage only")
69
81
  catch e
70
82
  e.name = "syntax error"
71
- @runner.emit 'test:error', name: @description, error: e
72
- @onDescriptionFinished(e)
73
- return true
74
- false
83
+ @bindingError = e
84
+
85
+ injectDsl: -> @binding[p] = v for p, v of @dsl; return
86
+
87
+ removeDsl: -> delete @binding[p] for p in RESERVED_FOR_DESCRIPTION_DSL; return
88
+
89
+ run: (@assertions, @onFinish, @beforeBlocks = [], @afterBlocks = [])->
90
+ @runner.emit 'context:start', name: @description
91
+ if @bindingError
92
+ @runner.emit 'test:error', name: @description, error: @bindingError
93
+ @onDescriptionFinished @bindingError
94
+ else
95
+ @doRun()
96
+
97
+ doRun: -> @runAround @beforeBlocks, @afterBlocks, @onDescriptionFinished, @processDescriptionBlock
75
98
 
76
99
  onDescriptionFinished: (error)=>
77
100
  if error and not error.handled
@@ -84,29 +107,16 @@ class Description
84
107
  new AroundBlock(befores, afters, block).run @runner, @assertions, @binding, @bare, onFinish
85
108
 
86
109
  processDescriptionBlock: (onFinish)=>
87
- @binding or= {}
88
- @injectDsl() unless @bare
89
- if @block.runSpecs or @block.prototype?.runSpecs
90
- @binding.runSpecs @dsl
91
- else
92
- @block.call @binding, @dsl
93
- @removeDsl() unless @bare
94
- @bare or= @binding.bare
95
110
  @runAround @dsl._beforeAllBlocks_, @dsl._afterAllBlocks_, onFinish, (@onExamplesFinished)=>
96
111
  @runNextStep()
97
112
 
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
-
102
113
  runNextStep: =>
103
114
  (@onExamplesFinished(); return) unless @dsl._examples_.length
104
115
  nextStep = @dsl._examples_.shift()
105
116
  (@reportDeferred(nextStep.description); @runNextStep(); return) if nextStep.pending
106
117
  nextTick =
107
118
  if nextStep instanceof Description then =>
108
- nextStep.run @runner, @assertions, @binding, @bare, @runNextStep, \
109
- @dsl._beforeBlocks_, @dsl._afterBlocks_
119
+ nextStep.run @assertions, @runNextStep, @dsl._beforeBlocks_, @dsl._afterBlocks_
110
120
  else => # ExampleWithHooks
111
121
  nextStep.run @runner, @assertions, @binding, @bare, @onExampleFinished
112
122
  setTimeout nextTick, 0
@@ -138,6 +148,7 @@ class DescribeDsl
138
148
  @_afterBlocks_ = []
139
149
  @_afterAllBlocks_ = []
140
150
  @_examples_ = []
151
+ @_examplesCount_ = 0 # only examples, not describes
141
152
  # aliases:
142
153
  @it = @specify = @example
143
154
  @context = @describe
@@ -151,8 +162,11 @@ class DescribeDsl
151
162
  @_examples_.push new Description(description, block, @_beforeBlocks_, @_afterBlocks_)
152
163
  example: (description, block)=>
153
164
  throw new Error("Examples must have a description and a block") unless description and block
165
+ @_examplesCount_++
154
166
  @_examples_.push new ExampleWithHooks(description, @_beforeBlocks_, @_afterBlocks_, block)
155
- pending: (description)=> @_examples_.push {description, pending: true}
167
+ pending: (description)=>
168
+ @_examplesCount_++
169
+ @_examples_.push {description, pending: true}
156
170
 
157
171
  class AroundBlock
158
172
  constructor: (@beforeBlocks, @afterBlocks, @block)->
@@ -0,0 +1,36 @@
1
+ new class ProgressStats
2
+ constructor: (@eh = oojspec.runner)->
3
+ @total = @count = 0
4
+ @eh.on 'suite:start', @createElements
5
+ @eh.on 'oojspec:examples:add', (count)=> @total += count
6
+ @eh.on 'test:success', => @addSuccess '. '
7
+ @eh.on 'test:deferred', => @addSuccess 'd '
8
+ @eh.on 'test:failure', => @addError 'F '
9
+ @eh.on 'test:error', => @addError 'E '
10
+ @eh.on 'test:timeout', => @addError 'T '
11
+
12
+ createElements: =>
13
+ @numericProgress = @addDivTo 'numeric-progress', document.body
14
+ @progressBar = @addDivTo 'progress-bar', document.body
15
+ @progress = @addDivTo 'progress', @progressBar
16
+
17
+ addDivTo: (id, to)->
18
+ div = document.createElement 'div'
19
+ div.id = id
20
+ to.appendChild div
21
+ div
22
+
23
+ addSuccess: (text)->
24
+ el = @addAssertElement text
25
+ el.className = 'deferred' if text is 'd '
26
+
27
+ addError: (text)-> e = @addAssertElement text; e.className = @progress.className = 'fail'
28
+
29
+ addAssertElement: (text)->
30
+ @count++
31
+ e = document.createElement('span')
32
+ e.textContent = text
33
+ @progress.appendChild e
34
+ @progress.style.width = @count / @total * 100 + '%'
35
+ @numericProgress.textContent = "#{@count} / #{@total}"
36
+ e
@@ -0,0 +1,25 @@
1
+ /* Progress bar */
2
+ #progress-bar {
3
+ background-color: yellow;
4
+ padding: 0;
5
+ }
6
+
7
+ #progress {
8
+ color: darkgreen;
9
+ font-weight: bold;
10
+ background-color: lightgreen;
11
+ position: relative;
12
+ width: 0;
13
+ }
14
+
15
+ #progress.fail {
16
+ background-color: lightpink;
17
+ }
18
+
19
+ #progress > span.fail {
20
+ color: red;
21
+ }
22
+
23
+ #progress > span.deferred {
24
+ color: yellow;
25
+ }
@@ -1,21 +1,9 @@
1
- /* =require buster/buster-test */
1
+ /*
2
+ =require buster/buster-test
3
+ =require_tree ./oojspec
4
+ */
5
+
2
6
  /* override background image for supporting IE7 */
3
7
  .buster-test h1 .buster-logo {
4
8
  background-image: url(<%= asset_path "buster/logo.png" %>);
5
9
  }
6
-
7
- /* override margin to use 0.2em on top and bottom instead of 1em at bottom only. */
8
- .buster-test h1,
9
- .buster-test h2,
10
- .buster-test h3,
11
- .buster-test h4,
12
- .buster-test h5,
13
- .buster-test h6,
14
- .buster-test p {
15
- margin: 0.2em 0;
16
- }
17
-
18
- /* was 0 0 1em 15px */
19
- .buster-test ul {
20
- margin: 0.2em 0 0.2em 15px;
21
- }
@@ -1,3 +1,3 @@
1
1
  module Oojspec
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
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.7
4
+ version: 0.0.8
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-25 00:00:00.000000000 Z
12
+ date: 2012-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coffee-rails
@@ -52,8 +52,10 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - app/views/oojspec/runner.html.erb
55
+ - lib/assets/javascripts/progress.js.coffee
55
56
  - lib/assets/javascripts/oojspec.js.coffee
56
57
  - lib/assets/stylesheets/oojspec.css.erb
58
+ - lib/assets/stylesheets/oojspec/progress.css
57
59
  - lib/tasks/oojspec_tasks.rake
58
60
  - lib/oojspec/engine.rb
59
61
  - lib/oojspec/version.rb
@@ -85,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
87
  version: '0'
86
88
  segments:
87
89
  - 0
88
- hash: 3773166015855678549
90
+ hash: -2878099860768326426
89
91
  required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  none: false
91
93
  requirements:
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  version: '0'
95
97
  segments:
96
98
  - 0
97
- hash: 3773166015855678549
99
+ hash: -2878099860768326426
98
100
  requirements: []
99
101
  rubyforge_project:
100
102
  rubygems_version: 1.8.24