Class: ActiveSpec::Specifications::ProcSpecification
- Inherits:
-
Object
- Object
- ActiveSpec::Specifications::ProcSpecification
- Defined in:
- lib/active_spec/specifications/proc_specification.rb
Overview
A ProcSpecification is a simple wrapper around a Proc object, that makes it conform to the Specification interface (with a satisfied_by?
method). If the given Proc returns true, the specification passes, otherwise it does not pass.
Instance Method Summary collapse
-
#initialize(proc) ⇒ ProcSpecification
constructor
A new instance of ProcSpecification.
-
#satisfied_by?(object) ⇒ Boolean
Calls the wrapped Proc object, passing the given object to the proc.
Constructor Details
#initialize(proc) ⇒ ProcSpecification
Returns a new instance of ProcSpecification.
8 9 10 |
# File 'lib/active_spec/specifications/proc_specification.rb', line 8 def initialize(proc) @proc = proc end |
Instance Method Details
#satisfied_by?(object) ⇒ Boolean
Calls the wrapped Proc object, passing the given object to the proc. Returns the result of the Proc (either true
or false
). If the Proc raises an exception of any kind, then satisfied_by?
will return false
.
16 17 18 19 20 |
# File 'lib/active_spec/specifications/proc_specification.rb', line 16 def satisfied_by?(object) @proc.call(object) rescue false end |