Class: ActiveSpec::Specifications::CompositeSpecification
- Inherits:
-
Object
- Object
- ActiveSpec::Specifications::CompositeSpecification
- Defined in:
- lib/active_spec/specifications/composite_specification.rb
Overview
Uses the Composite pattern to allow an object to be run against any number of specifications in one operation. A specification can be any object that responds to satisfied_by?
. Because the composite specification also responds to satisfied_by?
, you can add composite specifications to other composite specifications.
Instance Method Summary collapse
-
#add_specification(spec) ⇒ Object
Adds a new specification to the composite.
-
#initialize ⇒ CompositeSpecification
constructor
A new instance of CompositeSpecification.
-
#satisfied_by?(object) ⇒ Boolean
Calls
satisfied_by?
on each specification with the given object.
Constructor Details
#initialize ⇒ CompositeSpecification
Returns a new instance of CompositeSpecification.
8 9 10 |
# File 'lib/active_spec/specifications/composite_specification.rb', line 8 def initialize @specs = [] end |
Instance Method Details
#add_specification(spec) ⇒ Object
Adds a new specification to the composite
13 14 15 |
# File 'lib/active_spec/specifications/composite_specification.rb', line 13 def add_specification(spec) @specs << spec end |
#satisfied_by?(object) ⇒ Boolean
Calls satisfied_by?
on each specification with the given object. Returns true
if all of the specifications pass, otherwise it returns false
.
20 21 22 |
# File 'lib/active_spec/specifications/composite_specification.rb', line 20 def satisfied_by?(object) @specs.collect { |s| s.satisfied_by?(object) }.grep(false).empty? end |