Class: Peck::Specification
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#expectations ⇒ Object
readonly
Returns the value of attribute expectations.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(context, before, after, description, &block) ⇒ Specification
constructor
A new instance of Specification.
- #label ⇒ Object
- #passed? ⇒ Boolean
- #run ⇒ Object
- #synchronized(&block) ⇒ Object
Constructor Details
#initialize(context, before, after, description, &block) ⇒ Specification
Returns a new instance of Specification.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/peck/specification.rb', line 29 def initialize(context, before, after, description, &block) @context = context.new(self) @before = before.dup @after = after.dup @description = description @block = block @expectations = [] @events = [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
26 27 28 |
# File 'lib/peck/specification.rb', line 26 def context @context end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
26 27 28 |
# File 'lib/peck/specification.rb', line 26 def description @description end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
27 28 29 |
# File 'lib/peck/specification.rb', line 27 def events @events end |
#expectations ⇒ Object (readonly)
Returns the value of attribute expectations.
27 28 29 |
# File 'lib/peck/specification.rb', line 27 def expectations @expectations end |
Instance Method Details
#empty? ⇒ Boolean
73 74 75 |
# File 'lib/peck/specification.rb', line 73 def empty? @expectations.empty? end |
#failed? ⇒ Boolean
77 78 79 |
# File 'lib/peck/specification.rb', line 77 def failed? !@events.empty? end |
#label ⇒ Object
40 41 42 |
# File 'lib/peck/specification.rb', line 40 def label "#{@context.class.label} #{@description}" end |
#passed? ⇒ Boolean
81 82 83 |
# File 'lib/peck/specification.rb', line 81 def passed? !failed? && !empty? end |
#run ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/peck/specification.rb', line 52 def run if @block @before.each { |cb| @context.instance_eval(&cb) } begin synchronized do Thread.current['peck-spec'] = self @context.instance_eval(&@block) Thread.current['peck-spec'] = nil end Peck.delegates.received_missing(self) if empty? ensure @after.each { |cb| @context.instance_eval(&cb) } end else Peck.delegates.received_missing(self) end rescue Object => e Peck.delegates.received_exception(self, e) @events << Event.new(e, self) end |
#synchronized(&block) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/peck/specification.rb', line 44 def synchronized(&block) if semaphore = Thread.current['peck-semaphore'] semaphore.synchronize(&block) else block.call end end |