spec/unit/choice_spec.rb in finite_machine-0.9.0 vs spec/unit/choice_spec.rb in finite_machine-0.9.1
- old
+ new
@@ -132,6 +132,56 @@
end
expect(fsm.current).to eq(:company_form)
fsm.next
expect(fsm.current).to eq(:company_form)
end
+
+ it "allows to transition from multiple states to choice pseudostate" do
+ fsm = FiniteMachine.define do
+ initial :red
+
+ event :go, from: [:yellow, :red] do
+ choice :pink, if: -> { false }
+ choice :green
+ end
+ end
+ expect(fsm.current).to eq(:red)
+ fsm.go
+ expect(fsm.current).to eq(:green)
+ fsm.restore!(:yellow)
+ expect(fsm.current).to eq(:yellow)
+ fsm.go
+ expect(fsm.current).to eq(:green)
+ end
+
+ it "allows to transition from any state to choice pseudo state" do
+ fsm = FiniteMachine.define do
+ initial :red
+
+ event :go, from: :any do
+ choice :pink, if: -> { false }
+ choice :green
+ end
+ end
+ expect(fsm.current).to eq(:red)
+ fsm.go
+ expect(fsm.current).to eq(:green)
+ end
+
+ it "groups correctly events under the same name" do
+ fsm = FiniteMachine.define do
+ initial :red
+
+ event :next, from: :yellow, to: :green
+
+ event :next, from: :red do
+ choice :pink, if: -> { false }
+ choice :yellow
+ end
+ end
+ expect(fsm.current).to eq(:red)
+ fsm.next
+ expect(fsm.current).to eq(:yellow)
+ fsm.next
+ expect(fsm.current).to eq(:green)
+ end
end