Module: ActiveSpec::Satisfies
- Defined in:
- lib/active_spec/satisfies.rb
Overview
Provides functionality for working with specifications inside your own classes. Simply include the module inside any class that you want to use with specifications.
Example usage:
specification :user do
should_require_presence_of :username
end
specification :authenticated_user do
# some other specs
end
class User
must_satisfy :user_specification
must_satisfy :authenticated_user_specification, :if => { |u| u.has_password? }
end
user = User.new
user.satisfies_specs? # returns false
user.username = 'joebloggs'
user.satisfies_specs? # returns true
For information on adding specifications, see the ActiveSpec::Satisfies::ClassMethods module.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#satisfies_specs? ⇒ Boolean
Checks that all relevant, assigned specifications pass.
Class Method Details
.included(base) ⇒ Object
28 29 30 |
# File 'lib/active_spec/satisfies.rb', line 28 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#satisfies_specs? ⇒ Boolean
Checks that all relevant, assigned specifications pass. Specifications assigned with the :if
option will only be evaluated if the :if
block returns true.
51 52 53 54 55 56 57 58 59 |
# File 'lib/active_spec/satisfies.rb', line 51 def satisfies_specs? satisfies = self.class.read_inheritable_attribute(:satisfies) || [] satisfies.collect do |s| if s[:options][:if] return true unless passes_predicate?(s[:options][:if]) end satisfies?(s[:spec]) end.grep(false).empty? end |