Class: ATP::Flow
- Inherits:
-
Object
- Object
- ATP::Flow
- Defined in:
- lib/atp/flow.rb
Overview
Implements the main user API for building and interacting with an abstract test program
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#program ⇒ Object
readonly
Returns the value of attribute program.
-
#raw ⇒ Object
readonly
Returns the raw AST.
Instance Method Summary collapse
-
#ast ⇒ Object
Returns a processed/optimized AST, this is the one that should be used to build and represent the given test flow.
- #bin(number, options = {}) ⇒ Object
- #context ⇒ Object
-
#context_changed?(options) ⇒ Boolean
Returns true if the test context generated from the supplied options + existing condition wrappers, is different from that which was applied to the previous test.
- #cz(instance, cz_setup, options = {}) ⇒ Object (also: #characterize)
-
#disable(var, options = {}) ⇒ Object
Disable a flow control variable.
-
#enable(var, options = {}) ⇒ Object
Enable a flow control variable.
-
#group(name, options = {}) ⇒ Object
Group all tests generated within the given block.
-
#initialize(program, name = nil) ⇒ Flow
constructor
A new instance of Flow.
-
#log(message, options = {}) ⇒ Object
Append a log message line to the flow.
- #marshal_dump ⇒ Object private
- #marshal_load(array) ⇒ Object private
-
#render(str, options = {}) ⇒ Object
Insert explicitly rendered content in to the flow.
-
#run(options = {}) ⇒ Object
Execute the given flow in the console.
-
#test(instance, options = {}) ⇒ Object
Add a test line to the flow.
- #with_condition(options) ⇒ Object (also: #with_conditions)
Constructor Details
#initialize(program, name = nil) ⇒ Flow
Returns a new instance of Flow.
10 11 12 13 14 |
# File 'lib/atp/flow.rb', line 10 def initialize(program, name = nil) @program = program @name = name @raw = builder.flow end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/atp/flow.rb', line 8 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/atp/flow.rb', line 5 def name @name end |
#program ⇒ Object (readonly)
Returns the value of attribute program.
5 6 7 |
# File 'lib/atp/flow.rb', line 5 def program @program end |
#raw ⇒ Object
Returns the raw AST
7 8 9 |
# File 'lib/atp/flow.rb', line 7 def raw @raw end |
Instance Method Details
#ast ⇒ Object
Returns a processed/optimized AST, this is the one that should be used to build and represent the given test flow
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/atp/flow.rb', line 28 def ast ast = Processors::PreCleaner.new.process(raw) # File.open("a1.txt", "w") { |f| f.write(ast) } ast = Processors::FlowID.new.run(ast, id) if id # File.open("a2.txt", "w") { |f| f.write(ast) } Validators::DuplicateIDs.new(self).process(ast) Validators::MissingIDs.new(self).process(ast) ast = Processors::Condition.new.process(ast) ast = Processors::Relationship.new.process(ast) ast = Processors::PostCleaner.new.process(ast) Validators::Jobs.new(self).process(ast) ast end |
#bin(number, options = {}) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/atp/flow.rb', line 88 def bin(number, = {}) () t = apply_open_conditions() do || fail 'A :type option set to :pass or :fail is required when calling bin' unless [:type] [:bin] = number [:softbin] ||= [:soft_bin] || [:sbin] builder.set_result([:type], ) end append(t) end |
#context ⇒ Object
165 166 167 |
# File 'lib/atp/flow.rb', line 165 def context builder.context end |
#context_changed?(options) ⇒ Boolean
Returns true if the test context generated from the supplied options + existing condition wrappers, is different from that which was applied to the previous test.
159 160 161 162 163 |
# File 'lib/atp/flow.rb', line 159 def context_changed?() a = context[:conditions] b = build_context()[:conditions] !conditions_equal?(a, b) end |
#cz(instance, cz_setup, options = {}) ⇒ Object Also known as: characterize
99 100 101 102 103 104 105 106 107 |
# File 'lib/atp/flow.rb', line 99 def cz(instance, cz_setup, = {}) () t = apply_open_conditions() do || conditions = .delete(:conditions) [:return] = true builder.cz(cz_setup, test(instance, ), conditions: conditions) end append(t) end |
#disable(var, options = {}) ⇒ Object
Disable a flow control variable
129 130 131 132 133 134 135 |
# File 'lib/atp/flow.rb', line 129 def disable(var, = {}) () t = apply_open_conditions() do || builder.disable_flow_flag(var, ) end append(t) end |
#enable(var, options = {}) ⇒ Object
Enable a flow control variable
120 121 122 123 124 125 126 |
# File 'lib/atp/flow.rb', line 120 def enable(var, = {}) () t = apply_open_conditions() do || builder.enable_flow_flag(var, ) end append(t) end |
#group(name, options = {}) ⇒ Object
Group all tests generated within the given block
49 50 51 52 53 |
# File 'lib/atp/flow.rb', line 49 def group(name, = {}) open_groups.push([]) yield append builder.group(name, open_groups.pop, ) end |
#log(message, options = {}) ⇒ Object
Append a log message line to the flow
111 112 113 114 115 116 117 |
# File 'lib/atp/flow.rb', line 111 def log(, = {}) () t = apply_open_conditions() do || builder.log(, ) end append(t) end |
#marshal_dump ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/atp/flow.rb', line 17 def marshal_dump [@name, @program, Processors::Marshal.new.process(@raw)] end |
#marshal_load(array) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 |
# File 'lib/atp/flow.rb', line 22 def marshal_load(array) @name, @program, @raw = array end |
#render(str, options = {}) ⇒ Object
Insert explicitly rendered content in to the flow
138 139 140 141 |
# File 'lib/atp/flow.rb', line 138 def render(str, = {}) () append builder.render(str) end |
#run(options = {}) ⇒ Object
Execute the given flow in the console
152 153 154 155 |
# File 'lib/atp/flow.rb', line 152 def run( = {}) Formatters::Datalog.run_and_format(ast, ) nil end |
#test(instance, options = {}) ⇒ Object
Add a test line to the flow
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/atp/flow.rb', line 64 def test(instance, = {}) () r = .delete(:return) t = apply_open_conditions() do || # Allows any continue, bin, or soft bin argument passed in at the options top-level to be assumed # to be the action to take if the test fails if b = .delete(:bin) [:on_fail] ||= {} [:on_fail][:bin] = b end if b = .delete(:softbin) || b = .delete(:sbin) || b = .delete(:soft_bin) [:on_fail] ||= {} [:on_fail][:softbin] = b end if .delete(:continue) [:on_fail] ||= {} [:on_fail][:continue] = true end builder.test(instance, ) end append(t) unless r t end |
#with_condition(options) ⇒ Object Also known as: with_conditions
143 144 145 146 147 148 |
# File 'lib/atp/flow.rb', line 143 def with_condition() () open_conditions.push() yield open_conditions.pop end |