peck 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -127,7 +127,39 @@ specifications:
127
127
  should.disallow.get :show
128
128
  end
129
129
 
130
- ## Documentation
130
+ ### Flavors
131
+
132
+ You can either require parts of Peck you're using for your test suite or
133
+ require an entire flavor. Flavors are pre-built configurations for common
134
+ use cases. Right now there are three flavors:
135
+
136
+ #### Vanilla
137
+
138
+ require 'peck/flavors/vanilla'
139
+
140
+ Reports running specs with dots and ends with a short report.
141
+
142
+ #### Quiet
143
+
144
+ require 'peck/flavors/quiet'
145
+
146
+ Runs your specs but doesn't report the results. This is useful when testing
147
+ Peck itself or your extensions for Peck.
148
+
149
+ If you want to learn more about testing Peck itself read `examples/preamble.rb`.
150
+
151
+ In the quiet flavor we do keep a counter, so you could write your own formatter using `Peck.counter`.
152
+
153
+ ##### Documentation
154
+
155
+ The documentation runner is based on various other ‘documentation’ runners which are generally used for running on CI. This flavor reports the entire label for a spec and colored output. It also shows the runtime for a spec and can report slow specs.
156
+
157
+ You can configure the report cutoff for slow specs. By default it's configured at 500ms.
158
+
159
+ require 'peck/notifiers/documentation'
160
+ Peck::Notifiers::Documentation.runtime_report_cutoff = 20 # milliseconds
161
+
162
+ ## Assertions
131
163
 
132
164
  Peck is still very much in flux and will probably change a lot in the coming
133
165
  months. Currently we support a small number of assertions:
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'peck'
4
+ require 'peck/delegates'
5
+ require 'peck/counter'
6
+ require 'peck/context'
7
+ require 'peck/specification'
8
+ require 'peck/expectations'
9
+ require 'peck/notifiers/documentation'
10
+
11
+ Peck::Notifiers::Documentation.use
12
+ Peck.run_at_exit
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+
3
+ require 'peck/notifiers/default'
4
+
5
+ class Peck
6
+ class Notifiers
7
+ class Documentation < Peck::Notifiers::Default
8
+ class << self
9
+ # The cutoff point beyond which a test is reported as being slow.
10
+ # Expressed in milliseconds. Default is 500ms.
11
+ attr_accessor :runtime_report_cutoff
12
+ end
13
+ self.runtime_report_cutoff = 500
14
+
15
+ # Keeps all the labels, start, and end times for the specs
16
+ attr_accessor :details
17
+
18
+ # A FIFO queue of all the started specs being first on the queue means
19
+ # the spec has been reported as started. Being on the queue means the
20
+ # spec still needs to be reported as being finished.
21
+ attr_accessor :running
22
+
23
+ # Mutex to synchronize the access of the global data structures
24
+ attr_accessor :semaphore
25
+
26
+ def initialize
27
+ self.details = {}
28
+ self.running = []
29
+ self.semaphore = Mutex.new
30
+ end
31
+
32
+ def started_specification(spec)
33
+ self.semaphore.synchronize do
34
+ spec_id = spec.object_id
35
+ self.running.push(spec_id)
36
+ self.details[spec_id] ||= {}
37
+ self.details[spec_id][:started_at] = Time.now
38
+ self.details[spec_id][:label] = spec.label
39
+ write_documentation
40
+ end
41
+ end
42
+
43
+ def finished_specification(spec)
44
+ self.semaphore.synchronize do
45
+ spec_id = spec.object_id
46
+ self.details[spec_id][:finished_at] = Time.now
47
+ self.details[spec_id][:passed] = spec.passed?
48
+ write_documentation
49
+ end
50
+ end
51
+
52
+ protected
53
+
54
+ def write_spec_started(details)
55
+ $stdout.write(details[:label])
56
+ end
57
+
58
+ def write_spec_finished(details)
59
+ elapsed_time = ((details[:finished_at] - details[:started_at]) * 1000).round
60
+ color = self.class.runtime_report_cutoff < elapsed_time ? "\e[35m" : ''
61
+ if details[:passed]
62
+ $stdout.puts " \e[32m✓\e[0m #{color}(#{elapsed_time} ms)\e[0m"
63
+ else
64
+ $stdout.puts " \e[31m✗ [FAILED]\e[0m"
65
+ end
66
+ end
67
+
68
+ def write_documentation
69
+ spec_id = self.running.first
70
+ details = self.details[spec_id]
71
+
72
+ unless details[:start_reported]
73
+ write_spec_started(details)
74
+ details[:start_reported] = true
75
+ end
76
+
77
+ if details[:finished_at]
78
+ write_spec_finished(details)
79
+ self.details.delete(spec_id)
80
+ self.running.shift
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
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: 2013-07-08 00:00:00.000000000 Z
12
+ date: 2013-08-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Concurrent spec framework.
15
15
 
@@ -26,10 +26,12 @@ files:
26
26
  - lib/peck/delegates.rb
27
27
  - lib/peck/error.rb
28
28
  - lib/peck/expectations.rb
29
+ - lib/peck/flavors/documentation.rb
29
30
  - lib/peck/flavors/quiet.rb
30
31
  - lib/peck/flavors/vanilla.rb
31
32
  - lib/peck/notifiers/base.rb
32
33
  - lib/peck/notifiers/default.rb
34
+ - lib/peck/notifiers/documentation.rb
33
35
  - lib/peck/specification.rb
34
36
  - lib/peck.rb
35
37
  - COPYING