module Blueprints
# A helper module that should be included in test framework. Adds methods build and demolish
module Helper
# Builds one or more blueprints by their names. You can pass names as symbols or strings. You can also pass additional
# options hash which will be available by calling options in blueprint block. Returns result of blueprint block.
# # build :apple and orange blueprints
# build :apple, :orange
#
# # build :apple scenario with additional options
# build :apple => {:color => 'red'}
#
# # options can also be passed for several blueprints
# build :pear, :apple => {:color => 'red'}, :orange => {:color => 'orange'}
def build_plan(*names)
returning(Namespace.root.build(*names)) { Namespace.root.copy_ivars(self) }
end
alias :build :build_plan
# Clears all tables in database. You can pass table names to clear only those tables. You can also pass :undo option
# to remove scenarios from built scenarios cache.
#
# TODO: add sample usage
def demolish(*args)
options = args.extract_options!
Blueprints.delete_tables(*args)
if options[:undo] == :all
Namespace.root.executed_plans.clear
else
undo = [options[:undo]].flatten.compact.collect {|bp| bp.to_s }
unless (not_found = undo - Namespace.root.executed_plans.to_a).blank?
raise(PlanNotFoundError, not_found)
end
Namespace.root.executed_plans -= undo
end
end
end
end