Sha256: 411eb2e8d160fcd057de27b36b0965147e3bee969b6394ee2153a0825ebc94e1
Contents?: true
Size: 1.32 KB
Versions: 4
Compression:
Stored size: 1.32 KB
Contents
require_relative "helper" setup do machine = MicroMachine.new(:pending) machine.when(:confirm, pending: :confirmed) machine.when(:ignore, pending: :ignored) machine.when(:reset, confirmed: :pending, ignored: :pending) machine end test "defines initial state" do |machine| assert_equal :pending, machine.state end test "raises an error if an invalid event is triggered" do |machine| assert_raise(MicroMachine::InvalidEvent) do machine.trigger(:random_event) end end test "preserves the state if transition is not possible" do |machine| assert !machine.trigger?(:reset) assert !machine.trigger(:reset) assert_equal :pending, machine.state end test "changes the state if transition is possible" do |machine| assert machine.trigger?(:confirm) assert machine.trigger(:confirm) assert_equal :confirmed, machine.state end test "discerns multiple transitions" do |machine| machine.trigger(:confirm) assert_equal :confirmed, machine.state machine.trigger(:reset) assert_equal :pending, machine.state machine.trigger(:ignore) assert_equal :ignored, machine.state machine.trigger(:reset) assert_equal :pending, machine.state end test "raises an error if event is triggered from/to a non complatible state" do |machine| assert_raise(MicroMachine::InvalidState) do machine.trigger!(:reset) end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
micromachine-3.0.0 | test/transitions.rb |
micromachine-2.1.0 | test/transitions.rb |
micromachine-2.0.0 | test/transitions.rb |
micromachine-1.2.0 | test/transitions.rb |