given
This expressions corresponds to a “case” statement in Ruby or a “switch”
in other languages.
It accepts two variants “given that” and “given an x of”.
‘given’ works in conjunction with the ‘that’ / ‘of’ expression.
“given that”
given do
that "${location} == paris" do
subprocess "notify_and_wait_for_pickup"
end
that "${state} == ready" do
subprocess "deliver"
end
# else...
subprocess "do_something_else"
end
“given an x of”
given "${status}" do
of "ordered" do
participant "alpha"
end
of "delivered" do
participant "alpha"
end
# else...
subprocess "do_something_else"
end
This variant also accepts regular expressions :
given "${target}" do
of "/-manager$/" do
# ...
end
of /^user-/ do
# ...
end
end
mixing ‘that’ and ‘of’
It’s OK to use a “that” inside a “given an x” :
given '${target}' do
that "${location} == paris" do
subprocess "notify_and_wait_for_pickup"
end
of "home" do
subprocess "return_procedure"
end
end
the else part
Anything that comes after the serie of ‘that’ and ‘of’ is considered in
the ‘else’ zone and is executed if none of the ‘that’ or ‘of’ triggered.
given '${target}' do
that "${location} == paris" do
subprocess "notify_and_wait_for_pickup"
end
of "home" do
subprocess "return_procedure"
end
subprocess "do_this"
subprocess "and_then_that"
end
Yes, two ‘else’ subprocesses will get executed one after the other (the
‘given’ acting like a ‘sequence’ for them.
Interestingly :
given '${target}' do
of "home" do
subprocess "return_procedure"
end
subprocess "do_this"
of "office" do
subprocess "go_to_work"
end
subprocess "and_then_that"
end
If the workitem field ‘target’ is set to ‘home’ only the ‘return_procedure’
subprocess will get called.
If the workitem field ‘target’ is set to ‘office’, the ‘do_this’
subprocess, then the ‘go_to_work’ one will get called.