module Trailblazer::Activity::Testing::Assertions

Constants

Activity

This is DSL-independent code, focusing only on run-time.













Inter

An {Intermediate} structure defines the structure of the circuit. It usually comes from a DSL or a visual editor.

Schema

Schema is primitive data structure + an invoker (usually coming from Activity etc)



TaskWrap

Example with tracing:

Call the task_wrap circuit:

|-- Start
|-- Trace.capture_args   [optional]
|-- Call (call actual task) id: "task_wrap.call_task"
|-- Trace.capture_return [optional]
|-- Wrap::End





Public Instance Methods

Cct(activity) click to toggle source
# File lib/trailblazer/activity/testing.rb, line 147
def Cct(activity)
  Trailblazer::Developer::Render::Circuit.(activity, inspect_task: Trailblazer::Activity::Testing.method(:render_task))
end
assert_circuit(schema, circuit) click to toggle source
# File lib/trailblazer/activity/testing.rb, line 140
def assert_circuit(schema, circuit)
  cct = Cct(schema)

  cct = cct.gsub("#<Trailblazer::Activity::TaskBuilder::Task user_proc=", "<*")
  assert_equal %{#{circuit}}, cct
end
assert_process_for(process, *args) click to toggle source

Tests {:circuit} and {:outputs} fields so far.

# File lib/trailblazer/activity/testing.rb, line 128
def assert_process_for(process, *args)
  semantics, circuit = args[0..-2], args[-1]

  inspects = semantics.collect { |semantic| %{#<struct Trailblazer::Activity::Output signal=#<Trailblazer::Activity::End semantic=#{semantic.inspect}>, semantic=#{semantic.inspect}>} }

  assert_equal %{[#{inspects.join(", ")}]}, process.to_h[:outputs].inspect

  assert_circuit(process, circuit)

  process
end
bc()
Alias for: flat_activity
bde()
Alias for: nested_activity
flat_activity() click to toggle source
# File lib/trailblazer/activity/testing.rb, line 70
def flat_activity
  return @_flat_activity if defined?(@_flat_activity)

  intermediate = Inter.new(
    {
      Inter::TaskRef("Start.default")      => [Inter::Out(:success, :B)],
      Inter::TaskRef(:B, additional: true) => [Inter::Out(:success, :C)],
      Inter::TaskRef(:C)                   => [Inter::Out(:success, "End.success")],
      Inter::TaskRef("End.success", stop_event: true) => [Inter::Out(:success, nil)]
    },
    ["End.success"],
    ["Start.default"], # start
  )

  implementation = {
    "Start.default" => Schema::Implementation::Task(st = Implementing::Start, [Activity::Output(Activity::Right, :success)],        []),
    :B => Schema::Implementation::Task(b = Implementing.method(:b), [Activity::Output(Activity::Right, :success)],                  []),
    :C => Schema::Implementation::Task(c = Implementing.method(:c), [Activity::Output(Activity::Right, :success)],                  []),
    "End.success" => Schema::Implementation::Task(_es = Implementing::Success, [Activity::Output(Implementing::Success, :success)], []), # DISCUSS: End has one Output, signal is itself?
  }

  schema = Inter.(intermediate, implementation)

  @_flat_activity = Activity.new(schema)
end
Also aliased as: bc
implementing() click to toggle source

TODO: Remove this once all it's references are removed

# File lib/trailblazer/activity/testing.rb, line 66
def implementing
  Implementing
end
nested_activity() click to toggle source
# File lib/trailblazer/activity/testing.rb, line 96
def nested_activity
  return @_nested_activity if defined?(@_nested_activity)

  intermediate = Inter.new(
    {
      Inter::TaskRef("Start.default") => [Inter::Out(:success, :B)],
      Inter::TaskRef(:B, more: true)  => [Inter::Out(:success, :D)],
      Inter::TaskRef(:D) => [Inter::Out(:success, :E)],
      Inter::TaskRef(:E) => [Inter::Out(:success, "End.success")],
      Inter::TaskRef("End.success", stop_event: true) => [Inter::Out(:success, nil)]
    },
    ["End.success"],
    ["Start.default"] # start
  )

  implementation = {
    "Start.default" => Schema::Implementation::Task(st = Implementing::Start, [Activity::Output(Activity::Right, :success)],        []),
    :B => Schema::Implementation::Task(b = Implementing.method(:b), [Activity::Output(Activity::Right, :success)],                  []),
    :D => Schema::Implementation::Task(c = bc, [Activity::Output(Implementing::Success, :success)],                  []),
    :E => Schema::Implementation::Task(e = Implementing.method(:f), [Activity::Output(Activity::Right, :success)],                  []),
    "End.success" => Schema::Implementation::Task(_es = Implementing::Success, [Activity::Output(Implementing::Success, :success)], []), # DISCUSS: End has one Output, signal is itself?
  }

  schema = Inter.(intermediate, implementation)

  @_nested_activity = Activity.new(schema)
end
Also aliased as: bde