Class: Peck
- Inherits:
-
Object
show all
- Defined in:
- lib/peck.rb,
lib/peck/debug.rb,
lib/peck/error.rb,
lib/peck/context.rb,
lib/peck/counter.rb,
lib/peck/delegates.rb,
lib/peck/expectations.rb,
lib/peck/specification.rb,
lib/peck/notifiers/base.rb,
lib/peck/notifiers/default.rb
Defined Under Namespace
Classes: Context, Counter, Delegates, Error, Event, Notifiers, Should, Specification
Constant Summary
collapse
- VERSION =
"0.1.0"
- PECK_PART_RE =
/Peck/
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.concurrency ⇒ Object
Sets the level of concurrency.
27
28
29
|
# File 'lib/peck.rb', line 27
def concurrency
@concurrency
end
|
.context_selector ⇒ Object
Used to select which contexts should be run. The match method will be called on these with the label of the context as argument. You can use a regular expression or a custom class to match what needs to be run.
module ContextMatcher
def self.match(label)
label =~ /^Birds/
end
end
Peck.context_selector = ContextMatcher
20
21
22
|
# File 'lib/peck.rb', line 20
def context_selector
@context_selector
end
|
Returns all the defined contexts.
8
9
10
|
# File 'lib/peck.rb', line 8
def contexts
@contexts
end
|
Returns the value of attribute counter.
5
6
7
|
# File 'lib/peck/counter.rb', line 5
def counter
@counter
end
|
.delegates ⇒ Object
This can be used by a ‘client’ to receive status updates.
Peck.delegates << Notifier.new
42
43
44
|
# File 'lib/peck/delegates.rb', line 42
def delegates
@delegates
end
|
.spec_selector ⇒ Object
Used to select which specs should be run. See Peck.select_context for more information.
24
25
26
|
# File 'lib/peck.rb', line 24
def spec_selector
@spec_selector
end
|
Class Method Details
.all_events ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/peck.rb', line 54
def self.all_events
contexts.inject([]) do |all, context|
context.specs.inject(all) do |events, spec|
events.concat(spec.events)
end
end
end
|
.all_specs ⇒ Object
48
49
50
51
52
|
# File 'lib/peck.rb', line 48
def self.all_specs
contexts.inject([]) do |all, context|
all.concat(context.specs)
end
end
|
.concurrent? ⇒ Boolean
Returns true if the suite should run concurrent.
35
36
37
|
# File 'lib/peck.rb', line 35
def self.concurrent?
concurrency && concurrency > 1
end
|
.join_description(description) ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/peck/context.rb', line 101
def self.join_description(description)
description.map do |part|
part = part.to_s
part = nil if part =~ PECK_PART_RE
part
end.compact.join(' ')
end
|
.log(message) ⇒ Object
A no-op unless you require ‘peck/debug’
31
32
|
# File 'lib/peck.rb', line 31
def self.log(message)
end
|
4
5
6
7
8
9
10
11
|
# File 'lib/peck/debug.rb', line 4
def self.logger
@logger ||= begin
require 'logger'
logger = Logger.new($stdout)
logger.formatter = Logger::Formatter.new
logger
end
end
|
39
40
41
|
# File 'lib/peck.rb', line 39
def self.reset!
@contexts = []
end
|
62
63
64
65
66
|
# File 'lib/peck.rb', line 62
def self.run
delegates.started
concurrent? ? run_concurrent : run_serial
delegates.finished
end
|
.run_at_exit ⇒ Object
68
69
70
71
72
73
|
# File 'lib/peck.rb', line 68
def self.run_at_exit
at_exit do
run
exit Peck.counter.failed
end
end
|
.run_concurrent ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/peck.rb', line 88
def self.run_concurrent
Peck.log("Running specs concurrently")
current_spec = -1
specs = all_specs
threaded do |nr|
Thread.current['peck-semaphore'] = Mutex.new
loop do
spec_index = Thread.exclusive { current_spec += 1 }
if specification = specs[spec_index]
specification.run(delegates)
else
break
end
end
end
delegates.finished
end
|
.run_serial ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/peck.rb', line 75
def self.run_serial
Peck.log("Running specs in serial")
Thread.current['peck-semaphore'] = Mutex.new
contexts.each do |context|
context.specs.each do |specification|
specification.run(delegates)
end
end
rescue Exception => e
log("An error bubbled up from the context, this should never happen and is possibly a bug.")
raise e
end
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/peck.rb', line 107
def self.threaded
threads = []
Peck.concurrency.times do |nr|
threads[nr] = Thread.new do
yield nr
end
end
threads.compact.each do |thread|
begin
thread.join
rescue Interrupt
end
end
end
|