Class: Quarry::Design::Specification
- Defined in:
- lib/quarry/design/spec.rb
Overview
Design specification. Sepcification can contains sub-specifications.
Defined Under Namespace
Classes: Context
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
-
#specification ⇒ Object
readonly
Returns the value of attribute specification.
Instance Method Summary collapse
-
#check(level = 0) ⇒ Object
Check Specification.
-
#initialize(relation, description, context = nil, &specification) ⇒ Specification
constructor
New Specification.
-
#outline(level = 0) ⇒ Object
Outline Specification.
Constructor Details
#initialize(relation, description, context = nil, &specification) ⇒ Specification
New Specification
44 45 46 47 48 49 50 51 |
# File 'lib/quarry/design/spec.rb', line 44 def initialize(relation, description, context=nil, &specification) @relation = relation @description = description @specification = specification @context = context @before = context.before if context @after = context.after if context end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
40 41 42 |
# File 'lib/quarry/design/spec.rb', line 40 def after @after end |
#before ⇒ Object (readonly)
Returns the value of attribute before.
39 40 41 |
# File 'lib/quarry/design/spec.rb', line 39 def before @before end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
38 39 40 |
# File 'lib/quarry/design/spec.rb', line 38 def context @context end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
36 37 38 |
# File 'lib/quarry/design/spec.rb', line 36 def description @description end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
35 36 37 |
# File 'lib/quarry/design/spec.rb', line 35 def relation @relation end |
#specification ⇒ Object (readonly)
Returns the value of attribute specification.
37 38 39 |
# File 'lib/quarry/design/spec.rb', line 37 def specification @specification end |
Instance Method Details
#check(level = 0) ⇒ Object
Check Specification
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/quarry/design/spec.rb', line 55 def check(level=0) padding = " " * 2 * level clause = "#{relation} #{description}".strip new_context = Context.new new_context.instance_eval(&before) if before begin new_context.instance_eval(&specification) puts ("=" * (level+1)) + " " + clause.gsub(/\b\w/){$&.upcase} rescue Assertion => e #puts padding + " (FAIL) [#{e.backtrace[2]}] " + clause puts "* " + clause.gsub('_',' ') + " [#{e.backtrace[2]}]" puts e if $VERBOSE rescue Exception => e raise e if $DEBUG print padding #puts padding + " (ERROR) [#{e.backtrace[2]}] " + clause puts padding + " (ERROR) #{e}" puts e.backtrace if $VERBOSE ensure new_context.instance_eval(&after) if after end new_context.specifications.each do |s| s.check(level+1) end end |
#outline(level = 0) ⇒ Object
Outline Specification
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/quarry/design/spec.rb', line 86 def outline(level=0) padding = (" " * 2 * level) + "- " context = Context.new begin context.instance_eval(&specification) rescue Assertion => e #rescue Exception => e end str = '' str << "#{relation} " if relation str << "#{description}" #str = str.strip #.gsub(/\b\w/){$&.upcase} puts padding + str.strip context.specifications.each do |s| s.outline(level+1) end end |