Class: ActiveSpec::Specifications::ProcSpecification

Inherits:
Object
  • Object
show all
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

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.

Returns:

  • (Boolean)


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