class Circumstance
Constants
- VERSION
Attributes
logger[RW]
Logger used for debugging information
registry[RW]
A registry which keeps track of all the circumstances you've defined
name[R]
Public Class Methods
define(name, &block)
click to toggle source
Define a circumstance on the global registry
Circumstance.define(:blue_ocean_fishing) {}
# File lib/circumstance.rb, line 43 def self.define(name, &block) logger.debug("Defining circumstance #{name}") registry.define(name, &block) end
evaluate(context, name)
click to toggle source
Find and evaluate a circumstance in a certain context. The context is usually either a test class or spec context.
Circumstance.evaluate(self, :blue_ocean_fishing)
# File lib/circumstance.rb, line 59 def self.evaluate(context, name) logger.debug("Loading circumstance #{name}") circumstance = find(name) circumstance.evaluate(context) circumstance end
find(name)
click to toggle source
Find a circumstance on the global registry
Circumstance.find(:blue_ocean_fishing) #=> Proc…
# File lib/circumstance.rb, line 51 def self.find(name) registry.find(name) end
new(name, block)
click to toggle source
# File lib/circumstance.rb, line 22 def initialize(name, block) @name, @block = name, block end
Public Instance Methods
evaluate(context)
click to toggle source
Evaluate this circumstance in the context
# File lib/circumstance.rb, line 32 def evaluate(context) logger.debug("Evaluating circumstance #{@name}") if defined?(FactoryGirl) context.send(:include, FactoryGirl::Syntax::Methods) end context.instance_eval(&@block) end
logger()
click to toggle source
Returns Circumstance.logger
for convenience
# File lib/circumstance.rb, line 27 def logger self.class.logger end