lib/rung/definition/steps_dsl.rb in rung-0.0.1.pre.alpha vs lib/rung/definition/steps_dsl.rb in rung-0.1
- old
+ new
@@ -1,49 +1,64 @@
module Rung
module Definition
module StepsDSL
def steps_definition
- @steps_definition ||= StepsDefinition.new
+ @steps_definition ||= []
end
- def step(reference = nil, &block)
- add_step(reference, &block)
+ def add_generic_step(action, options = {}, &block)
+ step = step_from_definition action, **options, &block
+ steps_definition.push step
end
- def failure(reference = nil, &block)
- add_step(reference, run_on: :failure, &block)
+ def step(*args, &block)
+ add_step_from_args args, &block
end
- def wrap(wrapper, &block)
- nested_steps = calculate_block_nested_steps(&block)
- add_nested_step wrapper, nested_steps
+ def tee(*args, &block)
+ add_step_from_args args, ignore_result: true, &block
end
+ def failure(*args, &block)
+ add_step_from_args args, run_on: :failure, ignore_result: true, &block
+ end
+
+ def always(*args, &block)
+ add_step_from_args args, run_on: :any, ignore_result: true, &block
+ end
+
private
- def add_step(reference, options = {}, &block)
- step = if block
- Step.new(block, *options, from_block: true)
- else
- Step.new(reference, options)
- end
- steps_definition.push(step)
+ def add_step_from_args(args, options = {}, &block)
+ action, action_options = extract_action_and_options!(args)
+ add_generic_step action, **options, **action_options, &block
end
- def add_nested_step(operation, nested_steps)
- steps_definition.push(NestedStep.new(operation, nested_steps))
+ def extract_action_and_options!(args)
+ options = args.last.is_a?(::Hash) ? args.pop : {}
+ [args.first, options]
end
+ def step_from_definition(action, options, &block)
+ if action && block
+ NestedStep.new(action, calculate_block_nested_steps(&block), options)
+ elsif block
+ Step.new(block, **options, from_block: true)
+ else
+ Step.new(action, options)
+ end
+ end
+
def calculate_block_nested_steps(&block)
with_new_steps_definition do
instance_exec(&block)
steps_definition
end
end
def with_new_steps_definition
old_steps_definition = @steps_definition
- @steps_definition = StepsDefinition.new
+ @steps_definition = []
yield
ensure
@steps_definition = old_steps_definition
end
end