Module: Trailblazer::Activity::Testing::Assertions

Defined in:
lib/trailblazer/activity/testing.rb

Defined Under Namespace

Modules: Implementing

Constant Summary collapse

Activity =
Trailblazer::Activity
Inter =
Trailblazer::Activity::Schema::Intermediate
Schema =
Trailblazer::Activity::Schema
TaskWrap =
Trailblazer::Activity::TaskWrap

Instance Method Summary collapse

Instance Method Details

#assert_circuit(schema, circuit) ⇒ Object



140
141
142
143
144
145
# 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) ⇒ Object

Tests :circuit and :outputs fields so far.



128
129
130
131
132
133
134
135
136
137
138
# 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

#Cct(activity) ⇒ Object



147
148
149
# 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

#flat_activityObject Also known as: bc



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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

#implementingObject

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



66
67
68
# File 'lib/trailblazer/activity/testing.rb', line 66

def implementing
  Implementing
end

#nested_activityObject Also known as: bde



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# 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