Class: TestCaseGenerator::DSLContext
- Inherits:
-
Object
- Object
- TestCaseGenerator::DSLContext
- Defined in:
- lib/test_case_generator/dsl_context.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Instance Method Summary collapse
- #<<(events) ⇒ Object
- #after {|@after| ... } ⇒ Object
- #before {|@before| ... } ⇒ Object
- #concat(&block) ⇒ Object (also: #seq)
- #def_labels {|@labels| ... } ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ DSLContext
constructor
A new instance of DSLContext.
- #pattern {|child_context| ... } ⇒ Object (also: #choice)
- #raw_each ⇒ Object
Constructor Details
#initialize ⇒ DSLContext
Returns a new instance of DSLContext.
8 9 10 11 12 13 14 |
# File 'lib/test_case_generator/dsl_context.rb', line 8 def initialize @patterns = [] @before = [] @after = [] @children = [] @labels = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
5 6 7 |
# File 'lib/test_case_generator/dsl_context.rb', line 5 def children @children end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
6 7 8 |
# File 'lib/test_case_generator/dsl_context.rb', line 6 def labels @labels end |
Instance Method Details
#<<(events) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/test_case_generator/dsl_context.rb', line 16 def <<(events) if events.is_a?(String) || events.is_a?(Symbol) @patterns << [events] @labels << events unless @labels.include? events else @patterns << events events.each do |label| @labels << label unless @labels.include? label end end end |
#after {|@after| ... } ⇒ Object
36 37 38 |
# File 'lib/test_case_generator/dsl_context.rb', line 36 def after yield @after end |
#before {|@before| ... } ⇒ Object
32 33 34 |
# File 'lib/test_case_generator/dsl_context.rb', line 32 def before yield @before end |
#concat(&block) ⇒ Object Also known as: seq
54 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/test_case_generator/dsl_context.rb', line 54 def concat(&block) child_context = DSLContext.new child_context.instance_eval &block first = true tmp = [] child_context.children.each do |ctx| tmp2 = [] ctx.raw_each do |ptn| if first tmp2 << ptn else tmp.each do |x| tmp2 << x + ptn end end end tmp = tmp2 first = false end tmp.each do |x| @patterns << x x.each do |label| @labels << label unless @labels.include? label end end end |
#def_labels {|@labels| ... } ⇒ Object
28 29 30 |
# File 'lib/test_case_generator/dsl_context.rb', line 28 def def_labels yield @labels end |
#each ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/test_case_generator/dsl_context.rb', line 89 def each raw_each do |raw_ptn| yield raw_ptn.map { |p| # p.to_s.split('_').inject([]) { |buffer, e| # buffer << (buffer.empty? ? e : e.capitalize) # }.join TestCaseGenerator::Utils.make_method_name p } end end |
#pattern {|child_context| ... } ⇒ Object Also known as: choice
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/test_case_generator/dsl_context.rb', line 40 def pattern child_context = DSLContext.new yield child_context @children << child_context child_context.raw_each do |ptn| @patterns << ptn ptn.each do |label| @labels << label unless @labels.include? label end end end |
#raw_each ⇒ Object
85 86 87 |
# File 'lib/test_case_generator/dsl_context.rb', line 85 def raw_each @patterns.each { |ptn| yield @before + ptn + @after } end |