Class: Peck
- 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/option_parser.rb,
lib/peck/specification.rb,
lib/peck/notifiers/base.rb,
lib/peck/notifiers/default.rb,
lib/peck/notifiers/documentation.rb
Defined Under Namespace
Classes: Context, Counter, Delegates, Error, Event, Notifiers, OptionParser, Should, Specification
Constant Summary collapse
- VERSION =
"0.5.4"
- PECK_PART_RE =
/Peck/
Class Attribute Summary collapse
-
.clean_backtrace ⇒ Object
Sets whether the backtrace should be cleaned in case of a failure.
-
.concurrency ⇒ Object
Sets the level of concurrency.
-
.context_selector ⇒ Object
Used to select which contexts should be run.
-
.contexts ⇒ Object
readonly
Returns all the defined contexts.
-
.counter ⇒ Object
Returns the value of attribute counter.
-
.delegates ⇒ Object
readonly
This can be used by a ‘client’ to receive status updates.
-
.fail_fast ⇒ Object
Sets whether Peck should exit at the first failing assertion.
-
.spec_selector ⇒ Object
Used to select which specs should be run.
Class Method Summary collapse
- .all_events ⇒ Object
- .all_specs ⇒ Object
-
.concurrent? ⇒ Boolean
Returns true if the suite should run concurrent.
- .join_description(description) ⇒ Object
-
.log(message) ⇒ Object
A no-op unless you require ‘peck/debug’.
- .logger ⇒ Object
- .reset! ⇒ Object
- .run ⇒ Object
- .run_at_exit ⇒ Object
- .run_concurrent ⇒ Object
- .run_serial ⇒ Object
- .stop_early? ⇒ Boolean
- .threaded ⇒ Object
Class Attribute Details
.clean_backtrace ⇒ Object
Sets whether the backtrace should be cleaned in case of a failure
32 33 34 |
# File 'lib/peck.rb', line 32 def clean_backtrace @clean_backtrace end |
.concurrency ⇒ Object
Sets the level of concurrency.
29 30 31 |
# File 'lib/peck.rb', line 29 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
22 23 24 |
# File 'lib/peck.rb', line 22 def context_selector @context_selector end |
.contexts ⇒ Object (readonly)
Returns all the defined contexts.
10 11 12 |
# File 'lib/peck.rb', line 10 def contexts @contexts end |
.counter ⇒ Object
Returns the value of attribute counter.
5 6 7 |
# File 'lib/peck/counter.rb', line 5 def counter @counter end |
.delegates ⇒ Object (readonly)
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 |
.fail_fast ⇒ Object
Sets whether Peck should exit at the first failing assertion
35 36 37 |
# File 'lib/peck.rb', line 35 def fail_fast @fail_fast end |
.spec_selector ⇒ Object
Used to select which specs should be run. See Peck.select_context for more information.
26 27 28 |
# File 'lib/peck.rb', line 26 def spec_selector @spec_selector end |
Class Method Details
.all_events ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/peck.rb', line 62 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
56 57 58 59 60 |
# File 'lib/peck.rb', line 56 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.
43 44 45 |
# File 'lib/peck.rb', line 43 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’
39 40 |
# File 'lib/peck.rb', line 39 def self.log() end |
.logger ⇒ Object
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 |
.reset! ⇒ Object
47 48 49 |
# File 'lib/peck.rb', line 47 def self.reset! @contexts = [] end |
.run ⇒ Object
70 71 72 73 74 |
# File 'lib/peck.rb', line 70 def self.run delegates.started concurrent? ? run_concurrent : run_serial delegates.finished end |
.run_at_exit ⇒ Object
76 77 78 79 80 81 |
# File 'lib/peck.rb', line 76 def self.run_at_exit at_exit do run exit Peck.counter.failed end end |
.run_concurrent ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/peck.rb', line 101 def self.run_concurrent Peck.log("Running specs concurrently (#{Peck.concurrency} threads)") 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) return if stop_early? else break end end end delegates.finished end |
.run_serial ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/peck.rb', line 87 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) return if stop_early? 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 |
.stop_early? ⇒ Boolean
83 84 85 |
# File 'lib/peck.rb', line 83 def self.stop_early? Peck.fail_fast && Peck.counter.failed > 0 end |
.threaded ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/peck.rb', line 121 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 |